private void InitFromXML(XmlDocument xmlDoc)
        {
            XmlNode headerNode = xmlDoc.SelectSingleNode("/ConfigurationAtom/HtmlHeader");
            String  header     = string.Empty;

            if (headerNode != null && !String.IsNullOrEmpty(headerNode.InnerText))
            {
                header = headerNode.InnerText;
            }

            XmlNode titleNode = xmlDoc.SelectSingleNode("/ConfigurationAtom/Title");
            string  title     = string.Empty;

            if (titleNode != null && !string.IsNullOrEmpty(titleNode.InnerText))
            {
                title = titleNode.InnerText;
            }

            List <AppConfigAtomInfo> configs = new List <AppConfigAtomInfo>();

            foreach (XmlNode acNode in xmlDoc.SelectNodes("/ConfigurationAtom/AppConfig"))
            {
                String name = null;

                XmlNode nameNode = acNode.SelectSingleNode("Name");
                if (nameNode == null || string.IsNullOrEmpty(nameNode.InnerText))
                {
                    throw new ArgumentException("Name node invalid.");
                }

                name = nameNode.InnerText;

                AppConfig ac            = AppConfigManager.GetAppConfig(0, nameNode.InnerText);
                Boolean   hasCreateInfo = false;
                if (ac == null)
                {
                    XmlNode createNode = acNode.SelectSingleNode("CreateValues");
                    if (createNode != null)
                    {
                        String        description     = string.Empty;
                        String        defaultValue    = string.Empty;
                        String        groupName       = "CUSTOM";
                        Boolean       superOnly       = false;
                        String        valueType       = "string";
                        List <String> allowableValues = new List <string>();

                        XmlNode descriptionNode = createNode.SelectSingleNode("Description");
                        if (descriptionNode != null && !String.IsNullOrEmpty(descriptionNode.InnerText))
                        {
                            description = descriptionNode.InnerText;
                        }

                        XmlNode defaultVauleNode = createNode.SelectSingleNode("DefaultValue");
                        if (defaultVauleNode != null && !String.IsNullOrEmpty(defaultVauleNode.InnerText))
                        {
                            defaultValue = defaultVauleNode.InnerText;
                        }

                        XmlNode groupNameNode = createNode.SelectSingleNode("GroupName");
                        if (groupNameNode != null && !String.IsNullOrEmpty(groupNameNode.InnerText))
                        {
                            groupName = groupNameNode.InnerText.ToUpper();
                        }

                        XmlNode superOnlyNode = createNode.SelectSingleNode("SuperOnly");
                        if (superOnlyNode != null && !String.IsNullOrEmpty(superOnlyNode.InnerText))
                        {
                            superOnly = superOnlyNode.InnerText.ToBool();
                        }

                        XmlNode valueTypeNode = createNode.SelectSingleNode("ValueType");
                        if (valueTypeNode != null && !String.IsNullOrEmpty(valueTypeNode.InnerText))
                        {
                            valueType = valueTypeNode.InnerText;
                        }

                        XmlNode allowableValuesNode = createNode.SelectSingleNode("AllowableValues");
                        if (allowableValuesNode != null && !String.IsNullOrEmpty(allowableValuesNode.InnerText))
                        {
                            allowableValues = allowableValuesNode.InnerText.Split(',').ToList();
                        }


                        ac            = new AppConfig(0, Guid.NewGuid(), name, description, defaultValue, groupName, superOnly, DateTime.Now, valueType, allowableValues);
                        ac.StoreId    = 0;
                        hasCreateInfo = true;
                    }
                }

                AppConfigAtomInfo acai = new AppConfigAtomInfo(ac);
                acai.HasCreateInfo = hasCreateInfo;

                if (acNode.Attributes["Required"] != null)
                {
                    acai.IsRequired = acNode.Attributes["Required"].InnerText.ToBool();
                }

                if (acNode.Attributes["Advanced"] != null)
                {
                    acai.IsAdvanced = acNode.Attributes["Advanced"].InnerText.ToBool();
                }

                if (acNode.Attributes["FriendlyName"] != null)
                {
                    acai.FriendlyName = acNode.Attributes["FriendlyName"].InnerText;
                }

                XmlNode contextualDescriptionNode = acNode.SelectSingleNode("ContextualDescription");
                if (contextualDescriptionNode != null && !String.IsNullOrEmpty(contextualDescriptionNode.InnerText))
                {
                    acai.ContextualDescription = contextualDescriptionNode.InnerText;
                }

                configs.Add(acai);
            }

            this.Init(configs, header, title);
        }
Exemple #2
0
        private void InitFromXML(XmlDocument xmlDoc)
        {
            var headerNode = xmlDoc.SelectSingleNode("/ConfigurationAtom/HtmlHeader");
            var header     = string.Empty;

            if (headerNode != null && !string.IsNullOrEmpty(headerNode.InnerText))
            {
                header = headerNode.InnerText;
            }

            var titleNode = xmlDoc.SelectSingleNode("/ConfigurationAtom/Title");
            var title     = string.Empty;

            if (titleNode != null && !string.IsNullOrEmpty(titleNode.InnerText))
            {
                title = titleNode.InnerText;
            }

            var configs = new List <AppConfigAtomInfo>();

            foreach (XmlNode acNode in xmlDoc.SelectNodes("/ConfigurationAtom/AppConfig"))
            {
                string name = null;

                var nameNode = acNode.SelectSingleNode("Name");
                if (nameNode == null || string.IsNullOrEmpty(nameNode.InnerText))
                {
                    throw new ArgumentException("Name node invalid.");
                }

                name = nameNode.InnerText;

                var  appConfig     = AppConfigManager.GetAppConfig(nameNode.InnerText);
                bool hasCreateInfo = false;
                if (appConfig == null)
                {
                    var createNode = acNode.SelectSingleNode("CreateValues");
                    if (createNode != null)
                    {
                        var  description     = string.Empty;
                        var  defaultValue    = string.Empty;
                        var  groupName       = "CUSTOM";
                        bool superOnly       = false;
                        var  valueType       = "string";
                        var  allowableValues = new List <string>();

                        var descriptionNode = createNode.SelectSingleNode("Description");
                        if (descriptionNode != null && !string.IsNullOrEmpty(descriptionNode.InnerText))
                        {
                            description = descriptionNode.InnerText;
                        }

                        var defaultVauleNode = createNode.SelectSingleNode("DefaultValue");
                        if (defaultVauleNode != null && !string.IsNullOrEmpty(defaultVauleNode.InnerText))
                        {
                            defaultValue = defaultVauleNode.InnerText;
                        }

                        var groupNameNode = createNode.SelectSingleNode("GroupName");
                        if (groupNameNode != null && !string.IsNullOrEmpty(groupNameNode.InnerText))
                        {
                            groupName = groupNameNode.InnerText.ToUpper();
                        }

                        var superOnlyNode = createNode.SelectSingleNode("SuperOnly");
                        if (superOnlyNode != null && !string.IsNullOrEmpty(superOnlyNode.InnerText))
                        {
                            superOnly = superOnlyNode.InnerText.ToBool();
                        }

                        var valueTypeNode = createNode.SelectSingleNode("ValueType");
                        if (valueTypeNode != null && !string.IsNullOrEmpty(valueTypeNode.InnerText))
                        {
                            valueType = valueTypeNode.InnerText;
                        }

                        var allowableValuesNode = createNode.SelectSingleNode("AllowableValues");
                        if (allowableValuesNode != null && !string.IsNullOrEmpty(allowableValuesNode.InnerText))
                        {
                            allowableValues = allowableValuesNode.InnerText.Split(',').ToList();
                        }

                        appConfig = new AppConfig(
                            appConfigId: 0,
                            appConfigGuid: Guid.NewGuid(),
                            storeId: 0,
                            name: name,
                            description: description,
                            configValue: defaultValue,
                            groupName: groupName,
                            superOnly: superOnly,
                            createdOn: DateTime.Now,
                            updatedOn: DateTime.Now,
                            valueType: valueType,
                            allowableValues: allowableValues,
                            hidden: false);
                        hasCreateInfo = true;
                    }
                }

                var appConfigAtomInfo = new AppConfigAtomInfo(appConfig);
                appConfigAtomInfo.HasCreateInfo = hasCreateInfo;

                if (acNode.Attributes["Required"] != null)
                {
                    appConfigAtomInfo.IsRequired = acNode.Attributes["Required"].InnerText.ToBool();
                }

                if (acNode.Attributes["Advanced"] != null)
                {
                    appConfigAtomInfo.IsAdvanced = acNode.Attributes["Advanced"].InnerText.ToBool();
                }

                if (acNode.Attributes["FriendlyName"] != null)
                {
                    appConfigAtomInfo.FriendlyName = acNode.Attributes["FriendlyName"].InnerText;
                }

                var contextualDescriptionNode = acNode.SelectSingleNode("ContextualDescription");
                if (contextualDescriptionNode != null && !string.IsNullOrEmpty(contextualDescriptionNode.InnerText))
                {
                    appConfigAtomInfo.ContextualDescription = contextualDescriptionNode.InnerText;
                }

                configs.Add(appConfigAtomInfo);
            }

            this.Init(configs, header, title);
        }