Ejemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ConfigLoader"/> class from the local machine config
        /// Note, there may be four machine config files per machine depending on the version of dotnet install and processor architecture
        /// throws an exception when authmode is specified and credentials are not
        /// throws an exception when no urls are specified for dcs and pcs and we are not operating in offline mode
        /// </summary>
        public ConfigLoader()
        {
            try
            {
                Configuration machineconfig = ConfigurationManager.OpenMachineConfiguration();
                LoadFrom(SimpleConfig.LoadFrom(machineconfig));
            }catch (Exception ex)
            {
                Console.Out.WriteLine(ex);
            }
            try
            {
                Configuration localApp = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                LoadFrom(SimpleConfig.LoadFrom(localApp));
            }
            catch (Exception ex) {
                //Logger.error(ex, "Error caught loading the config");
                Console.Out.WriteLine(ex);
            }
            try {
                System.Configuration.Configuration configuration = null;
                if (System.Web.HttpContext.Current != null) //this is null in wcf services running in iis express and probably self hosted services
                {
                    configuration =
                        System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~");
                    LoadFrom(SimpleConfig.LoadFrom(configuration));
                }
            }
            catch (Exception ex) {
                //Logger.error(ex, "Error caught loading the config");
                Console.Out.WriteLine(ex);
            }
            if (WebConfigurationManager.AppSettings != null)
            {
                LoadFrom(SimpleConfig.LoadFrom(WebConfigurationManager.AppSettings));
            }



            ValidateConfig();
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ConfigLoader"/> class using a mapped machine config
 /// throws an exception when authmode is specified and credentials are not
 /// throws an exception when no urls are specified for dcs and pcs and we are not operating in offline mode
 /// </summary>
 public ConfigLoader(Configuration machineconfig)
 {
     LoadFrom(SimpleConfig.LoadFrom(machineconfig));
     ValidateConfig();
 }