Esempio n. 1
0
        /// <summary>
        /// 基于web.config模型的AppSettings设置
        /// </summary>
        /// <param name="configPath">配置文件路径,相对或完整路径。</param>
        /// <param name="key">健</param>
        /// <param name="Value">健的值</param>
        /// <returns>成功则为0,失败则返回异常信息。</returns>
        public static string SetAppSettings(string configPath, string key, string Value)
        {
            string configFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, configPath);

            try
            {
                System.Configuration.ConfigXmlDocument xmlConfig = new System.Configuration.ConfigXmlDocument();
                xmlConfig.Load(configFile);

                System.Xml.XmlNode node = xmlConfig.SelectSingleNode("configuration/appSettings/add[@key='" + key + "']");
                if (node != null)
                {
                    node.Attributes["value"].Value = Value;
                }
                else
                {
                    XmlElement element = xmlConfig.CreateElement("add");
                    element.SetAttribute("key", key);
                    element.SetAttribute("value", Value);
                    node = xmlConfig.SelectSingleNode("configuration/appSettings");
                    node.AppendChild(element);
                }
                xmlConfig.Save(configFile);
                return("0");
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
        }
Esempio n. 2
0
    public void Save()
    {
        string errorMessage = null;

        if (!HROne.CommonLib.FileIOProcess.IsFolderAllowWritePermission(AppDomain.CurrentDomain.BaseDirectory, out errorMessage))
        {
            throw new Exception(errorMessage);
        }
        string filename = getFilename();


        System.Configuration.ConfigXmlDocument config = new System.Configuration.ConfigXmlDocument();
        XmlElement   settings = config.CreateElement("Settings");
        XmlAttribute version  = config.CreateAttribute("Version");

        version.Value = "2.0";
        settings.Attributes.Append(version);
        config.AppendChild(settings);
        //SetDatabaseConfigList(settings);

        settings.AppendChild(config.CreateElement("HROneConfigFullPath"));
        settings["HROneConfigFullPath"].InnerText = HROneConfigFullPath;


        config.Save(filename);
    }
Esempio n. 3
0
    public void Save()
    {
        string errorMessage = null;

        if (!HROne.CommonLib.FileIOProcess.IsFolderAllowWritePermission(AppDomain.CurrentDomain.BaseDirectory, out errorMessage))
        {
            throw new Exception(errorMessage);
        }
        string filename = getFilename();

        if (config == null)
        {
            config = new System.Configuration.ConfigXmlDocument();
        }
        else
        {
            filename = config.Filename;
        }

        XmlElement settings = GetOrCreateElement(config, "Settings");

        if (settings.Attributes["Version"] == null)
        {
            settings.RemoveAll();
        }
        settings.RemoveAttribute("Version");
        XmlAttribute version = config.CreateAttribute("Version");

        version.Value = "2.0";
        settings.Attributes.Append(version);
        config.AppendChild(settings);
        SetDatabaseConfigList(settings);

        XmlElement shutdownOption = GetOrCreateElement(settings, "ShutdownAfterUsed");

        shutdownOption.InnerText = ShutDownDomainAfterUsed ? "true" : "false";

        XmlElement multiDBOption = GetOrCreateElement(settings, "AllowMultiDB");

        multiDBOption.InnerText = AllowMultiDB ? "true" : "false";

        XmlElement EncryptedURLOption = GetOrCreateElement(settings, "EncryptedURLQueryString");

        EncryptedURLOption.InnerText = EncryptedURLQueryString ? "true" : "false";

        XmlElement UsePDFCreatorOption = GetOrCreateElement(settings, "UsePDFCreator");

        UsePDFCreatorOption.InnerText = UsePDFCreator ? "true" : "false";

        XmlElement PDFCreatorPrinterNameOption = GetOrCreateElement(settings, "PDFCreatorPrinterNameOption");

        PDFCreatorPrinterNameOption.InnerText = PDFCreatorPrinterName;

        config.Save(filename);
    }
Esempio n. 4
0
    public void Save()
    {
        string errorMessage = null;

        if (!HROne.CommonLib.FileIOProcess.IsFolderAllowWritePermission(AppDomain.CurrentDomain.BaseDirectory, out errorMessage))
        {
            throw new Exception(errorMessage);
        }
        string filename = getFilename();

        if (config == null)
        {
            config = new System.Configuration.ConfigXmlDocument();
        }
        else
        {
            filename = config.Filename;
        }
        XmlElement settings = GetOrCreateElement(config, "Settings");
        //{
        //    XmlAttribute version = config.CreateAttribute("Version");
        //    version.Value = "2.0";
        //    settings.Attributes.Append(version);
        //    config.AppendChild(settings);
        //}
        //SetDatabaseConfigList(settings);

        XmlElement masterDatabaseNode = GetOrCreateElement(settings, "MasterDatabaseConfig");

        SetDatabaseConfig(masterDatabaseNode, MasterDatabaseConfig);

        XmlElement databaseEncryptKeyNode = GetOrCreateElement(settings, "DatabaseEncryptKey");

        databaseEncryptKeyNode.InnerText = databaseEncryptKey;
        config.Save(filename);
    }
    public static bool SaveSection(string fileName, string name, MailerConfiguration section)
    {
      System.Configuration.ConfigXmlDocument doc = new ConfigXmlDocument();
      try
      {
        doc.Load(fileName);
        XmlNode configNode = doc.ChildNodes[1];
        foreach (XmlNode node in configNode.ChildNodes)
        {
          if (node.Name == name)
            configNode.RemoveChild(node);
        }

        XmlNode newNode = section.CreateNode(doc, name);
        configNode.AppendChild(newNode);
        doc.Save(fileName);
        return true;
      }
      catch
      {
        return false;
      }
    }
        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);
        }
Esempio n. 7
0
        public static bool UpdateConnectionString( )
        {
            Project pjt = Kit.GetProjectByName(Kit.SlnKeel.UIProjectName);

            if (pjt == null)
            {
                Common.ShowInfo("您尚未设置UI主界面项目, 因此无法自动配置连接字符串到你的app.config 或者web.config中!");
                return(true);
            }
            ProjectItem PI = null;

            for (int i = 1; i <= pjt.ProjectItems.Count; i++)
            {
                ProjectItem pix = pjt.ProjectItems.Item(i);
                if (pix.Name.ToLower().Contains("app.config") || pix.Name.ToLower().Contains("web.config"))
                {
                    PI = pix;
                    break;
                }
            }
            if (PI == null)
            {
                Common.ShowInfo(string.Format("您设置的主UI项目{0}中未找到app.config 或者web.config,因此无法自动设置链接字符串配置", pjt.Name));
            }
            else
            {
                bool needUpdate = true;

                ConfigXmlDocument cxd = new System.Configuration.ConfigXmlDocument();

                cxd.Load(PI.get_FileNames(1));
                XmlNode xnx  = cxd.SelectSingleNode("descendant::configuration/connectionStrings");
                string  csss = GetProjectConfigNamespec(GetProjectLangType(GetProjectUI()));

                string name = "";
                if (pjt.Kind == "{E24C65DC-7377-472b-9ABA-BC803B73C61A}")
                {
                    name = "Keel" + csss + ".ConnectionString";
                }
                else
                {
                    name = ((string)pjt.Properties.Item("RootNamespace").Value) + csss + ".ConnectionString";
                }
                if (xnx != null)
                {
                    for (int i = 0; i < xnx.ChildNodes.Count; i++)
                    {
                        if (xnx.ChildNodes[i].Attributes["name"].Value.Contains(name))
                        {
                            if (xnx.ChildNodes[i].Attributes["providerName"].Value != Kit.SlnKeel.ProviderName)
                            {
                                xnx.ChildNodes[i].Attributes["providerName"].Value = Kit.SlnKeel.ProviderName;
                            }
                            if (xnx.ChildNodes[i].Attributes["connectionString"].Value != Kit.SlnKeel.ConnectString)
                            {
                                xnx.ChildNodes[i].Attributes["connectionString"].Value = Kit.SlnKeel.ConnectString;
                            }
                            cxd.Save(PI.get_FileNames(1));
                            needUpdate = false;
                            break;
                        }
                    }
                }
                if (needUpdate)
                {
                    XmlNode      xn             = cxd.CreateNode("element", "add", "");
                    XmlAttribute xzproviderName = cxd.CreateAttribute("providerName");
                    xzproviderName.Value = Kit.SlnKeel.ProviderName;
                    XmlAttribute xaconnectionString = cxd.CreateAttribute("connectionString");
                    xaconnectionString.Value = Kit.SlnKeel.ConnectString;
                    XmlAttribute xaname = cxd.CreateAttribute("name");
                    xaname.Value = name;
                    xn.Attributes.Append(xaname);
                    xn.Attributes.Append(xaconnectionString);
                    xn.Attributes.Append(xzproviderName);
                    if (xnx == null)
                    {
                        XmlNode xnx1 = cxd.SelectSingleNode("descendant::configuration");
                        xnx = cxd.CreateElement("connectionStrings");
                        xnx1.AppendChild(xnx);
                    }
                    xnx.AppendChild(xn);
                    // cxd.SelectSingleNode("descendant::configuration/connectionStrings").InnerXml = xnx.InnerXml;
                    cxd.Save(PI.get_FileNames(1));
                    //;// = cxd.SelectSingleNode("descendant::configuration/connectionStrings/add[@name='" + appnamespace + ".Properties.Settings.ConnectionString']");
                    //if (xnl.Attributes["providerName"] != null && xnl.Attributes["connectionString"] != null)
                    //{

                    //}
                }
                Common.ShowInfo(string.Format("您设置的主UI项目{0}中到app.config 或者web.config,已经设置了链接字符串{1}", pjt.Name, name));
            }
            return(true);
        }