Exemple #1
0
        /// <summary>
        /// 加载machine、local配置文件,meta配置文件,meta中的配置节,将其缓存并建立缓存失效依赖。
        /// 查找并在 ConfigFilesSetting 类实例中记录machine、local、meta和global配置文件的地址和
        /// meta配置文件位置(枚举)
        /// </summary>
        /// <returns>ConfigFilesSetting 类实例</returns>
        private static ConfigFilesSetting LoadFilesSetting()
        {
            ConfigFilesSetting settings = new ConfigFilesSetting();

            settings.MachineConfigurationFile = ConfigurationBroker.MachineConfigurationFile;
            settings.LocalConfigurationFile   = ConfigurationBroker.LocalConfigurationFile;
            settings.GlobalConfigurationFile  = ConfigurationBroker.GlobalConfigurationFile;

            MetaConfigurationSourceInstanceSection metaSection = ConfigurationBroker.GetMetaSourceInstanceSection(settings);

            if (metaSection != null)
            {
                string currPath;

                if (EnvironmentHelper.Mode == InstanceMode.Web)
                {
                    currPath = HttpContext.Current.Request.Url.AbsoluteUri;
                }
                else
                {
                    currPath = AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
                }

                settings.GlobalConfigurationFile = ConfigurationBroker.ReplaceEnvironmentVariablesInFilePath(metaSection.Instances.GetMatchedPath(currPath));

                if (string.IsNullOrEmpty(settings.GlobalConfigurationFile))
                {
                    settings.GlobalConfigurationFile = ConfigurationBroker.GlobalConfigurationFile;
                }
                else
                {
                    if (false == Path.IsPathRooted(settings.GlobalConfigurationFile))
                    {
                        settings.GlobalConfigurationFile =
                            AppDomain.CurrentDomain.BaseDirectory.TrimEnd('\\') + "\\" + settings.GlobalConfigurationFile;
                    }

                    ExceptionHelper.FalseThrow(File.Exists(settings.GlobalConfigurationFile), Resource.GlobalFileNotFound, settings.GlobalConfigurationFile);
                }
            }

            return(settings);
        }
Exemple #2
0
        /// <summary>
        /// 从单独的meta.config文件中读取meta配置
        /// </summary>
        /// <param name="fileSettings">ConfigFilesSetting 实体</param>
        /// <returns>MetaConfigurationSourceInstanceSection 实体</returns>
        private static MetaConfigurationSourceInstanceSection LoadMetaSourceInstanceSectionFromMetaFile(ConfigFilesSetting fileSettings)
        {
            System.Configuration.Configuration config = ConfigurationBroker.GetSingleFileConfiguration(
                fileSettings.MetaConfigurationFile,
                true,
                fileSettings.MachineConfigurationFile,
                fileSettings.LocalConfigurationFile);

            MetaConfigurationSectionGroup group =
                config.GetSectionGroup(ConfigurationBroker.MetaConfigurationSectionGroupItem) as MetaConfigurationSectionGroup;

            MetaConfigurationSourceInstanceSection section = null;

            if (group != null)
            {
                section = group.SourceConfigurationMapping;
            }

            return(section);
        }
Exemple #3
0
        /// <summary>
        /// 从本地config文件中读取meta配置
        /// </summary>
        /// <param name="fileSettings">ConfigFilesSetting 类实例</param>
        /// <returns>MetaConfigurationSourceInstanceSection 实体</returns>
        private static MetaConfigurationSourceInstanceSection LoadMetaSourceInstanceSectionFromLocal(ConfigFilesSetting fileSettings)
        {
            System.Configuration.Configuration config;

            if (EnvironmentHelper.Mode == InstanceMode.Web)
            {
                config = ConfigurationBroker.GetStandardWebConfiguration(fileSettings.MachineConfigurationFile, true);
            }
            else
            {
                config = ConfigurationBroker.GetStandardExeConfiguration(fileSettings.MachineConfigurationFile, fileSettings.LocalConfigurationFile, true);
            }

            MetaConfigurationSectionGroup group =
                (MetaConfigurationSectionGroup)config.GetSectionGroup(ConfigurationBroker.MetaConfigurationSectionGroupItem);
            MetaConfigurationSourceInstanceSection section = null;

            if (group != null)
            {
                section = group.SourceConfigurationMapping;
            }

            return(section);
        }