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


C# JsonTextWriter.WriteEndArray方法代码示例

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


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

示例1: ExportDeletions

		public override async Task ExportDeletions(JsonTextWriter jsonWriter, ExportDataResult result, LastEtagsInfo maxEtagsToFetch)
		{
			jsonWriter.WritePropertyName("DocsDeletions");
			jsonWriter.WriteStartArray();
			result.LastDocDeleteEtag = await Operations.ExportDocumentsDeletion(jsonWriter, result.LastDocDeleteEtag, maxEtagsToFetch.LastDocDeleteEtag.IncrementBy(1));
			jsonWriter.WriteEndArray();

			jsonWriter.WritePropertyName("AttachmentsDeletions");
			jsonWriter.WriteStartArray();
			result.LastAttachmentsDeleteEtag = await Operations.ExportAttachmentsDeletion(jsonWriter, result.LastAttachmentsDeleteEtag, maxEtagsToFetch.LastAttachmentsDeleteEtag.IncrementBy(1));
			jsonWriter.WriteEndArray();
		}
开发者ID:bbqchickenrobot,项目名称:ravendb,代码行数:12,代码来源:DatabaseDataDumper.cs

示例2: ExportDeletions

        /// <summary>
        /// 
        /// </summary>
        /// <param name="jsonWriter"></param>
        /// <param name="options"></param>
        /// <param name="result"></param>
        /// <param name="maxEtags">Max etags are inclusive</param>
        protected async override void ExportDeletions(JsonTextWriter jsonWriter, SmugglerOptions options, ExportDataResult result, LastEtagsInfo maxEtags)
        {
            jsonWriter.WritePropertyName("DocsDeletions");
            jsonWriter.WriteStartArray();
            result.LastDocDeleteEtag = await ExportDocumentsDeletion(options, jsonWriter, result.LastDocDeleteEtag, maxEtags.LastDocDeleteEtag.IncrementBy(1));
            jsonWriter.WriteEndArray();

            jsonWriter.WritePropertyName("AttachmentsDeletions");
            jsonWriter.WriteStartArray();
            result.LastAttachmentsDeleteEtag = await ExportAttachmentsDeletion(options, jsonWriter, result.LastAttachmentsDeleteEtag, maxEtags.LastAttachmentsDeleteEtag.IncrementBy(1));
            jsonWriter.WriteEndArray();
        }
开发者ID:randacc,项目名称:ravendb,代码行数:19,代码来源:DataDumper.cs

示例3: 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

示例4: 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

示例5: 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();
         //Attachments
         jsonWriter.WritePropertyName("Attachments");
         jsonWriter.WriteStartArray();
         WriteAttachments(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:IdanHaim,项目名称:ravendb,代码行数:42,代码来源:StorageExporter.cs

示例6: 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

示例7: 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

示例8: 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

示例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: ExportData

		public virtual async Task<string> ExportData(Stream stream, SmugglerOptions options, bool incremental, bool lastEtagsFromFile, PeriodicBackupStatus backupStatus)
		{
			options = options ?? SmugglerOptions;
			if (options == null)
				throw new ArgumentNullException("options");

			var file = options.BackupPath;

#if !SILVERLIGHT
			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 && backupStatus == null) ReadLastEtagsFromFile(options);
				if (backupStatus != null) ReadLastEtagsFromClass(options, backupStatus);

				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++;
					}
				}
			}
#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;
					    }
					}
//.........这里部分代码省略.........
开发者ID:JohannesRudolph,项目名称:ravendb,代码行数:101,代码来源:SmugglerApiBase.cs

示例11: ReadLongJsonArray

    public void ReadLongJsonArray()
    {
      int valueCount = 10000;
      StringWriter sw = new StringWriter();
      JsonTextWriter writer = new JsonTextWriter(sw);
      writer.WriteStartArray();
      for (int i = 0; i < valueCount; i++)
      {
        writer.WriteValue(i);
      }
      writer.WriteEndArray();

      string json = sw.ToString();

      JsonTextReader reader = new JsonTextReader(new StringReader(json));
      Assert.IsTrue(reader.Read());
      for (int i = 0; i < valueCount; i++)
      {
        Assert.IsTrue(reader.Read());
        Assert.AreEqual((long)i, reader.Value);
      }
      Assert.IsTrue(reader.Read());
      Assert.IsFalse(reader.Read());
    }
开发者ID:WimVergouwe,项目名称:ravendb,代码行数:24,代码来源:JsonTextReaderTest.cs

示例12: WriteReadBoundaryDecimals

    public void WriteReadBoundaryDecimals()
    {
      StringWriter sw = new StringWriter();
      JsonTextWriter writer = new JsonTextWriter(sw);

      writer.WriteStartArray();
      writer.WriteValue(decimal.MaxValue);
      writer.WriteValue(decimal.MinValue);
      writer.WriteEndArray();

      string json = sw.ToString();

      StringReader sr = new StringReader(json);
      JsonTextReader reader = new JsonTextReader(sr);

      Assert.IsTrue(reader.Read());

      decimal? max = reader.ReadAsDecimal();
      Assert.AreEqual(decimal.MaxValue, max);

      decimal? min = reader.ReadAsDecimal();
      Assert.AreEqual(decimal.MinValue, min);

      Assert.IsTrue(reader.Read());
    }
开发者ID:WimVergouwe,项目名称:ravendb,代码行数:25,代码来源:JsonTextReaderTest.cs

示例13: WriteReadWrite

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

      using (JsonWriter jsonWriter = new JsonTextWriter(sw)
        {
          Formatting = Formatting.Indented
        })
      {
        jsonWriter.WriteStartArray();
        jsonWriter.WriteValue(true);

        jsonWriter.WriteStartObject();
        jsonWriter.WritePropertyName("integer");
        jsonWriter.WriteValue(99);
        jsonWriter.WritePropertyName("string");
        jsonWriter.WriteValue("how now brown cow?");
        jsonWriter.WritePropertyName("array");

        jsonWriter.WriteStartArray();
        for (int i = 0; i < 5; i++)
        {
          jsonWriter.WriteValue(i);
        }

        jsonWriter.WriteStartObject();
        jsonWriter.WritePropertyName("decimal");
        jsonWriter.WriteValue(990.00990099m);
        jsonWriter.WriteEndObject();

        jsonWriter.WriteValue(5);
        jsonWriter.WriteEndArray();

        jsonWriter.WriteEndObject();

        jsonWriter.WriteValue("This is a string.");
        jsonWriter.WriteNull();
        jsonWriter.WriteNull();
        jsonWriter.WriteEndArray();
      }

      string json = sb.ToString();

      JsonSerializer serializer = new JsonSerializer();

      object jsonObject = serializer.Deserialize(new JsonTextReader(new StringReader(json)));

      sb = new StringBuilder();
      sw = new StringWriter(sb);

      using (JsonWriter jsonWriter = new JsonTextWriter(sw)
        {
          Formatting = Formatting.Indented
        })
      {
        serializer.Serialize(jsonWriter, jsonObject);
      }

      Assert.AreEqual(json, sb.ToString());
    }
开发者ID:WimVergouwe,项目名称:ravendb,代码行数:61,代码来源:JsonTextReaderTest.cs

示例14: FloatingPointNonFiniteNumbers

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

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

        jsonWriter.WriteStartArray();
        jsonWriter.WriteValue(double.NaN);
        jsonWriter.WriteValue(double.PositiveInfinity);
        jsonWriter.WriteValue(double.NegativeInfinity);
        jsonWriter.WriteValue(float.NaN);
        jsonWriter.WriteValue(float.PositiveInfinity);
        jsonWriter.WriteValue(float.NegativeInfinity);
        jsonWriter.WriteEndArray();

        jsonWriter.Flush();
      }

      string expected = @"[
  NaN,
  Infinity,
  -Infinity,
  NaN,
  Infinity,
  -Infinity
]";
      string result = sb.ToString();

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

示例15: ValueFormatting

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

      using (JsonWriter jsonWriter = new JsonTextWriter(sw))
      {
        jsonWriter.WriteStartArray();
        jsonWriter.WriteValue('@');
        jsonWriter.WriteValue("\r\n\t\f\b?{\\r\\n\"\'");
        jsonWriter.WriteValue(true);
        jsonWriter.WriteValue(10);
        jsonWriter.WriteValue(10.99);
        jsonWriter.WriteValue(0.99);
        jsonWriter.WriteValue(0.000000000000000001d);
        jsonWriter.WriteValue(0.000000000000000001m);
        jsonWriter.WriteValue((string)null);
        jsonWriter.WriteValue((object)null);
        jsonWriter.WriteValue("This is a string.");
        jsonWriter.WriteNull();
        jsonWriter.WriteUndefined();
        jsonWriter.WriteEndArray();
      }

      string expected = @"[""@"",""\r\n\t\f\b?{\\r\\n\""'"",true,10,10.99,0.99,1E-18,0.000000000000000001,null,null,""This is a string."",null,undefined]";
      string result = sb.ToString();

      Console.WriteLine("ValueFormatting");
      Console.WriteLine(result);

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


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