/// <summary> /// Writes a BSON DateTime to the writer. /// </summary> /// <param name="value">The DateTime value.</param> public override void WriteDateTime( DateTime value ) { if (disposed) { throw new ObjectDisposedException("BsonBinaryWriter"); } if (state != BsonWriterState.Value) { var message = string.Format("WriteDateTime cannot be called when State is: {0}", state); throw new InvalidOperationException(message); } if (value.Kind != DateTimeKind.Utc) { throw new ArgumentException("DateTime value must be in UTC"); } buffer.WriteByte((byte)BsonType.DateTime); WriteNameHelper(); long milliseconds = (long)Math.Floor((value.ToUniversalTime() - BsonConstants.UnixEpoch).TotalMilliseconds); buffer.WriteInt64(milliseconds); state = GetNextState(); }
// protected methods protected override void WriteBody(BsonBuffer buffer) { buffer.WriteInt32(0); // reserved buffer.WriteCString(new UTF8Encoding(false, true), _collectionFullName); buffer.WriteInt32(_numberToReturn); buffer.WriteInt64(_cursorId); }
// internal methods internal override void WriteBodyTo(BsonBuffer buffer) { buffer.WriteInt32(_cursorIds.Length); foreach (long cursorId in _cursorIds) { buffer.WriteInt64(cursorId); } }
/// <summary> /// Writes a BSON DateTime to the writer. /// </summary> /// <param name="value">The number of milliseconds since the Unix epoch.</param> public override void WriteDateTime(long value) { if (Disposed) { throw new ObjectDisposedException("BsonBinaryWriter"); } if (State != BsonWriterState.Value) { ThrowInvalidState("WriteDateTime", BsonWriterState.Value); } _buffer.WriteByte((byte)BsonType.DateTime); WriteNameHelper(); _buffer.WriteInt64(value); State = GetNextState(); }
// protected methods protected override void WriteBody(BsonBuffer buffer) { buffer.WriteInt32(0); // reserved buffer.WriteInt32(_cursorIds.Length); foreach (long cursorId in _cursorIds) { buffer.WriteInt64(cursorId); } }
/// <summary> /// Writes a BSON DateTime to the writer. /// </summary> /// <param name="value">The number of milliseconds since the Unix epoch.</param> public override void WriteDateTime( long value ) { if (disposed) { throw new ObjectDisposedException("BsonBinaryWriter"); } if (state != BsonWriterState.Value) { var message = string.Format("WriteDateTime cannot be called when State is: {0}", state); throw new InvalidOperationException(message); } buffer.WriteByte((byte)BsonType.DateTime); WriteNameHelper(); buffer.WriteInt64(value); state = GetNextState(); }
// internal methods internal override void WriteBodyTo(BsonBuffer buffer) { buffer.WriteInt64(_cursorId); }