/// <summary>
        ///
        /// </summary>
        /// <param name="propertyDescriptor"></param>
        /// <returns></returns>
        protected virtual bool IsSupportedType(DbQueryPropertyDescriptor propertyDescriptor)
        {
            return
                (
                propertyDescriptor.RetrunType.Equals(typeof(bool)) ||
                propertyDescriptor.RetrunType.Equals(typeof(decimal)) ||
                propertyDescriptor.RetrunType.Equals(typeof(double)) ||
                propertyDescriptor.RetrunType.Equals(typeof(string)) ||
                propertyDescriptor.RetrunType.Equals(typeof(int)) ||
                propertyDescriptor.RetrunType.Equals(typeof(long)) ||
                propertyDescriptor.RetrunType.Equals(typeof(short)) ||
                propertyDescriptor.RetrunType.Equals(typeof(byte))

                || propertyDescriptor.RetrunType.Equals(typeof(DateTime)) ||
                propertyDescriptor.RetrunType.Equals(typeof(TimeSpan))

                || propertyDescriptor.RetrunType.Equals(typeof(sbyte)) ||
                propertyDescriptor.RetrunType.Equals(typeof(uint)) ||
                propertyDescriptor.RetrunType.Equals(typeof(ushort)) ||
                propertyDescriptor.RetrunType.Equals(typeof(ulong))

                || propertyDescriptor.RetrunType.Equals(typeof(byte[])) ||
                propertyDescriptor.RetrunType.Equals(typeof(string[]))

                || propertyDescriptor.RetrunType.Equals(typeof(Uri)) ||
                propertyDescriptor.RetrunType.Equals(typeof(Single))
                );
        }
Exemple #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="declaringPropertyDescriptor"></param>
        /// <returns></returns>
        public IgnoreChildPropertyDescriptors GetDescriptors(DbQueryPropertyDescriptor declaringPropertyDescriptor)
        {
            var _ignoreChildProperties = GetDescriptorsByQueryAction(declaringPropertyDescriptor.QueryAction)
                                         .Where(prop => prop.DeclaringQueryProperty.Name.Equals(declaringPropertyDescriptor.Name, StringComparison.CurrentCultureIgnoreCase));

            return(new IgnoreChildPropertyDescriptors(_ignoreChildProperties, DeclaringDescriptor));
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="reader"></param>
        /// <param name="propertyDescriptor"></param>
        /// <param name="destination"></param>
        protected void DeserializeReferenceTypeData(XmlNodeReader reader, DbQueryPropertyDescriptor propertyDescriptor, object destination)
        {
            if (CanDeserialize(reader) && CanDeserialize(propertyDescriptor))
            {
                if (ObjectUtils.IsListType(propertyDescriptor.RetrunType))
                {
                    var _destination     = (propertyDescriptor.GetValue(destination) as IList) ?? ObjectUtils.CreateInstanceOf <IList>(propertyDescriptor.RetrunType);
                    var _destiDescriptor = OperationContext.DescriptorManager.GetDescriptor(_destination);

                    Deserialize(reader, _destiDescriptor.PropertyDescriptors, _destination);

                    propertyDescriptor.SetValue(destination, _destination);
                }
                else
                {
                    var _parentName      = reader.Name;
                    var _destination     = propertyDescriptor.GetValue(destination) ?? ObjectUtils.CreateInstanceOf(propertyDescriptor.RetrunType);
                    var _destiDescriptor = OperationContext.DescriptorManager.GetDescriptor(_destination);

                    while (reader.Read())
                    {
                        if (!(reader.NodeType.Equals(XmlNodeType.EndElement) &&
                              _parentName.Equals(reader.Name, StringComparison.CurrentCultureIgnoreCase)))
                        {
                            DeserializeValueTypeData(reader, _destiDescriptor.PropertyDescriptors, _destination);
                            continue;
                        }

                        propertyDescriptor.SetValue(destination, _destination);
                        break;
                    }
                }
            }
        }
Exemple #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="destination"></param>
        /// <param name="source"></param>
        /// <param name="propertyDescriptor"></param>
        protected void MapXmlTypeData(object destination, IDbQueryResult source, DbQueryPropertyDescriptor propertyDescriptor)
        {
            var _propertyName  = propertyDescriptor.GetName(false);
            var _propertyValue = source[propertyDescriptor.Prefix, _propertyName];

            if (ObjectUtils.IsXmlType(_propertyValue))
            {
                var _destination = propertyDescriptor.GetValue(destination)
                                   ?? ObjectUtils.CreateInstanceOf(propertyDescriptor.RetrunType);

                var _serializer   = new DbQueryXmlSerializer(OperatingSession.OperationContext);
                var _descriptor   = OperatingSession.OperationContext.DescriptorManager.GetDescriptor(_destination);
                var _deserialized = _serializer.Deserialize(_propertyValue as XmlDocument, _descriptor.PropertyDescriptors, _destination);

                propertyDescriptor.SetValue(destination, _deserialized);
            }
            else if (propertyDescriptor.IsNullable)
            {
                var _destination = propertyDescriptor.GetValue(destination)
                                   ?? ObjectUtils.CreateInstanceOf(propertyDescriptor.RetrunType);

                HandleReferenceTypeData(_destination, source);

                propertyDescriptor.SetValue(destination, _destination);
            }
        }
Exemple #5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="propertyDescriptor"></param>
        /// <param name="queryAction"></param>
        internal DbQueryPropertyDescriptor(DbQueryPropertyDescriptor propertyDescriptor, DbQueryActions?queryAction)
            : base(propertyDescriptor.Member)
        {
            _queryProperty       = propertyDescriptor._queryProperty;
            _declaringDescriptor = propertyDescriptor._declaringDescriptor;

            _queryAction = queryAction;
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="propertyDescriptor"></param>
        /// <returns></returns>
        protected virtual bool IsExceptionalType(DbQueryPropertyDescriptor propertyDescriptor)
        {
            if (propertyDescriptor.RetrunType.IsPrimitive ||
                propertyDescriptor.RetrunType.Equals(typeof(string)))
            {
                return(false);
            }

            return(ObjectUtils.IsClassType(propertyDescriptor.RetrunType));
        }
Exemple #7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="propertyDescriptor"></param>
        /// <returns></returns>
        public IgnoreChildPropertyDescriptor GetDescriptor(DbQueryPropertyDescriptor propertyDescriptor)
        {
            foreach (var _property in this)
            {
                if (_property.PropertyName.Equals(propertyDescriptor.Name, StringComparison.CurrentCultureIgnoreCase))
                {
                    return(_property);
                }
            }

            return(null);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="attributeDescriptor"></param>
        /// <param name="declaringDescriptor"></param>
        /// <param name="declaringQueryProperty"></param>
        public IgnoreChildPropertyDescriptor(AttributeMemberDescriptor attributeDescriptor, IEntryDescriptor declaringDescriptor, DbQueryPropertyDescriptor declaringQueryProperty)
            : base(attributeDescriptor.Member)
        {
            _declaringDescriptor    = declaringDescriptor;
            _declaringQueryProperty = declaringQueryProperty;

            _ignoreChildProperty = attributeDescriptor.Member as IIgnoreChildProperty;

            _queryAction       = _ignoreChildProperty.QueryAction;
            _propertyName      = _ignoreChildProperty.PropertyName;
            _propertyDirection = _ignoreChildProperty.PropertyDirection;
        }
Exemple #9
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="propertyDescriptor"></param>
        /// <param name="declaringDescriptor"></param>
        /// <returns></returns>
        public static IgnoreChildPropertyDescriptors RetrieveMemberDescriptors(DbQueryPropertyDescriptor propertyDescriptor, IEntryDescriptor declaringDescriptor)
        {
            var _ignoreChildProperties = new ListCollection <IgnoreChildPropertyDescriptor>();
            var _attributeDescriptors  = propertyDescriptor.GetAttributeDescriptorsByAttributeType(typeof(IIgnoreChildProperty));

            foreach (var _attributeDescriptor in _attributeDescriptors)
            {
                _ignoreChildProperties.Add(new IgnoreChildPropertyDescriptor(_attributeDescriptor, declaringDescriptor, propertyDescriptor));
            }

            return(new IgnoreChildPropertyDescriptors(_ignoreChildProperties, declaringDescriptor));
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="reader"></param>
        /// <param name="propertyDescriptor"></param>
        /// <param name="destination"></param>
        protected void DeserializeValueTypeData(XmlNodeReader reader, DbQueryPropertyDescriptor propertyDescriptor, object destination)
        {
            if (CanDeserialize(reader) && CanDeserialize(propertyDescriptor))
            {
                reader.Read();

                if (reader.NodeType.Equals(XmlNodeType.Text) && reader.HasValue)
                {
                    var _value = _typeConverter.Convert(propertyDescriptor.RetrunType, reader.Value);

                    if (!ObjectUtils.IsNullOrDefault(_value))
                    {
                        propertyDescriptor.SetValue(destination, _value);
                    }
                }

                reader.Read();
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="propertyDescriptor"></param>
        /// <param name="source"></param>
        /// <returns></returns>
        protected virtual SqlParameter[] CreateParameters(DbQueryPropertyDescriptor propertyDescriptor)
        {
            var _parameters = new ListCollection <SqlParameter>();

            if (propertyDescriptor.HasInputDirection && propertyDescriptor.HasOutputDirection)
            {
                var _inputName  = propertyDescriptor.GetName(DbQueryPropertyDirections.Input);
                var _outputName = propertyDescriptor.GetName(DbQueryPropertyDirections.Output);

                if (_inputName.Equals(_outputName))
                {
                    _parameters.Add(CreateParameter(propertyDescriptor, _inputName, DbQueryPropertyDirections.InputOutput));
                }
                else
                {
                    _parameters.Add(CreateParameter(propertyDescriptor, _inputName, DbQueryPropertyDirections.Input));
                    _parameters.Add(CreateParameter(propertyDescriptor, _outputName, DbQueryPropertyDirections.Output));
                }
            }
            else if (propertyDescriptor.HasOutputDirection)
            {
                var _direction     = DbQueryPropertyDirections.Output;
                var _parameterName = propertyDescriptor.GetName(_direction);

                _parameters.Add(CreateParameter(propertyDescriptor, _parameterName, _direction));
            }
            else if (propertyDescriptor.HasInputDirection)
            {
                var _direction     = DbQueryPropertyDirections.Input;
                var _parameterName = propertyDescriptor.GetName(_direction);

                _parameters.Add(CreateParameter(propertyDescriptor, _parameterName, _direction));
            }

            return(_parameters.ToArray());
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="propertyDescriptor"></param>
        /// <param name="parameterName"></param>
        /// <param name="propertyDirection"></param>
        /// <returns></returns>
        protected virtual SqlParameter CreateParameter(DbQueryPropertyDescriptor propertyDescriptor, string parameterName, DbQueryPropertyDirections propertyDirection)
        {
            var _parameter = new SqlParameter();

            _parameter.ParameterName = AdoDotNetDbParameterHelpers.StringToParameterName(parameterName);
            _parameter.Direction     = AdoDotNetDbParameterHelpers.PropertyDirectionToParameterDirection(propertyDirection);
            _parameter.SqlDbType     = propertyDescriptor.DbType;
            _parameter.Size          = propertyDescriptor.Size;

            if (propertyDescriptor.DbType.Equals(SqlDbType.Decimal))
            {
                if (!ObjectUtils.IsNullOrDefault(propertyDescriptor.Scale))
                {
                    _parameter.Scale = propertyDescriptor.Scale;
                }

                if (!ObjectUtils.IsNullOrDefault(propertyDescriptor.Precision))
                {
                    _parameter.Precision = propertyDescriptor.Precision;
                }
            }

            return(_parameter);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="destination"></param>
        /// <param name="source"></param>
        /// <param name="propertyDescriptor"></param>
        protected void MapXmlTypeData(IDbQueryParameterizable destination, object source, DbQueryPropertyDescriptor propertyDescriptor)
        {
            var _parameters    = CreateParameters(propertyDescriptor);
            var _propertyValue = propertyDescriptor.GetValue(source);

            foreach (var _parameter in _parameters)
            {
                if (_parameter.Direction.Equals(ParameterDirection.Input) ||
                    _parameter.Direction.Equals(ParameterDirection.InputOutput))
                {
                    if (null != _propertyValue)
                    {
                        var _serializer = new DbQueryXmlSerializer(OperatingSession.OperationContext);
                        var _descriptor = OperatingSession.OperationContext.DescriptorManager.GetDescriptor(_propertyValue);
                        var _document   = _serializer.Serialize(_descriptor.PropertyDescriptors, _propertyValue);

                        if (_document.HasChildNodes)
                        {
                            _parameter.Value = _typeConverter.Convert(typeof(SqlXml), _document);

                            destination.AddParameter(_parameter);
                        }

                        continue;
                    }
                }

                destination.AddParameter(_parameter);
            }

            if (propertyDescriptor.IsNullable)
            {
                var _source = _propertyValue ?? ObjectUtils.CreateInstanceOf(propertyDescriptor.RetrunType);

                MapReferenceTypeData(destination, _source, propertyDescriptor);
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="destination"></param>
        /// <param name="source"></param>
        /// <param name="propertyDescriptor"></param>
        protected void MapReferenceTypeData(IDbQueryParameterizable destination, object source, DbQueryPropertyDescriptor propertyDescriptor)
        {
            var _sourceDescriptor = OperatingSession.OperationContext.DescriptorManager.GetDescriptor(source);
            var _ignoreProperties = propertyDescriptor.DeclaringDescriptor.IgnorePropertyDescriptors.GetDescriptors(propertyDescriptor);
            var _sourceProperties = _sourceDescriptor.PropertyDescriptors.GetDescriptors(propertyDescriptor.QueryAction, _ignoreProperties);

            if (!_sourceProperties.IsEmpty)
            {
                var _parameterMapper = OperatingSession.CreateDbQueryParameterMapper(_sourceProperties, true);

                _parameterMapper.Map(destination, source);
            }
        }
Exemple #15
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="destination"></param>
        /// <param name="source"></param>
        /// <param name="propertyDescriptor"></param>
        protected virtual void MapValueTypeData(object destination, IDbQueryResult source, DbQueryPropertyDescriptor propertyDescriptor)
        {
            var _propertyName  = propertyDescriptor.GetName(false);
            var _propertyValue = _typeConverter.Convert(propertyDescriptor.RetrunType, source[propertyDescriptor.Prefix, _propertyName]);

            if (ObjectUtils.IsXmlType(_propertyValue) || !ObjectUtils.IsNullOrDefault(_propertyValue))
            {
                propertyDescriptor.SetValue(destination, _propertyValue);
            }
            else
            {
                if (!propertyDescriptor.IsNullable && !propertyDescriptor.IsReadOnly && null != propertyDescriptor.DefaultValue)
                {
                    _propertyValue = propertyDescriptor.GetValue(destination);

                    if (ObjectUtils.IsNullOrDefault(_propertyValue))
                    {
                        var _defaultValue = _typeConverter.Convert(propertyDescriptor.RetrunType, propertyDescriptor.DefaultValue);

                        propertyDescriptor.SetValue(destination, _defaultValue);
                    }
                }
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="destination"></param>
        /// <param name="source"></param>
        /// <param name="propertyDescriptor"></param>
        protected void MapValueTypeData(IDbQueryParameterizable destination, object source, DbQueryPropertyDescriptor propertyDescriptor)
        {
            var _parameters = CreateParameters(propertyDescriptor);

            foreach (var _parameter in _parameters)
            {
                if (_parameter.Direction.Equals(ParameterDirection.Input) ||
                    _parameter.Direction.Equals(ParameterDirection.InputOutput))
                {
                    _parameter.Value = propertyDescriptor.GetValue(source);

                    if (ObjectUtils.IsNullOrDefault(_parameter.Value))
                    {
                        if (!IsInChild)
                        {
                            if (!propertyDescriptor.IsNullable && null != propertyDescriptor.DefaultValue)
                            {
                                _parameter.Value = propertyDescriptor.DefaultValue;

                                destination.AddParameter(_parameter);
                            }
                        }

                        continue;
                    }
                }

                destination.AddParameter(_parameter);
            }
        }
 /// <summary>
 ///
 /// </summary>
 /// <param name="propertyDescriptor"></param>
 /// <returns></returns>
 protected virtual bool CanDeserialize(DbQueryPropertyDescriptor propertyDescriptor)
 {
     return(null != propertyDescriptor);
 }