Example #1
0
        void IConfigurationSystem.Init()
        {
            lock (this)
            {
                if (_application == null)
                {
                    ConfigurationRecord machineConfig = null;
                    string machineConfigFilename      = MachineConfigurationFilePath;
                    _application = machineConfig = new ConfigurationRecord();
                    bool machineConfigExists = machineConfig.Load(machineConfigFilename);

                    if (!machineConfigExists)
                    {
                        // Load machine.config from embedded resource
                        System.Resources.ResourceManager resMgr = new System.Resources.ResourceManager("OpenNETCF.Configuration.machineconfig", System.Reflection.Assembly.GetExecutingAssembly());
                        string machineConfigXml    = resMgr.GetString("machine.config");
                        bool   machineConfigLoaded = machineConfig.LoadXml(machineConfigXml);
                    }

                    Uri appConfigFilename = AppConfigPath;

                    // test to see if a unit test config exists first
                    string unitTestConfig = appConfigFilename.LocalPath + UnitTestExtension;

                    if (File.Exists(unitTestConfig))
                    {
                        appConfigFilename = new Uri("file://" + unitTestConfig);
                    }

                    // Only load the app.config is machine.config exists
                    if (appConfigFilename != null)
                    {
                        _application = new ConfigurationRecord(machineConfig);
                        //jsm - Bug 80 - need to throw exception if app.config file doesn't exist
                        if (!_application.Load(appConfigFilename.ToString()))
                        {
                            throw new ConfigurationException("Unable to load application configuration file");
                        }
                    }
                }
            }
        }
        void IConfigurationSystem.Init()
        {
            lock (this)
            {
                if (_application == null)
                {
                    ConfigurationRecord machineConfig = null;
                    string machineConfigFilename      = MachineConfigurationFilePath;
                    Uri    appConfigFilename          = AppConfigPath;
                    _application = machineConfig = new ConfigurationRecord();
                    bool machineConfigExists = machineConfig.Load(machineConfigFilename);

                    // Only load the app.config is machine.config exists
                    if (machineConfigExists && appConfigFilename != null)
                    {
                        _application = new ConfigurationRecord(machineConfig);
                        _application.Load(appConfigFilename.ToString());
                    }
                }
            }
        }