Exemplo n.º 1
0
        /// <summary>
        /// 存储一个模型对象,如果存根管理器中没有该对象则增加该对象
        /// </summary>
        /// <param name="value">要存储的模型对象</param>
        public virtual void Save(IModelBase value)
        {
            Type            type            = value.GetType();
            ModelCollection modelCollection = this[type];

            if (modelCollection == null)
            {
                return;
            }
            if (modelCollection.Contains(value.Rid))
            {
                IModelBase   model = modelCollection[value.Rid];
                ModelMapping mf    = modelCollection.ModelField;
                foreach (PropertyFieldPair pfp in mf.PropertyFields)
                {
                    object obj = pfp.Property.GetValue(value, null);
                    pfp.Property.SetValue(model, obj, null);
                }
                while (mf.Parent != null)
                {
                    foreach (PropertyFieldPair pfp in mf.Parent.PropertyFields)
                    {
                        object obj = pfp.Property.GetValue(value, null);
                        pfp.Property.SetValue(model, obj, null);
                    }
                    mf = mf.Parent;
                }
                modelCollection.AddAltKey(value);
            }
            else
            {
                modelCollection.Add(value);
                modelCollection.AddAltKey(value);
                type = type.BaseType;
                while (type.BaseType != typeof(object) && type.Name != "ScadaModel")
                {
                    modelCollection = this[type.Name];
                    if (modelCollection.Contains(value.Rid))
                    {
                        IModelBase   model = modelCollection[value.Rid];
                        ModelMapping mf    = modelCollection.ModelField;
                        foreach (PropertyFieldPair pfp in mf.PropertyFields)
                        {
                            object obj = pfp.Property.GetValue(model, null);
                            pfp.Property.SetValue(value, obj, null);
                        }
                        modelCollection.Remove(value.Rid);
                        modelCollection.RemoveAltKey(value);
                    }
                    modelCollection.Add(value);
                    modelCollection.AddAltKey(value);
                    type = type.BaseType;
                }
            }
            value.Initialize();
            if (ModelSaved != null)
            {
                ModelSaved(this, new ModelCacheChangedEventArgs(value.GetType(), value.Rid));
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 移除一个模型对象
        /// </summary>
        /// <param name="value">要移除的模型对象</param>
        public virtual void Remove(IModelBase value)
        {
            if (value == null)//于艳辉添加
            {
                return;
            }
            Type type = value.GetType();

            while (type.BaseType != typeof(object))
            {
                ModelCollection modelCollection = this[type.Name];
                if (modelCollection != null &&
                    modelCollection.Contains(value.Rid))
                {
                    IModelBase model = modelCollection[value.Rid];
                    modelCollection.Remove(model);
                    modelCollection.RemoveAltKey(model);
                }
                type = type.BaseType;
            }
            if (ModelRemoved != null)
            {
                ModelRemoved(this, new ModelCacheChangedEventArgs(value));
            }
        }
Exemplo n.º 3
0
 /// <summary>
 /// 通过远程传输的模型对象获取本地对应的模型对象
 /// </summary>
 /// <param name="value">远程传输来的模型对象</param>
 /// <returns>本地模型对象</returns>
 public IModelBase this[IModelBase value]
 {
     get
     {
         ModelCollection modelDictionary = this[value.GetType()];
         if (modelDictionary != null && modelDictionary.Contains(value.Rid))
         {
             return(modelDictionary[value.Rid]);
         }
         return(null);
     }
 }
Exemplo n.º 4
0
 /// <summary>
 /// 获取一个模型对象
 /// </summary>
 /// <param name="type">模型对象的类型</param>
 /// <param name="rid">模型对象的Rid</param>
 /// <returns>模型对象</returns>
 public IModelBase this[Type type, int rid]
 {
     get
     {
         ModelCollection modelDictionary = this[type];
         if (modelDictionary != null && modelDictionary.Contains(rid))
         {
             return(modelDictionary[rid]);
         }
         return(null);
     }
 }