ToJson() публичный метод

Translate the json document to a RavenJObject
public ToJson ( ) : RavenJObject
Результат RavenJObject
		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);
			}
		}
Пример #2
0
		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);
			}
		}
Пример #3
0
        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);
                });

            if (addedDocs != pageSize)
                nextStart = start; // will mark as last page
            else if (canPerformRapidPagination)
                nextStart = start + matchedDocs;
            else
                nextStart = actualStart;
        }
Пример #4
0
	    private void UpdateBeforeDocument(JsonDocument doc)
	    {
            recentDocuments.Add(doc);
	        OriginalDoc.SetText(doc.ToJson().ToString());
	        NewDoc.SetText("");
	        ShowBeforeAndAfterPrompt = false;
	        ShowAfterPrompt = true;
	    }