/// <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; }
/// <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(); }
// 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)); } }
/// <summary> /// Compile the configuration that this object represents - subsequent calls will skip recompilation /// </summary> /// <param name="store"></param> /// <param name="compiler"></param> /// <param name="parser"></param> /// <param name="translator"></param> /// <param name="logger">optional logger to pass during the compilation-phase</param> /// <param name="assumeLatestVersion"> /// set to true, to use latest available versions of Environment and Structure instead of <see cref="DomainObject.CurrentVersion" /> /// </param> /// <returns></returns> public async Task <IResult> Compile(IDomainObjectStore store, IConfigurationCompiler compiler, IConfigurationParser parser, IJsonTranslator translator, ILogger logger = null, bool assumeLatestVersion = false) { if (Built) { return(Result.Success()); } CheckCompileParameters(store, compiler, parser, translator); var compilationVersion = assumeLatestVersion ? long.MaxValue : CurrentVersion; logger?.LogDebug($"version used during compilation: {compilationVersion} ({nameof(assumeLatestVersion)}: {assumeLatestVersion})"); var envResult = await store.ReplayObject(new ConfigEnvironment(Identifier.Environment), Identifier.Environment.ToString(), compilationVersion); if (envResult.IsError) { return(envResult); } var structResult = await store.ReplayObject(new ConfigStructure(Identifier.Structure), Identifier.Structure.ToString(), compilationVersion); if (structResult.IsError) { return(structResult); } var environment = envResult.Data; var structure = structResult.Data; try { var compilationResult = compiler.Compile( new EnvironmentCompilationInfo { Name = $"{Identifier.Environment.Category}/{Identifier.Environment.Name}", Keys = environment.GetKeysAsDictionary() }, new StructureCompilationInfo { Name = $"{Identifier.Structure.Name}/{Identifier.Structure.Version}", Keys = structure.Keys, Variables = structure.Variables }, parser); Keys = compilationResult.CompiledConfiguration; Json = translator.ToJson(Keys).ToString(); UsedKeys = compilationResult.GetUsedKeys().ToList(); Built = true; return(Result.Success()); } catch (Exception e) { logger?.LogWarning(e, "failed to compile configuration, see exception for more details"); return(Result.Error($"failed to compile configuration: {e.Message}", ErrorCode.InvalidData)); } }