public SectionGroup GenerateContentFromConfig(SectionGroup group) { string configFile = _pluginLoader.GetPlugins().First(m => m.ID == SectionPlug.PluginID).RelativePath + @"\Thumbnail\{0}.xml".FormatWith(group.PartialView); List <SectionContent> contents = new List <SectionContent>(); if (File.Exists(configFile)) { XmlDocument doc = new XmlDocument(); FileStream fileStream = new FileStream(configFile, FileMode.Open); doc.Load(fileStream); var nodes = doc.SelectNodes("/required/item"); foreach (XmlNode item in nodes) { var attr = item.Attributes["type"]; if (attr != null && attr.Value.IsNotNullAndWhiteSpace()) { try { if (SectionPlug.ContentTypes.ContainsKey(attr.Value)) { var content = Activator.CreateInstance(SectionPlug.ContentTypes[attr.Value]) as SectionContent; var properties = item.SelectNodes("property"); foreach (XmlNode property in properties) { var name = property.Attributes["name"]; if (name != null && name.Value.IsNotNullAndWhiteSpace() && property.InnerText.IsNotNullAndWhiteSpace()) { ClassAction.SetObjPropertyValue(content, name.Value, property.InnerText); } } content.SectionGroupId = group.ID; content.SectionWidgetId = group.SectionWidgetId; contents.Add(content); } } catch (Exception ex) { Logger.Error(ex); } } } } group.SectionContents = contents; return(group); }
public SectionGroup GenerateContentFromConfig(SectionGroup group) { string configFile = PluginBase.GetPath <SectionPlug>().CombinePath("Thumbnail/{0}.xml".FormatWith(group.PartialView).ToFilePath()); List <SectionContent> contents = new List <SectionContent>(); if (File.Exists(configFile)) { using (FileStream fileStream = new FileStream(configFile, FileMode.Open)) { XmlDocument doc = new XmlDocument(); doc.Load(fileStream); var nodes = doc.SelectNodes("/required/item"); const string fullNameSpace = "ZKEACMS.SectionWidget.Models.{0}"; foreach (XmlNode item in nodes) { var attr = item.Attributes["type"]; if (attr != null && attr.Value.IsNotNullAndWhiteSpace()) { var typeInfoArray = attr.Value.Split('.'); string fullTypeInfo = fullNameSpace.FormatWith(typeInfoArray[typeInfoArray.Length - 1]); if (SectionPlug.ContentTypes.ContainsKey(fullTypeInfo)) { var content = Activator.CreateInstance(SectionPlug.ContentTypes[fullTypeInfo]) as SectionContent; var properties = item.SelectNodes("property"); foreach (XmlNode property in properties) { var name = property.Attributes["name"]; if (name != null && name.Value.IsNotNullAndWhiteSpace() && property.InnerText.IsNotNullAndWhiteSpace()) { ClassAction.SetObjPropertyValue(content, name.Value, property.InnerText); } } content.SectionGroupId = group.ID; content.SectionWidgetId = group.SectionWidgetId; contents.Add(content); } } } } } group.SectionContents = contents; return(group); }
public SectionGroup GenerateContentFromConfig(SectionGroup group) { string configFile = AppDomain.CurrentDomain.BaseDirectory + @"Modules\Section\Views\Thumbnail\{0}.xml".FormatWith(group.PartialView); List <SectionContent> contents = new List <SectionContent>(); if (File.Exists(configFile)) { XmlDocument doc = new XmlDocument(); doc.Load(configFile); var nodes = doc.SelectNodes("/required/item"); foreach (XmlNode item in nodes) { var attr = item.Attributes["type"]; if (attr != null && attr.Value.IsNotNullAndWhiteSpace()) { try { var content = Activator.CreateInstance("Easy.CMS.Section", "Easy.CMS.Section.Models." + attr.Value).Unwrap() as SectionContent; var properties = item.SelectNodes("property"); foreach (XmlNode property in properties) { var name = property.Attributes["name"]; if (name != null && name.Value.IsNotNullAndWhiteSpace() && property.InnerText.IsNotNullAndWhiteSpace()) { ClassAction.SetObjPropertyValue(content, name.Value, property.InnerText); } } content.SectionGroupId = group.ID; content.SectionWidgetId = group.SectionWidgetId; contents.Add(content); } catch (Exception ex) { Logger.Error(ex); } } } } group.SectionContents = contents; return(group); }