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


C# BsonWriter.Flush方法代码示例

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


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

示例1: Populate

 public static void Populate(Db db, int count)
 {
     Console.WriteLine ("Generating object graph");
     var stream = new MemoryStream();
     var node = CreateTreeNode(3, 50, 0);
     BsonWriter writer = new BsonWriter(stream);
     var obj = RavenJObject.FromObject(node);
     obj.WriteTo(writer);
     writer.Flush();
     for(var i =0 ; i < count; i++) {
         Console.WriteLine ("Writing object with key: {0}, and {1} bytes", i, stream.Length);
     db.Put(i, stream.ToArray());
     }
 }
开发者ID:robashton,项目名称:marshal-benchmark,代码行数:14,代码来源:program.cs

示例2: WriteValueOutsideOfObjectOrArray

    public void WriteValueOutsideOfObjectOrArray()
    {
      ExceptionAssert.Throws<JsonWriterException>("Error writing String value. BSON must start with an Object or Array. Path ''.",
      () =>
      {
        MemoryStream stream = new MemoryStream();

        using (BsonWriter writer = new BsonWriter(stream))
        {
          writer.WriteValue("test");
          writer.Flush();
        }
      });
    }
开发者ID:nberardi,项目名称:ravendb,代码行数:14,代码来源:BsonWriterTests.cs

示例3: WriteNestedArray

    public void WriteNestedArray()
    {
      MemoryStream ms = new MemoryStream();
      BsonWriter writer = new BsonWriter(ms);
      writer.WriteStartObject();

      writer.WritePropertyName("_id");
      writer.WriteValue(MiscellaneousUtils.HexToBytes("4A-78-93-79-17-22-00-00-00-00-61-CF"));

      writer.WritePropertyName("a");
      writer.WriteStartArray();
      for (int i = 1; i <= 8; i++)
      {
        double value = (i != 5)
                         ? Convert.ToDouble(i)
                         : 5.78960446186581E+77d;

        writer.WriteValue(value);
      }
      writer.WriteEndArray();

      writer.WritePropertyName("b");
      writer.WriteValue("test");

      writer.WriteEndObject();

      writer.Flush();

      ms.Seek(0, SeekOrigin.Begin);

      string expected = "87-00-00-00-05-5F-69-64-00-0C-00-00-00-00-4A-78-93-79-17-22-00-00-00-00-61-CF-04-61-00-5D-00-00-00-01-30-00-00-00-00-00-00-00-F0-3F-01-31-00-00-00-00-00-00-00-00-40-01-32-00-00-00-00-00-00-00-08-40-01-33-00-00-00-00-00-00-00-10-40-01-34-00-00-00-00-00-00-00-14-50-01-35-00-00-00-00-00-00-00-18-40-01-36-00-00-00-00-00-00-00-1C-40-01-37-00-00-00-00-00-00-00-20-40-00-02-62-00-05-00-00-00-74-65-73-74-00-00";
      string bson = MiscellaneousUtils.BytesToHex(ms.ToArray());

      Assert.AreEqual(expected, bson);
    }
开发者ID:nberardi,项目名称:ravendb,代码行数:35,代码来源:BsonWriterTests.cs

示例4: WriteBytes

    public void WriteBytes()
    {
      byte[] data = Encoding.UTF8.GetBytes("Hello world!");

      MemoryStream ms = new MemoryStream();
      BsonWriter writer = new BsonWriter(ms);
      writer.WriteStartArray();
      writer.WriteValue("a");
      writer.WriteValue("b");
      writer.WriteValue(data);
      writer.WriteEndArray();

      writer.Flush();

      ms.Seek(0, SeekOrigin.Begin);

      string expected = "2B-00-00-00-02-30-00-02-00-00-00-61-00-02-31-00-02-00-00-00-62-00-05-32-00-0C-00-00-00-00-48-65-6C-6C-6F-20-77-6F-72-6C-64-21-00";
      string bson = MiscellaneousUtils.BytesToHex(ms.ToArray());

      Assert.AreEqual(expected, bson);

      BsonReader reader = new BsonReader(new MemoryStream(ms.ToArray()));
      reader.ReadRootValueAsArray = true;
      reader.Read();
      reader.Read();
      reader.Read();
      reader.Read();
      Assert.AreEqual(JsonToken.Bytes, reader.TokenType);
      CollectionAssert.AreEquivalent(data, (byte[])reader.Value);
    }
开发者ID:nberardi,项目名称:ravendb,代码行数:30,代码来源:BsonWriterTests.cs

示例5: WriteArrayBsonFromSite

    public void WriteArrayBsonFromSite()
    {
      MemoryStream ms = new MemoryStream();
      BsonWriter writer = new BsonWriter(ms);
      writer.WriteStartArray();
      writer.WriteValue("a");
      writer.WriteValue("b");
      writer.WriteValue("c");
      writer.WriteEndArray();
      
      writer.Flush();

      ms.Seek(0, SeekOrigin.Begin);

      string expected = "20-00-00-00-02-30-00-02-00-00-00-61-00-02-31-00-02-00-00-00-62-00-02-32-00-02-00-00-00-63-00-00";
      string bson = MiscellaneousUtils.BytesToHex(ms.ToArray());

      Assert.AreEqual(expected, bson);
    }
开发者ID:nberardi,项目名称:ravendb,代码行数:19,代码来源:BsonWriterTests.cs

示例6: AppendAsync

		public async Task AppendAsync(RavenJObject data)
		{
			if (disposed)
				throw new ObjectDisposedException("EventStream");
			var nextEtag = _options.Status.NextEtag();
			data["@etag"] = nextEtag.ToString();
			data["@date"] = DateTime.UtcNow.ToString("o");

			using (var stream = new BufferPoolMemoryStream(_options.BufferPool))
			{
				var bsonWriter = new BsonWriter(stream);
				data.WriteTo(bsonWriter);
				bsonWriter.Flush();
				stream.Position = 0;
				var mine = new PendingWrite(stream, nextEtag);

				_pending.Enqueue(mine);

				while (mine.Done() == false && _pending.Peek() != mine)
				{
					await _writeCompletedEvent.WaitAsync();
				}

				if (mine.Done())
					return;

				await AppendInternalAsync(mine);
			}
		}
开发者ID:mattwarren,项目名称:temp.raven.storage,代码行数:29,代码来源:EventStream.cs

示例7: ReadNestedArrayIntoLinq

        public void ReadNestedArrayIntoLinq()
        {
            string hexdoc = "87-00-00-00-05-5F-69-64-00-0C-00-00-00-00-4A-78-93-79-17-22-00-00-00-00-61-CF-04-61-00-5D-00-00-00-01-30-00-00-00-00-00-00-00-F0-3F-01-31-00-00-00-00-00-00-00-00-40-01-32-00-00-00-00-00-00-00-08-40-01-33-00-00-00-00-00-00-00-10-40-01-34-00-00-00-00-00-00-00-14-50-01-35-00-00-00-00-00-00-00-18-40-01-36-00-00-00-00-00-00-00-1C-40-01-37-00-00-00-00-00-00-00-20-40-00-02-62-00-05-00-00-00-74-65-73-74-00-00";

            byte[] data = HexToBytes(hexdoc);

            BsonReader reader = new BsonReader(new MemoryStream(data));
#pragma warning disable 612,618
            reader.JsonNet35BinaryCompatibility = true;
#pragma warning restore 612,618

            JObject o = (JObject)JToken.ReadFrom(reader);
            Assert.AreEqual(3, o.Count);

            MemoryStream ms = new MemoryStream();
            BsonWriter writer = new BsonWriter(ms);
            o.WriteTo(writer);
            writer.Flush();

            string bson = BytesToHex(ms.ToArray());
            Assert.AreEqual(hexdoc, bson);
        }
开发者ID:j2jensen,项目名称:ravendb,代码行数:22,代码来源:BsonReaderTests.cs

示例8: MultibyteCharacterPropertyNamesAndStrings

    public void MultibyteCharacterPropertyNamesAndStrings()
    {
      string json = @"{
  ""ΕΝΤΟΛΗ ΧΧΧ ΧΧΧΧΧΧΧΧΧ ΤΑ ΠΡΩΤΑΣΦΑΛΙΣΤΗΡΙΑ ΠΟΥ ΔΕΝ ΕΧΟΥΝ ΥΠΟΛΟΙΠΟ ΝΑ ΤΑ ΣΤΕΛΝΟΥΜΕ ΑΠΕΥΘΕΙΑΣ ΣΤΟΥΣ ΠΕΛΑΤΕΣ"": ""ΕΝΤΟΛΗ ΧΧΧ ΧΧΧΧΧΧΧΧΧ ΤΑ ΠΡΩΤΑΣΦΑΛΙΣΤΗΡΙΑ ΠΟΥ ΔΕΝ ΕΧΟΥΝ ΥΠΟΛΟΙΠΟ ΝΑ ΤΑ ΣΤΕΛΝΟΥΜΕ ΑΠΕΥΘΕΙΑΣ ΣΤΟΥΣ ΠΕΛΑΤΕΣ""
}";
      JObject parsed = JObject.Parse(json);
      var memoryStream = new MemoryStream();
      var bsonWriter = new BsonWriter(memoryStream);
      parsed.WriteTo(bsonWriter);
      bsonWriter.Flush();
      memoryStream.Position = 0;

      BsonReader reader = new BsonReader(memoryStream);

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.StartObject, reader.TokenType);

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.PropertyName, reader.TokenType);
      Assert.AreEqual("ΕΝΤΟΛΗ ΧΧΧ ΧΧΧΧΧΧΧΧΧ ΤΑ ΠΡΩΤΑΣΦΑΛΙΣΤΗΡΙΑ ΠΟΥ ΔΕΝ ΕΧΟΥΝ ΥΠΟΛΟΙΠΟ ΝΑ ΤΑ ΣΤΕΛΝΟΥΜΕ ΑΠΕΥΘΕΙΑΣ ΣΤΟΥΣ ΠΕΛΑΤΕΣ", reader.Value);

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.String, reader.TokenType);
      Assert.AreEqual("ΕΝΤΟΛΗ ΧΧΧ ΧΧΧΧΧΧΧΧΧ ΤΑ ΠΡΩΤΑΣΦΑΛΙΣΤΗΡΙΑ ΠΟΥ ΔΕΝ ΕΧΟΥΝ ΥΠΟΛΟΙΠΟ ΝΑ ΤΑ ΣΤΕΛΝΟΥΜΕ ΑΠΕΥΘΕΙΑΣ ΣΤΟΥΣ ΠΕΛΑΤΕΣ", reader.Value);

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.EndObject, reader.TokenType);
    }
开发者ID:nberardi,项目名称:ravendb,代码行数:28,代码来源:BsonReaderTests.cs

示例9: Utf8Text

        public void Utf8Text()
        {
            string badText = System.IO.File.ReadAllText(@"PoisonText.txt");
            var j = new JObject();
            j["test"] = badText;

            var memoryStream = new MemoryStream();
            var bsonWriter = new BsonWriter(memoryStream);
            j.WriteTo(bsonWriter);
            bsonWriter.Flush();

            memoryStream.Position = 0;
            JObject o = JObject.Load(new BsonReader(memoryStream));

            Assert.AreEqual(badText, (string)o["test"]);
        }
开发者ID:j2jensen,项目名称:ravendb,代码行数:16,代码来源:BsonReaderTests.cs

示例10: DeserializeByteArrayWithTypeNameHandling

        public void DeserializeByteArrayWithTypeNameHandling()
        {
            TestObject test = new TestObject("Test", new byte[] { 72, 63, 62, 71, 92, 55 });

            JsonSerializer serializer = new JsonSerializer();
            serializer.TypeNameHandling = TypeNameHandling.All;

            byte[] objectBytes;
            using (MemoryStream bsonStream = new MemoryStream())
            using (JsonWriter bsonWriter = new BsonWriter(bsonStream))
            {
                serializer.Serialize(bsonWriter, test);
                bsonWriter.Flush();

                objectBytes = bsonStream.ToArray();
            }

            using (MemoryStream bsonStream = new MemoryStream(objectBytes))
            using (JsonReader bsonReader = new BsonReader(bsonStream))
            {
                // Get exception here
                TestObject newObject = (TestObject)serializer.Deserialize(bsonReader);

                Assert.AreEqual("Test", newObject.Name);
                CollectionAssert.AreEquivalent(new byte[] { 72, 63, 62, 71, 92, 55 }, newObject.Data);
            }
        }
开发者ID:j2jensen,项目名称:ravendb,代码行数:27,代码来源:BsonReaderTests.cs

示例11: UriGuidTimeSpanTestClassValuesTest

        public void UriGuidTimeSpanTestClassValuesTest()
        {
            UriGuidTimeSpanTestClass c1 = new UriGuidTimeSpanTestClass
            {
                Guid = new Guid("1924129C-F7E0-40F3-9607-9939C531395A"),
                NullableGuid = new Guid("9E9F3ADF-E017-4F72-91E0-617EBE85967D"),
                TimeSpan = TimeSpan.FromDays(1),
                NullableTimeSpan = TimeSpan.FromHours(1),
                Uri = new Uri("http://testuri.com")
            };

            var memoryStream = new MemoryStream();
            var bsonWriter = new BsonWriter(memoryStream);
            JsonSerializer serializer = new JsonSerializer();
            serializer.Serialize(bsonWriter, c1);
            bsonWriter.Flush();
            memoryStream.Position = 0;

            var bsonReader = new BsonReader(memoryStream);

            UriGuidTimeSpanTestClass c2 = serializer.Deserialize<UriGuidTimeSpanTestClass>(bsonReader);
            Assert.AreEqual(c1.Guid, c2.Guid);
            Assert.AreEqual(c1.NullableGuid, c2.NullableGuid);
            Assert.AreEqual(c1.TimeSpan, c2.TimeSpan);
            Assert.AreEqual(c1.NullableTimeSpan, c2.NullableTimeSpan);
            Assert.AreEqual(c1.Uri, c2.Uri);
        }
开发者ID:j2jensen,项目名称:ravendb,代码行数:27,代码来源:BsonReaderTests.cs

示例12: UriGuidTimeSpanTestClassEmptyTest

        public void UriGuidTimeSpanTestClassEmptyTest()
        {
            UriGuidTimeSpanTestClass c1 = new UriGuidTimeSpanTestClass();

            var memoryStream = new MemoryStream();
            var bsonWriter = new BsonWriter(memoryStream);
            JsonSerializer serializer = new JsonSerializer();
            serializer.Serialize(bsonWriter, c1);
            bsonWriter.Flush();
            memoryStream.Position = 0;

            var bsonReader = new BsonReader(memoryStream);

            UriGuidTimeSpanTestClass c2 = serializer.Deserialize<UriGuidTimeSpanTestClass>(bsonReader);
            Assert.AreEqual(c1.Guid, c2.Guid);
            Assert.AreEqual(c1.NullableGuid, c2.NullableGuid);
            Assert.AreEqual(c1.TimeSpan, c2.TimeSpan);
            Assert.AreEqual(c1.NullableTimeSpan, c2.NullableTimeSpan);
            Assert.AreEqual(c1.Uri, c2.Uri);
        }
开发者ID:j2jensen,项目名称:ravendb,代码行数:20,代码来源:BsonReaderTests.cs

示例13: MultibyteCharacterPropertyNamesAndStrings

        public void MultibyteCharacterPropertyNamesAndStrings()
        {
            string json = @"{
  ""?????? ??? ????????? ?? ??O??SF???S????? ??? ??? ????? ???????? ?? ?? S???????? ????T???S S???S ??????S"": ""?????? ??? ????????? ?? ??O??SF???S????? ??? ??? ????? ???????? ?? ?? S???????? ????T???S S???S ??????S""
}";
            JObject parsed = JObject.Parse(json);
            var memoryStream = new MemoryStream();
            var bsonWriter = new BsonWriter(memoryStream);
            parsed.WriteTo(bsonWriter);
            bsonWriter.Flush();
            memoryStream.Position = 0;

            BsonReader reader = new BsonReader(memoryStream);

            Assert.IsTrue(reader.Read());
            Assert.AreEqual(JsonToken.StartObject, reader.TokenType);

            Assert.IsTrue(reader.Read());
            Assert.AreEqual(JsonToken.PropertyName, reader.TokenType);
            Assert.AreEqual("?????? ??? ????????? ?? ??O??SF???S????? ??? ??? ????? ???????? ?? ?? S???????? ????T???S S???S ??????S", reader.Value);

            Assert.IsTrue(reader.Read());
            Assert.AreEqual(JsonToken.String, reader.TokenType);
            Assert.AreEqual("?????? ??? ????????? ?? ??O??SF???S????? ??? ??? ????? ???????? ?? ?? S???????? ????T???S S???S ??????S", reader.Value);

            Assert.IsTrue(reader.Read());
            Assert.AreEqual(JsonToken.EndObject, reader.TokenType);
        }
开发者ID:j2jensen,项目名称:ravendb,代码行数:28,代码来源:BsonReaderTests.cs

示例14: CanRoundTripStackOverflowData

        public void CanRoundTripStackOverflowData()
        {
            var doc =
                @"{
""AboutMe"": ""<p>I'm the Director for Research and Development for <a href=\""http://www.prophoenix.com\"" rel=\""nofollow\"">ProPhoenix</a>, a public safety software company.  This position allows me to investigate new and existing technologies and incorporate them into our product line, with the end goal being to help public safety agencies to do their jobs more effeciently and safely.</p>\r\n\r\n<p>I'm an advocate for PowerShell, as I believe it encourages administrative best practices and allows developers to provide additional access to their applications, without needing to explicity write code for each administrative feature.  Part of my advocacy for PowerShell includes <a href=\""http://blog.usepowershell.com\"" rel=\""nofollow\"">my blog</a>, appearances on various podcasts, and acting as a Community Director for <a href=\""http://powershellcommunity.org\"" rel=\""nofollow\"">PowerShellCommunity.Org</a></p>\r\n\r\n<p>I’m also a co-host of Mind of Root (a weekly audio podcast about systems administration, tech news, and topics).</p>\r\n"",
""WebsiteUrl"": ""http://blog.usepowershell.com""
}";
            JObject parsed = JObject.Parse(doc);
            var memoryStream = new MemoryStream();
            var bsonWriter = new BsonWriter(memoryStream);
            parsed.WriteTo(bsonWriter);
            bsonWriter.Flush();
            memoryStream.Position = 0;

            BsonReader reader = new BsonReader(memoryStream);

            Assert.IsTrue(reader.Read());
            Assert.AreEqual(JsonToken.StartObject, reader.TokenType);

            Assert.IsTrue(reader.Read());
            Assert.AreEqual(JsonToken.PropertyName, reader.TokenType);
            Assert.AreEqual("AboutMe", reader.Value);
            Assert.AreEqual(typeof(string), reader.ValueType);

            Assert.IsTrue(reader.Read());
            Assert.AreEqual(JsonToken.String, reader.TokenType);
            Assert.AreEqual("<p>I'm the Director for Research and Development for <a href=\"http://www.prophoenix.com\" rel=\"nofollow\">ProPhoenix</a>, a public safety software company.  This position allows me to investigate new and existing technologies and incorporate them into our product line, with the end goal being to help public safety agencies to do their jobs more effeciently and safely.</p>\r\n\r\n<p>I'm an advocate for PowerShell, as I believe it encourages administrative best practices and allows developers to provide additional access to their applications, without needing to explicity write code for each administrative feature.  Part of my advocacy for PowerShell includes <a href=\"http://blog.usepowershell.com\" rel=\"nofollow\">my blog</a>, appearances on various podcasts, and acting as a Community Director for <a href=\"http://powershellcommunity.org\" rel=\"nofollow\">PowerShellCommunity.Org</a></p>\r\n\r\n<p>I’m also a co-host of Mind of Root (a weekly audio podcast about systems administration, tech news, and topics).</p>\r\n", reader.Value);
            Assert.AreEqual(typeof(string), reader.ValueType);

            Assert.IsTrue(reader.Read());
            Assert.AreEqual(JsonToken.PropertyName, reader.TokenType);
            Assert.AreEqual("WebsiteUrl", reader.Value);
            Assert.AreEqual(typeof(string), reader.ValueType);

            Assert.IsTrue(reader.Read());
            Assert.AreEqual(JsonToken.String, reader.TokenType);
            Assert.AreEqual("http://blog.usepowershell.com", reader.Value);
            Assert.AreEqual(typeof(string), reader.ValueType);

            Assert.IsTrue(reader.Read());
            Assert.AreEqual(JsonToken.EndObject, reader.TokenType);

            Assert.IsFalse(reader.Read());
            Assert.AreEqual(JsonToken.None, reader.TokenType);
        }
开发者ID:j2jensen,项目名称:ravendb,代码行数:45,代码来源:BsonReaderTests.cs

示例15: WriteToBuffer

        private void WriteToBuffer(Stream bufferedStream, out long bytesWritten)
        {
            using (var gzip = new GZipStream(bufferedStream, CompressionMode.Compress, leaveOpen: true))
            using (var stream = new CountingStream(gzip))
            {
                var binaryWriter = new BinaryWriter(stream);
                binaryWriter.Write(1);
                var bsonWriter = new BsonWriter(binaryWriter)
                {
                    DateTimeKindHandling = DateTimeKind.Unspecified
                };

                bsonWriter.WriteStartObject();

                bsonWriter.WritePropertyName(String.Empty);
                bsonWriter.WriteValue("ABCDEFG");

                bsonWriter.WriteEndObject();

                bsonWriter.Flush();
                binaryWriter.Flush();
                stream.Flush();
                bytesWritten = stream.NumberOfWrittenBytes;
            }
        }
开发者ID:j2jensen,项目名称:ravendb,代码行数:25,代码来源:RavenDB_3276.cs


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