internal void SaveSettings()
        {
            // Load the web.config file
            var filename  = HttpContext.Current.Server.MapPath("~/web.config");
            var webconfig = new ConfigXmlDocument();

            webconfig.Load(filename);

            var node = webconfig.SelectSingleNode("/configuration/connectionStrings/add[@name='RedisCachingProvider']");

            SaveAttribute(node, "connectionString", ConnectionString);

            node = webconfig.SelectSingleNode("/configuration/dotnetnuke/caching");
            SaveAttribute(node, "defaultProvider", CachingProviderEnabled ? "RedisCachingProvider" : "FileBasedCachingProvider");

            node = webconfig.SelectSingleNode("/configuration/dotnetnuke/outputCaching");
            SaveAttribute(node, "defaultProvider", OutputCachingProviderEnabled ? "RedisOutputCachingProvider" : "MemoryOutputCachingProvider");

            node = webconfig.SelectSingleNode("/configuration/dotnetnuke/caching/providers/add[@name='RedisCachingProvider']");
            SaveAttribute(node, "useCompression", UseCompression.ToString());
            SaveAttribute(node, "silentMode", SilentMode.ToString());
            SaveAttribute(node, "keyPrefix", KeyPrefix);

            node = webconfig.SelectSingleNode("/configuration/dotnetnuke/outputCaching/providers/add[@name='RedisOutputCachingProvider']");
            SaveAttribute(node, "useCompression", UseCompression.ToString());
            SaveAttribute(node, "silentMode", SilentMode.ToString());
            SaveAttribute(node, "keyPrefix", KeyPrefix);

            webconfig.Save(filename);

            // Clear the cache
            DotNetNuke.Services.Cache.CachingProvider.Instance().PurgeCache();
        }
Beispiel #2
0
        public void LoadXML(string path)
        {
            ConfigXmlDocument xml = new ConfigXmlDocument();

            xml.Load("config.xml");
            XmlNode node = xml.SelectSingleNode("/configuration/appSettings");

            EDPCheckHelper.st.STID   = Convert.ToInt32(node.SelectSingleNode("st").Attributes["value"].Value);
            EDPCheckHelper.st.zctime = Convert.ToInt32(node.SelectSingleNode("zctime").Attributes["value"].Value);
            EDPCheckHelper.st.gztime = Convert.ToInt32(node.SelectSingleNode("gztime").Attributes["value"].Value);
            EDPCheckHelper.st.dd     = node.SelectSingleNode("dd").Attributes["value"].Value;
            EDPCheckHelper.st.ph     = node.SelectSingleNode("admin").Attributes["value"].Value;
            var ips = xml.SelectSingleNode("/configuration/Check/PC");

            foreach (XmlNode xn in ips.ChildNodes)
            {
                EDPCheckHelper.EDPMsg em = new EDPCheckHelper.EDPMsg();
                em.MacName = xn.Attributes["key"].Value;
                em.IP      = xn.Attributes["value"].Value;
                em.MsgTime = DateTime.Now;
                em.succes  = true;
                em.Type    = Convert.ToInt32(xn.Attributes["type"].Value);
                EDPCheckHelper.ems.Add(em.MacName, em);
            }
        }
        /// <summary>
        /// Update RunTimeData appSettings sections
        /// Add a new key
        /// </summary>
        /// <param name="key"></param>
        /// <param name="value"></param>
        public static void AddKeyAppSettings(string key, string value)
        {
            //Update custom configuration sections - Add a new key
            ConfigXmlDocument xmlDoc = new ConfigXmlDocument();

            //var projectDir = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.Parent.FullName;
            //var fileDir = projectDir + @"\AcceptanceTests\DataFiles\";
            //var xmlDir = fileDir + "RunTimeData.xml";

            //Replace with get xmlDir Method()
            xmlDoc.Load(xmlDir);

            // create new node <add key="New Key" value="New Key Value1" />
            var node = xmlDoc.CreateElement("add");

            //node.SetAttribute("key", "New Key");
            //node.SetAttribute("value", "New Key Value1");

            node.SetAttribute("key", key);
            node.SetAttribute("value", value);

            xmlDoc.SelectSingleNode("//appSettings").AppendChild(node);


            //xmlDoc.Save(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile);
            xmlDoc.Save(xmlDir);

            ConfigurationManager.RefreshSection("//appSettings");
        }
Beispiel #4
0
        private void ModifyAppInsightsConfigFile(bool removeSettings = false)
        {
            var configFile = Server.MapPath("~/ApplicationInsights.config");

            if (!File.Exists(configFile))
            {
                File.Copy(Server.MapPath("~/DesktopModules/AppInsights/ApplicationInsights.config"), configFile);
            }

            // Load the ApplicationInsights.config file
            var config = new ConfigXmlDocument();

            config.Load(configFile);
            var key = removeSettings ? string.Empty : ModuleSettings.GetValueOrDefault("InstrumentationKey", string.Empty);

            const string namespaceUri = "http://schemas.microsoft.com/ApplicationInsights/2013/Settings";
            var          nsmgr        = new XmlNamespaceManager(config.NameTable);

            nsmgr.AddNamespace("nr", namespaceUri);

            // Change instrumentation key
            var keyNode = config.SelectSingleNode("//nr:InstrumentationKey", nsmgr);

            if (keyNode != null)
            {
                keyNode.InnerText = key;
            }

            // Save the modifications
            config.Save(configFile);
        }
        /// <summary>
        /// Update RunTimeData custom configuration sections
        /// Edit an existing key's value
        /// </summary>
        /// <param name="key"></param>
        /// <param name="value"></param>
        public static void UpdateKeyConfigSectionData(string key, string value)
        {
            //First get the current environment from the appSettings section
            var environment = AppConfig.GetAppSettingsValue("Environment");

            // Update custom configuration sections - Edit an existing key's value
            ConfigXmlDocument xmlDoc = new ConfigXmlDocument();

            //this dir accesses the \bin runtime location
            //not the project app.config file
            //xmlDoc.Load(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile);

            //var projectDir = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.Parent.FullName;
            //var fileDir = projectDir + @"\AcceptanceTests\DataFiles\";
            //var xmlDir = fileDir + "RunTimeData.xml";

            //Replace with get xmlDir Method()
            xmlDoc.Load(xmlDir);

            //Update the key value
            //xmlDoc.SelectSingleNode("//Local/add[@key='Test']").Attributes["value"].Value = "New Value6";
            var node = "//" + environment + "/add[@key='" + key + "']";

            xmlDoc.SelectSingleNode(node).Attributes["value"].Value = value;

            //xmlDoc.Save(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile);
            xmlDoc.Save(xmlDir);

            ConfigurationManager.RefreshSection("//" + environment);
        }
        /// <summary>
        /// Update RunTimeData custom configuration sections
        /// Delete an existing key
        /// </summary>
        /// <param name="key"></param>
        public static void DeleteKeyConfigSectionData(string key)
        {
            //First get the current environment from the appSettings section
            var environment = AppConfig.GetAppSettingsValue("Environment");

            //Update custom configuration sections - Add a new key
            ConfigXmlDocument xmlDoc = new ConfigXmlDocument();

            //var projectDir = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.Parent.FullName;
            //var fileDir = projectDir + @"\AcceptanceTests\DataFiles\";
            //var xmlDir = fileDir + "RunTimeData.xml";

            //Replace with get xmlDir Method()
            xmlDoc.Load(xmlDir);

            //XmlNode node = xmlDoc.SelectSingleNode("//Dev/add[@key='Key1']");
            var nodeString = "//" + environment + "/add[@key='" + key + "']";

            XmlNode node = xmlDoc.SelectSingleNode(nodeString);

            node.ParentNode.RemoveChild(node);

            //xmlDoc.Save(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile);
            xmlDoc.Save(xmlDir);

            ConfigurationManager.RefreshSection("//" + environment);
        }
Beispiel #7
0
        private string GetConnectionString(string strPathToConfigFile, string strAppSettingsKey)
        {
            try
            {
                ConfigXmlDocument doc = new ConfigXmlDocument();
                doc.Load(strPathToConfigFile);

                XmlNode nodeKey     = doc.SelectSingleNode("//appSettings/add[@key='" + strAppSettingsKey + "']");
                string  strEncValue = nodeKey.Attributes["value"].Value.ToString();
                string  strDecValue = ICICRYPT.Reversible.StrDecode(strEncValue, 2026820330, true);

                // MessageBox.Show(strDecValue);

                SqlConnection objConn = new SqlConnection(strDecValue);
                objConn.Open();
                objConn.Close();
                objConn.Dispose();

                return(strDecValue);
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(this, "Error obtaining connection to " + strLocation + " database\n\n\"" + ex.Message + "\"\n" + ex.StackTrace, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                this.Close();
            }

            return(null);
        }
Beispiel #8
0
        public void LoadAppConfigTest()
        {
            SharpCvsLibConfigHandler configHandler =
                new SharpCvsLibConfigHandler();
            ConfigXmlDocument xmlDoc =
                new ConfigXmlDocument();

            xmlDoc.Load(CONFIG_FILE);

            SharpCvsLibConfig config = null;

            config =
                (SharpCvsLibConfig)configHandler.Create
                    (xmlDoc.SelectSingleNode("configuration"),
                    null,
                    xmlDoc.SelectSingleNode("//" +
                                            SharpCvsLibConfigHandler.APP_CONFIG_SECTION));
            this.CheckValues(config);
        }
Beispiel #9
0
        private void buttonSave_Click(object sender, EventArgs e)
        {
            string            AK            = this.textBoxAK.Text;
            string            SK            = this.textBoxSK.Text;
            string            defaultbucket = this.comboBoxBuckets.SelectedItem.ToString();
            ConfigXmlDocument xmlDoc        = new ConfigXmlDocument();
            string            currentPath   = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
            // App.config所在路径
            string configPath = currentPath.Substring(0, currentPath.Length - 10) + "App.config";

            xmlDoc.Load(configPath);
            XmlElement xmlElementAK            = (XmlElement)xmlDoc.SelectSingleNode("//appSettings/add[1]");
            XmlElement xmlElementSK            = (XmlElement)xmlDoc.SelectSingleNode("//appSettings/add[2]");
            XmlElement xmlElementDefaultBucket = (XmlElement)xmlDoc.SelectSingleNode("//appSettings/add[last()]");

            xmlElementAK.SetAttribute("value", AK);
            xmlElementSK.SetAttribute("value", SK);
            xmlElementDefaultBucket.SetAttribute("value", defaultbucket);
            xmlDoc.Save(configPath);
        }
Beispiel #10
0
        public void SetAppSetting(string name, string value)
        {
            // Ensure there's an <appSettings> node inside <configuration>
            // If not, create it.
            XmlNode settingsNode = config.SelectSingleNode("configuration/appSettings");

            if (settingsNode == null)
            {
                settingsNode = config.CreateNode(XmlNodeType.Element, "appSettings", "");
                config.SelectSingleNode("configuration").AppendChild(settingsNode);
            }

            XmlAttribute key = config.CreateAttribute("key");

            key.Value = name;

            XmlAttribute val = config.CreateAttribute("value");

            val.Value = value;

            bool found = false;

            foreach (XmlNode n in settingsNode.ChildNodes)
            {
                if (n.Name == "add" && n.Attributes.GetNamedItem("key").Value == name)
                {
                    n.Attributes.SetNamedItem(key);
                    n.Attributes.SetNamedItem(val);
                    found = true;
                    break;
                }
            }

            if (!found)
            {
                XmlNode itemNode = config.CreateNode(XmlNodeType.Element, "add", "");
                settingsNode.AppendChild(itemNode);
                itemNode.Attributes.SetNamedItem(key);
                itemNode.Attributes.SetNamedItem(val);
            }
        }
        internal void LoadSettings()
        {
            ConnectionString = ConfigurationManager.ConnectionStrings["RedisCachingProvider"]?.ConnectionString;

            // Load the web.config file
            var webconfig = new ConfigXmlDocument();

            webconfig.Load(HttpContext.Current.Server.MapPath("~/web.config"));

            var node = webconfig.SelectSingleNode("/configuration/dotnetnuke/caching");

            CachingProviderEnabled = node?.Attributes["defaultProvider"]?.Value == "RedisCachingProvider";

            node = webconfig.SelectSingleNode("/configuration/dotnetnuke/outputCaching");
            OutputCachingProviderEnabled = node?.Attributes["defaultProvider"]?.Value == "RedisOutputCachingProvider";

            node           = webconfig.SelectSingleNode("/configuration/dotnetnuke/caching/providers/add[@name='RedisCachingProvider']");
            UseCompression = bool.Parse(node?.Attributes["useCompression"]?.Value);
            SilentMode     = bool.Parse(node?.Attributes["silentMode"]?.Value);
            KeyPrefix      = NotNull(node?.Attributes["keyPrefix"]?.Value);
        }
Beispiel #12
0
        private string createId(int increase = 1)
        {
            ConfigXmlDocument doc = new ConfigXmlDocument();

            doc.Load(ConstInfo.TicketID_Path);
            var    date     = doc.SelectSingleNode("TicketID/date").InnerText;
            string ticketId = "";

            if (date != currentDate)
            {
                var dateNode = doc.SelectSingleNode("TicketID/date");
                dateNode.InnerText = currentDate;
                ticketId           = "0000";
            }
            else
            {
                var id        = doc.SelectSingleNode("TicketID/id").InnerText;
                var currentID = Convert.ToInt32(id) + increase;
                ticketId = currentID.ToString().PadLeft(4, '0');
            }
            doc.SelectSingleNode("TicketID/id").InnerText = ticketId;
            doc.Save(ConstInfo.TicketID_Path);
            return(currentDate + "-" + ticketId);
        }
        private ConfigSectionResource CreateConfigSectionResource(string filename)
        {
            ConfigXmlDocument xmlDoc = new ConfigXmlDocument();

            Uri testUri = TestResourceLoader.GetUri(this, filename);

            xmlDoc.Load("test config section", testUri.AbsoluteUri);
            XmlNamespaceManager nsmgr = new XmlNamespaceManager(xmlDoc.NameTable);

            nsmgr.AddNamespace("od", "http://www.springframework.net");
            XmlElement configElement = (XmlElement)xmlDoc.SelectSingleNode("//configuration/spring/od:objects", nsmgr);

            ConfigSectionResource csr = new ConfigSectionResource(configElement);

            return(csr);
        }
        //**********************************************
        // RunTimeData.xml appSettings Section Methods *
        //**********************************************

        /// <summary>
        /// Return RunTimeData appSettings sections
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public static string GetKeyAppSettings(string key)
        {
            ConfigXmlDocument xmlDoc = new ConfigXmlDocument();

            //var projectDir = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.Parent.FullName;
            //var fileDir = projectDir + @"\AcceptanceTests\DataFiles\";
            //var xmlDir = fileDir + "RunTimeData.xml";

            xmlDoc.Load(xmlDir);

            //var node = "//appSettings/add[@key='Test1']";
            var node  = "//appSettings/add[@key='" + key + "']";
            var value = xmlDoc.SelectSingleNode(node).Attributes["value"].Value;

            return(value);
        }
        private void ShowCurrentDataSource(ConfigXmlDocument doc)
        {
            XmlNode xmlNode = doc.SelectSingleNode("//connectionStrings");

            if (xmlNode == null || !xmlNode.HasChildNodes)
            {
                int num = (int)MessageBox.Show("配置文件中不存在有效的 connectionStrings 节点或节点下没有有效的配置信息");
            }
            foreach (XmlNode childNode in xmlNode.ChildNodes)
            {
                if (childNode.NodeType == XmlNodeType.Element)
                {
                    this.rtbConnectString.Text = (Utility.DeBase64(((XmlElement)childNode).GetAttribute("connectionString")));
                }
            }
        }
Beispiel #16
0
        private static string GetConfiguration(ConfigXmlDocument cxd, string key)
        {
            if (string.IsNullOrEmpty(key))
            {
                return(string.Empty);
            }
            /*XmlNodeList xns = cxd.GetElementsByTagName("appSettings");*/
            XmlNode xn = cxd.SelectSingleNode(@"//add[@key='" + key + "']");

            if (xn == null || xn.Attributes == null)
            {
                return(string.Empty);
            }
            string value = xn.Attributes["value"].Value;

            return(value);
        }
        //********************************************************
        // RunTimeData.xml custom configuration sections Methods *
        //********************************************************

        /// <summary>
        /// Return RunTimeData custom configuration sections
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public static string GetKeyConfigSectionData(string key)
        {
            //First get the current environment from the appSettings section
            var environment = AppConfig.GetAppSettingsValue("Environment");

            ConfigXmlDocument xmlDoc = new ConfigXmlDocument();

            //var projectDir = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.Parent.FullName;
            //var fileDir = projectDir + @"\AcceptanceTests\DataFiles\";
            //var xmlDir = fileDir + "RunTimeData.xml";

            xmlDoc.Load(xmlDir);

            //var node = "//QA/add[@key='Test1']";
            var node  = "//" + environment + "/add[@key='" + key + "']";
            var value = xmlDoc.SelectSingleNode(node).Attributes["value"].Value;

            return(value);
        }
 private bool ChangeConfig(ConfigXmlDocument doc)
 {
     foreach (XmlNode childNode in doc.SelectSingleNode("//connectionStrings").ChildNodes)
     {
         if (childNode.NodeType == XmlNodeType.Element)
         {
             XmlElement xmlElement = (XmlElement)childNode;
             string     str        = Utility.EnBase64(this.rtbConnectString.Text);
             xmlElement.SetAttribute("connectionString", str);
         }
     }
     try
     {
         doc.Save(this.webConfigPath);
     }
     catch (Exception ex)
     {
         int num = (int)MessageBox.Show(string.Format("更改配置失败:{0}", (object)ex));
         return(false);
     }
     return(true);
 }
Beispiel #19
0
        private static ConfigurationSection HandleLegacyConfigurationSection(string exeConfigFilename, ConfigurationSectionGroupPath groupPath, string sectionKey)
        {
            var sectionPath = groupPath.GetChildGroupPath(sectionKey).ToString();

            foreach (var shredSettingsType in _shredSettingsTypes)
            {
                if (LegacyShredConfigSectionAttribute.IsMatchingLegacyShredConfigSectionType(shredSettingsType, sectionPath))
                {
                    var xmlDocument = new ConfigXmlDocument();
                    xmlDocument.Load(exeConfigFilename);

                    var sectionElement = xmlDocument.SelectSingleNode("//" + sectionPath);
                    if (sectionElement != null)
                    {
                        var section = (ShredConfigSection)Activator.CreateInstance(shredSettingsType, true);
                        section.LoadXml(sectionElement.OuterXml);
                        return(section);
                    }
                }
            }
            return(null);
        }
Beispiel #20
0
        private void btnSelect_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Filter      = ".Net config file(*.config)|*.config";
            ofd.Multiselect = false;
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                txtConfigFile.Text = ofd.FileName;
                //load configuration
                ConfigXmlDocument cxd = new ConfigXmlDocument();
                cxd.Load(txtConfigFile.Text);
                xnConnectionStrings = cxd.SelectSingleNode("/configuration/" + HKHConnectionStringsSection.TagName);

                cbConfigs.SelectedIndexChanged -= cbConfigs_SelectedIndexChanged;
                cbConfigs.Items.Clear();
                foreach (XmlNode xnConfig in xnConnectionStrings.ChildNodes)
                {
                    cbConfigs.Items.Add(xnConfig.Attributes["name"].Value);
                    //default select
                    if (xnConfig.Attributes["isDefault"] != null && xnConfig.Attributes["isDefault"].Value.ToLower() == "true")
                    {
                        cbConfigs.SelectedIndex = cbConfigs.Items.Count - 1;
                    }
                }

                //select first item if no default setting
                if (cbConfigs.Items.Count > 0 && cbConfigs.SelectedIndex == -1)
                {
                    cbConfigs.SelectedIndex = 0;
                }
                cbConfigs.SelectedIndexChanged += cbConfigs_SelectedIndexChanged;

                cbConfigs_SelectedIndexChanged(cbConfigs, EventArgs.Empty);
            }
        }
        public static void Install(String machineConfigPath, String patchFileName)
        {
            ConfigXmlDocument machineConfig = new ConfigXmlDocument();

            machineConfig.PreserveWhitespace = true;
            machineConfig.Load(machineConfigPath);

            XmlDocument patch = new XmlDocument();

            patch.PreserveWhitespace = true;
            patch.Load(patchFileName);

            // Remove original <result type=""> node, replace by
            // comment.  Only one <result> node allowed in machine.config.
            String resultPath      = "/configuration/system.web/browserCaps/result";
            String browserCapsPath = "/configuration/system.web/browserCaps";

            XmlNode resultNode           = machineConfig.SelectSingleNode(resultPath);
            XmlNode browserCapsNode      = machineConfig.SelectSingleNode(browserCapsPath);
            XmlNode patchResultNode      = patch.SelectSingleNode(resultPath);
            XmlNode patchBrowserCapsNode = patch.SelectSingleNode(browserCapsPath);
            XmlNode patchResultNodeClone = machineConfig.ImportNode(patchResultNode, true);

            patchBrowserCapsNode.RemoveChild(patchResultNode);

            ArrayList browserCapsLeadingWhitespace = new ArrayList();

            foreach (XmlNode child in browserCapsNode.ChildNodes)
            {
                if (child.NodeType == XmlNodeType.Whitespace)
                {
                    browserCapsLeadingWhitespace.Add(child);
                }
                else
                {
                    break;
                }
            }

            StringBuilder commentText = new StringBuilder();

            if (resultNode != null)
            {
                XmlTextWriter commentWriter = new XmlTextWriter(new StringWriter(commentText));
                resultNode.WriteTo(commentWriter);
                browserCapsNode.RemoveChild(resultNode);
            }

            MergePrepend(machineConfig, patch,
                         "/configuration/system.web/httpModules");
            MergePrepend(machineConfig, patch,
                         "/configuration/configSections/sectionGroup[@name='system.web']");
            MergePrepend(machineConfig, patch,
                         "/configuration/system.web/compilation/assemblies");
            Merge(machineConfig, patch,
                  "/configuration/system.web/browserCaps");
            Insert(machineConfig, patch,
                   "/configuration/system.web", "mobileControls");
            Insert(machineConfig, patch,
                   "/configuration/system.web", "deviceFilters");

            // Prepend these nodes (in reverse order) so that they occur
            // before any other children.
            if (resultNode != null)
            {
                PrependComment(machineConfig, browserCapsNode, _removedEltEndComment);
                PrependComment(machineConfig, browserCapsNode, commentText.ToString());
                PrependComment(machineConfig, browserCapsNode, _removedEltBeginComment);
            }
            PrependComment(machineConfig, browserCapsNode, _endComment);
            browserCapsNode.PrependChild(patchResultNodeClone);

            // Clone formatting for inserted node.
            foreach (XmlNode child in browserCapsLeadingWhitespace)
            {
                browserCapsNode.PrependChild(child.CloneNode(false /* deep */));
            }
            PrependComment(machineConfig, browserCapsNode, _beginComment);

            // Clone formatting for uninstall.
            foreach (XmlNode child in browserCapsLeadingWhitespace)
            {
                browserCapsNode.PrependChild(child.CloneNode(false /* deep */));
                browserCapsNode.RemoveChild(child);
            }

            RemoveExtraWhitespace(machineConfig);

            StreamWriter s = new StreamWriter(machineConfigPath);
            XmlIndentAttributeTextWriter writer = new XmlIndentAttributeTextWriter(s);

            writer.Formatting  = Formatting.Indented;
            writer.Indentation = 4;
            machineConfig.Save(writer);
            writer.Flush();
            writer.Close();
        }
Beispiel #22
0
        private static void AppendConfig(ConfigXmlDocument configDocument, ConfigurationUserLevel userLevel)
        {
            var c = ConfigurationManager.OpenExeConfiguration(userLevel);

            if (c.HasFile)
            {
                if (configDocument.DocumentElement == null)
                {
                    configDocument.Load(c.FilePath);
                }
                else
                {
                    var other = new ConfigXmlDocument();
                    other.Load(c.FilePath);

                    {
                        XmlElement usg         = null;
                        string     usgChildren = null;

                        foreach (XmlElement s in other.SelectNodes("/configuration/configSections/sectionGroup[@name=\"userSettings\"]/section"))
                        {
                            if (usg == null)
                            {
                                usg = (XmlElement)configDocument.SelectSingleNode("/configuration/configSections/sectionGroup[@name=\"userSettings\"]");
                                if (usg == null)
                                {
                                    var cs = configDocument.DocumentElement.GetOrPrepend("configSections");

                                    usg = configDocument.CreateElement("sectionGroup");

                                    foreach (XmlAttribute attr in s.ParentNode.Attributes)
                                    {
                                        usg.SetAttribute(attr.LocalName, attr.NamespaceURI, attr.Value);
                                    }
                                    usg.InnerXml = s.ParentNode.InnerXml;
                                    cs.AppendChild(usg);
                                    break;
                                }
                                usgChildren = usg.InnerXml;
                            }

                            usgChildren += s.OuterXml;
                        }
                        if (usgChildren != null)
                        {
                            usg.InnerXml = usgChildren;
                        }
                    }
                    {
                        XmlElement us = null;
                        foreach (XmlElement se in other.SelectNodes("/configuration/userSettings/*/setting"))
                        {
                            if (us == null)
                            {
                                us = configDocument.DocumentElement.GetOrAppend("userSettings");
                            }
                            var secName = se.ParentNode.LocalName;
                            var ps      = us.GetOrAppend(secName);
                            var name    = se.GetAttribute("name");
                            var sete    = ps.GetByNameOrAppend("setting", name, "name", name, "serializeAs", se.GetAttribute("serializeAs"));
                            sete.InnerXml = se.InnerXml;
                        }
                    }
                }
            }
        }