Example #1
0
        private IDataEntityType BindToType(IDataEntityType canUseType)
        {
            string name = this._reader.Name;
            Dictionary <string, string> attributes = new Dictionary <string, string>();
            int attributeCount = this._reader.AttributeCount;

            for (int i = 0; i < attributeCount; i++)
            {
                this._reader.MoveToAttribute(i);
                attributes.Add(this._reader.Name, this._reader.Value);
            }
            IDataEntityType type = this._binder.BindToType(name, attributes);

            if ((type == null) && (canUseType != null))
            {
                string a = this._binder.BindToName(canUseType);
                if (this._binder.IgnoreCase ? string.Equals(a, name, StringComparison.OrdinalIgnoreCase) : string.Equals(a, name, StringComparison.Ordinal))
                {
                    type = canUseType;
                }
            }
            if (type == null)
            {
                SerializationException.SerializationExceptionData data = new SerializationException.SerializationExceptionData
                {
                    CanIgnore = false
                };
                this.ThrowXmlException("??????", string.Format(ResManager.LoadKDString("未能找到{0}对应的数据类型,请检查是否Xml中拼写错误。", "014009000001751", SubSystemType.SL, new object[0]), name), data, null);
            }
            return(type);
        }
Example #2
0
        private bool MoveToNextElement(string currentName)
        {
            while (this._reader.Read())
            {
                XmlNodeType nodeType = this._reader.NodeType;
                if (nodeType != XmlNodeType.Element)
                {
                    if (nodeType == XmlNodeType.EndElement)
                    {
                        goto Label_001B;
                    }
                    continue;
                }
                return(true);

Label_001B:
                if (this._reader.Name == currentName)
                {
                    return(false);
                }
                SerializationException.SerializationExceptionData data = new SerializationException.SerializationExceptionData
                {
                    CanIgnore = true
                };
                this.ThrowXmlException("??????", ResManager.LoadKDString("不应该出现其他节点的结束符号", "014009000001752", SubSystemType.SL, new object[0]), data, null);
            }
            return(false);
        }
Example #3
0
        public object ReadElement(IDataEntityType dt, object entity)
        {
            MoveToFirstElement(this._reader);
            string name = this._reader.Name;

            if (entity == null)
            {
                dt = this.BindToType(dt);
                if (dt.Flag != DataEntityTypeFlag.Primitive)
                {
                    entity = this._binder.CreateInstance(dt);
                }
            }
            else
            {
                IDataEntityType dataEntityType = this.GetDataEntityType(entity);
                if (dataEntityType != null)
                {
                    dt = this.BindToType(dt);
                    if ((!object.Equals(dt, dataEntityType) && !dt.IsAssignableFrom(dataEntityType)) && (dt.Flag != DataEntityTypeFlag.Primitive))
                    {
                        entity = this._binder.CreateInstance(dt);
                    }
                }
            }
            this.Push(entity);
            if (!this._reader.IsEmptyElement)
            {
                if (dt.Flag != DataEntityTypeFlag.Primitive)
                {
                    while (this.MoveToNextElement(name))
                    {
                        IDataEntityProperty property;
                        if ((dt.Properties.TryGetValue(this._reader.Name, out property) && !this.ReadSimpleProperty(property as ISimpleProperty, entity)) && (!this.ReadComplexProperty(property as IComplexProperty, entity) && !this.ReadCollectionProperty(property as ICollectionProperty, entity)))
                        {
                            SerializationException.SerializationExceptionData data = new SerializationException.SerializationExceptionData
                            {
                                CanIgnore = true
                            };
                            this.ThrowXmlException("??????", string.Format(ResManager.LoadKDString("XML节点中出现的属性{0},必须是简单属性、复杂或集合属性的一种。", "014009000001739", SubSystemType.SL, new object[0]), property.Name), data, null);
                        }
                        this.SafeDo();
                    }
                    return(entity);
                }
                string str2          = this._reader.ReadString();
                Type   primitiveType = DcxmlBinder.GetPrimitiveType(dt.Name.ToLowerInvariant());
                if (primitiveType != typeof(string))
                {
                    entity = Convert.ChangeType(str2, primitiveType, this._binder.Culture);
                }
                else
                {
                    entity = str2;
                }
                this.SafeDo();
            }
            return(entity);
        }
Example #4
0
        private void ThrowXmlException(string code, string message, SerializationException.SerializationExceptionData data, Exception innerException = null)
        {
            XmlTextReader reader = this._reader as XmlTextReader;

            if (reader != null)
            {
                data.LineNumber   = reader.LineNumber;
                data.LinePosition = reader.LinePosition;
            }
            data.OnReading = true;
            this._binder.ThrowException(new SerializationException(code, message, data, innerException));
        }
Example #5
0
        private void DoComplexPropertyAction(string action, IComplexProperty property, object entity)
        {
            string str2 = action;

            if (str2 != null)
            {
                if (!(str2 == "edit"))
                {
                    if (str2 == "setnull")
                    {
                        property.SetValue(entity, null);
                        goto Label_00E4;
                    }
                }
                else
                {
                    string name           = this._reader.Name;
                    bool   isEmptyElement = false;
                    isEmptyElement = this._reader.IsEmptyElement;
                    if (!isEmptyElement)
                    {
                        isEmptyElement = !this.MoveToNextElement(name);
                    }
                    if (!isEmptyElement)
                    {
                        object obj2 = property.GetValue(entity);
                        object objB = this.ReadElement(property.ComplexPropertyType, obj2);
                        if (!property.IsReadOnly && !object.ReferenceEquals(obj2, objB))
                        {
                            property.SetValue(entity, objB);
                        }
                        this.MoveToNextElement(name);
                    }
                    else if (!property.IsReadOnly)
                    {
                        property.SetValue(entity, null);
                    }
                    goto Label_00E4;
                }
            }
            SerializationException.SerializationExceptionData data = new SerializationException.SerializationExceptionData
            {
                CanIgnore = true
            };
            this.ThrowXmlException("??????", string.Format(ResManager.LoadKDString("不能识别的属性操作符{0}", "014009000001742", SubSystemType.SL, new object[0]), action), data, null);
Label_00E4:
            this.SafeDo();
        }
Example #6
0
        private IList SafeGetList(ICollectionProperty property, object entity)
        {
            if (object.ReferenceEquals(this._lastColProperty, property) && object.ReferenceEquals(this._lastColEntity, entity))
            {
                return(this._lastList);
            }
            object obj2 = property.GetValue(entity);

            if (obj2 == null)
            {
                if (property.IsReadOnly)
                {
                    SerializationException.SerializationExceptionData data = new SerializationException.SerializationExceptionData
                    {
                        CanIgnore = true
                    };
                    this.ThrowXmlException("??????", string.Format(ResManager.LoadKDString("集合属性{0}是只读且未初始化值,请初始化的值或提供Set功能。", "014009000001748", SubSystemType.SL, new object[0]), property.Name), data, null);
                }
                try
                {
                    obj2 = Activator.CreateInstance(property.PropertyType);
                    property.SetValue(entity, obj2);
                }
                catch (Exception exception)
                {
                    SerializationException.SerializationExceptionData data2 = new SerializationException.SerializationExceptionData
                    {
                        CanIgnore = true
                    };
                    this.ThrowXmlException("??????", string.Format(ResManager.LoadKDString("自动创建集合属性{0}的值失败,{1}。", "014009000001749", SubSystemType.SL, new object[0]), property.Name, exception.Message), data2, exception);
                }
            }
            IList list = obj2 as IList;

            if (list == null)
            {
                SerializationException.SerializationExceptionData data3 = new SerializationException.SerializationExceptionData
                {
                    CanIgnore = true
                };
                this.ThrowXmlException("??????", string.Format(ResManager.LoadKDString("集合属性{0}必须支持IList接口", "014009000001750", SubSystemType.SL, new object[0]), property.Name), data3, null);
            }
            this._lastColProperty = property;
            this._lastColEntity   = entity;
            this._lastList        = list;
            return(list);
        }
Example #7
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);
        }
Example #8
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();
        }
Example #9
0
        private void DoCollectionPropertyAction(string action, ICollectionProperty property, object entity)
        {
            string str = action;

            if (str != null)
            {
                if (!(str == "add"))
                {
                    if (str == "edit")
                    {
                        object obj3;
                        int    num2 = this.FindItemByOid(property, entity, out obj3);
                        if (num2 >= 0)
                        {
                            this.ReadElement(property.CollectionItemPropertyType, obj3);
                        }
                        else if (num2 == -1)
                        {
                            SerializationException.SerializationExceptionData data = new SerializationException.SerializationExceptionData
                            {
                                CanIgnore = true
                            };
                            this.ThrowXmlException("??????", ResManager.LoadKDString("试图编辑的节点在现有集合中没有找到。", "014009000001743", SubSystemType.SL, new object[0]), data, null);
                        }
                        goto Label_0196;
                    }
                    if (str == "remove")
                    {
                        if (!this.OnlyLocaleValue)
                        {
                            object obj4;
                            int    index = this.FindItemByOid(property, entity, out obj4);
                            if (index >= 0)
                            {
                                this.SafeGetList(property, entity).RemoveAt(index);
                            }
                            else if (index == -1)
                            {
                                SerializationException.SerializationExceptionData data2 = new SerializationException.SerializationExceptionData
                                {
                                    CanIgnore = true
                                };
                                this.ThrowXmlException("??????", ResManager.LoadKDString("试图删除的节点在现有集合中没有找到。", "014009000001744", SubSystemType.SL, new object[0]), data2, null);
                            }
                        }
                        goto Label_0196;
                    }
                }
                else
                {
                    object obj2 = this.ReadElement(property.CollectionItemPropertyType, null);
                    IList  list = this.SafeGetList(property, entity);
                    if (list != null)
                    {
                        if (this._colloctionIgnorePKValue)
                        {
                            list.Add(obj2);
                        }
                        else if (this.FindItemIndex(property, entity, obj2) < 0)
                        {
                            list.Add(obj2);
                        }
                    }
                    goto Label_0196;
                }
            }
            SerializationException.SerializationExceptionData data3 = new SerializationException.SerializationExceptionData
            {
                CanIgnore = true
            };
            this.ThrowXmlException("??????", string.Format(ResManager.LoadKDString("不能识别的集合操作符{0}", "014009000001745", SubSystemType.SL, new object[0]), action), data3, null);
Label_0196:
            this.SafeDo();
        }