Esempio n. 1
0
        /// <summary>
        /// 获取索引对象模型集合
        /// </summary>
        /// <returns>用户所有对象模型索引集合</returns>
        public static ContentModelCollection GetAllContentModel()
        {
            ContentModelCollection contentModels = AppCtx.Cache.RetrieveObject <ContentModelCollection>(CATCH_CONTENTMODEL_COLLECTION);

            if (contentModels == null)
            {
                //判断配置文件是否存在,不存在则创建个空文件
                if (File.Exists(ContentModelConfigPath))
                {
                    contentModels = SerializationHelper.Load(typeof(ContentModelCollection), ContentModelConfigPath)
                                    as ContentModelCollection;
                    if (contentModels == null)
                    {
                        contentModels = new ContentModelCollection();
                        SaveContentModel(contentModels);
                    }
                }
                else
                {
                    contentModels = new ContentModelCollection();
                    SaveContentModel(contentModels);
                }
                AppCtx.Cache.AddObjectWithFileChange(CATCH_CONTENTMODEL_COLLECTION, contentModels, ContentModelConfigPath);
            }

            return(contentModels);
        }
Esempio n. 2
0
        /// <summary>
        /// 获取索引对象模型
        /// </summary>
        /// <returns>对象模型索引</returns>
        public static ContentModel GetContentModelByName(string name)
        {
            ContentModel model = new ContentModel();

            ContentModelCollection contentModels = GetAllContentModel();

            if (contentModels != null && contentModels.Count > 0)
            {
                model = contentModels[name];
            }
            return(model);
        }
Esempio n. 3
0
        /// <summary>
        /// 重新创建内容模型索引
        /// </summary>
        public static void ReCreateModelIndex()
        {
            DirectoryInfo di = new DirectoryInfo(HttpContext.Current.Server.MapPath(ModelConfig.ModelsDirectory));

            if (!di.Exists)
            {
                return;
            }

            ContentModelCollection cm  = new ContentModelCollection();
            ModelGroupCollection   mgc = ModelHelper.GetModelGroups();

            foreach (DirectoryInfo d in di.GetDirectories())
            {
                if (String.Compare(d.Name, "inc", true) == 0)
                {
                    continue;
                }
                foreach (FileInfo fi in d.GetFiles())
                {
                    if (!fi.FullName.EndsWith(".xml", StringComparison.CurrentCultureIgnoreCase))
                    {
                        continue;
                    }
                    try
                    {
                        ModelInfo    model = ModelHelper.GetModelInfo(String.Format("{0}.{1}", d.Name, Path.GetFileNameWithoutExtension(fi.Name)));
                        ContentModel c     = new ContentModel();
                        c.Name               = model.ModelName;
                        c.Label              = model.Label;
                        c.Description        = model.Desc;
                        c.Type               = model.Type;
                        c.DefaultContentName = c.GetDefaultModel(model.Type);
                        c.State              = 1;
                        cm.Add(c);
                        ModelGroup mg = mgc[model.GroupName];
                        if (mg == null)
                        {
                            mg             = new ModelGroup();
                            mg.Name        = d.Name;
                            mg.Label       = d.Name;
                            mg.System      = false;
                            mg.Description = "重建索引时自动生成";
                            mgc.Add(mg);
                        }
                    }
                    catch { }
                }
            }
            ModelHelper.SaveContentModel(cm);
            ModelHelper.SaveModelGroups(mgc);
        }
Esempio n. 4
0
        public static ContentModel GetModelByValue(int value)
        {
            ContentModelCollection cmc = GetAllContentModel();

            foreach (ContentModel c in cmc)
            {
                if (c.Value == value)
                {
                    return(c);
                }
            }
            return(null);
        }
Esempio n. 5
0
        /// <summary>
        /// 按模型类型来取模型集合
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public static ContentModelCollection GetContentModel(ModelType type)
        {
            ContentModelCollection result = new ContentModelCollection();
            ContentModelCollection cmc    = GetAllContentModel();

            foreach (ContentModel c in cmc)
            {
                if (c.Type == type)
                {
                    result.Add(c);
                }
            }
            return(result);
        }
Esempio n. 6
0
 /// <summary>
 /// 取得模型的Value值
 /// </summary>
 /// <param name="modename"></param>
 /// <returns></returns>
 public static int GetModelValue(string modename)
 {
     if (!String.IsNullOrEmpty(modename))
     {
         ContentModelCollection cmc = GetAllContentModel();
         foreach (ContentModel c in cmc)
         {
             if (modename.Equals(c.Name, StringComparison.OrdinalIgnoreCase))
             {
                 return(c.Value);
             }
         }
     }
     return(0);
 }
Esempio n. 7
0
        /// <summary>
        ///  保存对象模型
        /// </summary>
        /// <param name="modelinfo">对象模型</param>
        /// <returns></returns>
        public static bool SaveContentModel(ContentModel model)
        {
            ContentModelCollection contentModels = ModelHelper.GetAllContentModel();

            if (contentModels == null)
            {
                contentModels = new ContentModelCollection();
            }
            else
            {
                //存在该对象名称,则保存,否则新建
                if (contentModels[model.Name] != null)
                {
                    contentModels[model.Name] = model;
                }
                else
                {
                    contentModels.Add(model);
                }
            }

            return(SaveContentModel(contentModels));
        }
Esempio n. 8
0
 /// <summary>
 /// 序列化对象模型集合
 /// </summary>
 /// <param name="collection"></param>
 /// <returns></returns>
 public static bool SaveContentModel(ContentModelCollection collection)
 {
     return(SerializationHelper.Save(collection, ContentModelConfigPath));
 }
Esempio n. 9
0
        /// <summary>
        /// 获取所有模型集合
        /// </summary>
        /// <returns></returns>
        public static ContentModelCollection GetContentModel()
        {
            ContentModelCollection cmc = GetAllContentModel();

            return(cmc);
        }