public void Serialize(BsonSerializationContext context, BsonSerializationArgs args, object value)
 {
     if (value == null)
     {
         context.Writer.WriteNull();
     }
     else
     {
         context.Writer.WriteString((string)value);
     }
 }
Ejemplo n.º 2
0
        public void Serialize(BsonSerializationContext context, BsonSerializationArgs args, object value)
        {
            BsonWriter bsonWriter = (BsonWriter)context.Writer;

            bsonWriter.WriteStartDocument();
            bsonWriter.WriteString(ID, this.Name);
            MemoryStream stream = new MemoryStream();
            new BinaryFormatter().Serialize(stream, this.Calendar);
            bsonWriter.WriteBinaryData(CONTENT_STREAM, new BsonBinaryData(stream.ToArray(), BsonBinarySubType.Binary));
            bsonWriter.WriteEndDocument();
        }
 // methods
 protected override void SerializeRequest(BsonSerializationContext context, WriteRequest request)
 {
     var deleteRequest = (DeleteRequest)request;
     var bsonWriter = (BsonBinaryWriter)context.Writer;
     bsonWriter.PushMaxDocumentSize(MaxDocumentSize);
     bsonWriter.WriteStartDocument();
     bsonWriter.WriteName("q");
     BsonSerializer.Serialize(bsonWriter, deleteRequest.Query);
     bsonWriter.WriteInt32("limit", deleteRequest.Limit);
     bsonWriter.WriteEndDocument();
     bsonWriter.PopMaxDocumentSize();
 }
Ejemplo n.º 4
0
        /// <summary>
        /// The Serialize function.
        /// </summary>
        /// <param name="context">The context parameter.</param>
        /// <param name="args">The arguments parameter.</param>
        /// <param name="value">The value parameter.</param>
        public override void Serialize(MongoDB.Bson.Serialization.BsonSerializationContext context, MongoDB.Bson.Serialization.BsonSerializationArgs args, List <ClientAddressDto> value)
        {
            context?.Writer.WriteStartArray();
            foreach (ClientAddressDto mvnt in value)
            {
                context.Writer.WriteStartDocument();
                context.Writer.WriteName("Street");
                context.Writer.WriteString(mvnt.Street);
                context.Writer.WriteName("Number");
                context.Writer.WriteString(mvnt.Number);
                context.Writer.WriteName("PostalCode");
                context.Writer.WriteString(mvnt.PostalCode);
                context.Writer.WriteEndDocument();
            }

            context.Writer.WriteEndArray();
        }
            // methods
            protected override void SerializeRequest(BsonSerializationContext context, WriteRequest request)
            {
                var deleteRequest = (DeleteRequest)request;
                Feature.Collation.ThrowIfNotSupported(ConnectionDescription.ServerVersion, deleteRequest.Collation);

                var bsonWriter = (BsonBinaryWriter)context.Writer;
                bsonWriter.PushMaxDocumentSize(ConnectionDescription.MaxDocumentSize);
                bsonWriter.WriteStartDocument();
                bsonWriter.WriteName("q");
                BsonSerializer.Serialize(bsonWriter, deleteRequest.Filter);
                bsonWriter.WriteInt32("limit", deleteRequest.Limit);
                if (deleteRequest.Collation != null)
                {
                    bsonWriter.WriteName("collation");
                    BsonDocumentSerializer.Instance.Serialize(context, deleteRequest.Collation.ToBsonDocument());
                }
                bsonWriter.WriteEndDocument();
                bsonWriter.PopMaxDocumentSize();
            }
        public void Serialize( BsonSerializationContext context, BsonSerializationArgs args, object value )
        {
            var dictionary = (DynamicDictionary)value;

            var bsonWriter = context.Writer;
            bsonWriter.WriteStartDocument();

            bsonWriter.WriteString( "_t", "DynamicDictionary" );

            if( dictionary != null )
            {
                foreach( var entry in dictionary )
                {
                    bsonWriter.WriteName( entry.Key.Replace( '.', '\x03' ) );
                    BsonSerializer.Serialize( bsonWriter, typeof( object ), entry.Value );
                }
            }

            bsonWriter.WriteEndDocument();
        }
            public void Serialize(BsonSerializationContext context, BsonSerializationArgs args, object value)
            {
                if (value == null)
                {
                    context.Writer.WriteNull();
                }
                else
                {
                    var stringValue = value.ToString();

                    if (string.IsNullOrWhiteSpace(stringValue))
                    {
                        context.Writer.WriteNull();
                    }
                    else
                    {
                        stringValue = string.Concat(char.ToLowerInvariant(stringValue[0]), stringValue.Substring(1));
                        context.Writer.WriteString(stringValue);
                    }
                }
            }
Ejemplo n.º 8
0
        /// <summary>
        /// Serializes a value.
        /// </summary>
        /// <param name="context">The serialization context.</param>
        /// <param name="args">The serialization args.</param>
        /// <param name="value">The object.</param>
        protected override void SerializeValue(BsonSerializationContext context, BsonSerializationArgs args, TClass value)
        {
            var backingDocument = ((BsonDocumentBackedClass)value).BackingDocument;

            BsonDocumentSerializer.Instance.Serialize(context, backingDocument);
        }
        /// <summary>
        /// Serializes a value.
        /// </summary>
        /// <typeparam name="TValue">The type that this serializer knows how to serialize.</typeparam>
        /// <param name="serializer">The serializer.</param>
        /// <param name="context">The serialization context.</param>
        /// <param name="value">The value.</param>
        public static void Serialize <TValue>(this IBsonSerializer <TValue> serializer, BsonSerializationContext context, TValue value)
        {
            var args = new BsonSerializationArgs {
                NominalType = serializer.ValueType
            };

            serializer.Serialize(context, args, value);
        }
Ejemplo n.º 10
0
 public void Serialize(BsonSerializationContext context, BsonSerializationArgs args, object value)
 {
     context.Writer.WriteString(value.ToString());
 }
            // methods
            protected override void SerializeRequest(BsonSerializationContext context, WriteRequest request)
            {
                var insertRequest = (InsertRequest)request;
                var document = insertRequest.Document;
                if (document == null)
                {
                    throw new ArgumentException("Batch contains one or more null documents.");
                }

                var serializer = insertRequest.Serializer;
                if (serializer == null)
                {
                    var actualType = document.GetType();
                    if (_cachedSerializerType != actualType)
                    {
                        _cachedSerializer = BsonSerializer.LookupSerializer(actualType);
                        _cachedSerializerType = actualType;
                    }
                    serializer = _cachedSerializer;
                }

                var bsonWriter = (BsonBinaryWriter)context.Writer;
                var savedCheckElementNames = bsonWriter.CheckElementNames;
                try
                {
                    bsonWriter.PushMaxDocumentSize(MaxDocumentSize);
                    bsonWriter.CheckElementNames = _checkElementNames;
                    var documentNominalType = serializer.ValueType;
                    var documentContext = context.CreateChild(documentNominalType);
                    serializer.Serialize(documentContext, document);
                }
                finally
                {
                    bsonWriter.PopMaxDocumentSize();
                    bsonWriter.CheckElementNames = savedCheckElementNames;
                }
            }
            protected override void SerializeRequest(BsonSerializationContext context, WriteRequest request)
            {
                var updateRequest = (UpdateRequest)request;
                Feature.Collation.ThrowIfNotSupported(ConnectionDescription.ServerVersion, updateRequest.Collation);

                var bsonWriter = (BsonBinaryWriter)context.Writer;
                bsonWriter.PushMaxDocumentSize(ConnectionDescription.MaxWireDocumentSize);
                try
                {
                    bsonWriter.WriteStartDocument();
                    bsonWriter.WriteName("q");
                    SerializeFilter(bsonWriter, updateRequest.Filter);
                    bsonWriter.WriteName("u");
                    SerializeUpdate(bsonWriter, updateRequest.Update, updateRequest.UpdateType);
                    if (updateRequest.IsMulti)
                    {
                        bsonWriter.WriteBoolean("multi", updateRequest.IsMulti);
                    }
                    if (updateRequest.IsUpsert)
                    {
                        bsonWriter.WriteBoolean("upsert", updateRequest.IsUpsert);
                    }
                    if (updateRequest.Collation != null)
                    {
                        bsonWriter.WriteName("collation");
                        BsonDocumentSerializer.Instance.Serialize(context, updateRequest.Collation.ToBsonDocument());
                    }
                    bsonWriter.WriteEndDocument();
                }
                finally
                {
                    bsonWriter.PopMaxDocumentSize();
                }
            }
 public void Serialize(BsonSerializationContext context, BsonSerializationArgs args, object value)
 {
     throw new NotImplementedException();
 }
            protected override void SerializeRequest(BsonSerializationContext context, WriteRequest request)
            {
                var updateRequest = (UpdateRequest)request;
                var bsonWriter = (BsonBinaryWriter)context.Writer;

                bsonWriter.PushMaxDocumentSize(MaxWireDocumentSize);
                try
                {
                    bsonWriter.WriteStartDocument();
                    bsonWriter.WriteName("q");
                    SerializeCriteria(bsonWriter, updateRequest.Criteria);
                    bsonWriter.WriteName("u");
                    SerializeUpdate(bsonWriter, updateRequest.Update);
                    if (updateRequest.IsMultiUpdate.HasValue)
                    {
                        bsonWriter.WriteBoolean("multi", updateRequest.IsMultiUpdate.Value);
                    }
                    if (updateRequest.IsUpsert.HasValue)
                    {
                        bsonWriter.WriteBoolean("upsert", updateRequest.IsUpsert.Value);
                    }
                    bsonWriter.WriteEndDocument();
                }
                finally
                {
                    bsonWriter.PopMaxDocumentSize();
                }
            }
Ejemplo n.º 15
0
        /// <summary>
        /// Serializes a value.
        /// </summary>
        /// <param name="context">The serialization context.</param>
        /// <param name="value">The object.</param>
        protected override void SerializeValue(BsonSerializationContext context, TClass value)
        {
            var backingDocument = ((BsonDocumentBackedClass)value).BackingDocument;

            context.SerializeWithChildContext(BsonDocumentSerializer.Instance, backingDocument);
        }
Ejemplo n.º 16
0
 private bool ShouldSerializeDiscriminator(BsonSerializationContext context)
 {
     return((context.NominalType != _classMap.ClassType || _classMap.DiscriminatorIsRequired || _classMap.HasRootClass) && !_classMap.IsAnonymous);
 }
Ejemplo n.º 17
0
 public void Serialize(BsonSerializationContext context, BsonSerializationArgs args, object value)
 {
     GenerateBsonValue(context.Writer, value as JToken);
 }
            // constructors
            internal Builder(BsonSerializationContext other, IBsonWriter writer)
            {
                if (writer == null)
                {
                    throw new ArgumentNullException("writer");
                }

                _writer = writer;
                if (other != null)
                {
                    _isDynamicType = other._isDynamicType;
                }
                else
                {
                    _isDynamicType = t =>
                        (BsonDefaults.DynamicArraySerializer != null && t == BsonDefaults.DynamicArraySerializer.ValueType) ||
                        (BsonDefaults.DynamicDocumentSerializer != null && t == BsonDefaults.DynamicDocumentSerializer.ValueType);
                }
            }
            // methods
            protected override void SerializeRequest(BsonSerializationContext context, WriteRequest request)
            {
                var insertRequest = (InsertRequest)request;
                var document = insertRequest.Document;

                var actualType = document.GetType();
                if (_cachedSerializerType != actualType)
                {
                    _cachedSerializer = BsonSerializer.LookupSerializer(actualType);
                    _cachedSerializerType = actualType;
                }

                var serializer = _cachedSerializer;

                var bsonWriter = (BsonBinaryWriter)context.Writer;
                bsonWriter.PushMaxDocumentSize(MaxDocumentSize);
                bsonWriter.PushElementNameValidator(_elementNameValidator);
                try
                {
                    serializer.Serialize(context, document);
                }
                finally
                {
                    bsonWriter.PopMaxDocumentSize();
                    bsonWriter.PopElementNameValidator();
                }
            }
Ejemplo n.º 20
0
 {                                                           // read most types as int but write to double
     public override void Serialize(MongoDB.Bson.Serialization.BsonSerializationContext context, MongoDB.Bson.Serialization.BsonSerializationArgs args, BsonInt32 ival)
     {
         context.Writer.WriteDouble(ival.ToDouble());
     }
 public void Serialize(BsonSerializationContext context, BsonSerializationArgs args, object value)
 {
     GrainReference gr = value as GrainReference;
     var str = gr != null ? gr.ToKeyString() : "";
     context.Writer.WriteString(str);
 }