Exemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="propertyDescriptors"></param>
        /// <param name="obj"></param>
        /// <returns></returns>
        public XmlDocument Serialize(DbQueryPropertyDescriptors propertyDescriptors, object obj)
        {
            var _document = new XmlDocument();

            if (null != obj)
            {
                using (var _stringWriter = new StringWriter())
                    using (var _xmlTextWriter = new XmlTextWriter(_stringWriter))
                    {
                        _xmlTextWriter.WriteStartElement(propertyDescriptors.DeclaringDescriptor.Name);

                        Serialize(_xmlTextWriter, propertyDescriptors, obj);

                        _xmlTextWriter.WriteEndElement();

                        _document.LoadXml(_stringWriter.ToString());

                        _xmlTextWriter.Flush();
                        _xmlTextWriter.Close();
                        _xmlTextWriter.Dispose();

                        _stringWriter.Flush();
                        _stringWriter.Close();
                        _stringWriter.Dispose();
                    }
            }

            return(_document);
        }
Exemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="propertyMemberDescriptors"></param>
        /// <returns></returns>
        public IDbQueryPropertyValidator CreateDbQueryPropertyValidator(DbQueryPropertyDescriptors propertyMemberDescriptors)
        {
            var _propertyValidator = new DbQueryPropertyValidator(this, propertyMemberDescriptors);

            _propertyValidator.Failed    += new DbQueryFailedEventHandler(_OnFailed);
            _propertyValidator.Validated += new DbQueryValidatedEventHandler(_OnValidated);

            return(_propertyValidator);
        }
Exemplo n.º 3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="writer"></param>
        /// <param name="propertyDescriptors"></param>
        /// <param name="obj"></param>
        protected void SerializeValueTypeData(XmlTextWriter writer, DbQueryPropertyDescriptors propertyDescriptors, object obj)
        {
            foreach (var _propertyDescriptor in propertyDescriptors)
            {
                if (!_propertyDescriptor.IgnoreXmlDataMember)
                {
                    if (IsExceptionalType(_propertyDescriptor))
                    {
                        var _propertyValue = _propertyDescriptor.GetValue(obj);

                        if (null != _propertyValue)
                        {
                            if (_propertyValue is IValueSerializable)
                            {
                                var _serializer = (_propertyValue as IValueSerializable);
                                var _serialized = _serializer.Serialize();

                                if (!ObjectUtils.IsNullOrDefault(_serialized))
                                {
                                    writer.WriteStartElement(_propertyDescriptor.GetName(true));
                                    writer.WriteValue(_serialized);
                                    writer.WriteEndElement();
                                }
                            }
                            else
                            {
                                var _valueDescriptor = OperationContext.DescriptorManager.GetDescriptor(_propertyValue);

                                writer.WriteStartElement(_propertyDescriptor.GetName(true));

                                Serialize(writer, _valueDescriptor.PropertyDescriptors, _propertyValue);

                                writer.WriteEndElement();
                            }
                        }
                    }
                    else
                    {
                        var _propertyName  = _propertyDescriptor.GetName(true);
                        var _propertyValue = _propertyDescriptor.GetValue(obj);

                        if (!ObjectUtils.IsNullOrDefault(_propertyValue))
                        {
                            if (!IsSupportedType(_propertyDescriptor))
                            {
                                _propertyValue = _propertyValue.ToString();
                            }

                            writer.WriteStartElement(_propertyName);
                            writer.WriteValue(_propertyValue);
                            writer.WriteEndElement();
                        }
                    }
                }
            }
        }
Exemplo n.º 4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="textWrite"></param>
        /// <param name="propertyDescriptors"></param>
        /// <param name="obj"></param>
        public void Serialize(XmlTextWriter writer, DbQueryPropertyDescriptors propertyDescriptors, object obj)
        {
            if (null != obj)
            {
                if (ObjectUtils.IsListType(obj))
                {
                    SerializeListTypeData(writer, propertyDescriptors, obj as IList);
                    return;
                }

                SerializeValueTypeData(writer, propertyDescriptors, obj);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="reader"></param>
        /// <param name="propertyDescriptors"></param>
        /// <param name="destination"></param>
        /// <returns></returns>
        public void Deserialize(XmlNodeReader reader, DbQueryPropertyDescriptors propertyDescriptors, object destination)
        {
            while (reader.Read())
            {
                if (CanDeserialize(reader))
                {
                    if (!reader.Name.Equals(ITEMWRAPPER_NODENAME, StringComparison.CurrentCultureIgnoreCase))
                    {
                        DeserializeValueTypeData(reader, propertyDescriptors, destination);
                        continue;
                    }

                    DeserializeListItemTypeData(reader, destination as IList);
                }
            }
        }
Exemplo n.º 6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="destination"></param>
        /// <param name="source"></param>
        /// <param name="propertyDescriptors"></param>
        protected virtual void Map(object destination, IDbQueryResult source, DbQueryPropertyDescriptors propertyDescriptors)
        {
            foreach (var _propertyDescriptor in propertyDescriptors)
            {
                if (_propertyDescriptor.IsMappable && !_propertyDescriptor.IsReadOnly)
                {
                    if (!IsExceptionalType(_propertyDescriptor))
                    {
                        MapValueTypeData(destination, source, _propertyDescriptor);
                    }
                    else
                    {
                        if (_propertyDescriptor.DbType.Equals(SqlDbType.Xml))
                        {
                            MapXmlTypeData(destination, source, _propertyDescriptor);
                        }
                        else
                        {
                            var _destination = _propertyDescriptor.GetValue(destination)
                                               ?? ObjectUtils.CreateInstanceOf(_propertyDescriptor.RetrunType);

                            if (_destination is IValueSerializable)
                            {
                                var _originName   = _propertyDescriptor.GetName(false);
                                var _serializer   = (_destination as IValueSerializable);
                                var _deserialized = _serializer.Deserialize(source[_propertyDescriptor.Prefix, _originName]);

                                if (!ObjectUtils.IsNullOrDefault(_deserialized))
                                {
                                    _propertyDescriptor.SetValue(destination, _deserialized);
                                }
                            }
                            else
                            {
                                HandleReferenceTypeData(_destination, source);

                                _propertyDescriptor.SetValue(destination, _destination);
                            }
                        }
                    }
                }
            }

            MapListTypeData(destination as IList, source);
        }
Exemplo n.º 7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="source"></param>
        /// <param name="propertyDescriptors"></param>
        /// <param name="destination"></param>
        /// <returns></returns>
        public object Deserialize(XmlDocument source, DbQueryPropertyDescriptors propertyDescriptors, object destination)
        {
            if (null != source && null != destination)
            {
                using (var _reader = new XmlNodeReader(source.FirstChild))
                {
                    //Fisrt node should be skipped.
                    _reader.Skip();

                    Deserialize(_reader, propertyDescriptors, destination);

                    _reader.Close();
                    _reader.Dispose();
                }

                return(destination);
            }

            return(null);
        }
Exemplo n.º 8
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="writer"></param>
        /// <param name="propertyDescriptors"></param>
        /// <param name="obj"></param>
        protected void SerializeListTypeData(XmlTextWriter writer, DbQueryPropertyDescriptors propertyDescriptors, IList obj)
        {
            if (null != obj)
            {
                SerializeValueTypeData(writer, propertyDescriptors, obj);

                writer.WriteStartElement(ITEMWRAPPER_NODENAME);

                foreach (var _item in obj)
                {
                    var _itemDescriptor = OperationContext.DescriptorManager.GetDescriptor(_item);

                    writer.WriteStartElement(_itemDescriptor.Name);

                    Serialize(writer, _itemDescriptor.PropertyDescriptors, _item);

                    writer.WriteEndElement();
                }

                writer.WriteEndElement();
            }
        }
Exemplo n.º 9
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="reader"></param>
        /// <param name="propertyDescriptors"></param>
        /// <param name="destination"></param>
        protected void DeserializeValueTypeData(XmlNodeReader reader, DbQueryPropertyDescriptors propertyDescriptors, object destination)
        {
            var _propertyDescriptor = propertyDescriptors.GetDescriptorByPropertyName(reader.Name);

            if (CanDeserialize(reader) && CanDeserialize(_propertyDescriptor))
            {
                if (IsExceptionalType(_propertyDescriptor))
                {
                    if (typeof(IValueSerializable).IsAssignableFrom(_propertyDescriptor.RetrunType))
                    {
                        reader.Read();

                        if (reader.NodeType.Equals(XmlNodeType.Text) && reader.HasValue)
                        {
                            var _destination  = _propertyDescriptor.GetValue(destination) ?? ObjectUtils.CreateInstanceOf(_propertyDescriptor.RetrunType);
                            var _serializer   = (_destination as IValueSerializable);
                            var _deserialized = _serializer.Deserialize(reader.Value);

                            if (!ObjectUtils.IsNullOrDefault(_deserialized))
                            {
                                _propertyDescriptor.SetValue(destination, _deserialized);
                            }
                        }

                        reader.Read();
                    }
                    else
                    {
                        DeserializeReferenceTypeData(reader, _propertyDescriptor, destination);
                    }

                    return;
                }

                DeserializeValueTypeData(reader, _propertyDescriptor, destination);
            }
        }
Exemplo n.º 10
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="operatingSession"></param>
 /// <param name="memberDescriptors"></param>
 public DbQueryResultMapper(DbQueryOperatingSession operatingSession, DbQueryPropertyDescriptors memberDescriptors)
     : base(operatingSession)
 {
     _propertyDescriptors = memberDescriptors;
 }
Exemplo n.º 11
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="propertyMemberDescriptors"></param>
 /// <returns></returns>
 public IDbQueryResultMapper CreateDbQueryResultMapper(DbQueryPropertyDescriptors propertyMemberDescriptors)
 {
     return(new DbQueryResultMapper(this, propertyMemberDescriptors));
 }
Exemplo n.º 12
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="propertyMemberDescriptors"></param>
 /// <param name="isInChild"></param>
 /// <returns></returns>
 public IDbQueryParameterMapper CreateDbQueryParameterMapper(DbQueryPropertyDescriptors propertyMemberDescriptors, bool isInChild)
 {
     return(new DbQueryParameterMapper(this, propertyMemberDescriptors, isInChild));
 }
Exemplo n.º 13
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="operationSession"></param>
 /// <param name="memberDescriptors"></param>
 /// <param name="isInChild"></param>
 public DbQueryParameterMapper(DbQueryOperatingSession operationSession, DbQueryPropertyDescriptors memberDescriptors, bool isInChild)
     : this(operationSession, memberDescriptors)
 {
     _isInChild = isInChild;
 }
Exemplo n.º 14
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="destination"></param>
        /// <param name="source"></param>
        /// <param name="propertyDescriptors"></param>
        protected virtual void Map(IDbQueryParameterizable destination, object source, DbQueryPropertyDescriptors propertyDescriptors)
        {
            foreach (var _propertyDescriptor in propertyDescriptors)
            {
                if (!IsExceptionalType(_propertyDescriptor))
                {
                    MapValueTypeData(destination, source, _propertyDescriptor);
                }
                else
                {
                    if (_propertyDescriptor.DbType.Equals(SqlDbType.Xml))
                    {
                        MapXmlTypeData(destination, source, _propertyDescriptor);
                    }
                    else
                    {
                        var _source = _propertyDescriptor.GetValue(source)
                                      ?? ObjectUtils.CreateInstanceOf(_propertyDescriptor.RetrunType);

                        if (_source is IValueSerializable)
                        {
                            var _parameters = CreateParameters(_propertyDescriptor);

                            foreach (var _parameter in _parameters)
                            {
                                if (_parameter.Direction.Equals(ParameterDirection.Input) ||
                                    _parameter.Direction.Equals(ParameterDirection.InputOutput))
                                {
                                    var _serializer = (_source as IValueSerializable);
                                    var _serialized = _serializer.Serialize();

                                    if (!ObjectUtils.IsNullOrDefault(_serialized))
                                    {
                                        _parameter.Value = _serialized;

                                        destination.AddParameter(_parameter);
                                    }

                                    continue;
                                }

                                destination.AddParameter(_parameter);
                            }
                        }
                        else
                        {
                            MapReferenceTypeData(destination, _source, _propertyDescriptor);
                        }
                    }
                }
            }
        }
Exemplo n.º 15
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="operatingSession"></param>
 /// <param name="propertyDescriptors"></param>
 public DbQueryPropertyValidator(DbQueryOperatingSession operatingSession, DbQueryPropertyDescriptors propertyDescriptors)
     : base(operatingSession)
 {
     _propertyDescriptors = propertyDescriptors;
 }