Пример #1
0
        public static TplMgr GetMgr(Type type)
        {
            TplMgr mgr = null;

            if (!TplDict.TryGetValue(type, out mgr))
            {
                throw new Exception(string.Format("没有找到类型[{0}]的管理对象", type));
            }
            return(mgr);
        }
Пример #2
0
        public static void Setup(byte[] bytes)
        {
            DynamicBuffer buffer = new DynamicBuffer(bytes);
            IList <Type>  keys   = new List <Type>(TplDict.Keys);

            for (int i = 0; i < keys.Count; i++)
            {
                Type   key     = keys[i];
                TplMgr oTplMgr = TplDict[key];
                oTplMgr.Setup(key, buffer);
            }
        }
Пример #3
0
        public static T Find <T>(int id) where T : BaseTpl, new()
        {
            TplMgr mgr = GetMgr(typeof(T));

            if (mgr == null)
            {
                return(default(T));
            }
            else
            {
                return(mgr.Find(id) as T);
            }
        }
Пример #4
0
        public static void Initialize()
        {
            Type[] types = ZCommUtil.GetTypes();
            Dictionary <string, Type> allTypes = new Dictionary <string, Type>();

            for (int i = 0; i < types.Length; i++)
            {
                Type type = types[i];
                allTypes[type.Name] = type;
            }

            List <TMPWarp> mgrWarpList = new List <TMPWarp>();

            foreach (var item in allTypes)
            {
                string typeName = item.Key;
                Type   type     = item.Value;
                if (type.IsClass && type.BaseType == typeof(TplMgr))
                {
                    TplMgr tplMgr    = Activator.CreateInstance(type) as TplMgr;
                    string paramName = type.Name.Replace("Mgr", "") + "Data";
                    Type   paramType = null;
                    if (allTypes.TryGetValue(paramName, out paramType))
                    {
                        mgrWarpList.Add(new TMPWarp()
                        {
                            Type = paramType, TplMgr = tplMgr
                        });
                    }
                    else
                    {
                        App.Logger.Error("Tempate 没有找到类型:{0}", paramName);
                    }
                }
            }
            mgrWarpList.Sort((a, b) => { return(a.Name.CompareTo(b.Name)); });

            for (int i = 0; i < mgrWarpList.Count; i++)
            {
                TMPWarp mgrWarp = mgrWarpList[i];
                if (!TplDict.ContainsKey(mgrWarp.Type))
                {
                    TplDict.Add(mgrWarp.Type, mgrWarp.TplMgr);
                }
                else
                {
                    App.Logger.Error("TplDict已经包含同样名称的键:{0}", mgrWarp.Type);
                }
            }
            App.Logger.Info("Template 完成模板添加操作");
        }
Пример #5
0
        public static IList <T> FindAll <T>() where T : BaseTpl, new()
        {
            List <T> list = new List <T>();
            TplMgr   mgr  = GetMgr(typeof(T));

            if (mgr == null)
            {
                return(list);
            }
            else
            {
                List <object> tmplist = mgr.FindAll();
                for (int i = 0; i < tmplist.Count; i++)
                {
                    list.Add(tmplist[i] as T);
                }
                return(list);
            }
        }