Exemple #1
0
        public static void LoadFromYaml(this CompositionExecutor executor, FileInfo file)
        {
            if (executor is null)
            {
                throw new ArgumentNullException(nameof(executor));
            }
            if (file is null)
            {
                throw new ArgumentNullException(nameof(file));
            }

            var    serializer = new Deserializer();
            string yaml       = File.ReadAllText(file.FullName);
            var    config     = serializer.Deserialize <YamlConfig>(yaml);

            foreach ((string name, CompositionConfig compositionCfg) in config.Compositions)
            {
                if (compositionCfg.Steps is null)
                {
                    continue;
                }

                var composition = new Composition(name, compositionCfg.Description);

                foreach ((string stepName, StepConfig stepCfg) in compositionCfg.Steps)
                {
                    if (!config.Composers.TryGetValue(stepCfg.Composer, out string composerTypeName))
                    {
                        throw new InvalidOperationException($"Cannot find composer named '{stepCfg.Composer}.");
                    }
                    Type composerType = Type.GetType(composerTypeName);
                    var  step         = new Step(stepName, composerType);
                    foreach (var(key, value) in stepCfg.Properties)
                    {
                        step.Add(key.Pascalize(), value);
                    }
                    composition.Add(step);
                }

                executor.Add(composition);
            }
        }
Exemple #2
0
        protected override async Task <int> HandleCommandAsync()
        {
            var executor = new CompositionExecutor();

            string configFilePath = Path.Combine(Directory.GetCurrentDirectory(), "just-compose.yml");
            var    file           = new FileInfo(configFilePath);

            executor.LoadFromYaml(file);
            executor.OnStatus += Executor_OnStatus;

            if (string.IsNullOrWhiteSpace(CompositionName))
            {
                await executor.ExecuteAsync().ConfigureAwait(false);
            }
            else
            {
                await executor.ExecuteAsync(CompositionName).ConfigureAwait(false);
            }

            return(0);
        }