当前位置: 首页>>代码示例>>C#>>正文


C# RavenJObject.TryGetValue方法代码示例

本文整理汇总了C#中RavenJObject.TryGetValue方法的典型用法代码示例。如果您正苦于以下问题:C# RavenJObject.TryGetValue方法的具体用法?C# RavenJObject.TryGetValue怎么用?C# RavenJObject.TryGetValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在RavenJObject的用法示例。


在下文中一共展示了RavenJObject.TryGetValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: OnPut

        public override void OnPut(string key, RavenJObject document, RavenJObject metadata, TransactionInformation transactionInformation)
        {
            if (!metadata.ContainsKey("IsRoutable") || !metadata.Value<bool>("IsRoutable")) {
                return;
            }

            RavenJToken parentIdToken;
            RavenJToken slugToken;
            if (document.TryGetValue("ParentId", out parentIdToken) && document.TryGetValue("Slug", out slugToken)) {
                var parentId = parentIdToken.Value<string>();
                var slug = slugToken.Value<string>();

                string parentPath = null;
                if (!String.IsNullOrEmpty(parentId)) {
                    var parent = Database.Get(parentId, transactionInformation);
                    parentPath = parent.DataAsJson["Path"].Value<string>();
                }

                if (String.IsNullOrEmpty(parentPath)) {
                    document["Path"] = slug;
                } else {
                    document["Path"] = parentPath + "/" + slug;
                }
            }

            base.OnPut(key, document, metadata, transactionInformation);
        }
开发者ID:thoemmi,项目名称:ViewComposition,代码行数:27,代码来源:PathUpdateTrigger.cs

示例2: EnsureQuotasBundleActivated

		private static void EnsureQuotasBundleActivated(RavenJObject settings)
		{
			RavenJToken value;
			if (settings.TryGetValue(Constants.ActiveBundles, out value) == false)
				settings[Constants.ActiveBundles] = value = new RavenJValue(string.Empty);

			var activeBundles = value.Value<string>();
			var bundles = activeBundles.GetSemicolonSeparatedValues();

			if (bundles.Contains("Quotas", StringComparer.OrdinalIgnoreCase) == false)
				bundles.Add("Quotas");

			int hardLimitInKb;
			if (int.TryParse(ConfigurationManager.AppSettings["Raven/Bundles/LiveTest/Quotas/Size/HardLimitInKB"], out hardLimitInKb) == false) 
				hardLimitInKb = QuotasHardLimitInKb;

			int softMarginInKb;
			if (int.TryParse(ConfigurationManager.AppSettings["Raven/Bundles/LiveTest/Quotas/Size/SoftLimitInKB"], out softMarginInKb) == false)
				softMarginInKb = QuotasSoftMarginInKb;

			settings[Constants.ActiveBundles] = string.Join(";", bundles);
			settings[Constants.SizeHardLimitInKB] = hardLimitInKb;
			settings[Constants.SizeSoftLimitInKB] = softMarginInKb;
			settings[Constants.DocsHardLimit] = null;
			settings[Constants.DocsSoftLimit] = null;
		}
开发者ID:GorelH,项目名称:ravendb,代码行数:26,代码来源:LiveTestDatabaseDocumentPutTrigger.cs

示例3: AllowRead

		public override ReadVetoResult AllowRead(string key, Stream data, RavenJObject metadata, ReadOperation operation)
		{
			RavenJToken value;
			if (metadata.TryGetValue("Raven-Delete-Marker", out value))
				return ReadVetoResult.Ignore;
			return ReadVetoResult.Allowed;
		}
开发者ID:neiz,项目名称:ravendb,代码行数:7,代码来源:HideVirtuallyDeletedAttachmentsReadTrigger.cs

示例4: OnPut

        /// <summary>
        /// Called when [put].
        /// </summary>
        /// <param name="key">The key.</param>
        /// <param name="document">The document.</param>
        /// <param name="metadata">The metadata.</param>
        /// <param name="transactionInformation">The transaction information.</param>
        public override void OnPut(string key, RavenJObject document, RavenJObject metadata, TransactionInformation transactionInformation)
        {
            if (key.StartsWith("Raven/",true,CultureInfo.InvariantCulture)) // we don't deal with system documents
                return;

            if (TriggerContext.IsInTriggerContext)
                return;

            using (TriggerContext.Enter()) {
                var meta = document["MetaData"] as RavenJObject;
                if(meta != null) {
                    var slug = meta.Value<string>("Slug");
                    RavenJToken parent;
                    if (document.TryGetValue("Parent", out parent) && parent.Type != JTokenType.Null) {
                        var parentId = parent.Value<string>("Id");
                        var parentDocument = Database.Get(parentId, transactionInformation);
                        var parentUrl = parentDocument.DataAsJson.Value<JObject>("Metadata").Value<string>("Url");
                        if (parentUrl != null) {
                            meta["Url"] = string.Format("{0}/{1}", parentUrl, slug);
                            base.OnPut(key, document, metadata, transactionInformation);
                            return;
                        }
                    }
                    meta["Url"] = slug;
                }
            }
            base.OnPut(key, document, metadata, transactionInformation);
        }
开发者ID:stemyers,项目名称:BrickPile,代码行数:35,代码来源:UpdateTrigger.cs

示例5: TryParseFeatureCollection

		private bool TryParseFeatureCollection(RavenJObject obj, out object result)
		{
			result = null;
			string typeString;
			if (TryParseTypeString(obj, out typeString) && typeString.ToLowerInvariant() == "featurecollection")
			{
				RavenJToken feats;
				if (obj.TryGetValue("features", out feats))
				{
					var features = feats as RavenJArray;
					if (features != null)
					{
						var temp = new object[features.Length];
						for (var index = 0; index < features.Length; index++)
						{
							var geometry = features[index];
							if (!TryParseFeature((RavenJObject)geometry, out temp[index]))
								return false;
						}
						result = _shapeConverter.ToFeatureCollection(temp);
						return true;
					}
				}
			}
			return false;
		}
开发者ID:sibartlett,项目名称:RavenDB.Client.Spatial,代码行数:26,代码来源:GeoJsonReader.cs

示例6: OnPut

        public override void OnPut(string key, RavenJObject document, RavenJObject metadata, TransactionInformation transactionInformation)
        {
            // leave raven system docs alone
            if (key.StartsWith("Raven/"))
                return;

            RavenJToken lastModified;
            if (!metadata.TryGetValue("Last-Modified", out lastModified))
                metadata.Add("Created", SystemTime.UtcNow);
        }
开发者ID:khalidabuhakmeh,项目名称:ravendb.contrib,代码行数:10,代码来源:CreatedDateTrigger.cs

示例7: TryParseTypeString

        private bool TryParseTypeString(RavenJObject obj, out string result)
        {
			RavenJToken type = null;
            if (obj != null)
                obj.TryGetValue("type", out type);
                
            result = ((RavenJValue) type).Value as string;
			
            return type != null;
        }
开发者ID:925coder,项目名称:ravendb,代码行数:10,代码来源:GeoJsonWktConverter.cs

示例8: AllowRead

		public override ReadVetoResult AllowRead(string key, RavenJObject metadata, ReadOperation operation,
												 TransactionInformation transactionInformation)
		{
			if(metadata == null)
				return ReadVetoResult.Allowed; // this is a projection, it is allowed
			RavenJToken value;
			if (metadata.TryGetValue("Raven-Delete-Marker", out value))
				return ReadVetoResult.Ignore;
			return ReadVetoResult.Allowed;
		}
开发者ID:nhsevidence,项目名称:ravendb,代码行数:10,代码来源:HideVirtuallyDeletedDocumentsReadTrigger.cs

示例9: TryParseFeature

		//private bool TryParseFeatureCollection(RavenJObject obj, StringBuilder result)
		//{
		//	result = null;
		//	string typeString;
		//	if (TryParseTypeString(obj, out typeString) && typeString.ToLowerInvariant() == "featurecollection")
		//	{
		//		RavenJToken feats = null;
		//		if (obj.TryGetValue("features", out feats))
		//		{
		//			var features = feats as RavenJArray;
		//			if (features != null)
		//			{
		//				var temp = new object[features.Length];
		//				for (var index = 0; index < features.Length; index++)
		//				{
		//					var geometry = features[index];
		//					if (!TryParseFeature((RavenJObject) geometry, out temp[index]))
		//						return false;
		//				}
		//				result = new FeatureCollection(temp.Cast<Feature>());
		//				return true;
		//			}
		//		}
		//	}
		//	return false;
		//}

		private bool TryParseFeature(RavenJObject obj, StringBuilder builder)
		{
			string typeString;
			if (TryParseTypeString(obj, out typeString) && typeString.ToLowerInvariant() == "feature")
			{
				RavenJToken geometry;
				if (obj.TryGetValue("geometry", out geometry) && TryParseGeometry((RavenJObject) geometry, builder))
					return true;
			}
			return false;
		}
开发者ID:cocytus,项目名称:ravendb,代码行数:38,代码来源:GeoJsonWktConverter.cs

示例10: TryParseTypeString

		private bool TryParseTypeString(RavenJObject obj, out string result)
		{
			RavenJToken type = null;
			if (obj != null)
				obj.TryGetValue("type", out type);

			var value = type as RavenJValue;
			if (value != null)
				result = value.Value as string;
			else
				result = null;

			return type != null;
		}
开发者ID:sibartlett,项目名称:RavenDB.Client.Spatial,代码行数:14,代码来源:GeoJsonReader.cs

示例11: OnPut

		public override void OnPut(string key, RavenJObject document, RavenJObject metadata, TransactionInformation transactionInformation)
		{
			if (string.IsNullOrEmpty(Database.Name) == false && Database.Name != Constants.SystemDatabase)
				return;

			if (key.StartsWith(Constants.Database.Prefix, StringComparison.OrdinalIgnoreCase) == false)
				return;

			RavenJObject settings;
			RavenJToken value;
			if (document.TryGetValue("Settings", out value) == false)
				document["Settings"] = settings = new RavenJObject();
			else
				settings = (RavenJObject)value;

			EnsureQuotasBundleActivated(settings);
			EnsureVoronIsSetAsStorageEngineAndIsRunningInMemory(settings);
		}
开发者ID:GorelH,项目名称:ravendb,代码行数:18,代码来源:LiveTestDatabaseDocumentPutTrigger.cs

示例12: OnPut

        public override void OnPut(
            string key,
            RavenJObject document,
            RavenJObject metadata,
            TransactionInformation transactionInformation)
        {
            Contract.Assume(!string.IsNullOrWhiteSpace(key));
            RavenJToken versionToken;
            if (!document.TryGetValue("Revision", out versionToken) || key.Contains(RevisionSegment))
            {
                return;
            }
            using (Database.DisableAllTriggersForCurrentThread())
            {
                var revisionCopy = new RavenJObject(document);
                var revisionKey  = $"{key}{RevisionSegment}{versionToken.Value<int>()}";

                Database.TransactionalStorage.Batch(storage => 
                    storage.Documents.AddDocument(revisionKey, null, revisionCopy, metadata));
            }
        }
开发者ID:damianh,项目名称:RavenDB.Bundles.Revisions,代码行数:21,代码来源:RevisionDocumentPutTrigger.cs

示例13: OnPut

        public override void OnPut(string key,
                                   RavenJObject document,
                                   RavenJObject metadata,
                                   TransactionInformation transactionInformation)
        {
            Contract.Assume(!string.IsNullOrWhiteSpace(key));

            RavenJToken versionToken;
            if (!document.TryGetValue("Revision", out versionToken) || key.Contains(RevisionSegment))
                return;

            var newRevision = versionToken.Value<int>();
            var currentRevision = metadata.ContainsKey(RavenDocumentRevision) ? metadata[RavenDocumentRevision].Value<int>() : 0;

            metadata[RavenDocumentRevisionStatus] = RavenJToken.FromObject("Current");

            //if we have a higher revision number than the existing then put a new revision
            if (newRevision > currentRevision)
            {
                metadata[RavenDocumentRevision] = RavenJToken.FromObject(versionToken.Value<int>());
                metadata.__ExternalState[RavenDocumentRevision] = metadata[RavenDocumentRevision];
            }
        }
开发者ID:nickchampion,项目名称:RavenDB.Bundles.Revisions,代码行数:23,代码来源:RevisionDocumentPutTrigger.cs

示例14: TryParseGeometryCollection

		private bool TryParseGeometryCollection(RavenJObject obj, out object result)
		{
			result = null;
			RavenJToken geom;
			if (obj.TryGetValue("geometries", out geom))
			{
				var geometries = geom as RavenJArray;

				if (geometries != null)
				{
					var temp = new object[geometries.Length];
					for (var index = 0; index < geometries.Length; index++)
					{
						var geometry = geometries[index];
						if (!TryParseGeometry((RavenJObject)geometry, out temp[index]))
							return false;
					}
					result = _shapeConverter.ToGeometryCollection(temp);
					return true;
				}
			}
			return false;
		}
开发者ID:sibartlett,项目名称:RavenDB.Client.Spatial,代码行数:23,代码来源:GeoJsonReader.cs

示例15: CreateDocument

        private static Document CreateDocument(string lowerKey, RavenJObject metadata)
        {
            var doc = new Document();
            doc.Add(new Field("__key", lowerKey, Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS));

            var fileName = Path.GetFileName(lowerKey);
            Debug.Assert(fileName != null);
            doc.Add(new Field("__fileName", fileName, Field.Store.NO, Field.Index.NOT_ANALYZED_NO_NORMS));
            // the reversed version of the file name is used to allow searches that start with wildcards
            char[] revFileName = fileName.ToCharArray();
            Array.Reverse(revFileName);
            doc.Add(new Field("__rfileName", new string(revFileName), Field.Store.NO, Field.Index.NOT_ANALYZED_NO_NORMS));

            int level = 0;
            var directoryName = Path.GetDirectoryName(lowerKey);
            do
            {
                level += 1;
                directoryName = (string.IsNullOrEmpty(directoryName) ? "" : directoryName.Replace("\\", "/"));
                if (directoryName.StartsWith("/") == false)
                    directoryName = "/" + directoryName;
                doc.Add(new Field("__directory", directoryName, Field.Store.NO, Field.Index.NOT_ANALYZED_NO_NORMS));
                directoryName = Path.GetDirectoryName(directoryName);
            } while (directoryName != null);
            doc.Add(new Field("__modified", DateTime.UtcNow.ToString(DateIndexFormat, CultureInfo.InvariantCulture), Field.Store.NO, Field.Index.NOT_ANALYZED_NO_NORMS));
            doc.Add(new Field("__level", level.ToString(CultureInfo.InvariantCulture), Field.Store.NO, Field.Index.NOT_ANALYZED_NO_NORMS));
            
            RavenJToken contentLen;
            if ( metadata.TryGetValue("Content-Length", out contentLen))
            {
                long len;
                if (long.TryParse(contentLen.Value<string>(), out len))
                {
                    doc.Add(new Field("__size", len.ToString("D20"), Field.Store.NO, Field.Index.NOT_ANALYZED_NO_NORMS));
                    doc.Add(new NumericField("__size_numeric", Field.Store.NO, true).SetLongValue(len));
                }
            }

            return doc;
        }
开发者ID:ReginaBricker,项目名称:ravendb,代码行数:40,代码来源:IndexStorage.cs


注:本文中的RavenJObject.TryGetValue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。