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


C# JsonTextWriter.WriteEndObject方法代码示例

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


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

示例1: StreamToClient

        private void StreamToClient(Stream stream, int pageSize, Etag etag)
        {
            using (var cts = new CancellationTokenSource())
			using (var timeout = cts.TimeoutAfter(FileSystemsLandlord.SystemConfiguration.DatabaseOperationTimeout))
			using (var writer = new JsonTextWriter(new StreamWriter(stream)))
			{
			    writer.WriteStartObject();
			    writer.WritePropertyName("Results");
			    writer.WriteStartArray();

                Storage.Batch(accessor =>
                {
                    var files = accessor.GetFilesAfter(etag, pageSize);
                    foreach (var file in files)
                    {
                        timeout.Delay();
                        var doc = RavenJObject.FromObject(file);
                        doc.WriteTo(writer);

                        writer.WriteRaw(Environment.NewLine);
                    }
                });

                writer.WriteEndArray();
                writer.WriteEndObject();
                writer.Flush();
			}
        }
开发者ID:bbqchickenrobot,项目名称:ravendb,代码行数:28,代码来源:FilesStreamsController.cs

示例2: StreamToClient

        private void StreamToClient(Stream stream, int pageSize, Etag etag, OrderedPartCollection<AbstractFileReadTrigger> readTriggers)
        {
            using (var cts = new CancellationTokenSource())
            using (var timeout = cts.TimeoutAfter(FileSystemsLandlord.SystemConfiguration.DatabaseOperationTimeout))
            using (var writer = new JsonTextWriter(new StreamWriter(stream)))
            {
                writer.WriteStartObject();
                writer.WritePropertyName("Results");
                writer.WriteStartArray();

                Storage.Batch(accessor =>
                {
                    var files = accessor.GetFilesAfter(etag, pageSize);
                    foreach (var file in files)
                    {
                        if (readTriggers.CanReadFile(file.FullPath, file.Metadata, ReadOperation.Load) == false)
                            continue;

                        timeout.Delay();
                        var doc = RavenJObject.FromObject(file);
                        doc.WriteTo(writer);

                        writer.WriteRaw(Environment.NewLine);
                    }
                });

                writer.WriteEndArray();
                writer.WriteEndObject();
                writer.Flush();
            }
        }
开发者ID:hero106wen,项目名称:ravendb,代码行数:31,代码来源:FilesStreamsController.cs

示例3: Execute

		public override void Execute(object parameter)
		{
            TaskCheckBox attachmentUI = taskModel.TaskInputs.FirstOrDefault(x => x.Name == "Include Attachments") as TaskCheckBox;
            includeAttachments = attachmentUI != null && attachmentUI.Value;

			var saveFile = new SaveFileDialog
			{
				DefaultExt = ".ravendump",
				Filter = "Raven Dumps|*.ravendump;*.raven.dump",
			};

			var name = ApplicationModel.Database.Value.Name;
			var normalizedName = new string(name.Select(ch => Path.GetInvalidPathChars().Contains(ch) ? '_' : ch).ToArray());
			var defaultFileName = string.Format("Dump of {0}, {1}", normalizedName, DateTimeOffset.Now.ToString("dd MMM yyyy HH-mm", CultureInfo.InvariantCulture));
			try
			{
				saveFile.DefaultFileName = defaultFileName;
			}
			catch { }

			if (saveFile.ShowDialog() != true)
				return;

			taskModel.CanExecute.Value = false;

			stream = saveFile.OpenFile();
			gZipStream = new GZipStream(stream, CompressionMode.Compress);
			streamWriter = new StreamWriter(gZipStream);
			jsonWriter = new JsonTextWriter(streamWriter)
			{
				Formatting = Formatting.Indented
			};
			taskModel.TaskStatus = TaskStatus.Started;

			output(String.Format("Exporting to {0}", saveFile.SafeFileName));
			jsonWriter.WriteStartObject();

		    Action finalized = () => 
            {
                jsonWriter.WriteEndObject();
                Infrastructure.Execute.OnTheUI(() => Finish(null));
		    };

		    Action readAttachments = () => ReadAttachments(Guid.Empty, 0, callback: finalized);
		    Action readDocuments = () => ReadDocuments(Guid.Empty, 0, callback: includeAttachments ? readAttachments : finalized);

            try
            {
                ReadIndexes(0, callback: readDocuments);
            }
            catch (Exception ex)
            {
                taskModel.ReportError(ex);
				Infrastructure.Execute.OnTheUI(() => Finish(ex));
            }
		}
开发者ID:XpressiveCode,项目名称:ravendb,代码行数:56,代码来源:ExportDatabaseCommand.cs

示例4: Respond

		public override void Respond(IHttpContext context)
		{
			using (context.Response.Streaming())
			{
				context.Response.ContentType = "application/json; charset=utf-8";

				using (var writer = new JsonTextWriter(new StreamWriter(context.Response.OutputStream)))
				{
					writer.WriteStartObject();
					writer.WritePropertyName("Results");
					writer.WriteStartArray();

					Database.TransactionalStorage.Batch(accessor =>
					{
						var startsWith = context.Request.QueryString["startsWith"];
						int pageSize = context.GetPageSize(int.MaxValue);
						if (string.IsNullOrEmpty(context.Request.QueryString["pageSize"]))
							pageSize = int.MaxValue;

						// we may be sending a LOT of documents to the user, and most 
						// of them aren't going to be relevant for other ops, so we are going to skip
						// the cache for that, to avoid filling it up very quickly
						using (DocumentCacher.SkipSettingDocumentsInDocumentCache())
						{
							if (string.IsNullOrEmpty(startsWith))
							{
								Database.GetDocuments(context.GetStart(), pageSize, context.GetEtagFromQueryString(),
								                      doc => doc.WriteTo(writer));
							}
							else
							{
								Database.GetDocumentsWithIdStartingWith(
									startsWith,
									context.Request.QueryString["matches"],
                                    context.Request.QueryString["exclude"],
									context.GetStart(),
									pageSize,
									doc => doc.WriteTo(writer));
							}
						}
					});

					writer.WriteEndArray();
					writer.WriteEndObject();
					writer.Flush();
				}
			}
		}
开发者ID:robashton,项目名称:ravendb,代码行数:48,代码来源:DocsStreams.cs

示例5: Export

        public void Export(string file)
        {
            using (var streamWriter =
                new StreamWriter(new GZipStream(File.Create(file), CompressionMode.Compress)))
            {
                var jsonWriter = new JsonTextWriter(streamWriter)
                    {
                        Formatting = Formatting.Indented
                    };

                jsonWriter.WriteStartObject();
                WriteItemsFromDb(jsonWriter, "Indexes", start => _documentDatabase.GetIndexes(start, 128));
                WriteItemsFromDb(jsonWriter, "Docs", start => _documentDatabase.GetDocuments(start, 128, null));
                WriteItemsFromDb(jsonWriter, "Attachments", GetAttachments);

                jsonWriter.WriteEndObject();
            }
        }
开发者ID:MrKevHunter,项目名称:SchoolsNearMe,代码行数:18,代码来源:RavenDbDumper.cs

示例6: StreamToClient

        private void StreamToClient(Stream stream, ExportOptions options, Lazy<NameValueCollection> headers, IPrincipal user)
        {
            var old = CurrentOperationContext.Headers.Value;
            var oldUser = CurrentOperationContext.User.Value;
            try
            {
                CurrentOperationContext.Headers.Value = headers;
                CurrentOperationContext.User.Value = user;

                Database.TransactionalStorage.Batch(accessor =>
                {
                    var bufferStream = new BufferedStream(stream, 1024 * 64);

                    using (var cts = new CancellationTokenSource())
                    using (var timeout = cts.TimeoutAfter(DatabasesLandlord.SystemConfiguration.DatabaseOperationTimeout))
                    using (var streamWriter = new StreamWriter(bufferStream))
                    using (var writer = new JsonTextWriter(streamWriter))
                    {
                        writer.WriteStartObject();
                        writer.WritePropertyName("Results");
                        writer.WriteStartArray();

                        var exporter = new SmugglerExporter(Database, options);

                        exporter.Export(item => WriteToStream(writer, item, timeout), cts.Token);

                        writer.WriteEndArray();
                        writer.WriteEndObject();
                        writer.Flush();
                        bufferStream.Flush();
                    }
                });
            }
            finally
            {
                CurrentOperationContext.Headers.Value = old;
                CurrentOperationContext.User.Value = oldUser;
            }
        }
开发者ID:IdanHaim,项目名称:ravendb,代码行数:39,代码来源:SmugglerController.cs

示例7: Respond

		public override void Respond(IHttpContext context)
		{
			context.Response.BufferOutput = false;
		
			using (var writer = new JsonTextWriter(new StreamWriter(context.Response.OutputStream)))
			{
				writer.WriteStartObject();
				writer.WritePropertyName("Results");
				writer.WriteStartArray();

				Database.TransactionalStorage.Batch(accessor =>
				{
					var startsWith = context.Request.QueryString["startsWith"];
					int pageSize = context.GetPageSize(int.MaxValue);
					if (string.IsNullOrEmpty(context.Request.QueryString["pageSize"]))
						pageSize = int.MaxValue;

					if (string.IsNullOrEmpty(startsWith))
					{
						Database.GetDocuments(context.GetStart(), pageSize, context.GetEtagFromQueryString(), 
							doc => doc.WriteTo(writer));
					}
					else
					{
						Database.GetDocumentsWithIdStartingWith(
							startsWith,
							context.Request.QueryString["matches"],
							context.GetStart(),
							pageSize,
							doc => doc.WriteTo(writer));
					}
				});

				writer.WriteEndArray();
				writer.WriteEndObject();
				writer.Flush();
			}
		}
开发者ID:samueldjack,项目名称:ravendb,代码行数:38,代码来源:DocsStreams.cs

示例8: ExportDatabase

 public void ExportDatabase()
 {
    
     using (var stream = File.Create(outputDirectory))
     using (var gZipStream = new GZipStream(stream, CompressionMode.Compress,leaveOpen: true))
     using (var streamWriter = new StreamWriter(gZipStream))
     {
         var jsonWriter = new JsonTextWriter(streamWriter)
         {
             Formatting = Formatting.Indented
         };
         jsonWriter.WriteStartObject();
         //Indexes
         jsonWriter.WritePropertyName("Indexes");
         jsonWriter.WriteStartArray();
         //WriteIndexes(jsonWriter);
         jsonWriter.WriteEndArray();
         //documents
         jsonWriter.WritePropertyName("Docs");
         jsonWriter.WriteStartArray();
         WriteDocuments(jsonWriter);
         jsonWriter.WriteEndArray();
         //Transformers
         jsonWriter.WritePropertyName("Transformers");
         jsonWriter.WriteStartArray();
         //WriteTransformers(jsonWriter);
         jsonWriter.WriteEndArray();
         //Identities
         jsonWriter.WritePropertyName("Identities");
         jsonWriter.WriteStartArray();
         WriteIdentities(jsonWriter);
         jsonWriter.WriteEndArray();
         //end of export
         jsonWriter.WriteEndObject();
         streamWriter.Flush();
     }
 }
开发者ID:j2jensen,项目名称:ravendb,代码行数:37,代码来源:StorageExporter.cs

示例9: GenerateOutput

		private static string GenerateOutput(Dictionary<string, object> result, int indent)
		{
			var stringWriter = new StringWriter();
			var writer = new JsonTextWriter(stringWriter)
			{
				Formatting = Formatting.Indented
			};

			writer.WriteStartObject();
			foreach (var o in result)
			{
				writer.WritePropertyName(o.Key);
				var ravenJToken = o.Value as RavenJToken;
				if (ravenJToken != null)
				{
					ravenJToken.WriteTo(writer);
					continue;
				}
				var conflicted = o.Value as Conflicted;
				if (conflicted != null)
				{
					writer.WriteComment(">>>> conflict start");
					writer.WriteStartArray();
					foreach (var token in conflicted.Values)
					{
						token.WriteTo(writer);
					}
					writer.WriteEndArray();
					writer.WriteComment("<<<< conflict end");
					continue;
				}

				var arrayWithWarning = o.Value as ArrayWithWarning;
				if(arrayWithWarning != null)
				{
					writer.WriteComment(">>>> auto merged array start");
					arrayWithWarning.MergedArray.WriteTo(writer);
					writer.WriteComment("<<<< auto merged array end");
					continue;
				}

				var resolver = o.Value as ConflictsResolver;
				if(resolver != null)
				{
					using(var stringReader = new StringReader(resolver.Resolve(indent + 1)))
					{
						var first = true;
						string line ;
						while((line = stringReader.ReadLine()) != null)
						{
							if(first == false)
							{
								writer.WriteRaw(Environment.NewLine);
								for (var i = 0; i < indent; i++)
								{
									writer.WriteRaw(new string(writer.IndentChar, writer.Indentation));
								}
							}
							if(first)
								writer.WriteRawValue(line);
							else
								writer.WriteRaw(line);


							first = false;

						}
					}
					continue;
				}
				throw new InvalidOperationException("Could not understand how to deal with: " + o.Value);
			}
			writer.WriteEndObject();
			return stringWriter.GetStringBuilder().ToString();
		}
开发者ID:925coder,项目名称:ravendb,代码行数:75,代码来源:ConflictsResolver.cs

示例10: StreamToClient

		private void StreamToClient(long id, SubscriptionActions subscriptions, Stream stream)
		{
			var sentDocuments = false;

			using (var streamWriter = new StreamWriter(stream))
			using (var writer = new JsonTextWriter(streamWriter))
			{
				var options = subscriptions.GetBatchOptions(id);

				writer.WriteStartObject();
				writer.WritePropertyName("Results");
				writer.WriteStartArray();

				using (var cts = new CancellationTokenSource())
				using (var timeout = cts.TimeoutAfter(DatabasesLandlord.SystemConfiguration.DatabaseOperationTimeout))
				{
                    Etag lastProcessedDocEtag = null;

					var batchSize = 0;
					var batchDocCount = 0;
					var hasMoreDocs = false;

					var config = subscriptions.GetSubscriptionConfig(id);
					var startEtag = config.AckEtag;
					var criteria = config.Criteria;

                    Action<JsonDocument> addDocument = doc =>
                    {
                        timeout.Delay();

                        if (options.MaxSize.HasValue && batchSize >= options.MaxSize)
                            return;

                        if (batchDocCount >= options.MaxDocCount)
                            return;

                        lastProcessedDocEtag = doc.Etag;

                        if (doc.Key.StartsWith("Raven/", StringComparison.InvariantCultureIgnoreCase))
                            return;

                        if (MatchCriteria(criteria, doc) == false)
                            return;

                        doc.ToJson().WriteTo(writer);
                        writer.WriteRaw(Environment.NewLine);

                        batchSize += doc.SerializedSizeOnDisk;
                        batchDocCount++;
                    };

                    int nextStart = 0;

					do
					{
						Database.TransactionalStorage.Batch(accessor =>
						{
							// we may be sending a LOT of documents to the user, and most 
							// of them aren't going to be relevant for other ops, so we are going to skip
							// the cache for that, to avoid filling it up very quickly
							using (DocumentCacher.SkipSettingDocumentsInDocumentCache())
							{    
                                if (!string.IsNullOrWhiteSpace(criteria.KeyStartsWith))
                                {
                                    Database.Documents.GetDocumentsWithIdStartingWith(criteria.KeyStartsWith, options.MaxDocCount - batchDocCount, startEtag, cts.Token, addDocument);
                                }
                                else
                                {
                                    Database.Documents.GetDocuments(-1, options.MaxDocCount - batchDocCount, startEtag, cts.Token, addDocument);
                                }
							}

							if (lastProcessedDocEtag == null)
								hasMoreDocs = false;
							else
							{
								var lastDocEtag = accessor.Staleness.GetMostRecentDocumentEtag();
								hasMoreDocs = EtagUtil.IsGreaterThan(lastDocEtag, lastProcessedDocEtag);

								startEtag = lastProcessedDocEtag;
							}
						});
					} while (hasMoreDocs && batchDocCount < options.MaxDocCount && (options.MaxSize.HasValue == false || batchSize < options.MaxSize));

					writer.WriteEndArray();

					if (batchDocCount > 0)
					{
						writer.WritePropertyName("LastProcessedEtag");
						writer.WriteValue(lastProcessedDocEtag.ToString());

						sentDocuments = true;
					}

					writer.WriteEndObject();
					writer.Flush();
				}
			}

			if (sentDocuments)
//.........这里部分代码省略.........
开发者ID:jrusbatch,项目名称:ravendb,代码行数:101,代码来源:SubscriptionsController.cs

示例11: Indenting

    public void Indenting()
    {
      StringBuilder sb = new StringBuilder();
      StringWriter sw = new StringWriter(sb);

      using (JsonWriter jsonWriter = new JsonTextWriter(sw))
      {
        jsonWriter.Formatting = Formatting.Indented;

        jsonWriter.WriteStartObject();
        jsonWriter.WritePropertyName("CPU");
        jsonWriter.WriteValue("Intel");
        jsonWriter.WritePropertyName("PSU");
        jsonWriter.WriteValue("500W");
        jsonWriter.WritePropertyName("Drives");
        jsonWriter.WriteStartArray();
        jsonWriter.WriteValue("DVD read/writer");
        jsonWriter.WriteComment("(broken)");
        jsonWriter.WriteValue("500 gigabyte hard drive");
        jsonWriter.WriteValue("200 gigabype hard drive");
        jsonWriter.WriteEnd();
        jsonWriter.WriteEndObject();
        Assert.AreEqual(WriteState.Start, jsonWriter.WriteState);
      }

      // {
      //   "CPU": "Intel",
      //   "PSU": "500W",
      //   "Drives": [
      //     "DVD read/writer"
      //     /*(broken)*/,
      //     "500 gigabyte hard drive",
      //     "200 gigabype hard drive"
      //   ]
      // }

      string expected = @"{
  ""CPU"": ""Intel"",
  ""PSU"": ""500W"",
  ""Drives"": [
    ""DVD read/writer""
    /*(broken)*/,
    ""500 gigabyte hard drive"",
    ""200 gigabype hard drive""
  ]
}";
      string result = sb.ToString();

      Assert.AreEqual(expected, result);
    }
开发者ID:925coder,项目名称:ravendb,代码行数:50,代码来源:JsonTextWriterTest.cs

示例12: ExportData


//.........这里部分代码省略.........

						if (File.Exists(file) == false)
							break;
						counter++;
					}
				}
			}
#else
			if(incremental)
				throw new NotSupportedException("Incremental exports are not supported in SL.");
#endif
			await DetectServerSupportedFeatures();

		    SmugglerExportException lastException = null;

			bool ownedStream = stream == null;
			try
			{
				stream = stream ?? File.Create(file);
				using (var gZipStream = new GZipStream(stream, CompressionMode.Compress,
#if SILVERLIGHT
                    CompressionLevel.BestCompression,
#endif
				                                       leaveOpen: true))
				using (var streamWriter = new StreamWriter(gZipStream))
				{
					var jsonWriter = new JsonTextWriter(streamWriter)
					{
						Formatting = Formatting.Indented
					};
					jsonWriter.WriteStartObject();
					jsonWriter.WritePropertyName("Indexes");
					jsonWriter.WriteStartArray();
					if ((options.OperateOnTypes & ItemType.Indexes) == ItemType.Indexes)
					{
						await ExportIndexes(jsonWriter);
					}
					jsonWriter.WriteEndArray();

					jsonWriter.WritePropertyName("Docs");
					jsonWriter.WriteStartArray();
					if (options.OperateOnTypes.HasFlag(ItemType.Documents))
					{
					    try
					    {
					        options.LastDocsEtag = await ExportDocuments(options, jsonWriter, options.LastDocsEtag);
					    }
					    catch (SmugglerExportException e)
					    {
					        options.LastDocsEtag = e.LastEtag;
					        e.File = file;
					        lastException = e;
					    }
					}
					jsonWriter.WriteEndArray();

					jsonWriter.WritePropertyName("Attachments");
					jsonWriter.WriteStartArray();
					if (options.OperateOnTypes.HasFlag(ItemType.Attachments) && lastException == null)
					{
					    try
					    {
					        options.LastAttachmentEtag = await ExportAttachments(jsonWriter, options.LastAttachmentEtag);
					    }
					    catch (SmugglerExportException e)
					    {
					        options.LastAttachmentEtag = e.LastEtag;
					        e.File = file;
					        lastException = e;
					    }
					}
					jsonWriter.WriteEndArray();

					jsonWriter.WritePropertyName("Transformers");
					jsonWriter.WriteStartArray();
					if (options.OperateOnTypes.HasFlag(ItemType.Transformers) && lastException == null)
					{
						await ExportTransformers(jsonWriter);
					}
					jsonWriter.WriteEndArray();

					jsonWriter.WriteEndObject();
					streamWriter.Flush();
				}

#if !SILVERLIGHT
				if (incremental && lastEtagsFromFile)
					WriteLastEtagsFromFile(options);
#endif

			    if (lastException != null)
			        throw lastException;
				return file;
			}
			finally
			{
				if (ownedStream && stream != null)
					stream.Dispose();
			}
		}
开发者ID:JohannesRudolph,项目名称:ravendb,代码行数:101,代码来源:SmugglerApiBase.cs

示例13: Path

    public void Path()
    {
      StringBuilder sb = new StringBuilder();
      StringWriter sw = new StringWriter(sb);

      string text = "Hello world.";
      byte[] data = Encoding.UTF8.GetBytes(text);

      using (JsonTextWriter writer = new JsonTextWriter(sw))
      {
        writer.Formatting = Formatting.Indented;

        writer.WriteStartArray();
        Assert.AreEqual("", writer.Path);
        writer.WriteStartObject();
        Assert.AreEqual("[0]", writer.Path);
        writer.WritePropertyName("Property1");
        Assert.AreEqual("[0].Property1", writer.Path);
        writer.WriteStartArray();
        Assert.AreEqual("[0].Property1", writer.Path);
        writer.WriteValue(1);
        Assert.AreEqual("[0].Property1[0]", writer.Path);
        writer.WriteStartArray();
        Assert.AreEqual("[0].Property1[1]", writer.Path);
        writer.WriteStartArray();
        Assert.AreEqual("[0].Property1[1][0]", writer.Path);
        writer.WriteStartArray();
        Assert.AreEqual("[0].Property1[1][0][0]", writer.Path);
        writer.WriteEndObject();
        Assert.AreEqual("[0]", writer.Path);
        writer.WriteStartObject();
        Assert.AreEqual("[1]", writer.Path);
        writer.WritePropertyName("Property2");
        Assert.AreEqual("[1].Property2", writer.Path);
        writer.WriteStartConstructor("Constructor1");
        Assert.AreEqual("[1].Property2", writer.Path);
        writer.WriteNull();
        Assert.AreEqual("[1].Property2[0]", writer.Path);
        writer.WriteStartArray();
        Assert.AreEqual("[1].Property2[1]", writer.Path);
        writer.WriteValue(1);
        Assert.AreEqual("[1].Property2[1][0]", writer.Path);
        writer.WriteEnd();
        Assert.AreEqual("[1].Property2[1]", writer.Path);
        writer.WriteEndObject();
        Assert.AreEqual("[1]", writer.Path);
        writer.WriteEndArray();
        Assert.AreEqual("", writer.Path);
      }

      Assert.AreEqual(@"[
  {
    ""Property1"": [
      1,
      [
        [
          []
        ]
      ]
    ]
  },
  {
    ""Property2"": new Constructor1(
      null,
      [
        1
      ]
    )
  }
]", sb.ToString());
    }
开发者ID:925coder,项目名称:ravendb,代码行数:71,代码来源:JsonTextWriterTest.cs

示例14: State

    public void State()
    {
      StringBuilder sb = new StringBuilder();
      StringWriter sw = new StringWriter(sb);

      using (JsonWriter jsonWriter = new JsonTextWriter(sw))
      {
        Assert.AreEqual(WriteState.Start, jsonWriter.WriteState);

        jsonWriter.WriteStartObject();
        Assert.AreEqual(WriteState.Object, jsonWriter.WriteState);
        Assert.AreEqual("", jsonWriter.Path);

        jsonWriter.WritePropertyName("CPU");
        Assert.AreEqual(WriteState.Property, jsonWriter.WriteState);
        Assert.AreEqual("CPU", jsonWriter.Path);

        jsonWriter.WriteValue("Intel");
        Assert.AreEqual(WriteState.Object, jsonWriter.WriteState);
        Assert.AreEqual("CPU", jsonWriter.Path);

        jsonWriter.WritePropertyName("Drives");
        Assert.AreEqual(WriteState.Property, jsonWriter.WriteState);
        Assert.AreEqual("Drives", jsonWriter.Path);

        jsonWriter.WriteStartArray();
        Assert.AreEqual(WriteState.Array, jsonWriter.WriteState);

        jsonWriter.WriteValue("DVD read/writer");
        Assert.AreEqual(WriteState.Array, jsonWriter.WriteState);
        Assert.AreEqual("Drives[0]", jsonWriter.Path);

        jsonWriter.WriteEnd();
        Assert.AreEqual(WriteState.Object, jsonWriter.WriteState);
        Assert.AreEqual("Drives", jsonWriter.Path);

        jsonWriter.WriteEndObject();
        Assert.AreEqual(WriteState.Start, jsonWriter.WriteState);
        Assert.AreEqual("", jsonWriter.Path);
      }
    }
开发者ID:925coder,项目名称:ravendb,代码行数:41,代码来源:JsonTextWriterTest.cs

示例15: ExportData

		public string ExportData(SmugglerOptions options, bool incremental, bool lastEtagsFromFile)
		{
			options = options ?? smugglerOptions;
			if (options == null)
				throw new ArgumentNullException("options");

			var file = options.BackupPath;
			if (incremental)
			{
				if (Directory.Exists(options.BackupPath) == false)
				{
					if (File.Exists(options.BackupPath))
						options.BackupPath = Path.GetDirectoryName(options.BackupPath) ?? options.BackupPath;
					else
						Directory.CreateDirectory(options.BackupPath);
				}

				if (lastEtagsFromFile) ReadLastEtagsFromFile(options);

				file = Path.Combine(options.BackupPath, SystemTime.UtcNow.ToString("yyyy-MM-dd-HH-mm", CultureInfo.InvariantCulture) + ".ravendb-incremental-dump");
				if (File.Exists(file))
				{
					var counter = 1;
					while (true)
					{
						file = Path.Combine(options.BackupPath, SystemTime.UtcNow.ToString("yyyy-MM-dd-HH-mm", CultureInfo.InvariantCulture) + " - " + counter + ".ravendb-incremental-dump");

						if (File.Exists(file) == false)
							break;
						counter++;
					}
				}
					}

			using (var streamWriter = new StreamWriter(new GZipStream(File.Create(file), CompressionMode.Compress)))
			{
				var jsonWriter = new JsonTextWriter(streamWriter)
									 {
										 Formatting = Formatting.Indented
									 };
				jsonWriter.WriteStartObject();
				jsonWriter.WritePropertyName("Indexes");
				jsonWriter.WriteStartArray();
				if ((options.OperateOnTypes & ItemType.Indexes) == ItemType.Indexes)
				{
					ExportIndexes(jsonWriter);
				}
				jsonWriter.WriteEndArray();

				jsonWriter.WritePropertyName("Docs");
				jsonWriter.WriteStartArray();
				if ((options.OperateOnTypes & ItemType.Documents) == ItemType.Documents)
				{
					options.LastDocsEtag = ExportDocuments(options, jsonWriter, options.LastDocsEtag);
				}
				jsonWriter.WriteEndArray();

				jsonWriter.WritePropertyName("Attachments");
				jsonWriter.WriteStartArray();
				if ((options.OperateOnTypes & ItemType.Attachments) == ItemType.Attachments)
				{
					options.LastAttachmentEtag = ExportAttachments(jsonWriter, options.LastAttachmentEtag);
				}
				jsonWriter.WriteEndArray();

				jsonWriter.WriteEndObject();
				streamWriter.Flush();
			}

			if (incremental && lastEtagsFromFile)
				WriteLastEtagsFromFile(options);

			return file;
		}
开发者ID:karlgrz,项目名称:ravendb,代码行数:74,代码来源:SmugglerApiBase.cs


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