/// <summary> /// 取得指定目录下的控件 /// </summary> /// <param name="dir"></param> /// <param name="prefixPath">前置目录 Weidget/We7Controls</param> private void LoadDataControls(List <DataControlInfo> controls, string dir, string prefixPath, string group) { DirectoryInfo di = new DirectoryInfo(dir); if (!di.Exists) { return; } DirectoryInfo[] cdi = di.GetDirectories(); DataControlInfo dci = new DataControlInfo(); for (int i = 0; i < cdi.Length; i++) { try { FileInfo[] fs = cdi[i].GetFiles("*.ascx"); if (fs != null && fs.Length > 0) { // DataControlInfo dci = new DataControlInfo(); dci.Group = group; foreach (FileInfo fileInfo in fs) { string virtualPath = string.Format("{0}/{1}/{2}", prefixPath, cdi[i].Name, fileInfo.Name); //获取控件上的描述属性,组描述属性 DataControl ctrl = BaseControlHelper.GetDataControlInfo(virtualPath); if (ctrl != null) { ctrl.FileName = virtualPath; ctrl.Name = fileInfo.Name.Replace(".ascx", ""); dci.Controls.Add(ctrl); //组描述设置 if (string.IsNullOrEmpty(dci.GroupLabel) && !string.IsNullOrEmpty(ctrl.GroupLabel)) { dci.GroupLabel = prefixPath.Substring(prefixPath.LastIndexOf('/') + 1, prefixPath.Length - (prefixPath.LastIndexOf('/') + 1)); } if (string.IsNullOrEmpty(dci.GroupIcon) && !string.IsNullOrEmpty(ctrl.GroupIcon)) { dci.GroupIcon = prefixPath.Substring(prefixPath.LastIndexOf('/') + 1, prefixPath.Length - (prefixPath.LastIndexOf('/') + 1)); } if (string.IsNullOrEmpty(dci.GroupDesc) && !string.IsNullOrEmpty(ctrl.GroupDesc)) { dci.GroupDesc = prefixPath.Substring(prefixPath.LastIndexOf('/') + 1, prefixPath.Length - (prefixPath.LastIndexOf('/') + 1)); } if (string.IsNullOrEmpty(dci.GroupDefaultType) && !string.IsNullOrEmpty(ctrl.GroupDefaultType)) { dci.GroupDefaultType = ctrl.GroupDefaultType; } } } if (dci.Controls != null && dci.Controls.Count > 0) { //Default.ascx放前面,排序 dci.Controls.Sort(SortDataControl); dci.DefaultControl = dci.Controls[0]; dci.Default = dci.Controls[0].Name; // dci.Name = dci.Controls[0].Name.Split('.')[0]; dci.Desc = dci.Controls[0].Description; if (string.IsNullOrEmpty(dci.Name)) { dci.Name = new CNspellTranslator().GetSpells(prefixPath.Substring(prefixPath.LastIndexOf('/') + 1, prefixPath.Length - (prefixPath.LastIndexOf('/') + 1))) + DateTime.Now.Ticks; } if (string.IsNullOrEmpty(dci.GroupLabel)) { dci.GroupLabel = di.Name; //dci.Desc; } if (string.IsNullOrEmpty(dci.GroupIcon)) { dci.GroupIcon = dci.Desc; } if (string.IsNullOrEmpty(dci.GroupDesc)) { dci.GroupDesc = dci.Desc; } if (string.IsNullOrEmpty(dci.GroupDefaultType)) { dci.GroupDefaultType = dci.Default; } else { //验证默认控件是否存在 string filePath = string.Format("{0}\\{1}.ascx", cdi[i].FullName, dci.GroupDefaultType); if (!File.Exists(filePath)) { dci.GroupDefaultType = dci.Default; } } } } else { LoadDataControls(controls, cdi[i].FullName, prefixPath + "/" + cdi[i].Name, group); } } catch (Exception ex) { throw ex; } } if (dci != null && dci.Controls.Count > 0) { controls.Add(dci); } }
/// <summary> /// 取得单个部件组的 /// </summary> /// <param name="path"></param> /// <returns></returns> public DataControlInfo GetWidgetControlInfo(string path) { DataControlInfo dci = null; string virtualPath = path; path = HttpContext.Current.Server.MapPath(path); FileInfo fileInfo = new FileInfo(path); DirectoryInfo d = fileInfo.Directory; if (d.Exists && fileInfo.Exists) { dci = new DataControlInfo(); dci.Group = group; //string virtualPath = string.Format("{0}/{1}/{2}", prefixPath, d.Name, fileInfo.Name); //获取控件上的描述属性,组描述属性 DataControl ctrl = GetDataControlInfoDeeply(virtualPath); if (ctrl != null) { ctrl.FileName = virtualPath; //ctrl.Name = fileInfo.Name.Replace(".ascx", ""); dci.Controls.Add(ctrl); //组描述设置 if (string.IsNullOrEmpty(dci.GroupLabel) && !string.IsNullOrEmpty(ctrl.GroupLabel)) { dci.GroupLabel = ctrl.GroupLabel; } if (string.IsNullOrEmpty(dci.GroupIcon) && !string.IsNullOrEmpty(ctrl.GroupIcon)) { dci.GroupIcon = ctrl.GroupIcon; } if (string.IsNullOrEmpty(dci.GroupDesc) && !string.IsNullOrEmpty(ctrl.GroupDesc)) { dci.GroupDesc = ctrl.GroupDesc; } if (string.IsNullOrEmpty(dci.GroupDefaultType) && !string.IsNullOrEmpty(ctrl.GroupDefaultType)) { dci.GroupDefaultType = ctrl.GroupDefaultType; } } } if (dci.Controls != null && dci.Controls.Count > 0) { //Default.ascx放前面,排序 dci.Controls.Sort(SortDataControl); dci.DefaultControl = dci.Controls[0]; dci.Default = dci.Controls[0].Name; dci.Name = dci.Controls[0].Name.Split('.')[0]; dci.Desc = dci.Controls[0].Description; if (string.IsNullOrEmpty(dci.GroupLabel)) { dci.GroupLabel = dci.Desc; } if (string.IsNullOrEmpty(dci.GroupIcon)) { dci.GroupIcon = dci.Desc; } if (string.IsNullOrEmpty(dci.GroupDesc)) { dci.GroupDesc = dci.Desc; } if (string.IsNullOrEmpty(dci.GroupDefaultType)) { dci.GroupDefaultType = dci.Default; } else { //验证默认控件是否存在 string filePath = string.Format("{0}\\{1}.ascx", d.FullName, dci.GroupDefaultType); if (!File.Exists(filePath)) { dci.GroupDefaultType = dci.Default; } } } return(dci); }
/// <summary> /// 获取包括 部件/控件 的列表 /// </summary> /// <returns></returns> public List <DataControlInfo> GetDataControlsInfos() { List <DataControlInfo> result = AppCtx.Cache.RetrieveObject <List <DataControlInfo> >(DCIKEY); if (result == null) { if (Directory.Exists(Constants.We7ControlPhysicalPath) || Directory.Exists(Constants.We7ModelPhysicalPath) || Directory.Exists(Constants.We7PluginPhysicalPath)) { string path = Path.Combine(Constants.We7WidgetsPhysicalFolder, "We7DataControlIndex.xml"); if (!File.Exists(path)) { DataControlHelper.CreateDataControlIndex(); if (!File.Exists(path)) { throw new Exception(path + "文件不存在!"); } } result = new List <DataControlInfo>(); XmlDocument doc = new XmlDocument(); doc.Load(path); XmlNodeList ctrs = doc.DocumentElement.SelectNodes("control"); foreach (XmlElement ctr in ctrs) { DataControlInfo dci = new DataControlInfo(); dci.Name = ctr.GetAttribute("name"); dci.Group = ctr.GetAttribute("group"); dci.Path = ctr.GetAttribute("path"); dci.Directory = ctr.GetAttribute("directory"); dci.Desc = ctr.GetAttribute("desc"); dci.Default = ctr.GetAttribute("default"); XmlNodeList items = ctr.SelectNodes("item"); foreach (XmlElement item in items) { DataControl dc = new DataControl(); dc.Control = item.GetAttribute("control"); dc.Name = item.GetAttribute("name"); dc.Type = item.GetAttribute("type"); dc.Version = item.GetAttribute("version"); DateTime dt; DateTime.TryParse(item.GetAttribute("created"), out dt); dc.Created = dt; dc.FileName = item.GetAttribute("fileName"); dc.DemoUrl = item.GetAttribute("demoUrl"); dci.Controls.Add(dc); } if (dci.Controls == null || dci.Controls.Count == 0) { continue; } if (String.IsNullOrEmpty(dci.Default)) { dci.DefaultControl = dci.Controls.Find(delegate(DataControl dctr) { return(String.Compare(dci.Default, dctr.Control, true) == 0); }); } if (dci.DefaultControl == null) { dci.DefaultControl = dci.Controls[0]; } result.Add(dci); } } if (Directory.Exists(Constants.We7WidgetsPhysicalFolder)) { string pathWidgets = Path.Combine(Constants.We7WidgetsPhysicalFolder, "WidgetsIndex.xml"); string pathContorl = Path.Combine(Constants.We7WidgetsPhysicalFolder, "We7DataControlIndex.xml"); List <DataControlInfo> ctrs = GetControls("/Widgets/WidgetCollection"); if (result == null) { result = new List <DataControlInfo>(); } //添加部件 result.AddRange(ctrs); string[] files = new string[] { pathWidgets, pathContorl }; AppCtx.Cache.AddObjectWithFileChange(DCIKEY, result, files); } } return(result); }
protected string GetGroup(object o) { DataControlInfo info = o as DataControlInfo; return(info != null ? (String.IsNullOrEmpty(info.Group) ? "System" : info.Group) : String.Empty); }