/// <inheritdoc /> public CompilationResult Compile(EnvironmentCompilationInfo environment, StructureCompilationInfo structure, IConfigurationParser parser) { _logger.LogInformation($"compiling environment '{environment.Name}' ({environment.Keys.Count} entries) " + $"and structure '{structure.Name}' ({structure.Keys.Count} entries)"); ICompilationTracer compilationTracer = new CompilationTracer(); var resolver = ValueResolverBuilder.CreateNew() .UseEnvironment(environment) .UseStructure(structure) .UseLogger(_resolverLogger) .UseEnvironmentKeyProvider() .UseStructureVariableProvider() .UseSecretProvider(_secretProvider) .BuildDefault(); var configuration = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase); foreach (var(key, value) in structure.Keys) { var result = resolver.Resolve(key, value, compilationTracer.AddKey(key, value), parser).RunSync(); if (result.IsError) { _logger.LogWarning(result.Message); } foreach (var(rk, rv) in result.Data) { configuration[rk] = rv; } } return(new CompilationResult(configuration, compilationTracer.GetResults())); }
public T GetConfigurations <T>() where T : class { managerOfLogging = new ManagerOfLogging(); if (path is null) { if (managerOfLogging.setuped == true) { managerOfLogging.LoggerMessage("File of configurations not found."); } return(null); } IConfigurationParser <T> configurationParser = null; switch (Path.GetExtension(path)) { case ".xml": Help.flg = true; break; case ".json": break; } configurationParser = new Parser <T>(path); return(configurationParser.Parse()); }
internal static IEnumerable <KeyValuePair <string, string> > ConvertToConfig( this KVPair kvPair, string rootKey, IConfigurationParser parser) { using (Stream stream = new MemoryStream(kvPair.Value)) { return(parser .Parse(stream) .Select(pair => { var key = $"{kvPair.Key.TrimEnd('/')}:{pair.Key}" .Replace('/', ':') .TrimStart(rootKey.ToCharArray()) .TrimStart(':') .TrimEnd(':'); if (string.IsNullOrEmpty(key)) { throw new InvalidKeyPairException( "The key must not be null or empty. Ensure that there is at least one key under the root of the config or that the data there contains more than just a single value."); } return new KeyValuePair <string, string>(key, pair.Value); })); } }
/// <summary> /// Adds an additional <see cref="IConfigurationParser"/> to use in a second round of parsing if /// <paramref name="key"/> is not used yet. /// </summary> /// <param name="key">The key to use.</param> /// <param name="parser"><see cref="IConfigurationParser"/> to add.</param> private void AddConfigurationParser(string key, IConfigurationParser parser) { if (!this._parsers.ContainsKey(key)) { this._parsers.Add(key, parser); } }
internal ConsulConfigurationProvider(ConsulConfigurationSource source) { string consulAddress = source.ConsulAddressProvider.GetBaseAddress(source.Host, source.Port); _consulKey = source.ConsulKey; _consulClient = new ConsulKvStoreClient(source.HttpClient, consulAddress, _consulKey); _parser = source.ConfigurationParser; }
internal static Dictionary <string, string> ToConfigDictionary( this QueryResult <KVPair[]> result, string keyToRemove, IConfigurationParser parser) { return((result.Response ?? new KVPair[0]) .Where(kvp => kvp.HasValue()) .SelectMany(kvp => kvp.ConvertToConfig(keyToRemove, parser)) .ToDictionary(kvp => kvp.Key, kvp => kvp.Value, StringComparer.OrdinalIgnoreCase)); }
/// <inheritdoc cref="RoundtripSnapshotCreator" /> public RoundtripSnapshotCreator(IEventStore eventStore, IConfigurationParser parser, IConfigurationCompiler compiler, IJsonTranslator translator, IDomainObjectStore domainObjectStore) { _eventStore = eventStore; _parser = parser; _compiler = compiler; _translator = translator; _domainObjectStore = domainObjectStore; }
/// <inheritdoc /> public InspectionController(IServiceProvider provider, ILogger <InspectionController> logger, IConfigurationCompiler compiler, IConfigurationParser parser, IJsonTranslator translator, IProjectionStore store) : base(provider, logger) { _compiler = compiler; _parser = parser; _translator = translator; _store = store; }
public Provider(string path) { switch (Path.GetExtension(path)) { case ".xml": configurationParser = new XmlParser <T>(path); break; case ".json": configurationParser = new JsonParser <T>(path); break; } }
public ConfigurationProvider(string confPath) { switch (Path.GetExtension(confPath)) { case ".json": confParser = new JSONParser(confPath); break; case ".xml": confParser = new XMLParser(confPath); break; } }
public void GetFilledOptions(object configModel, string text, IConfigurationParser parser) { ParsedObject parsedObject = null; try { parsedObject = parser.Parse(text); } catch { throw new Exception("Couldn't parse file"); } FillOptions(configModel, parsedObject); }
public ConfigurationProvider(string path) { this.path = path; switch (Path.GetExtension(path)) { case ".xml": parser = new XMLParser(); break; case ".json": parser = new JSONParser(); break; } }
/// <inheritdoc cref="ConfigurationProjectionStore" /> public ConfigurationProjectionStore(ILogger <ConfigurationProjectionStore> logger, IDomainObjectStore domainObjectStore, IConfigurationCompiler compiler, IConfigurationParser parser, IJsonTranslator translator, IEventStore eventStore, IEnumerable <ICommandValidator> validators) { _logger = logger; _domainObjectStore = domainObjectStore; _compiler = compiler; _parser = parser; _translator = translator; _eventStore = eventStore; _validators = validators.ToList(); }
public ConfigurationProvider(string filePath) { contents = File.ReadAllText(filePath); string ext = Path.GetExtension(filePath); if (ext == ".json") { configParser = new JSONParser(); } else if (ext == ".xml") { configParser = new XMLParser(); } else { throw new Exception("Invalid extension"); } }
public ConfigurationParser(FileInfo modulePath) { if (File.Exists(Path.Combine(modulePath.FullName, Helper.YamlSpecFile))) { parser = new ConfigurationYamlParser(modulePath); } else { if (File.Exists(Path.Combine(modulePath.FullName, ".cm", "spec.xml"))) { parser = new ConfigurationXmlParser(modulePath); } else { parser = null; } } }
public StylizeEngine(IConfigurationParser configurationParser) { if (configurationParser == null) { throw new ArgumentNullException(nameof(configurationParser)); } Log.WriteVerbose("Initializing MEF"); var catalog = new AggregateCatalog( new AssemblyCatalog(Assembly.GetExecutingAssembly().Location)); string currentDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); foreach (string exportAssemblyName in configurationParser.ExportAssemblyNames) { string exportAssemblyPath = Path.IsPathRooted(exportAssemblyName) ? exportAssemblyName : Path.Combine(currentDirectory, exportAssemblyName); catalog.Catalogs.Add(new AssemblyCatalog(exportAssemblyPath)); } this.container = new CompositionContainer(catalog); IReadOnlyList<IOption> supportedOptions = this.container.GetExportedValues<IOption>( ExportStylizeOptionAttribute.OptionContractName).ToList(); Log.WriteVerbose("Parsing configuration"); StylizeConfiguration configuration = configurationParser.ParseConfiguration(supportedOptions); this.globalOptions = configuration.GlobalOptions; Log.WriteVerbose("Loading exports"); if (!String.IsNullOrEmpty(configuration.RepositoryName)) { this.repository = this.container.GetExportedValue<ISourceRepository>(configuration.RepositoryName); this.container.ComposeExportedValue(ExportSourceRepositoryAttribute.CurrentName, this.repository); } this.exclusionMatchers = this.container.GetExports<IDocumentMatcher, INamedMetadata>( configuration.ExclusionMatchers); IReadOnlyList<Export<IStyleRule, StyleRuleMetadata>> rules = this.container.GetExports<IStyleRule, StyleRuleMetadata>(configuration.Rules); this.languageRuleMap = OrderAndMapRules(rules); Log.WriteVerbose("Engine initialized"); }
// ReSharper disable ParameterOnlyUsedForPreconditionCheck.Local private void CheckCompileParameters(IDomainObjectStore store, IConfigurationCompiler compiler, IConfigurationParser parser, IJsonTranslator translator) { if (store is null) { throw new ArgumentNullException(nameof(store)); } if (compiler is null) { throw new ArgumentNullException(nameof(compiler)); } if (parser is null) { throw new ArgumentNullException(nameof(parser)); } if (translator is null) { throw new ArgumentNullException(nameof(translator)); } }
public ConfigurationManager(IEnumerable <Dep> processedDeps, IConfigurationParser parser) { ProcessedDeps = processedDeps.Select(dep => dep.Configuration).ToList(); this.parser = parser; }
public ConfigurationManager(string moduleName, IEnumerable <string> processedConfigurations) { ProcessedDeps = processedConfigurations.ToList(); parser = new ConfigurationParser(new FileInfo(Path.Combine(Helper.CurrentWorkspace, moduleName))); }
public RemoteConfigurationProvider(RemoteConfigurationSource source) { _source = source ?? throw new ArgumentNullException(nameof(source)); if (source.ConfigurationName == null) { throw new ArgumentNullException(nameof(source.ConfigurationName)); } if (source.ConfigurationServiceUri == null) { throw new ArgumentNullException(nameof(source.ConfigurationServiceUri)); } Logger.LoggerFactory = source.LoggerFactory ?? new NullLoggerFactory(); _logger = Logger.CreateLogger <RemoteConfigurationProvider>(); _logger.LogInformation("Initializing remote configuration source for configuration '{ConfigurationName}'.", source.ConfigurationName); _httpClient = new Lazy <HttpClient>(CreateHttpClient); _parser = source.Parser; if (_parser == null) { var extension = Path.GetExtension(source.ConfigurationName).ToLower(); _logger.LogInformation("A file parser was not specified. Attempting to resolve parser from file extension '{extension}'.", extension); switch (extension) { case ".ini": _parser = new IniConfigurationFileParser(); break; case ".xml": _parser = new XmlConfigurationFileParser(); break; case ".yaml": _parser = new YamlConfigurationFileParser(); break; default: _parser = new JsonConfigurationFileParser(); break; } } _logger.LogInformation("Using parser {Name}.", _parser.GetType().Name); if (source.ReloadOnChange) { if (source.Subscriber == null) { _logger.LogWarning("ReloadOnChange is enabled but a subscriber has not been configured."); return; } var subscriber = source.Subscriber(); _logger.LogInformation("Initializing remote configuration {Name} subscriber for configuration '{ConfigurationName}'.", subscriber.Name, source.ConfigurationName); subscriber.Subscribe(source.ConfigurationName, message => { _logger.LogInformation("Received remote configuration change subscription for configuration '{ConfigurationName}' with hash {message}. " + "Current hash is {Hash}.", source.ConfigurationName, message, Hash); if (message != null && message.ToString().Equals(Hash, StringComparison.OrdinalIgnoreCase)) { _logger.LogInformation("Configuration '{ConfigurationName}' current hash {Hash} matches new hash. " + "Configuration will not be updated.", source.ConfigurationName, Hash); return; } Load(); OnReload(); }); } }
public static Dictionary <string, string> GetValueAsDictionary(this KeyValueNode node, IConfigurationParser parser) { if (node.FullKey == null) { throw new ArgumentException("Key is empty"); } if (string.IsNullOrWhiteSpace(node.Value)) { return(new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase) { { node.FullKey, null } }); } using (var configStream = new MemoryStream(node.RawValue)) { return(new Dictionary <string, string>( parser.Parse(configStream), StringComparer.OrdinalIgnoreCase)); } }
public ConfigurationManager(IConfigurationParser configParser) { this.configParser = configParser; }
public static IReadOnlyList <KeyValueNode> ParseConfig(this KeyValueNode node, IConfigurationParser parser) { if (node.FullKey == null) { throw new ArgumentException("Key is empty"); } if (string.IsNullOrWhiteSpace(node.Value)) { return(new [] { new KeyValueNode(node.FullKey, null as string) }); } var config = node.GetValueAsDictionary(parser); var result = config.Select(x => new KeyValueNode(ConfigurationPath.Combine(node.FullKey, x.Key), x.Value)).ToList(); return(result); }
public DefaultConfigurationReader(IConfigurationParser configurationConverter) { this.configurationConverter = configurationConverter ?? throw new ArgumentNullException(nameof(configurationConverter)); }
public ConfigurationFactory(IConfigurationParser parser) { _parser = parser; }
private static bool CanParse(IConfigurationParser parser) { return(parser != null); }
public ConfigurationRetriever(IConfigurationParser parser) { this._parser = parser; }
public MasterConnection(IConnectionInfmxGetData connectionInformix, IConfigurationParser configuration, IConnectionInfmxEditTable connectionInfmxEditTable) { this.connectionInformix = connectionInformix; this.configuration = configuration; this.connectionInfmxEditTable = connectionInfmxEditTable; }
// do an initial check to see if we're dealing with a range-query or not // route responsibility to either ResolveValue or ResolveRange /// <inheritdoc /> public Task <IResult <IDictionary <string, string> > > Resolve(string path, string value, ITracer tracer, IConfigurationParser parser) => ResolveInternal(new KeyResolveContext(path, value, tracer, parser));
public KeyResolveContext(string basePath, string originalValue, ITracer tracer, IConfigurationParser parser) : this(basePath, originalValue, tracer, parser, 0, new (string, ITracer)[0])
/// <summary> /// Constructor optionally accepts config file name. /// If nothing is passed considers App.config as config file /// </summary> /// <param name="configFilePath">Config file name</param> public ConfigurationProvider(string configFilePath = null) { IConfigurationParserFactory configParserFactory = new ConfigurationParserFactory(); configParser = configParserFactory.GetConfigurationParser(configFilePath); }
public DownAction(IConfigurationParser parser) { _parser = parser; }