protected Document Deserialize(string base64, BsonReaderSettings settings)
 {
     using(var mem = new MemoryStream(Convert.FromBase64String(base64)))
     {
         var reader = new BsonReader(mem, settings);
         return (Document)reader.ReadObject();
     }
 }
Beispiel #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BsonReader"/> class.
 /// </summary>
 /// <param name="stream">The stream.</param>
 /// <param name="settings">The settings.</param>
 public BsonReader(Stream stream, BsonReaderSettings settings)
 {
     if(settings == null)
         throw new ArgumentNullException("settings");
     
     _builder = settings.Builder;
     _readLocalTime = settings.ReadLocalTime;
     Position = 0;
     _stream = stream;
     _reader = new BinaryReader(_stream);
 }
Beispiel #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BsonReader"/> class.
        /// </summary>
        /// <param name="stream">The stream.</param>
        /// <param name="settings">The settings.</param>
        public BsonReader(Stream stream, BsonReaderSettings settings)
        {
            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }

            _builder       = settings.Builder;
            _readLocalTime = settings.ReadLocalTime;
            Position       = 0;
            _stream        = stream;
            _reader        = new BinaryReader(_stream);
        }
        public void TestReadUtcTimeToLocalTime()
        {
            var settings = new BsonReaderSettings {ReadLocalTime = true};

            var document = Deserialize("EwAAAAl0aW1lAADJU+klAQAAAA==", settings);

            var localtzoffset =TimeZoneInfo.Local.BaseUtcOffset.Hours - 1; //gmt offset the local date was saved in along with the local offset.

            var dateTime = new DateTime(2010, 1, 1, 11, 0, 0, DateTimeKind.Local).AddHours(localtzoffset);
            Assert.AreEqual(dateTime, document["time"]);
        }