private void WriteSettings(string sectionName, IEnumerable <SettingElement> settingElements) { var userConfig = OpenConfigurationFile(); var section = GetUserSettingsSection(sectionName, userConfig); if (section == null) { var userSettingsSectionGroup = (UserSettingsGroup)userConfig.SectionGroups["userSettings"]; if (userSettingsSectionGroup == null) { userSettingsSectionGroup = new UserSettingsGroup(); userConfig.SectionGroups.Add("userSettings", userSettingsSectionGroup); } section = new ClientSettingsSection(); userSettingsSectionGroup.Sections.Add(sectionName, section); } var settings = section.Settings; foreach (var element in settingElements) { settings.Add(element); } userConfig.Save(); }
public static void MutabakatAl(int FirmaID, int ServisTipi, int SablonTipi) { sqltestEntities data = new sqltestEntities(); var list = data.S_WebServisTanimlari(FirmaID).Where(c => c.ServisTipi_Tip1 == ServisTipi && c.ServisYonu == true).ToList(); string url = list.FirstOrDefault().URL; var tiplist = data.S_Tip(ServisTipi, -1).ToList(); string parametre = tiplist.FirstOrDefault().Parametre; Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); ConfigurationSectionGroup applicationSectionGroup = config.GetSectionGroup("applicationSettings"); ConfigurationSection applicationConfigSection = applicationSectionGroup.Sections["ConnectorV2.Properties.Settings"]; ClientSettingsSection clientSection = (ClientSettingsSection)applicationConfigSection; //Database Configuration Setting SettingElement applicationSetting = clientSection.Settings.Get(parametre); applicationSetting.Value.ValueXml.InnerXml = url; applicationConfigSection.SectionInformation.ForceSave = true; config.Save(ConfigurationSaveMode.Modified); ConfigurationManager.RefreshSection("applicationSettings"); string degisiklik = applicationSetting.Value.ValueXml.InnerXml; }
private string GetSettingValueFromAppConfigForDLL(string aNombreSetting) { string lrutadminpaq = Directory.GetCurrentDirectory(); if (Directory.GetCurrentDirectory() != aRutaExe) { Directory.SetCurrentDirectory(aRutaExe); } string value = ""; System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal); ClientSettingsSection userSettingsSection = (ClientSettingsSection)config.SectionGroups["userSettings"].Sections[_NombreAplicacion + ".Properties.Settings"]; //SettingElement elemToDelete = null; foreach (SettingElement connStr in userSettingsSection.Settings) { if (connStr.Name == aNombreSetting) { value = connStr.Value.ValueXml.InnerText; break; } } if (lrutadminpaq != aRutaExe) { Directory.SetCurrentDirectory(lrutadminpaq); } return(value); }
public static void NewMethod() { try { configExe = System.IO.Path.GetDirectoryName(typeof(LittlePane).Assembly.Location) + "\\3DSearch.dll.config"; if (System.IO.File.Exists(configExe)) { ExeConfigurationFileMap fileMap = new ExeConfigurationFileMap(); fileMap.ExeConfigFilename = configExe; Configuration conf = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None); SQLConnection1 = conf.ConnectionStrings.ConnectionStrings["_3DSearch.Properties.Settings.SQLConnection1"] == null ? string.Empty : conf.ConnectionStrings.ConnectionStrings["_3DSearch.Properties.Settings.SQLConnection1"].ToString(); ClientSettingsSection localPathSect = (ClientSettingsSection)conf.SectionGroups["applicationSettings"].Sections["_3DSearch.Properties.Settings"]; LocalPath = localPathSect.Settings.Get("LocalPath").Value.ValueXml.InnerText; System.Windows.Forms.MessageBox.Show(SQLConnection1 + "\n" + LocalPath); } } catch (Exception e) { System.Windows.Forms.MessageBox.Show("NewMethod " + e.Message); throw e; } }
public void EditBeforeAdd() { UserSettingsGroup u = new UserSettingsGroup(); ClientSettingsSection c = new ClientSettingsSection(); u.Sections.Add("mine", c); }
//Utilities.UpdateConfig(APPNODE, "lastQueryTime", now.ToString()); public static void UpdateApplicationSettings(string section, string key, string value) { Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); ClientSettingsSection applicationSettingsSection = (ClientSettingsSection)config.SectionGroups["applicationSettings"].Sections[section]; SettingElement element = applicationSettingsSection.Settings.Get(key); if (null != element) { applicationSettingsSection.Settings.Remove(element); element.Value.ValueXml.InnerXml = value; applicationSettingsSection.Settings.Add(element); } else { element = new SettingElement(key, SettingsSerializeAs.String); element.Value = new SettingValueElement(); System.Xml.XmlDocument doc = new System.Xml.XmlDocument(); element.Value.ValueXml = doc.CreateElement("value"); element.Value.ValueXml.InnerXml = value; applicationSettingsSection.Settings.Add(element); } config.Save(ConfigurationSaveMode.Modified); ConfigurationManager.RefreshSection("applicationSettings"); }
public override void Commit(IDictionary savedState) { string assemblypath = Context.Parameters["assemblypath"]; string mak = Context.Parameters["MAK"]; string configFile = assemblypath + ".config"; ExeConfigurationFileMap configurationMap = new ExeConfigurationFileMap(); configurationMap.ExeConfigFilename = configFile; Configuration appconfig = ConfigurationManager.OpenMappedExeConfiguration(configurationMap, ConfigurationUserLevel.None); ConfigurationSectionGroup appSettings = appconfig.GetSectionGroup("applicationSettings"); if (appSettings != null) { ClientSettingsSection mySettings = appSettings.Sections["TivoDiskUsage.Properties.Settings"] as ClientSettingsSection; if (mySettings != null) { SettingElement makElement = mySettings.Settings.Get("MediaAccessKey"); if (makElement != null) { makElement.Value.ValueXml.InnerText = mak; appconfig.Save(ConfigurationSaveMode.Minimal, true); } } } base.Commit(savedState); }
/// <summary> /// Obtiene el value de un Setting /// </summary> /// <param name="doc">XmlDocument</param> /// <param name="pSettings">XmlNode</param> /// <returns></returns> internal static SettingElement Get_SettingByName(ConfigurationSection wSection, String pSettingName) { ClientSettingsSection wClientSettingsSection = (System.Configuration.ClientSettingsSection)wSection; SettingElement setting = wClientSettingsSection.Settings.Get(pSettingName); return(setting); }
/// <summary> /// Retrieve specific section value from the web.config /// </summary> /// <param name="configSection">Main Web.config section</param> /// <param name="subSection">Child Section{One layer down}</param> /// <param name="innersection">Keyed on Section Name</param> /// <param name="propertyName">Element property name</param> /// <returns></returns> /// <example>string setting = MercuryCRM.Common.Utilities.SiteSupport.RetrieveApplicationSetting("applicationSettings", "Mercury.UPSWorldship.Properties.Settings", "ShipWS_ShipWebReference_ShipService", "value")</example> public static string RetrieveApplicationSetting(string configSection, string subSection, string innersection, string propertyName) { string result = string.Empty; HttpWorkerRequest fakeWorkerRequest = null; try { using (TextWriter textWriter = new StringWriter()) { fakeWorkerRequest = new SimpleWorkerRequest("default.aspx", "", textWriter); var fakeHTTPContext = new HttpContext(fakeWorkerRequest); Configuration config = ConfigurationManager.OpenMappedExeConfiguration(new ExeConfigurationFileMap() { ExeConfigFilename = fakeHTTPContext.Server.MapPath(@"~/Web.config") }, ConfigurationUserLevel.None); ConfigurationSectionGroup group = config.SectionGroups[configSection]; if (group != null) { ClientSettingsSection clientSection = group.Sections[subSection] as ClientSettingsSection; if (clientSection != null) { SettingElement settingElement = clientSection.Settings.Get(innersection); if (settingElement != null) { result = (((SettingValueElement)(settingElement.ElementInformation.Properties[propertyName].Value)).ValueXml).InnerText; } } } } } catch (Exception ex) { throw ex; } finally { fakeWorkerRequest.CloseConnection(); } return(result); }
private bool _SetValueRunTime(string itemName, string itemValue, string sectionSpace, string sectionGroup) { string[] ssp = new string[2]; try { if ( (string.IsNullOrWhiteSpace(itemName)) || (string.IsNullOrWhiteSpace(itemValue)) || (!this._CheckConfigSpace(ref ssp, sectionSpace, sectionGroup)) ) { throw new ArgumentNullException(); } ClientSettingsSection gs = null; SettingElement ele = this._GetItem(itemName, ssp, ref gs); if ((ele == null) || (gs == null)) { throw new ArgumentNullException(); } SettingElement nele = new SettingElement(itemName, SettingsSerializeAs.String); nele.Value = new SettingValueElement(); nele.Value.ValueXml = new XmlDocument().CreateElement("value"); nele.Value.ValueXml.InnerText = itemValue; gs.Settings.Remove(ele); gs.Settings.Add(nele); return(true); } catch (Exception) { return(false); } }
/// <summary> /// Obtiene el value de un Setting /// </summary> /// <param name="doc">XmlDocument</param> /// <param name="pSettings">XmlNode</param> /// <returns></returns> internal static string Get_SettingValue(ConfigurationSection wSection, String pSettingName) { ClientSettingsSection wClientSettingsSection = (System.Configuration.ClientSettingsSection)wSection; SettingElement setting = wClientSettingsSection.Settings.Get(pSettingName); return(setting.Value.ValueXml.InnerXml); }
private SettingElement _GetItem(string itemName, string[] ssp, ref ClientSettingsSection gs) { gs = (ClientSettingsSection)this._config .GetSectionGroup(ssp[1]) .Sections[ssp[0] + ".Properties.Settings"]; return((SettingElement)((gs == null) ? null : gs.Settings.Get(itemName))); }
static void Main(string[] args) { System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); // Retrieve the userSettings gorup ConfigurationSectionGroup group = config.SectionGroups[@"userSettings"]; if (group == null) { return; } // Get the program settings ClientSettingsSection clientSection = group.Sections["CA.Properties.Settings"] as ClientSettingsSection; if (clientSection == null) { return; } // This retrieves the value associated with the key string sFileName = clientSection.Settings.Get("ab123").Value.ValueXml.InnerText; // Check if ab123 has a value and the file exists if (!string.IsNullOrEmpty(sFileName) && System.IO.File.Exists(sFileName)) { using (StreamReader sr = new StreamReader(sFileName)) { string line; // Read and display lines from the file until the end of // the file is reached. while ((line = sr.ReadLine()) != null) { System.Diagnostics.Debug.WriteLine(line); } } } }
public BoxSalesReportImportService() { this.ServiceName = "BoxSalesReportImportService"; this.CanShutdown = true; ClientSettingsSection clientSettingsSection = (ClientSettingsSection)ConfigurationManager.GetSection("EBP.BoxSalesReportImport"); pathTimeFrequency = clientSettingsSection.Settings.Get("TimeFrequency").Value.ValueXml.InnerText; pathOfLogFile = clientSettingsSection.Settings.Get("LogFile").Value.ValueXml.InnerText; basePath = clientSettingsSection.Settings.Get("BasePath").Value.ValueXml.InnerText; TraceService("BoxSalesReportImportService", false); InitializeComponent(); try { boxSettings = new BoxSettings { ClientID = clientSettingsSection.Settings.Get("CLIENT_ID").Value.ValueXml.InnerText, ClientSecret = clientSettingsSection.Settings.Get("CLIENT_SECRET").Value.ValueXml.InnerText, EnterpriceId = clientSettingsSection.Settings.Get("ENTERPRISE_ID").Value.ValueXml.InnerText, JwtPrivateKeyPassword = clientSettingsSection.Settings.Get("JWT_PRIVATE_KEY_PASSWORD").Value.ValueXml.InnerText, JwtPublicKeyId = clientSettingsSection.Settings.Get("JWT_PUBLIC_KEY_ID").Value.ValueXml.InnerText, PrivateKey = clientSettingsSection.Settings.Get("PRIVATE_KEY").Value.ValueXml.InnerText, }; } catch (Exception ex) { TraceService("ERROR: " + ex.Message, false); } }
public static void WriteSettingElement(Configuration config, ConfigurationSectionGroup sectionGroup, SettingsSerializeAs sas, string name, string value, string namespaceclass) { ConfigurationSection sec = sectionGroup.Sections.Get(namespaceclass); System.Configuration.ClientSettingsSection clisec = sec as ClientSettingsSection; if (clisec == null) { //创建节 clisec = new ClientSettingsSection(); sectionGroup.Sections.Add(namespaceclass, clisec); } SettingElement secEle = clisec.Settings.Get(name); if (secEle == null) { secEle = new SettingElement(name, sas); clisec.Settings.Add(secEle); } secEle.Value.ValueXml = new XmlDocument().CreateElement("value"); if (sas == SettingsSerializeAs.Xml) { XmlDocument xmdoc = new XmlDocument(); xmdoc.LoadXml(value); secEle.Value.ValueXml.InnerXml = xmdoc.DocumentElement.OuterXml; } else { secEle.Value.ValueXml.InnerText = value; } }
public static void SetApplicationSettingInConfigFile(string configFileName, string settingsTypeName, string settingName, string value) { var conf = OpenConfigFile(configFileName); var applicationSettings = conf.SectionGroups["applicationSettings"] as ApplicationSettingsGroup; if (applicationSettings == null) { applicationSettings = new ApplicationSettingsGroup(); conf.SectionGroups.Add("applicationSettings", applicationSettings); } var configSettings = applicationSettings.Sections[settingsTypeName] as ClientSettingsSection; if (configSettings == null) { configSettings = new ClientSettingsSection(); applicationSettings.Sections.Add(settingsTypeName, configSettings); } var settingElement = configSettings.Settings.Get(settingName); if (settingElement == null) { settingElement = new SettingElement(settingName, SettingsSerializeAs.String); } settingElement.Value.ValueXml = new XmlDocument().CreateNode(XmlNodeType.Element, "value", ""); settingElement.Value.ValueXml.InnerText = value; configSettings.Settings.Add(settingElement); conf.Save(ConfigurationSaveMode.Full); }
public void Save() { //string sectionName = "applicationSettings/" + System.Windows.Forms.Application.ProductName + ".Properties.Settings"; //string sectionName = "userSettings/" + System.Windows.Forms.Application.ProductName + ".Properties.Settings"; //ClientSettingsSection section = // (ClientSettingsSection) ConfigurationManager.GetSection(sectionName); //ClientSettingsSection section = (ClientSettingsSection)m_Config.GetSection(sectionName); ClientSettingsSection section = m_Config.GetSectionGroup("userSettings").Sections.Get(0) as ClientSettingsSection; //[System.Reflection.Assembly.GetExecutingAssembly().GetName() + ".Properties.Settings"] as ClientSettingsSection; foreach (SettingElement setting in section.Settings) { string value = setting.Value.ValueXml.InnerText; string name = setting.Name; // reflection PropertyInfo info = Properties.Settings.Default.GetType().GetProperty(name); object v = info.GetValue(Properties.Settings.Default, null); // serialize string ss = System.ComponentModel.TypeDescriptor.GetConverter(info.PropertyType).ConvertToString(v); //System.Diagnostics.Debug.WriteLine(ss); setting.Value.ValueXml.InnerText = ss; } section.SectionInformation.ForceSave = true; m_Config.Save(ConfigurationSaveMode.Full); }
private void SaveModifiedSettings(ClientSettingsSection settings, IEnumerable <SettingsPropertyValue> sets) { if (settings == null) { throw new ApplicationException("Configuration settings are corrupt!"); } bool ismod = false; foreach (var s in sets.Where(x => HasChanged(x))) { ismod = true; OverwriteSetting(settings, s.Name, s.SerializedValue.ToString()); } if (ismod) { try { settings.CurrentConfiguration.Save(ConfigurationSaveMode.Modified); } catch (ConfigurationErrorsException e) { LogHelper.Warning("Error while saving user settings:"); foreach (var error in e.Errors) { LogHelper.Warning(error.ToString()); } throw; } } }
private bool Initialize() { IConfiguration configuration = GetConfiguration(SettingsLocation); if (configuration == null) { return(false); } _configuration = configuration; IConfigurationSectionGroup userGroup = this._configuration.GetSectionGroup(UserSettingsGroupName); if (userGroup == null) { userGroup = configuration.AddSectionGroup(UserSettingsGroupName); } ClientSettingsSection clientSettings = userGroup.Get(SettingsSection) as ClientSettingsSection; if (clientSettings == null) { clientSettings = new ClientSettingsSection(); clientSettings.SectionInformation.AllowExeDefinition = ConfigurationAllowExeDefinition.MachineToLocalUser; clientSettings.SectionInformation.RequirePermission = false; userGroup.Add(SettingsSection, clientSettings); } _clientSettings = clientSettings; return(true); }
public void EditBeforeAdd() { UserSettingsGroup u = new UserSettingsGroup(); ClientSettingsSection c = new ClientSettingsSection(); Assert.Throws <InvalidOperationException>(() => u.Sections.Add("mine", c)); }
// 修改applicationSettings中App.Properties.Settings中服务的IP地址 public static void UpdateConfig(string configPath, string serverIP) { Configuration config = ConfigurationManager.OpenExeConfiguration(configPath); ConfigurationSectionGroup sec = config.SectionGroups["applicationSettings"]; ConfigurationSection configSection = sec.Sections["DataService.Properties.Settings"]; ClientSettingsSection clientSettingsSection = configSection as ClientSettingsSection; if (clientSettingsSection != null) { SettingElement element1 = clientSettingsSection.Settings.Get("DataService_SystemManagerWS_SystemManagerWS"); if (element1 != null) { clientSettingsSection.Settings.Remove(element1); string oldValue = element1.Value.ValueXml.InnerXml; element1.Value.ValueXml.InnerXml = GetNewIP(oldValue, serverIP); clientSettingsSection.Settings.Add(element1); } SettingElement element2 = clientSettingsSection.Settings.Get("DataService_EquipManagerWS_EquipManagerWS"); if (element2 != null) { clientSettingsSection.Settings.Remove(element2); string oldValue = element2.Value.ValueXml.InnerXml; element2.Value.ValueXml.InnerXml = GetNewIP(oldValue, serverIP); clientSettingsSection.Settings.Add(element2); } } config.Save(ConfigurationSaveMode.Modified); ConfigurationManager.RefreshSection("applicationSettings"); }
public void WriteAppSettings(string sectionName, IDictionary newSettings) { Configuration appConfig = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); ClientSettingsSection section = GetAppConfigSection(appConfig, sectionName, true); if (section == null) { throw new ConfigurationErrorsException("SettingsSaveFailedNoSection"); } SettingElementCollection settings = section.Settings; foreach (DictionaryEntry entry in newSettings) { StoredSetting setting = (StoredSetting)entry.Value; SettingElement element = settings.Get((string)entry.Key); if (element == null) { element = new SettingElement(); element.Name = (string)entry.Key; settings.Add(element); } element.SerializeAs = setting.SerializeAs; element.Value.ValueXml = setting.Value; } try { appConfig.Save(); } catch (ConfigurationErrorsException ex) { throw new ConfigurationErrorsException("SettingsSaveFailed: " + ex.Message, ex); } }
public void UpdateConfigurationString() { string s = @"Data Source =" + ConfigurationSettings.ServName + "; Initial Catalog =" + ConfigurationSettings.BaseName + "; User ID =" + ConfigurationSettings.UserName + "; Password ="******"; TrustServerCertificate = True"; try { configExe = System.IO.Path.GetDirectoryName(typeof(LittlePane).Assembly.Location) + "\\3DSearch.dll.config"; if (System.IO.File.Exists(configExe)) { ExeConfigurationFileMap fileMap = new ExeConfigurationFileMap(); fileMap.ExeConfigFilename = configExe; Configuration conf = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None); conf.ConnectionStrings.ConnectionStrings["_3DSearch.Properties.Settings.SQLConnection1"].ConnectionString = s; ClientSettingsSection localPathSect = (ClientSettingsSection)conf.SectionGroups["applicationSettings"].Sections["_3DSearch.Properties.Settings"]; localPathSect.Settings.Get("LocalPath").Value.ValueXml.InnerText = ConfigurationSettings.LocalPath; conf.Save(ConfigurationSaveMode.Full); NewMethod(); } } catch (ConfigurationErrorsException ex) { System.Windows.Forms.MessageBox.Show("UpdateConfigurationString " + ex.BareMessage); throw ex; } }
/// <summary> /// method to initialize fields utilized by the service /// </summary> private void InitializeService() { m_diagnostics.ServiceInitializing(); // load the settings from the related sections in app.config DnsServerSettings dnsServerSettings = DnsServerSettingsSection.GetSection().AsDnsServerSettings(); if (dnsServerSettings.ResolutionMode == DnsResolutionMode.AuthoritativeResolution) { AuthoritativeResolutionSettings settings = AuthoritativeResolutionSettingsSection.GetSection().AsAuthoritativeResolutionSettings(); m_store = new AuthoritativeRecordResolver(settings); } else if (dnsServerSettings.ResolutionMode == DnsResolutionMode.RecordStorageService) { ClientSettings recordRetrievalSettings = ClientSettingsSection.GetSection().AsClientSettings(); m_store = new DnsRecordStorageService(recordRetrievalSettings); } else { throw new System.Configuration.ConfigurationErrorsException("Unknown resolution mode"); } // create the DNS Server instance m_dnsServer = new DnsServer(m_store, dnsServerSettings); // // Hook up events for logging/debugging // m_diagnostics.HookEvents(m_dnsServer); m_diagnostics.ServiceInitializingComplete(dnsServerSettings); }
/// <summary> /// Get applicationConfiguration value from app.<ENV>.config file /// This automatically loads the config file for the startup application i.e. Specs /// </summary> /// <param name="key"></param> /// <returns></returns> public static string Get(string key) { Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); ConfigurationSectionGroup applicationSettingsGroup = config.GetSectionGroup("applicationSettings"); ConfigurationSection applicationConfigSection = applicationSettingsGroup.Sections["BPOWBAutomation.Properties.Settings"]; ClientSettingsSection clientSection = (ClientSettingsSection)applicationConfigSection; return(clientSection.Settings.Get(key).Value.ValueXml.InnerText); }
private static void loadSettingsSection() { if (_config == null) { loadConfig(); } _settingsSection = _config.GetSection("userSettings/TimeSheetBuilder.Properties.Settings") as ClientSettingsSection; }
public void EditAfterAdd() { Config cfg = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); UserSettingsGroup u = new UserSettingsGroup(); cfg.SectionGroups.Add("userSettings", u); ClientSettingsSection c = new ClientSettingsSection(); u.Sections.Add("mine", c); }
private static void AddValueToSetting(string name, string value, ClientSettingsSection section) { var doc = new XmlDocument(); doc.LoadXml($"<value>{value}</value>"); section.Settings.Get(name).Value = new SettingValueElement() { ValueXml = doc.DocumentElement }; }
private void OverwriteSetting(ClientSettingsSection section, string settingName, string newValue) { var val = section.Settings.Get(settingName).Value; val.ValueXml.FirstChild.Value = newValue; // Forces the setting to be marked as updated as it's done in the ValueXml setter. // If not, the setting would be considered as unchanged as we directly changed the underlying value instead above. val.ValueXml = val.ValueXml; }
public static string GetConfigSection(string sectionGroupName, string sectionName, string sectionKey) { Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); ConfigurationSectionGroup applicationSectionGroup = config.GetSectionGroup(sectionGroupName); ConfigurationSection applicationConfigSection = applicationSectionGroup.Sections[sectionName]; ClientSettingsSection clientSection = (ClientSettingsSection)applicationConfigSection; return(clientSection.Settings.Get(sectionKey).Value.ValueXml.InnerText); }