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


C# JsonDocument.ToJson方法代码示例

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


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

示例1: Save

		private static async Task Save(string serverHash, JsonDocument document)
		{
			var path = "RavenDB Replication Information For - " + serverHash;

			var file = await folder.CreateFileAsync(path, CreationCollisionOption.ReplaceExisting);
			using (var stream = await file.OpenStreamForWriteAsync())
			{
				document.ToJson().WriteTo(stream);
			}
		}
开发者ID:925coder,项目名称:ravendb,代码行数:10,代码来源:ReplicationInformerLocalCache.cs

示例2: TrySavingReplicationInformationToLocalCache

		public static void TrySavingReplicationInformationToLocalCache(string serverHash, JsonDocument document)
		{
			try
			{
				using (var machineStoreForApplication = GetIsolatedStorageFileForReplicationInformation())
				{
					var path = "RavenDB Replication Information For - " + serverHash;
					using (var stream = new IsolatedStorageFileStream(path, FileMode.Create, machineStoreForApplication))
					{
						document.ToJson().WriteTo(stream);
					}
				}
			}
			catch (Exception e)
			{
				log.ErrorException("Could not persist the replication information", e);
			}
		}
开发者ID:925coder,项目名称:ravendb,代码行数:18,代码来源:ReplicationInformerCache.cs

示例3: GetDocumentsWithIdStartingWith

        public void GetDocumentsWithIdStartingWith(string idPrefix, string matches, string exclude, int start, int pageSize,
                                                   CancellationToken token, ref int nextStart, Action<RavenJObject> addDoc,
                                                   string transformer = null, Dictionary<string, RavenJToken> transformerParameters = null,
												   string skipAfter = null)
        {
            if (idPrefix == null)
                throw new ArgumentNullException("idPrefix");
            idPrefix = idPrefix.Trim();

            var canPerformRapidPagination = nextStart > 0 && start == nextStart;
            var actualStart = canPerformRapidPagination ? start : 0;
            var addedDocs = 0;
            var matchedDocs = 0;

            TransactionalStorage.Batch(
                actions =>
                {
                    var docsToSkip = canPerformRapidPagination ? 0 : start;
                    int docCount;

                    AbstractTransformer storedTransformer = null;
                    if (transformer != null)
                    {
                        storedTransformer = IndexDefinitionStorage.GetTransformer(transformer);
                        if (storedTransformer == null)
                            throw new InvalidOperationException("No transformer with the name: " + transformer);
                    }

                    do
                    {
                        docCount = 0;
						var docs = actions.Documents.GetDocumentsWithIdStartingWith(idPrefix, actualStart, pageSize, string.IsNullOrEmpty(skipAfter) ? null : skipAfter);
                        var documentRetriever = new DocumentRetriever(actions, Database.ReadTriggers, Database.InFlightTransactionalState, transformerParameters);

                        foreach (var doc in docs)
                        {
                            token.ThrowIfCancellationRequested();
                            docCount++;
                            var keyTest = doc.Key.Substring(idPrefix.Length);

                            if (!WildcardMatcher.Matches(matches, keyTest) || WildcardMatcher.MatchesExclusion(exclude, keyTest))
                                continue;

                            DocumentRetriever.EnsureIdInMetadata(doc);
                            var nonAuthoritativeInformationBehavior = Database.InFlightTransactionalState.GetNonAuthoritativeInformationBehavior<JsonDocument>(null, doc.Key);

                            var document = nonAuthoritativeInformationBehavior != null ? nonAuthoritativeInformationBehavior(doc) : doc;
                            document = documentRetriever.ExecuteReadTriggers(document, null, ReadOperation.Load);
                            if (document == null)
                                continue;

                            matchedDocs++;

                            if (matchedDocs <= docsToSkip)
                                continue;

                            token.ThrowIfCancellationRequested();

                            if (storedTransformer != null)
                            {
                                using (new CurrentTransformationScope(Database, documentRetriever))
                                {
                                    var transformed =
                                        storedTransformer.TransformResultsDefinition(new[] { new DynamicJsonObject(document.ToJson()) })
                                                         .Select(x => JsonExtensions.ToJObject(x))
                                                         .ToArray();

                                    if (transformed.Length == 0)
                                    {
                                        throw new InvalidOperationException("The transform results function failed on a document: " + document.Key);
                                    }

                                    var transformedJsonDocument = new JsonDocument
                                    {
                                        Etag = document.Etag.HashWith(storedTransformer.GetHashCodeBytes()).HashWith(documentRetriever.Etag),
                                        NonAuthoritativeInformation = document.NonAuthoritativeInformation,
                                        LastModified = document.LastModified,
                                        DataAsJson = new RavenJObject { { "$values", new RavenJArray(transformed) } },
                                    };

                                    addDoc(transformedJsonDocument.ToJson());
                                }

                            }
                            else
                            {
                                addDoc(document.ToJson());
                            }

                            addedDocs++;

                            if (addedDocs >= pageSize)
                                break;
                        }

                        actualStart += pageSize;
                    }
                    while (docCount > 0 && addedDocs < pageSize && actualStart > 0 && actualStart < int.MaxValue);
                });

//.........这里部分代码省略.........
开发者ID:mdavis,项目名称:ravendb,代码行数:101,代码来源:DocumentActions.cs

示例4: UpdateBeforeDocument

	    private void UpdateBeforeDocument(JsonDocument doc)
	    {
            recentDocuments.Add(doc);
	        OriginalDoc.SetText(doc.ToJson().ToString());
	        NewDoc.SetText("");
	        ShowBeforeAndAfterPrompt = false;
	        ShowAfterPrompt = true;
	    }
开发者ID:jasondentler,项目名称:ravendb,代码行数:8,代码来源:PatchModel.cs


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