bool IProcessConfiguration.ProcessConfiguration(ConfigurationUserLevel userLevel) { try { Configuration config = ConfigurationManager.OpenExeConfiguration(userLevel); CsrSection section = null; if (!config.HasFile) { return(true); } try { section = config.GetSection("csr") as CsrSection; } catch (ConfigurationException e) { Output.Error("Problem loading program configuration - {0}", e.Message); } if (section == null) { // This means that either there was no section or that it was improperly specified in // the .config file. Make sure that the configSection is at the top of the file. return(true); } GetBoolSetting(section, "DebugMessages", ref debugMessages); GetBoolSetting(section, "StackTraces", ref stackTraces); GetBoolSetting(section, "SearchSystemPath", ref searchSystemPath); GetBoolSetting(section, "AllowUnsafeCode", ref allowUnsafeCode); } catch (ConfigurationErrorsException) { Output.Warning("Application configuration could not be loaded"); return(false); } return(true); }
private void GetBoolSetting(CsrSection section, string setting, ref bool val) { try { for (int i = 0; i < section.Settings.Count; i++) { TypeElement element = section.Settings[i]; if (String.Compare(element.Key, setting, true) == 0) { if (!TryParseTrueFalse(element.Value, ref val)) { Output.Warning(CsrResources.ErrorParsingBooleanInConfig(element.Value, element.Key)); } return; } } } catch (ConfigurationException e) { Output.Warning(e.Message); } }