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


C# Bson.BsonWriter类代码示例

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


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

示例1: WriteBson

        private void WriteBson(BsonWriter writer, Regex regex)
        {
            // Regular expression - The first cstring is the regex pattern, the second
            // is the regex options string. Options are identified by characters, which 
            // must be stored in alphabetical order. Valid options are 'i' for case 
            // insensitive matching, 'm' for multiline matching, 'x' for verbose mode, 
            // 'l' to make \w, \W, etc. locale dependent, 's' for dotall mode 
            // ('.' matches everything), and 'u' to make \w, \W, etc. match unicode.

            string options = null;

            if (HasFlag(regex.Options, RegexOptions.IgnoreCase))
                options += "i";

            if (HasFlag(regex.Options, RegexOptions.Multiline))
                options += "m";

            if (HasFlag(regex.Options, RegexOptions.Singleline))
                options += "s";

            options += "u";

            if (HasFlag(regex.Options, RegexOptions.ExplicitCapture))
                options += "x";

            writer.WriteRegex(regex.ToString(), options);
        }
开发者ID:GorelH,项目名称:ravendb,代码行数:27,代码来源:RegexConverter.cs

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

示例3: WriteSingleObject

    public void WriteSingleObject()
    {
      MemoryStream ms = new MemoryStream();
      BsonWriter writer = new BsonWriter(ms);

      writer.WriteStartObject();
      writer.WritePropertyName("Blah");
      writer.WriteValue(1);
      writer.WriteEndObject();

      string bson = MiscellaneousUtils.BytesToHex(ms.ToArray());
      Assert.AreEqual("0F-00-00-00-10-42-6C-61-68-00-01-00-00-00-00", bson);
    }
开发者ID:nberardi,项目名称:ravendb,代码行数:13,代码来源:BsonWriterTests.cs

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

示例5: SerializeToBson

    public void SerializeToBson()
    {
      Regex regex = new Regex("abc", RegexOptions.IgnoreCase | RegexOptions.CultureInvariant);

      MemoryStream ms = new MemoryStream();
      BsonWriter writer = new BsonWriter(ms);
      JsonSerializer serializer = new JsonSerializer();
      serializer.Converters.Add(new RegexConverter());

      serializer.Serialize(writer, new RegexTestClass { Regex = regex });

      string expected = "13-00-00-00-0B-52-65-67-65-78-00-61-62-63-00-69-75-00-00";
      string bson = MiscellaneousUtils.BytesToHex(ms.ToArray());

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

示例6: CloseOutput

    public void CloseOutput()
    {
      MemoryStream ms = new MemoryStream();
      BsonWriter writer = new BsonWriter(ms);

      Assert.IsTrue(ms.CanRead);
      writer.Close();
      Assert.IsFalse(ms.CanRead);

      ms = new MemoryStream();
      writer = new BsonWriter(ms) { CloseOutput = false };

      Assert.IsTrue(ms.CanRead);
      writer.Close();
      Assert.IsTrue(ms.CanRead);
    }
开发者ID:nberardi,项目名称:ravendb,代码行数:16,代码来源:BsonWriterTests.cs

示例7: WriteRegexPlusContent

    public void WriteRegexPlusContent()
    {
      MemoryStream ms = new MemoryStream();
      BsonWriter writer = new BsonWriter(ms);

      writer.WriteStartObject();
      writer.WritePropertyName("regex");
      writer.WriteRegex("abc", "i");
      writer.WritePropertyName("test");
      writer.WriteRegex(string.Empty, null);
      writer.WriteEndObject();

      byte[] expected = MiscellaneousUtils.HexToBytes("1A-00-00-00-0B-72-65-67-65-78-00-61-62-63-00-69-00-0B-74-65-73-74-00-00-00-00");

      CollectionAssert.AreEquivalent(expected, ms.ToArray());
    }
开发者ID:nberardi,项目名称:ravendb,代码行数:16,代码来源:BsonWriterTests.cs

示例8: WriteOidPlusContent

    public void WriteOidPlusContent()
    {
      MemoryStream ms = new MemoryStream();
      BsonWriter writer = new BsonWriter(ms);

      writer.WriteStartObject();
      writer.WritePropertyName("_id");
      writer.WriteObjectId(MiscellaneousUtils.HexToBytes("4ABBED9D1D8B0F0218000001"));
      writer.WritePropertyName("test");
      writer.WriteValue("1234£56");
      writer.WriteEndObject();

      byte[] expected = MiscellaneousUtils.HexToBytes("29000000075F6964004ABBED9D1D8B0F02180000010274657374000900000031323334C2A335360000");

      CollectionAssert.AreEquivalent(expected, ms.ToArray());
    }
开发者ID:nberardi,项目名称:ravendb,代码行数:16,代码来源:BsonWriterTests.cs

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

示例10: WriteValues

    public void WriteValues()
    {
      MemoryStream ms = new MemoryStream();
      BsonWriter writer = new BsonWriter(ms);

      writer.WriteStartArray();
      writer.WriteValue(long.MaxValue);
      writer.WriteValue((ulong)long.MaxValue);
      writer.WriteValue(int.MaxValue);
      writer.WriteValue((uint)int.MaxValue);
      writer.WriteValue(byte.MaxValue);
      writer.WriteValue(sbyte.MaxValue);
      writer.WriteValue('a');
      writer.WriteValue(decimal.MaxValue);
      writer.WriteValue(double.MaxValue);
      writer.WriteValue(float.MaxValue);
      writer.WriteValue(true);
      writer.WriteValue(new byte[] { 0, 1, 2, 3, 4 });
      writer.WriteValue(new DateTimeOffset(2000, 12, 29, 12, 30, 0, TimeSpan.Zero));
      writer.WriteValue(new DateTime(2000, 12, 29, 12, 30, 0, DateTimeKind.Utc));
      writer.WriteEnd();

      string bson = MiscellaneousUtils.BytesToHex(ms.ToArray());
      Assert.AreEqual("8C-00-00-00-12-30-00-FF-FF-FF-FF-FF-FF-FF-7F-12-31-00-FF-FF-FF-FF-FF-FF-FF-7F-10-32-00-FF-FF-FF-7F-10-33-00-FF-FF-FF-7F-10-34-00-FF-00-00-00-10-35-00-7F-00-00-00-02-36-00-02-00-00-00-61-00-01-37-00-00-00-00-00-00-00-F0-45-01-38-00-FF-FF-FF-FF-FF-FF-EF-7F-01-39-00-00-00-00-E0-FF-FF-EF-47-08-31-30-00-01-05-31-31-00-05-00-00-00-00-00-01-02-03-04-09-31-32-00-40-C5-E2-BA-E3-00-00-00-09-31-33-00-40-C5-E2-BA-E3-00-00-00-00", bson);
    }
开发者ID:nberardi,项目名称:ravendb,代码行数:25,代码来源:BsonWriterTests.cs

示例11: DateTimeZoneHandling

    public void DateTimeZoneHandling()
    {
      MemoryStream ms = new MemoryStream();
      JsonWriter writer = new BsonWriter(ms)
      {
        DateTimeZoneHandling = Json.DateTimeZoneHandling.Utc
      };

      writer.WriteStartArray();
      writer.WriteValue(new DateTime(2000, 1, 1, 1, 1, 1, DateTimeKind.Unspecified));
      writer.WriteEndArray();

      Assert.AreEqual("10-00-00-00-09-30-00-C8-88-07-6B-DC-00-00-00-00", (BitConverter.ToString(ms.ToArray())));
    }
开发者ID:nberardi,项目名称:ravendb,代码行数:14,代码来源:BsonWriterTests.cs

示例12: WriteDateTimes

    public void WriteDateTimes()
    {
      MemoryStream ms = new MemoryStream();
      BsonWriter writer = new BsonWriter(ms);
      writer.DateTimeKindHandling = DateTimeKind.Unspecified;

      writer.WriteStartArray();
      writer.WriteValue(new DateTime(2000, 10, 12, 20, 55, 0, DateTimeKind.Utc));
      writer.WriteValue(new DateTime(2000, 10, 12, 20, 55, 0, DateTimeKind.Local));
      writer.WriteValue(new DateTime(2000, 10, 12, 20, 55, 0, DateTimeKind.Unspecified));
      writer.WriteEndArray();

      ms.Seek(0, SeekOrigin.Begin);

      BsonReader reader = new BsonReader(ms);
      reader.ReadRootValueAsArray = true;
      reader.DateTimeKindHandling = DateTimeKind.Utc;

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

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.Date, reader.TokenType);
      Assert.AreEqual(new DateTime(2000, 10, 12, 20, 55, 0, DateTimeKind.Utc), reader.Value);

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.Date, reader.TokenType);
      Assert.AreEqual(new DateTime(2000, 10, 12, 20, 55, 0, DateTimeKind.Utc), reader.Value);

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.Date, reader.TokenType);
      Assert.AreEqual(new DateTime(2000, 10, 12, 20, 55, 0, DateTimeKind.Utc), reader.Value);

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

      Assert.IsFalse(reader.Read());
    }
开发者ID:nberardi,项目名称:ravendb,代码行数:38,代码来源:BsonWriterTests.cs

示例13: WriteEmptyStrings

    public void WriteEmptyStrings()
    {
      MemoryStream ms = new MemoryStream();
      BsonWriter writer = new BsonWriter(ms);

      writer.WriteStartObject();
      writer.WritePropertyName("");
      writer.WriteValue("");
      writer.WriteEndObject();

      string bson = MiscellaneousUtils.BytesToHex(ms.ToArray());
      Assert.AreEqual("0C-00-00-00-02-00-01-00-00-00-00-00", bson);
    }
开发者ID:nberardi,项目名称:ravendb,代码行数:13,代码来源:BsonWriterTests.cs

示例14: SerializeGoogleGeoCode

    public void SerializeGoogleGeoCode()
    {
      string json = @"{
  ""name"": ""1600 Amphitheatre Parkway, Mountain View, CA, USA"",
  ""Status"": {
    ""code"": 200,
    ""request"": ""geocode""
  },
  ""Placemark"": [
    {
      ""address"": ""1600 Amphitheatre Pkwy, Mountain View, CA 94043, USA"",
      ""AddressDetails"": {
        ""Country"": {
          ""CountryNameCode"": ""US"",
          ""AdministrativeArea"": {
            ""AdministrativeAreaName"": ""CA"",
            ""SubAdministrativeArea"": {
              ""SubAdministrativeAreaName"": ""Santa Clara"",
              ""Locality"": {
                ""LocalityName"": ""Mountain View"",
                ""Thoroughfare"": {
                  ""ThoroughfareName"": ""1600 Amphitheatre Pkwy""
                },
                ""PostalCode"": {
                  ""PostalCodeNumber"": ""94043""
                }
              }
            }
          }
        },
        ""Accuracy"": 8
      },
      ""Point"": {
        ""coordinates"": [-122.083739, 37.423021, 0]
      }
    }
  ]
}";

      GoogleMapGeocoderStructure jsonGoogleMapGeocoder = JsonConvert.DeserializeObject<GoogleMapGeocoderStructure>(json);

      MemoryStream ms = new MemoryStream();
      BsonWriter writer = new BsonWriter(ms);

      JsonSerializer serializer = new JsonSerializer();
      serializer.Serialize(writer, jsonGoogleMapGeocoder);

      ms.Seek(0, SeekOrigin.Begin);
      BsonReader reader = new BsonReader(ms);
      GoogleMapGeocoderStructure bsonGoogleMapGeocoder = (GoogleMapGeocoderStructure)serializer.Deserialize(reader, typeof (GoogleMapGeocoderStructure));

      Assert.IsNotNull(bsonGoogleMapGeocoder);
      Assert.AreEqual("1600 Amphitheatre Parkway, Mountain View, CA, USA", bsonGoogleMapGeocoder.Name);
      Assert.AreEqual("200", bsonGoogleMapGeocoder.Status.Code);
      Assert.AreEqual("geocode", bsonGoogleMapGeocoder.Status.Request);

      IList<Placemark> placemarks = bsonGoogleMapGeocoder.Placemark;
      Assert.IsNotNull(placemarks);
      Assert.AreEqual(1, placemarks.Count);

      Placemark placemark = placemarks[0];
      Assert.AreEqual("1600 Amphitheatre Pkwy, Mountain View, CA 94043, USA", placemark.Address);
      Assert.AreEqual(8, placemark.AddressDetails.Accuracy);
      Assert.AreEqual("US", placemark.AddressDetails.Country.CountryNameCode);
      Assert.AreEqual("CA", placemark.AddressDetails.Country.AdministrativeArea.AdministrativeAreaName);
      Assert.AreEqual("Santa Clara", placemark.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.SubAdministrativeAreaName);
      Assert.AreEqual("Mountain View", placemark.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.Locality.LocalityName);
      Assert.AreEqual("1600 Amphitheatre Pkwy", placemark.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.Locality.Thoroughfare.ThoroughfareName);
      Assert.AreEqual("94043", placemark.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.Locality.PostalCode.PostalCodeNumber);
      Assert.AreEqual(-122.083739m, placemark.Point.Coordinates[0]);
      Assert.AreEqual(37.423021m, placemark.Point.Coordinates[1]);
      Assert.AreEqual(0m, placemark.Point.Coordinates[2]);
    }
开发者ID:nberardi,项目名称:ravendb,代码行数:73,代码来源:BsonWriterTests.cs

示例15: WriteLargeStrings

    public void WriteLargeStrings()
    {
      MemoryStream ms = new MemoryStream();
      BsonWriter writer = new BsonWriter(ms);

      StringBuilder largeStringBuilder = new StringBuilder();
      for (int i = 0; i < 100; i++)
      {
        if (i > 0)
          largeStringBuilder.Append("-");

        largeStringBuilder.Append(i.ToString(CultureInfo.InvariantCulture));
      }
      string largeString = largeStringBuilder.ToString();

      writer.WriteStartObject();
      writer.WritePropertyName(largeString);
      writer.WriteValue(largeString);
      writer.WriteEndObject();

      string bson = MiscellaneousUtils.BytesToHex(ms.ToArray());
      Assert.AreEqual("4E-02-00-00-02-30-2D-31-2D-32-2D-33-2D-34-2D-35-2D-36-2D-37-2D-38-2D-39-2D-31-30-2D-31-31-2D-31-32-2D-31-33-2D-31-34-2D-31-35-2D-31-36-2D-31-37-2D-31-38-2D-31-39-2D-32-30-2D-32-31-2D-32-32-2D-32-33-2D-32-34-2D-32-35-2D-32-36-2D-32-37-2D-32-38-2D-32-39-2D-33-30-2D-33-31-2D-33-32-2D-33-33-2D-33-34-2D-33-35-2D-33-36-2D-33-37-2D-33-38-2D-33-39-2D-34-30-2D-34-31-2D-34-32-2D-34-33-2D-34-34-2D-34-35-2D-34-36-2D-34-37-2D-34-38-2D-34-39-2D-35-30-2D-35-31-2D-35-32-2D-35-33-2D-35-34-2D-35-35-2D-35-36-2D-35-37-2D-35-38-2D-35-39-2D-36-30-2D-36-31-2D-36-32-2D-36-33-2D-36-34-2D-36-35-2D-36-36-2D-36-37-2D-36-38-2D-36-39-2D-37-30-2D-37-31-2D-37-32-2D-37-33-2D-37-34-2D-37-35-2D-37-36-2D-37-37-2D-37-38-2D-37-39-2D-38-30-2D-38-31-2D-38-32-2D-38-33-2D-38-34-2D-38-35-2D-38-36-2D-38-37-2D-38-38-2D-38-39-2D-39-30-2D-39-31-2D-39-32-2D-39-33-2D-39-34-2D-39-35-2D-39-36-2D-39-37-2D-39-38-2D-39-39-00-22-01-00-00-30-2D-31-2D-32-2D-33-2D-34-2D-35-2D-36-2D-37-2D-38-2D-39-2D-31-30-2D-31-31-2D-31-32-2D-31-33-2D-31-34-2D-31-35-2D-31-36-2D-31-37-2D-31-38-2D-31-39-2D-32-30-2D-32-31-2D-32-32-2D-32-33-2D-32-34-2D-32-35-2D-32-36-2D-32-37-2D-32-38-2D-32-39-2D-33-30-2D-33-31-2D-33-32-2D-33-33-2D-33-34-2D-33-35-2D-33-36-2D-33-37-2D-33-38-2D-33-39-2D-34-30-2D-34-31-2D-34-32-2D-34-33-2D-34-34-2D-34-35-2D-34-36-2D-34-37-2D-34-38-2D-34-39-2D-35-30-2D-35-31-2D-35-32-2D-35-33-2D-35-34-2D-35-35-2D-35-36-2D-35-37-2D-35-38-2D-35-39-2D-36-30-2D-36-31-2D-36-32-2D-36-33-2D-36-34-2D-36-35-2D-36-36-2D-36-37-2D-36-38-2D-36-39-2D-37-30-2D-37-31-2D-37-32-2D-37-33-2D-37-34-2D-37-35-2D-37-36-2D-37-37-2D-37-38-2D-37-39-2D-38-30-2D-38-31-2D-38-32-2D-38-33-2D-38-34-2D-38-35-2D-38-36-2D-38-37-2D-38-38-2D-38-39-2D-39-30-2D-39-31-2D-39-32-2D-39-33-2D-39-34-2D-39-35-2D-39-36-2D-39-37-2D-39-38-2D-39-39-00-00", bson);
    }
开发者ID:nberardi,项目名称:ravendb,代码行数:23,代码来源:BsonWriterTests.cs


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