Example #1
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);
        }
Example #2
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);
        }