Esempio n. 1
0
 // public methods
 /// <summary>
 /// Deserializes a value.
 /// </summary>
 /// <param name="context">The deserialization context.</param>
 /// <param name="args">The deserialization args.</param>
 /// <returns>A deserialized value.</returns>
 public virtual TValue Deserialize(BsonDeserializationContext context, BsonDeserializationArgs args)
 {
     throw CreateCannotBeDeserializedException();
 }
Esempio n. 2
0
        // protected methods
        /// <summary>
        /// Deserializes a value.
        /// </summary>
        /// <param name="context">The deserialization context.</param>
        /// <param name="args">The deserialization args.</param>
        /// <returns>An object.</returns>
        protected override BsonRegularExpression DeserializeValue(BsonDeserializationContext context, BsonDeserializationArgs args)
        {
            var bsonReader = context.Reader;

            return(bsonReader.ReadRegularExpression());
        }
Esempio n. 3
0
 /// <summary>
 /// Deserialize a Lst<A>
 /// </summary>
 /// <param name="context"></param>
 /// <param name="args"></param>
 /// <returns></returns>
 public override A Deserialize(BsonDeserializationContext context, BsonDeserializationArgs args)
 => CreateFromValues(EnumerateValues(context, args));
        public override Type Deserialize(BsonDeserializationContext context, BsonDeserializationArgs args)
        {
            var value = context.Reader.ReadString();

            return(Type.GetType(value));
        }
Esempio n. 5
0
            protected override InsertRequest DeserializeValue(BsonDeserializationContext context, BsonDeserializationArgs args)
            {
                var document = BsonDocumentSerializer.Instance.Deserialize(context, args);

                return(new InsertRequest(document));
            }
        // protected methods
        /// <summary>
        /// Deserializes a value.
        /// </summary>
        /// <param name="context">The deserialization context.</param>
        /// <param name="args">The deserialization args.</param>
        /// <returns>The value.</returns>
        protected override GeoJsonGeometryCollection <TCoordinates> DeserializeValue(BsonDeserializationContext context, BsonDeserializationArgs args)
        {
            var geoJsonObjectArgs = new GeoJsonObjectArgs <TCoordinates>();
            List <GeoJsonGeometry <TCoordinates> > geometries = null;

            _helper.DeserializeMembers(context, (elementName, flag) =>
            {
                switch (flag)
                {
                case Flags.Geometries: geometries = DeserializeGeometries(context); break;

                default: _helper.DeserializeBaseMember(context, elementName, flag, geoJsonObjectArgs); break;
                }
            });

            return(new GeoJsonGeometryCollection <TCoordinates>(geoJsonObjectArgs, geometries));
        }
        // protected methods
        /// <summary>
        /// Deserializes a value.
        /// </summary>
        /// <param name="context">The deserialization context.</param>
        /// <param name="args">The deserialization args.</param>
        /// <returns>The value.</returns>
        protected override GeoJsonMultiPolygonCoordinates <TCoordinates> DeserializeValue(BsonDeserializationContext context, BsonDeserializationArgs args)
        {
            var bsonReader = context.Reader;
            var polygons   = new List <GeoJsonPolygonCoordinates <TCoordinates> >();

            bsonReader.ReadStartArray();
            while (bsonReader.ReadBsonType() != BsonType.EndOfDocument)
            {
                var polygon = _polygonCoordinatesSerializer.Deserialize(context);
                polygons.Add(polygon);
            }
            bsonReader.ReadEndArray();

            return(new GeoJsonMultiPolygonCoordinates <TCoordinates>(polygons));
        }
Esempio n. 8
0
            protected override DependencyValueStorage DeserializeValue(BsonDeserializationContext context, BsonDeserializationArgs args)
            {
                var dict   = new Dictionary <DependencyProperty, SortedList <float, IEffectiveValue> >();
                var reader = context.Reader;

                reader.ReadStartDocument();

                while (reader.ReadBsonType() != BsonType.EndOfDocument)
                {
                    DeserializeValues(context, dict);
                }

                reader.ReadEndDocument();
                return(new DependencyValueStorage(dict));
            }
Esempio n. 9
0
        public override Instant Deserialize(BsonDeserializationContext context, BsonDeserializationArgs args)
        {
            var value = context.Reader.ReadDateTime();

            return(Instant.FromUnixTimeMilliseconds(value));
        }
 object IBsonSerializer.Deserialize(BsonDeserializationContext context, BsonDeserializationArgs args)
 {
     throw new NotSupportedException();
 }
Esempio n. 11
0
 /// <summary>
 /// Deserialises a value, first reading the <see cref="Type"/> information from the provide <paramref name="context"/>.
 /// </summary>
 /// <param name="context">The deserialisation context.</param>
 /// <param name="args">The deserialisation arguments.</param>
 /// <returns>
 /// A deserialised value.
 /// </returns>
 public object Deserialize(BsonDeserializationContext context, BsonDeserializationArgs args)
 {
     return(((IBsonSerializer <Type>) this).Deserialize(context, args));
 }
 // public methods
 /// <inheritdoc />
 public TDocument Deserialize(BsonDeserializationContext context, BsonDeserializationArgs args)
 {
     throw new NotSupportedException();
 }
Esempio n. 13
0
 public object Deserialize(BsonDeserializationContext context, BsonDeserializationArgs args)
 {
     return(_context.DeserializeValue(context.Reader));
 }
Esempio n. 14
0
 object IBsonSerializer.Deserialize(BsonDeserializationContext context, BsonDeserializationArgs args)
 {
     return(Deserialize(context, args));
 }
Esempio n. 15
0
 public override IgnoredReply Deserialize(BsonDeserializationContext context, BsonDeserializationArgs args)
 {
     context.Reader.ReadStartDocument();
     while (context.Reader.ReadBsonType() != BsonType.EndOfDocument)
     {
         context.Reader.SkipName();
         context.Reader.SkipValue();
     }
     context.Reader.ReadEndDocument();
     return(IgnoredReply.Instance);
 }
Esempio n. 16
0
        // protected methods
        /// <summary>
        /// Deserializes a value.
        /// </summary>
        /// <param name="context">The deserialization context.</param>
        /// <param name="args">The deserialization args.</param>
        /// <returns>A deserialized value.</returns>
        protected override RawBsonDocument DeserializeValue(BsonDeserializationContext context, BsonDeserializationArgs args)
        {
            var bsonReader = context.Reader;
            var slice      = bsonReader.ReadRawBsonDocument();

            return(new RawBsonDocument(slice));
        }
        // protected methods
        /// <summary>
        /// Deserializes a value.
        /// </summary>
        /// <param name="context">The deserialization context.</param>
        /// <param name="args">The deserialization args.</param>
        /// <returns>The value.</returns>
        protected override GeoJsonMultiPolygon <TCoordinates> DeserializeValue(BsonDeserializationContext context, BsonDeserializationArgs args)
        {
            var geoJsonObjectArgs = new GeoJsonObjectArgs <TCoordinates>();
            GeoJsonMultiPolygonCoordinates <TCoordinates> coordinates = null;

            _helper.DeserializeMembers(context, (elementName, flag) =>
            {
                switch (flag)
                {
                case Flags.Coordinates: coordinates = DeserializeCoordinates(context); break;

                default: _helper.DeserializeBaseMember(context, elementName, flag, geoJsonObjectArgs); break;
                }
            });

            return(new GeoJsonMultiPolygon <TCoordinates>(geoJsonObjectArgs, coordinates));
        }
Esempio n. 18
0
 public override string Deserialize(BsonDeserializationContext context, BsonDeserializationArgs args)
 {
     return(context.Reader.ReadObjectId().ToString());
 }
Esempio n. 19
0
        // protected methods
        /// <summary>
        /// Deserializes a value.
        /// </summary>
        /// <param name="context">The deserialization context.</param>
        /// <param name="args">The deserialization args.</param>
        /// <returns>A deserialized value.</returns>
        protected override BsonDateTime DeserializeValue(BsonDeserializationContext context, BsonDeserializationArgs args)
        {
            var bsonReader = context.Reader;

            return(new BsonDateTime(bsonReader.ReadDateTime()));
        }
Esempio n. 20
0
        // public methods
        /// <summary>
        /// Deserializes a value.
        /// </summary>
        /// <param name="context">The deserialization context.</param>
        /// <param name="args">The deserialization args.</param>
        /// <returns>A deserialized value.</returns>
        protected override BsonValue DeserializeValue(BsonDeserializationContext context, BsonDeserializationArgs args)
        {
            var bsonReader = context.Reader;

            var bsonType = bsonReader.GetCurrentBsonType();

            switch (bsonType)
            {
            case BsonType.Array: return(BsonArraySerializer.Instance.Deserialize(context));

            case BsonType.Binary: return(BsonBinaryDataSerializer.Instance.Deserialize(context));

            case BsonType.Boolean: return(BsonBooleanSerializer.Instance.Deserialize(context));

            case BsonType.DateTime: return(BsonDateTimeSerializer.Instance.Deserialize(context));

            case BsonType.Decimal128: return(BsonDecimal128Serializer.Instance.Deserialize(context));

            case BsonType.Document: return(BsonDocumentSerializer.Instance.Deserialize(context));

            case BsonType.Double: return(BsonDoubleSerializer.Instance.Deserialize(context));

            case BsonType.Int32: return(BsonInt32Serializer.Instance.Deserialize(context));

            case BsonType.Int64: return(BsonInt64Serializer.Instance.Deserialize(context));

            case BsonType.JavaScript: return(BsonJavaScriptSerializer.Instance.Deserialize(context));

            case BsonType.JavaScriptWithScope: return(BsonJavaScriptWithScopeSerializer.Instance.Deserialize(context));

            case BsonType.MaxKey: return(BsonMaxKeySerializer.Instance.Deserialize(context));

            case BsonType.MinKey: return(BsonMinKeySerializer.Instance.Deserialize(context));

            case BsonType.Null: return(BsonNullSerializer.Instance.Deserialize(context));

            case BsonType.ObjectId: return(BsonObjectIdSerializer.Instance.Deserialize(context));

            case BsonType.RegularExpression: return(BsonRegularExpressionSerializer.Instance.Deserialize(context));

            case BsonType.String: return(BsonStringSerializer.Instance.Deserialize(context));

            case BsonType.Symbol: return(BsonSymbolSerializer.Instance.Deserialize(context));

            case BsonType.Timestamp: return(BsonTimestampSerializer.Instance.Deserialize(context));

            case BsonType.Undefined: return(BsonUndefinedSerializer.Instance.Deserialize(context));

            default:
                var message = string.Format("Invalid BsonType {0}.", bsonType);
                throw new BsonInternalException(message);
            }
        }
        // public methods
        /// <summary>
        /// Deserializes a value.
        /// </summary>
        /// <param name="context">The deserialization context.</param>
        /// <param name="args">The deserialization args.</param>
        /// <returns>A deserialized value.</returns>
        protected override string DeserializeValue(BsonDeserializationContext context, BsonDeserializationArgs args)
        {
            var bsonReader = context.Reader;

            var bsonType = bsonReader.GetCurrentBsonType();

            switch (bsonType)
            {
            case BsonType.ObjectId:
                if (_representation == BsonType.ObjectId)
                {
                    return(bsonReader.ReadObjectId().ToString());
                }
                else
                {
                    goto default;
                }

            case BsonType.String:
                return(bsonReader.ReadString());

            case BsonType.Symbol:
                return(bsonReader.ReadSymbol());

            default:
                throw CreateCannotDeserializeFromBsonTypeException(bsonType);
            }
        }
            public override AggregateResult Deserialize(BsonDeserializationContext context, BsonDeserializationArgs args)
            {
                var             reader = context.Reader;
                AggregateResult result = null;

                reader.ReadStartDocument();
                while (reader.ReadBsonType() != 0)
                {
                    var elementName = reader.ReadName();
                    if (elementName == "cursor")
                    {
                        var cursorDeserializer = new CursorDeserializer(_resultSerializer);
                        result = cursorDeserializer.Deserialize(context);
                    }
                    else if (elementName == "result")
                    {
                        var arraySerializer = new ArraySerializer <TResult>(_resultSerializer);
                        result         = new AggregateResult();
                        result.Results = arraySerializer.Deserialize(context);
                    }
                    else
                    {
                        reader.SkipValue();
                    }
                }
                reader.ReadEndDocument();
                return(result);
            }
        // protected methods
        /// <summary>
        /// Deserializes a value.
        /// </summary>
        /// <param name="context">The deserialization context.</param>
        /// <param name="args">The deserialization args.</param>
        /// <returns>A deserialized value.</returns>
        protected override LazyBsonArray DeserializeValue(BsonDeserializationContext context, BsonDeserializationArgs args)
        {
            var bsonReader = context.Reader;
            var slice      = bsonReader.ReadRawBsonArray();

            return(new LazyBsonArray(slice));
        }
            public override AggregateResult Deserialize(BsonDeserializationContext context, BsonDeserializationArgs args)
            {
                var reader = context.Reader;
                var result = new AggregateResult();

                reader.ReadStartDocument();
                while (reader.ReadBsonType() != 0)
                {
                    var elementName = reader.ReadName();
                    if (elementName == "id")
                    {
                        result.CursorId = new Int64Serializer().Deserialize(context);
                    }
                    else if (elementName == "firstBatch")
                    {
                        var arraySerializer = new ArraySerializer <TResult>(_resultSerializer);
                        result.Results = arraySerializer.Deserialize(context);
                    }
                    else
                    {
                        reader.SkipValue();
                    }
                }
                reader.ReadEndDocument();
                return(result);
            }
Esempio n. 25
0
        public override Guid Deserialize(BsonDeserializationContext context, BsonDeserializationArgs args)
        {
            string serializedValue = context.Reader.ReadString();

            return(Guid.Parse(serializedValue));
        }
Esempio n. 26
0
        public override DateTime Deserialize(BsonDeserializationContext context, BsonDeserializationArgs args)
        {
            var obj = base.Deserialize(context, args);

            return(new DateTime(obj.Ticks, DateTimeKind.Unspecified));
        }
        // public methods
        /// <summary>
        /// Deserializes a value.
        /// </summary>
        /// <param name="context">The deserialization context.</param>
        /// <param name="args">The deserialization args.</param>
        /// <returns>An object.</returns>
        public override KeyValuePair <TKey, TValue> Deserialize(BsonDeserializationContext context, BsonDeserializationArgs args)
        {
            var bsonReader = context.Reader;
            var bsonType   = bsonReader.GetCurrentBsonType();

            switch (bsonType)
            {
            case BsonType.Array:
                return(DeserializeArrayRepresentation(context));

            case BsonType.Document:
                return(DeserializeDocumentRepresentation(context));

            default:
                throw CreateCannotDeserializeFromBsonTypeException(bsonType);
            }
        }
        // public methods
        /// <summary>
        /// Deserializes a value.
        /// </summary>
        /// <param name="context">The deserialization context.</param>
        /// <param name="args">The deserialization args.</param>
        /// <returns>A deserialized value.</returns>
        protected override BsonDocument DeserializeValue(BsonDeserializationContext context, BsonDeserializationArgs args)
        {
            var bsonReader = context.Reader;

            bsonReader.ReadStartDocument();
            var document = new BsonDocument(allowDuplicateNames: context.AllowDuplicateElementNames);

            while (bsonReader.ReadBsonType() != BsonType.EndOfDocument)
            {
                var name  = bsonReader.ReadName();
                var value = BsonValueSerializer.Instance.Deserialize(context);
                document.Add(name, value);
            }
            bsonReader.ReadEndDocument();

            return(document);
        }
Esempio n. 29
0
 private static BsonDeserializationArgs GetItemDeserializationArgs(BsonDeserializationArgs args)
 => ArgumentHelper.GetSpecificDeserializationArgs(args);
Esempio n. 30
0
            public override BsonInt32 Deserialize(BsonDeserializationContext context, BsonDeserializationArgs args)
            {
                var    type = context.Reader.GetCurrentBsonType();
                var    dval = 0.0;
                String s;

                switch (type)
                {
                case BsonType.Int32:
                    return(context.Reader.ReadInt32());

                case BsonType.Int64:
                    dval = context.Reader.ReadInt64();
                    break;

                case BsonType.Double:
                    dval = context.Reader.ReadDouble();
                    break;

                case BsonType.Null:
                    context.Reader.ReadNull();
                    break;

                case BsonType.String:
                    s = context.Reader.ReadString();
                    try
                    {
                        dval = double.Parse(s);
                    }
                    catch (Exception)
                    {
                    }
                    break;

                case BsonType.ObjectId:
                    s = context.Reader.ReadObjectId().ToString();
                    try
                    {
                        dval = double.Parse(s);
                    }
                    catch (Exception)
                    {
                    }
                    break;

                case BsonType.JavaScript:
                    s = context.Reader.ReadJavaScript();
                    try
                    {
                        dval = double.Parse(s);
                    }
                    catch (Exception)
                    {
                    }
                    break;

                case BsonType.Decimal128:
                    dval = System.Convert.ToDouble(context.Reader.ReadDecimal128());
                    break;

                case BsonType.Boolean:
                    dval = System.Convert.ToDouble(context.Reader.ReadBoolean());
                    break;
                }
                return(System.Convert.ToInt32(dval));
            }