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()); } }
/// <summary> /// Initializes a new instance of the <see cref="ReplyMessage<T>"/> class. /// </summary> /// <param name="readerSettings">The reader settings.</param> public ReplyMessage(BsonReaderSettings readerSettings) { if (readerSettings == null) { throw new ArgumentNullException("readerSettings"); } _readerSettings = readerSettings; }
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"]); }
/// <summary> /// Sends the two way message core. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="message">The message.</param> /// <param name="readerSettings">The reader settings.</param> /// <returns></returns> internal ReplyMessage <T> SendTwoWayMessageCore <T>(IRequestMessage message, BsonReaderSettings readerSettings) where T : class { EnsureOpenConnection(); try { var reply = new ReplyMessage <T>(readerSettings); lock (_connection) { message.Write(_connection.GetStream()); reply.Read(_connection.GetStream()); } return(reply); } catch (IOException) { ReplaceInvalidConnection(); throw; } }
/// <summary> /// Used for sending a message that gets a reply such as a query. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="message">The message.</param> /// <param name="readerSettings">The reader settings.</param> /// <param name="database">The database.</param> /// <returns></returns> /// <exception cref="IOException">A reconnect will be issued but it is up to the caller to handle the error.</exception> public ReplyMessage <T> SendTwoWayMessage <T>(IRequestMessage message, BsonReaderSettings readerSettings, string database) where T : class { AuthenticateIfRequired(database); return(SendTwoWayMessageCore <T>(message, readerSettings)); }