Пример #1
0
        private bool ReadSimpleProperty(ISimpleProperty property, object entity)
        {
            if (property == null)
            {
                return(false);
            }
            string action = GetAttributeValue(this._reader, "action", "setvalue");

            this.DoSimplePropertyAction(action, property, entity);
            return(true);
        }
Пример #2
0
 public static IEnumerable <ISimpleProperty> GetSimpleProperties(this IDataEntityPropertyCollection properties, bool onlyDbProperty = true)
 {
     for (int i = 0; i < properties.Count; i++)
     {
         IDataEntityProperty metadata          = properties[i];
         ISimpleProperty     iteratorVariable0 = metadata as ISimpleProperty;
         if ((iteratorVariable0 != null) && (!onlyDbProperty || !metadata.IsDbIgnore()))
         {
             yield return(iteratorVariable0);
         }
     }
 }
Пример #3
0
        private int FindItemIndex(ICollectionProperty property, object entity, object item)
        {
            object          obj3;
            ISimpleProperty primaryKey = this._binder.GetDataEntityType(item).PrimaryKey;

            if (primaryKey == null)
            {
                return(-1);
            }
            object obj2 = primaryKey.GetValue(item);
            string oid  = (obj2 == null) ? "" : obj2.ToString();

            return(this.FindItemByOid(property, entity, oid, out obj3));
        }
Пример #4
0
        private int FindItemByOid(ICollectionProperty property, object entity, string oid, out object item)
        {
            if (string.IsNullOrEmpty(oid))
            {
                SerializationException.SerializationExceptionData data = new SerializationException.SerializationExceptionData
                {
                    CanIgnore = true
                };
                this.ThrowXmlException("??????", ResManager.LoadKDString("试图处理节点却没有指定oid", "014009000001746", SubSystemType.SL, new object[0]), data, null);
                item = null;
                return(-2);
            }
            ISimpleProperty primaryKey = property.CollectionItemPropertyType.PrimaryKey;

            if (primaryKey == null)
            {
                SerializationException.SerializationExceptionData data2 = new SerializationException.SerializationExceptionData
                {
                    CanIgnore = false
                };
                this.ThrowXmlException("??????", string.Format(ResManager.LoadKDString("需要处理的集合{0}其元素类型{1}没有定义主键。", "014009000001747", SubSystemType.SL, new object[0]), property.Name, property.CollectionItemPropertyType.Name), data2, null);
                item = null;
                return(-2);
            }
            object objB = this.ConvertFromString(primaryKey, entity, oid);
            IList  list = this.SafeGetList(property, entity);

            if (list == null)
            {
                item = null;
                return(-2);
            }
            for (int i = 0; i < list.Count; i++)
            {
                item = list[i];
                if ((item != null) && object.Equals(this._binder.GetDataEntityType(item).PrimaryKey.GetValue(item), objB))
                {
                    return(i);
                }
            }
            item = null;
            return(-1);
        }
Пример #5
0
        public static T GetPrimaryKeyValue <T>(this IDataEntityBase dataEntity, bool throwOnError = true)
        {
            if (dataEntity == null)
            {
                if (throwOnError)
                {
                    throw new ArgumentNullException("dataEntity");
                }
                return(default(T));
            }
            ISimpleProperty primaryKey = dataEntity.GetDataEntityType().PrimaryKey;

            if (primaryKey != null)
            {
                return((T)primaryKey.GetValue(dataEntity));
            }
            if (throwOnError)
            {
                throw new NotSupportedException(string.Format(ResManager.LoadKDString("实体类型{0}沒有定义主键,无法获取。", "014009000001732", SubSystemType.SL, new object[0]), dataEntity.GetDataEntityType().Name));
            }
            return(default(T));
        }
Пример #6
0
 private object ConvertFromString(ISimpleProperty property, object dataEntity, string str)
 {
     this._context.SetInstance(property, dataEntity);
     return(property.Converter.ConvertFromString(this._context, this._binder.Culture, str));
 }
Пример #7
0
        private void DoSimplePropertyAction(string action, ISimpleProperty property, object entity)
        {
            string str = action;

            if (str != null)
            {
                if (!(str == "setvalue"))
                {
                    if (str == "reset")
                    {
                        if (typeof(ILocaleValue).IsAssignableFrom(property.PropertyType))
                        {
                            ILocaleValue value2 = (ILocaleValue)property.GetValue(entity);
                            if (value2 == null)
                            {
                                property.ResetValue(entity);
                            }
                            else if (property is SimpleProperty)
                            {
                                int lCID = this._binder.Culture.LCID;
                                if (lCID != 0x804)
                                {
                                    value2[lCID] = value2[0x804];
                                }
                                else
                                {
                                    property.ResetValue(entity);
                                }
                            }
                        }
                        else
                        {
                            property.ResetValue(entity);
                        }
                        goto Label_01FC;
                    }
                    if (str == "setnull")
                    {
                        try
                        {
                            property.SetValue(entity, null);
                        }
                        catch (Exception exception2)
                        {
                            SerializationException.SerializationExceptionData data2 = new SerializationException.SerializationExceptionData
                            {
                                CanIgnore = true
                            };
                            this.ThrowXmlException("??????", string.Format(ResManager.LoadKDString("在赋值{0}:{1}的值 Null 时失败,{2}", "014009000001741", SubSystemType.SL, new object[0]), property.Name, property.PropertyType.Name, exception2.Message), data2, exception2);
                        }
                        goto Label_01FC;
                    }
                }
                else
                {
                    try
                    {
                        this.GetSetValueAction(property.PropertyType)(property, this._reader, entity);
                    }
                    catch (Exception exception)
                    {
                        SerializationException.SerializationExceptionData data = new SerializationException.SerializationExceptionData
                        {
                            CanIgnore = true
                        };
                        this.ThrowXmlException("??????", string.Format(ResManager.LoadKDString("在赋值{0}:{1}的值'{2}'时失败,{3}", "014009000001740", SubSystemType.SL, new object[0]), new object[] { property.Name, property.PropertyType.Name, this._reader.ReadString(), exception.Message }), data, exception);
                    }
                    goto Label_01FC;
                }
            }
            SerializationException.SerializationExceptionData data3 = new SerializationException.SerializationExceptionData
            {
                CanIgnore = true
            };
            this.ThrowXmlException("??????", string.Format(ResManager.LoadKDString("不能识别的属性操作符{0}", "014009000001742", SubSystemType.SL, new object[0]), action), data3, null);
Label_01FC:
            this.SafeDo();
        }
Пример #8
0
        /// <summary>
        /// 把一个实体数据拷贝到另一个实体
        /// </summary>
        /// <param name="dataEntity"></param>
        /// <param name="newEntity"></param>
        /// <param name="copyHandler"></param>
        /// <param name="clearPrimaryKeyValue"></param>
        /// <param name="onlyDbProperty"></param>
        /// <param name="onlyDirtyProperty"></param>
        public static void CopyData(this IDataEntityBase dataEntity, IDataEntityBase newEntity, Func <string, string, bool> copyHandler = null, bool clearPrimaryKeyValue = false, bool onlyDbProperty = false, bool onlyDirtyProperty = false)
        {
            IDataEntityType dataEntityType = dataEntity.GetDataEntityType();
            IDataEntityType type2          = newEntity.GetDataEntityType();

            if (copyHandler == null)
            {
                copyHandler = (dtName, propName) => true;
            }
            IEnumerable <IDataEntityProperty> dirtyProperties = dataEntityType.GetDirtyProperties(dataEntity);

            foreach (ISimpleProperty property in type2.Properties.GetSimpleProperties(onlyDbProperty))
            {
                if (copyHandler(type2.Name, property.Name))
                {
                    IDataEntityProperty dpOldProperty = null;
                    TryGetOldProperty(property, dataEntityType, out dpOldProperty);
                    if ((!onlyDirtyProperty || dirtyProperties.Contains <IDataEntityProperty>(dpOldProperty)) && !(property.IsReadOnly || (dpOldProperty == null)))
                    {
                        property.SetValue(newEntity, dpOldProperty.GetValue(dataEntity));
                    }
                }
            }
            if (clearPrimaryKeyValue)
            {
                ISimpleProperty primaryKey = type2.PrimaryKey;
                if (primaryKey != null)
                {
                    primaryKey.ResetValue(newEntity);
                }
                type2.SetDirty(newEntity, true);
            }
            foreach (IComplexProperty property4 in type2.Properties.GetComplexProperties(onlyDbProperty))
            {
                IDataEntityProperty property5 = null;
                TryGetOldProperty(property4, dataEntityType, out property5);
                IDataEntityBase base2 = property5.GetValue(dataEntity) as IDataEntityBase;
                if (base2 != null)
                {
                    IDataEntityBase base3;
                    if (property4.IsReadOnly)
                    {
                        base3 = property4.GetValue(newEntity) as IDataEntityBase;
                        if (base3 == null)
                        {
                            throw new ORMDesignException("??????", ResManager.LoadKDString("哦,真不幸,只读的属性却返回了NULL值。", "014009000001633", SubSystemType.SL, new object[0]));
                        }
                        base2.CopyData(base3, copyHandler, false, onlyDbProperty, false);
                    }
                    else
                    {
                        base3 = property4.ComplexPropertyType.CreateInstance() as IDataEntityBase;
                        base2.CopyData(base3, copyHandler, clearPrimaryKeyValue, onlyDbProperty, false);
                        property4.SetValue(newEntity, base3);
                    }
                }
            }
            foreach (ICollectionProperty property6 in type2.Properties.GetCollectionProperties(onlyDbProperty))
            {
                IDataEntityProperty property7 = null;
                TryGetOldProperty(property6, dataEntityType, out property7);
                object obj2 = property7.GetValue(dataEntity);
                if (obj2 != null)
                {
                    IEnumerable enumerable2 = obj2 as IEnumerable;
                    if (enumerable2 == null)
                    {
                        throw new ORMDesignException("??????", ResManager.LoadKDString("哦,真不幸,集合的属性返回值不支持枚举。", "014009000001634", SubSystemType.SL, new object[0]));
                    }
                    object obj3 = property6.GetValue(newEntity);
                    if (obj3 == null)
                    {
                        if (property6.IsReadOnly)
                        {
                            throw new ORMDesignException("??????", ResManager.LoadKDString("哦,真不幸,集合的属性返回值为null。", "014009000001635", SubSystemType.SL, new object[0]));
                        }
                        obj3 = Activator.CreateInstance(property6.PropertyType);
                        property6.SetValue(newEntity, obj3);
                    }
                    IList list = obj3 as IList;
                    if (list == null)
                    {
                        throw new ORMDesignException("??????", ResManager.LoadKDString("哦,真不幸,集合的属性返回值不支持IList。", "014009000001636", SubSystemType.SL, new object[0]));
                    }
                    list.Clear();
                    foreach (IDataEntityBase base4 in enumerable2)
                    {
                        IDataEntityBase base5 = property6.CollectionItemPropertyType.CreateInstance() as IDataEntityBase;
                        base4.CopyData(base5, copyHandler, clearPrimaryKeyValue, onlyDbProperty, false);
                        list.Add(base5);
                    }
                }
            }
        }
Пример #9
0
        private void CopyData(IDataEntityType dt, object dataEntity, object newEntity, bool clearPrimaryKeyValue)
        {
            IDataEntityType objA = dt;
            IDataEntityType objB = dt;

            if (dataEntity is IDataEntityBase)
            {
                objA = (dataEntity as IDataEntityBase).GetDataEntityType();
            }
            if (newEntity is IDataEntityBase)
            {
                objB = (newEntity as IDataEntityBase).GetDataEntityType();
            }
            if ((dataEntity is DynamicObject) && object.ReferenceEquals(objA, objB))
            {
                ((DynamicObject)newEntity).DataStorage = ((DynamicObject)dataEntity).DataStorage.MemberClone();
            }
            else
            {
                foreach (ISimpleProperty property in dt.Properties.GetSimpleProperties(this._onlyDbProperty))
                {
                    IDataEntityProperty dpOldProperty = null;
                    this.TryGetOldProperty(property, objA, out dpOldProperty);
                    if (!property.IsReadOnly && (dpOldProperty != null))
                    {
                        property.SetValue(newEntity, dpOldProperty.GetValue(dataEntity));
                    }
                }
            }
            if (clearPrimaryKeyValue)
            {
                ISimpleProperty primaryKey = dt.PrimaryKey;
                if (primaryKey != null)
                {
                    primaryKey.ResetValue(newEntity);
                }
                objB.SetDirty(newEntity, true);
            }
            foreach (IComplexProperty property4 in dt.Properties.GetComplexProperties(this._onlyDbProperty))
            {
                if (!property4.IsRefrenceObject())
                {
                    IDataEntityProperty property5 = null;
                    this.TryGetOldProperty(property4, objA, out property5);
                    object obj2 = property5.GetValue(dataEntity);
                    if (obj2 != null)
                    {
                        object          obj3;
                        IDataEntityType dataEntityType;
                        IDataEntityBase base2 = obj2 as IDataEntityBase;
                        if (base2 != null)
                        {
                            dataEntityType = base2.GetDataEntityType();
                        }
                        else
                        {
                            dataEntityType = property4.ComplexPropertyType;
                        }
                        if (property4.IsReadOnly)
                        {
                            obj3 = property4.GetValue(newEntity);
                            if (obj3 == null)
                            {
                                throw new ORMDesignException("??????", ResManager.LoadKDString("哦,真不幸,只读的属性却返回了NULL值。", "014009000001633", SubSystemType.SL, new object[0]));
                            }
                            this.CopyData(dataEntityType, obj2, obj3, false);
                        }
                        else
                        {
                            if (property4.IsDbIgnore())
                            {
                                obj3 = this.Clone(dataEntityType, obj2, false);
                            }
                            else
                            {
                                obj3 = this.Clone(dataEntityType, obj2, this._clearPrimaryKeyValue);
                            }
                            property4.SetValue(newEntity, obj3);
                        }
                    }
                }
            }
            foreach (ICollectionProperty property6 in dt.Properties.GetCollectionProperties(this._onlyDbProperty))
            {
                IDataEntityProperty property7 = null;
                this.TryGetOldProperty(property6, objA, out property7);
                object obj4 = property7.GetValue(dataEntity);
                if (obj4 != null)
                {
                    IEnumerable enumerable = obj4 as IEnumerable;
                    if (enumerable == null)
                    {
                        throw new ORMDesignException("??????", ResManager.LoadKDString("哦,真不幸,集合的属性返回值不支持枚举。", "014009000001634", SubSystemType.SL, new object[0]));
                    }
                    if (newEntity is DynamicObject)
                    {
                        ((DynamicObject)newEntity).DataStorage.SetLocalValue((DynamicProperty)property6, null);
                    }
                    object obj5 = property6.GetValue(newEntity);
                    if (obj5 == null)
                    {
                        if (property6.IsReadOnly)
                        {
                            throw new ORMDesignException("??????", ResManager.LoadKDString("哦,真不幸,集合的属性返回值为null。", "014009000001635", SubSystemType.SL, new object[0]));
                        }
                        obj5 = Activator.CreateInstance(property6.PropertyType);
                        property6.SetValue(newEntity, obj5);
                    }
                    IList list = obj5 as IList;
                    if (list == null)
                    {
                        throw new ORMDesignException("??????", ResManager.LoadKDString("哦,真不幸,集合的属性返回值不支持IList。", "014009000001636", SubSystemType.SL, new object[0]));
                    }
                    list.Clear();
                    foreach (object obj6 in enumerable)
                    {
                        IDataEntityType collectionItemPropertyType;
                        IDataEntityBase base3 = obj6 as IDataEntityBase;
                        if (base3 == null)
                        {
                            collectionItemPropertyType = property6.CollectionItemPropertyType;
                        }
                        else
                        {
                            collectionItemPropertyType = base3.GetDataEntityType();
                        }
                        list.Add(this.Clone(collectionItemPropertyType, obj6));
                    }
                }
            }
        }