Exemple #1
0
        private ConfigLoadResult CombineFileConfigProviders()
        {
            var configBuilder = CreateAnalyzerConfigBuilder();

            var anyConfigFound = false;

            foreach (var childConfigProvider in Enumerable.Reverse(_fileConfigProviders))
            {
                var childConfigState = childConfigProvider.ConfigState;

                LogTraceMessage(IndentHelper.Indent($"Combining {childConfigProvider}, state={childConfigState}", 1));

                switch (childConfigState)
                {
                case AnalyzerConfigState.NoConfig:
                    break;

                case AnalyzerConfigState.Disabled:
                    anyConfigFound = true;
                    configBuilder.SetIsEnabled(false);
                    break;

                case AnalyzerConfigState.Enabled:
                    anyConfigFound = true;

                    var childConfigBuilder = childConfigProvider.ConfigBuilder;
                    configBuilder.Combine(childConfigBuilder);
                    LogTraceMessage(IndentHelper.Indent(childConfigBuilder.ToStrings(), 2));
                    break;

                case AnalyzerConfigState.ConfigError:
                    return(ConfigLoadResult.CreateWithError(childConfigProvider.ConfigException));

                default:
                    throw new ArgumentOutOfRangeException(nameof(childConfigState), childConfigState, "Unexpected value.");
                }
            }

            return(anyConfigFound
                ? ConfigLoadResult.CreateWithConfig(configBuilder)
                : ConfigLoadResult.CreateWithNoConfig());
        }
        private ConfigLoadResult LoadConfigFromFile()
        {
            try
            {
                _configFileExists = File.Exists(ConfigFilePath);
                if (!_configFileExists)
                {
                    return(ConfigLoadResult.CreateWithNoConfig());
                }

                _configLastLoadUtc = DateTime.UtcNow;

                var configBuilder = CreateConfigBuilderFromFile(ConfigFilePath)
                                    .SetDefaultInfoImportance(DefaultInfoImportance);

                return(ConfigLoadResult.CreateWithConfig(configBuilder));
            }
            catch (Exception e)
            {
                LogTraceMessage($"BuildConfig exception: {e}");
                return(ConfigLoadResult.CreateWithError(e));
            }
        }