//public static List<MarkupScript> ParseScriptsFromXml(ModuleConfiguration config) //{ // List<MarkupScript> scripts = new List<MarkupScript>(); // string fullPath = string.Empty; // XmlDocument doc = new XmlDocument(); // if (DefinitionExists(config.FieldDefinitionSrc, out doc)) // { // XmlNode node = doc.DocumentElement.SelectSingleNode("/Fields/Scripts"); // if (node == null) return scripts; // try // { // scripts = SuperFlexiHelpers.ParseScriptsFromXmlNode(node); // } // catch (System.Xml.XmlException ex) // { // log.Error(ex); // } // } // return scripts; //} /// <summary> /// Creates a list of Field from field definition xml file. /// </summary> /// <param name="fieldDefinitionSrc"></param> /// <returns>IList</returns> public static List <Field> ParseFieldDefinitionXml(ModuleConfiguration config, Guid siteGuid) { List <Field> fields = new List <Field>(); string fullPath = string.Empty; XmlDocument doc = new XmlDocument(); FileSystemProvider p = FileSystemManager.Providers[WebConfigSettings.FileSystemProvider]; if (p == null) { log.Error("File System Provider Could Not Be Loaded."); return(fields); } IFileSystem fileSystem = p.GetFileSystem(); if (fileSystem == null) { log.Error("File System Could Not Be Loaded."); return(fields); } //implemented "solutions" on 9/13/2017 (mojoPortal 2.6.0.0) which allows for markup definitions and field definitions to be wrapped up in a single folder //b/c of this, we added the ability to pull the field definition file from the location of the markup definition (.sfmarkup) file w/o needing to use the full path in the fieldDefinitionSrc property string solutionFieldDefSrc = string.Empty; if (config.FieldDefinitionSrc.StartsWith("~/")) { solutionFieldDefSrc = config.FieldDefinitionSrc; } else if (config.FieldDefinitionSrc.StartsWith("/")) { solutionFieldDefSrc = "~" + config.FieldDefinitionSrc; } //else if (File.Exists(System.Web.Hosting.HostingEnvironment.MapPath(config.MarkupDefinitionFile))) else { var sfMarkupFile = fileSystem.RetrieveFile(config.MarkupDefinitionFile); string sfFieldPath = fileSystem.CombinePath(sfMarkupFile.FolderVirtualPath, config.FieldDefinitionSrc); var sfFieldFile = fileSystem.RetrieveFile(sfFieldPath); //FileInfo fileInfo = new FileInfo(System.Web.Hosting.HostingEnvironment.MapPath(config.MarkupDefinitionFile)); //solutionFieldDefSrc = fileInfo.DirectoryName + "/" + config.FieldDefinitionSrc; solutionFieldDefSrc = sfFieldFile.VirtualPath; } if (DefinitionExists(solutionFieldDefSrc, out doc)) { XmlNode node = doc.DocumentElement.SelectSingleNode("/Fields"); if (node != null) { XmlAttributeCollection attribs = node.Attributes; string definitionName = string.Empty; Guid definitionGuid = Guid.NewGuid(); if (attribs["definitionName"] != null) { definitionName = attribs["definitionName"].Value; } if (attribs["definitionGuid"] != null) { definitionGuid = Guid.Parse(attribs["definitionGuid"].Value); } if (definitionGuid != config.FieldDefinitionGuid) { log.ErrorFormat(@" SuperFlexi Solution [{0}] located at [{1}] uses fieldDefinitionGuid = [{2}] but the field definition at [{3}] uses definitionGuid = [{4}]. Items will not display properly and may end up corrupted. " , config.MarkupDefinitionName, config.MarkupDefinitionFile, config.FieldDefinitionGuid.ToString(), solutionFieldDefSrc, definitionGuid); return(null); } foreach (XmlNode childNode in node) { if (childNode.Name == "Field") { try { Field field = new Field(); XmlAttributeCollection itemDefAttribs = childNode.Attributes; field.DefinitionName = definitionName; field.DefinitionGuid = definitionGuid; if (itemDefAttribs["name"] != null) { field.Name = itemDefAttribs["name"].Value; } if (itemDefAttribs["label"] != null) { field.Label = itemDefAttribs["label"].Value; } if (itemDefAttribs["defaultValue"] != null) { field.DefaultValue = itemDefAttribs["defaultValue"].Value; } if (itemDefAttribs["controlType"] != null) { field.ControlType = itemDefAttribs["controlType"].Value; } if (itemDefAttribs["controlSrc"] != null) { field.ControlSrc = itemDefAttribs["controlSrc"].Value; } field.SortOrder = XmlUtils.ParseInt32FromAttribute(itemDefAttribs, "sortOrder", field.SortOrder); if (itemDefAttribs["helpKey"] != null) { field.HelpKey = itemDefAttribs["helpKey"].Value; } field.Required = XmlUtils.ParseBoolFromAttribute(itemDefAttribs, "required", field.Required); if (itemDefAttribs["requiredMessageFormat"] != null) { field.RequiredMessageFormat = itemDefAttribs["requiredMessageFormat"].Value; } if (itemDefAttribs["regex"] != null) { field.Regex = itemDefAttribs["regex"].Value; } if (itemDefAttribs["regexMessageFormat"] != null) { field.RegexMessageFormat = itemDefAttribs["regexMessageFormat"].Value; } if (itemDefAttribs["token"] != null && !String.IsNullOrWhiteSpace(itemDefAttribs["token"].Value)) { field.Token = itemDefAttribs["token"].Value; } field.Searchable = XmlUtils.ParseBoolFromAttribute(itemDefAttribs, "isSearchable", field.Searchable); if (itemDefAttribs["editPageControlWrapperCssClass"] != null) { field.EditPageControlWrapperCssClass = itemDefAttribs["editPageControlWrapperCssClass"].Value; } if (itemDefAttribs["editPageLabelCssClass"] != null) { field.EditPageLabelCssClass = itemDefAttribs["editPageLabelCssClass"].Value; } if (itemDefAttribs["editPageControlCssClass"] != null) { field.EditPageControlCssClass = itemDefAttribs["editPageControlCssClass"].Value; } field.DatePickerIncludeTimeForDate = XmlUtils.ParseBoolFromAttribute(itemDefAttribs, "datePickerIncludeTimeForDate", field.DatePickerIncludeTimeForDate); field.DatePickerShowMonthList = XmlUtils.ParseBoolFromAttribute(itemDefAttribs, "datePickerShowMonthList", field.DatePickerShowMonthList); field.DatePickerShowYearList = XmlUtils.ParseBoolFromAttribute(itemDefAttribs, "datePickerShowYearList", field.DatePickerShowYearList); if (itemDefAttribs["datePickerYearRange"] != null) { field.DatePickerYearRange = itemDefAttribs["datePickerYearRange"].Value; } if (itemDefAttribs["imageBrowserEmptyUrl"] != null) { field.ImageBrowserEmptyUrl = itemDefAttribs["imageBrowserEmptyUrl"].Value; } field.CheckBoxReturnBool = XmlUtils.ParseBoolFromAttribute(itemDefAttribs, "checkBoxReturnBool", field.CheckBoxReturnBool); if (itemDefAttribs["checkBoxReturnValueWhenTrue"] != null) { field.CheckBoxReturnValueWhenTrue = itemDefAttribs["checkBoxReturnValueWhenTrue"].Value; } if (itemDefAttribs["checkBoxReturnValueWhenFalse"] != null) { field.CheckBoxReturnValueWhenFalse = itemDefAttribs["checkBoxReturnValueWhenFalse"].Value; } if (itemDefAttribs["dateFormat"] != null) { field.DateFormat = itemDefAttribs["dateFormat"].Value; } if (itemDefAttribs["textBoxMode"] != null) { field.TextBoxMode = itemDefAttribs["textBoxMode"].Value; } field.IsDeleted = XmlUtils.ParseBoolFromAttribute(itemDefAttribs, "isDeleted", field.IsDeleted); field.IsGlobal = XmlUtils.ParseBoolFromAttribute(itemDefAttribs, "isGlobal", field.IsGlobal); if (itemDefAttribs["viewRoles"] != null) { string viewRoles = itemDefAttribs["viewRoles"].Value; if (String.IsNullOrWhiteSpace(viewRoles)) { viewRoles = "All Users;"; } field.ViewRoles = viewRoles; } if (itemDefAttribs["editRoles"] != null) { field.EditRoles = itemDefAttribs["editRoles"].Value; } StringBuilder options = new StringBuilder(); StringBuilder attributes = new StringBuilder(); foreach (XmlNode subNode in childNode) { switch (subNode.Name) { case "Options": options = XmlHelper.GetKeyValuePairsAsStringBuilder(subNode.ChildNodes); //GetKeyValuePairs(subNode.ChildNodes, out options); break; case "Attributes": attributes = XmlHelper.GetKeyValuePairsAsStringBuilder(subNode.ChildNodes); //GetKeyValuePairs(subNode.ChildNodes, out attributes); break; case "PreTokenString": field.PreTokenString = subNode.InnerText.Trim(); break; case "PostTokenString": field.PostTokenString = subNode.InnerText.Trim(); break; case "PreTokenStringWhenTrue": field.PreTokenStringWhenTrue = subNode.InnerText.Trim(); break; case "PostTokenStringWhenTrue": field.PostTokenStringWhenTrue = subNode.InnerText.Trim(); break; case "PreTokenStringWhenFalse": field.PreTokenStringWhenFalse = subNode.InnerText.Trim(); break; case "PostTokenStringWhenFalse": field.PostTokenStringWhenFalse = subNode.InnerText.Trim(); break; } } if (options.Length > 0) { field.Options = options.ToString(); } if (attributes.Length > 0) { field.Attributes = attributes.ToString(); } fields.Add(field); } catch (System.Xml.XmlException ex) { log.Error(ex); } } else if (childNode.Name == "Scripts") { try { config.EditPageScripts = SuperFlexiHelpers.ParseScriptsFromXmlNode(childNode); } catch (System.Xml.XmlException ex) { log.Error(ex); } } else if (childNode.Name == "Styles") { try { config.EditPageCSS = SuperFlexiHelpers.ParseCssFromXmlNode(childNode); } catch (System.Xml.XmlException ex) { log.Error(ex); } } else if (childNode.Name == "SearchDefinition") { try { SuperFlexiHelpers.ParseSearchDefinition(childNode, definitionGuid, siteGuid); } catch (XmlException ex) { log.Error(ex); } } } } } fields.Sort(); return(fields); }
//public static List<MarkupScript> ParseScriptsFromXml(ModuleConfiguration config) //{ // List<MarkupScript> scripts = new List<MarkupScript>(); // string fullPath = string.Empty; // XmlDocument doc = new XmlDocument(); // if (DefinitionExists(config.FieldDefinitionSrc, out doc)) // { // XmlNode node = doc.DocumentElement.SelectSingleNode("/Fields/Scripts"); // if (node == null) return scripts; // try // { // scripts = SuperFlexiHelpers.ParseScriptsFromXmlNode(node); // } // catch (System.Xml.XmlException ex) // { // log.Error(ex); // } // } // return scripts; //} /// <summary> /// Creates a list of Field from field definition xml file. /// </summary> /// <param name="fieldDefinitionSrc"></param> /// <returns>IList</returns> public static List <Field> ParseFieldDefinitionXml(ModuleConfiguration config, Guid siteGuid) { List <Field> fields = new List <Field>(); string fullPath = string.Empty; XmlDocument doc = new XmlDocument(); if (DefinitionExists(config.FieldDefinitionSrc, out doc)) { XmlNode node = doc.DocumentElement.SelectSingleNode("/Fields"); if (node != null) { XmlAttributeCollection attribs = node.Attributes; string definitionName = string.Empty; Guid definitionGuid = Guid.NewGuid(); if (attribs["definitionName"] != null) { definitionName = attribs["definitionName"].Value; } if (attribs["definitionGuid"] != null) { definitionGuid = Guid.Parse(attribs["definitionGuid"].Value); } foreach (XmlNode childNode in node) { if (childNode.Name == "Field") { try { Field field = new Field(); XmlAttributeCollection itemDefAttribs = childNode.Attributes; field.DefinitionName = definitionName; field.DefinitionGuid = definitionGuid; if (itemDefAttribs["name"] != null) { field.Name = itemDefAttribs["name"].Value; } if (itemDefAttribs["label"] != null) { field.Label = itemDefAttribs["label"].Value; } if (itemDefAttribs["defaultValue"] != null) { field.DefaultValue = itemDefAttribs["defaultValue"].Value; } if (itemDefAttribs["controlType"] != null) { field.ControlType = itemDefAttribs["controlType"].Value; } if (itemDefAttribs["controlSrc"] != null) { field.ControlSrc = itemDefAttribs["controlSrc"].Value; } field.SortOrder = XmlUtils.ParseInt32FromAttribute(itemDefAttribs, "sortOrder", field.SortOrder); if (itemDefAttribs["helpKey"] != null) { field.HelpKey = itemDefAttribs["helpKey"].Value; } field.Required = XmlUtils.ParseBoolFromAttribute(itemDefAttribs, "required", field.Required); if (itemDefAttribs["requiredMessageFormat"] != null) { field.RequiredMessageFormat = itemDefAttribs["requiredMessageFormat"].Value; } if (itemDefAttribs["regex"] != null) { field.Regex = itemDefAttribs["regex"].Value; } if (itemDefAttribs["regexMessageFormat"] != null) { field.RegexMessageFormat = itemDefAttribs["regexMessageFormat"].Value; } if (itemDefAttribs["token"] != null && !String.IsNullOrWhiteSpace(itemDefAttribs["token"].Value)) { field.Token = itemDefAttribs["token"].Value; } field.Searchable = XmlUtils.ParseBoolFromAttribute(itemDefAttribs, "isSearchable", field.Searchable); if (itemDefAttribs["editPageControlWrapperCssClass"] != null) { field.EditPageControlWrapperCssClass = itemDefAttribs["editPageControlWrapperCssClass"].Value; } if (itemDefAttribs["editPageLabelCssClass"] != null) { field.EditPageLabelCssClass = itemDefAttribs["editPageLabelCssClass"].Value; } if (itemDefAttribs["editPageControlCssClass"] != null) { field.EditPageControlCssClass = itemDefAttribs["editPageControlCssClass"].Value; } field.DatePickerIncludeTimeForDate = XmlUtils.ParseBoolFromAttribute(itemDefAttribs, "datePickerIncludeTimeForDate", field.DatePickerIncludeTimeForDate); field.DatePickerShowMonthList = XmlUtils.ParseBoolFromAttribute(itemDefAttribs, "datePickerShowMonthList", field.DatePickerShowMonthList); field.DatePickerShowYearList = XmlUtils.ParseBoolFromAttribute(itemDefAttribs, "datePickerShowYearList", field.DatePickerShowYearList); if (itemDefAttribs["datePickerYearRange"] != null) { field.DatePickerYearRange = itemDefAttribs["datePickerYearRange"].Value; } if (itemDefAttribs["imageBrowserEmptyUrl"] != null) { field.ImageBrowserEmptyUrl = itemDefAttribs["imageBrowserEmptyUrl"].Value; } field.CheckBoxReturnBool = XmlUtils.ParseBoolFromAttribute(itemDefAttribs, "checkBoxReturnBool", field.CheckBoxReturnBool); if (itemDefAttribs["checkBoxReturnValueWhenTrue"] != null) { field.CheckBoxReturnValueWhenTrue = itemDefAttribs["checkBoxReturnValueWhenTrue"].Value; } if (itemDefAttribs["checkBoxReturnValueWhenFalse"] != null) { field.CheckBoxReturnValueWhenFalse = itemDefAttribs["checkBoxReturnValueWhenFalse"].Value; } if (itemDefAttribs["dateFormat"] != null) { field.DateFormat = itemDefAttribs["dateFormat"].Value; } if (itemDefAttribs["textBoxMode"] != null) { field.TextBoxMode = itemDefAttribs["textBoxMode"].Value; } field.IsDeleted = XmlUtils.ParseBoolFromAttribute(itemDefAttribs, "isDeleted", field.IsDeleted); field.IsGlobal = XmlUtils.ParseBoolFromAttribute(itemDefAttribs, "isGlobal", field.IsGlobal); StringBuilder options = new StringBuilder(); StringBuilder attributes = new StringBuilder(); foreach (XmlNode subNode in childNode) { switch (subNode.Name) { case "Options": GetKeyValuePairs(subNode.ChildNodes, out options); break; case "Attributes": GetKeyValuePairs(subNode.ChildNodes, out attributes); break; case "PreTokenString": field.PreTokenString = subNode.InnerText.Trim(); break; case "PostTokenString": field.PostTokenString = subNode.InnerText.Trim(); break; } } if (options.Length > 0) { field.Options = options.ToString(); } if (attributes.Length > 0) { field.Attributes = attributes.ToString(); } fields.Add(field); } catch (System.Xml.XmlException ex) { log.Error(ex); } } else if (childNode.Name == "Scripts") { try { config.EditPageScripts = SuperFlexiHelpers.ParseScriptsFromXmlNode(childNode); } catch (System.Xml.XmlException ex) { log.Error(ex); } } else if (childNode.Name == "Styles") { try { config.EditPageCSS = SuperFlexiHelpers.ParseCssFromXmlNode(childNode); } catch (System.Xml.XmlException ex) { log.Error(ex); } } else if (childNode.Name == "SearchDefinition") { try { SuperFlexiHelpers.ParseSearchDefinition(childNode, definitionGuid, siteGuid); } catch (XmlException ex) { log.Error(ex); } } } } } fields.Sort(); return(fields); }