private ContextInformation _evalContext;                        // evaluation context

        internal Configuration(string locationSubPath, Type typeConfigHost, params object[] hostInitConfigurationParams)
        {
            _typeConfigHost = typeConfigHost;
            _hostInitConfigurationParams = hostInitConfigurationParams;

            _configRoot = new InternalConfigRoot();

            IInternalConfigHost configHost = (IInternalConfigHost)TypeUtil.CreateInstanceWithReflectionPermission(typeConfigHost);

            // Wrap the host with the UpdateConfigHost to support SaveAs.
            IInternalConfigHost updateConfigHost = new UpdateConfigHost(configHost);

            _configRoot.Init(updateConfigHost, true);

            //
            // Set the configuration paths for this Configuration.
            // We do this in a separate step so that the WebConfigurationHost
            // can use this object's _configRoot to get the <sites> section,
            // which is used in it's MapPath implementation.
            //
            string configPath, locationConfigPath;

            configHost.InitForConfiguration(ref locationSubPath, out configPath, out locationConfigPath, _configRoot, hostInitConfigurationParams);

            if (!String.IsNullOrEmpty(locationSubPath) && !updateConfigHost.SupportsLocation)
            {
                throw ExceptionUtil.UnexpectedError("Configuration::ctor");
            }

            if (String.IsNullOrEmpty(locationSubPath) != String.IsNullOrEmpty(locationConfigPath))
            {
                throw ExceptionUtil.UnexpectedError("Configuration::ctor");
            }

            // Get the configuration record for this config file.
            _configRecord = (MgmtConfigurationRecord)_configRoot.GetConfigRecord(configPath);

            //
            // Create another MgmtConfigurationRecord for the location that is a child of the above record.
            // Note that this does not match the resolution hiearchy that is used at runtime.
            //
            if (!String.IsNullOrEmpty(locationSubPath))
            {
                _configRecord = MgmtConfigurationRecord.Create(
                    _configRoot, _configRecord, locationConfigPath, locationSubPath);
            }

            //
            // Throw if the config record we created contains global errors.
            //
            _configRecord.ThrowIfInitErrors();
        }
        private ContextInformation                  _evalContext;       // evaluation context

        internal Configuration(string locationSubPath, Type typeConfigHost, params object[] hostInitConfigurationParams) {
            _typeConfigHost = typeConfigHost;
            _hostInitConfigurationParams = hostInitConfigurationParams;

            _configRoot = new InternalConfigRoot();

            IInternalConfigHost configHost = (IInternalConfigHost) TypeUtil.CreateInstanceWithReflectionPermission(typeConfigHost);

            // Wrap the host with the UpdateConfigHost to support SaveAs.
            IInternalConfigHost updateConfigHost = new UpdateConfigHost(configHost);

            _configRoot.Init(updateConfigHost, true);

            //
            // Set the configuration paths for this Configuration.
            // We do this in a separate step so that the WebConfigurationHost
            // can use this object's _configRoot to get the <sites> section,
            // which is used in it's MapPath implementation.
            //
            string configPath, locationConfigPath;
            configHost.InitForConfiguration(ref locationSubPath, out configPath, out locationConfigPath, _configRoot, hostInitConfigurationParams);

            if (!String.IsNullOrEmpty(locationSubPath) && !updateConfigHost.SupportsLocation) {
                throw ExceptionUtil.UnexpectedError("Configuration::ctor");
            }

            if (String.IsNullOrEmpty(locationSubPath) != String.IsNullOrEmpty(locationConfigPath)) {
                throw ExceptionUtil.UnexpectedError("Configuration::ctor");
            }

            // Get the configuration record for this config file.
            _configRecord = (MgmtConfigurationRecord) _configRoot.GetConfigRecord(configPath);

            //
            // Create another MgmtConfigurationRecord for the location that is a child of the above record.
            // Note that this does not match the resolution hiearchy that is used at runtime.
            //
            if (!String.IsNullOrEmpty(locationSubPath)) {
                _configRecord = MgmtConfigurationRecord.Create(
                    _configRoot, _configRecord, locationConfigPath, locationSubPath);
            }

            //
            // Throw if the config record we created contains global errors.
            //
            _configRecord.ThrowIfInitErrors();
        }
Exemplo n.º 3
0
        // Ensure that initialization has completed, while handling re-entrancy issues
        // for certain sections that may be used during initialization itself.
        private void EnsureInit(string configKey)
        {
            bool doInit = false;

            lock (this)
            {
                // If the user config is not initialized, then we must either:
                //    a. Perform the initialization ourselves if no other thread is doing it, or
                //    b. Wait for the initialization to complete if we know the section is not used during initialization itself, or
                //    c. Ignore initialization if the section can be used during initialization. Note that GetSection()
                //       returns null is initialization has not completed.
                if (!_isUserConfigInited)
                {
                    if (!_isInitInProgress)
                    {
                        _isInitInProgress = true;
                        doInit            = true;
                    }
                    else
                    {
                        if (!IsSectionUsedInInit(configKey))
                        {
                            // Wait for initialization to complete.
                            Monitor.Wait(this);
                        }
                    }
                }
            }

            if (!doInit)
            {
                return;
            }
            try
            {
                try
                {
                    // Initialize machine configuration.
                    _machineConfigRecord = _configRoot.GetConfigRecord(
                        ClientConfigurationHost.MachineConfigPath);

                    _machineConfigRecord.ThrowIfInitErrors();

                    // Make machine configuration available to system.net sections
                    // when application configuration is downloaded via http.
                    _isMachineConfigInited = true;

                    // If we add System.Net.Configuration we'll need to kick the initialization here
                    // to prevent deadlocks in the networking classes by loading networking config
                    // before making any networking requests.
                    //
                    // Any requests for sections used in initialization during the call to
                    // EnsureConfigLoaded() will be served by _machine.config or will return null.

                    //if (_isAppConfigHttp)
                    //{
                    //}

                    // Now load the rest of configuration
                    var configHostPaths = (IInternalConfigHostPaths)_configHost;
                    configHostPaths.RefreshConfigPaths();

                    string configPath;
                    if (configHostPaths.HasLocalConfig)
                    {
                        configPath = ClientConfigurationHost.LocalUserConfigPath;
                    }
                    else
                    {
                        configPath = configHostPaths.HasRoamingConfig
                            ? ClientConfigurationHost.RoamingUserConfigPath
                            : ClientConfigurationHost.ExeConfigPath;
                    }

                    _completeConfigRecord = _configRoot.GetConfigRecord(configPath);
                    _completeConfigRecord.ThrowIfInitErrors();

                    _isUserConfigInited = true;
                }
                catch (Exception e)
                {
                    _initError =
                        new ConfigurationErrorsException(SR.Config_client_config_init_error, e);
                    throw _initError;
                }
            }
            catch
            {
                ConfigurationManager.SetInitError(_initError);
                _isMachineConfigInited = true;
                _isUserConfigInited    = true;
                throw;
            }
            finally
            {
                lock (this)
                {
                    try
                    {
                        // Notify ConfigurationSettings that initialization has fully completed,
                        // even if unsuccessful.
                        ConfigurationManager.CompleteConfigInit();

                        _isInitInProgress = false;
                    }
                    finally
                    {
                        // Wake up all threads waiting for initialization to complete.
                        Monitor.PulseAll(this);
                    }
                }
            }
        }
Exemplo n.º 4
0
 public IInternalConfigRecord GetConfigRecord(string configPath)
 {
     return(CreateConfigRecord(originalRoot.GetConfigRecord(configPath)));
 }