public void RunSingleParameterSlice()
        {
            _output?.WriteLine("This is output from {0}", "RunSingleParameterSlice");
            RunningConfig settings = RunningConfig.MakeDefaults();

            settings.MyOptions.Add(Options.ReadFromExcel);
            settings.LimitToYears.Add(2050);
            settings.LimitToScenarios.Add(Scenario.FromEnum(ScenarioEnum.Utopia));
            settings.MakeCharts = false;
            using (Logger logger = new Logger(_output, settings)) {
                settings.InitializeSlices(logger);
                using (var container = CreateBuilderContainer(_output, logger, settings)) {
                    using (var scope = container.BeginLifetimeScope()) {
                        if (settings.Slices == null)
                        {
                            throw new FlaException("slices was not initalized");
                        }

                        ScenarioSliceParameters ssp = settings.Slices[0];
                        //ssp = Constants.PresentSlice;
                        var s1 = scope.Resolve <Z_GeneralExporter>();
                        s1.RunForScenarios(ssp);
                        var pm = scope.Resolve <PlotMaker>();
                        pm.Finish();
                        PngSvgConverter con = new PngSvgConverter(logger, Stage.Preparation);
                        con.ConvertAllSVG(settings);
                        logger.SaveToDatabase(Constants.PresentSlice);
                    }
                }
            }
        }
        public void RunIsnImport()
        {
            RunningConfig rc = RunningConfig.MakeDefaults();

            using (Logger logger = new Logger(_output, rc)) {
                using (var container = CreateBuilderContainer(_output, logger, rc)) {
                    using (var scope = container.BeginLifetimeScope()) {
                        var s1 = scope.Resolve <A02_DirenIsnImport>();
                        s1.Run();
                        var s2 = scope.Resolve <C07_SupplementalISN>();
                        s2.Run();
                        var pm = scope.Resolve <PlotMaker>();
                        pm.Finish();
                        PngSvgConverter con = new PngSvgConverter(logger, Stage.Preparation);
                        con.ConvertAllSVG(rc);
                        logger.SaveToDatabase(Constants.PresentSlice);
                        Process.Start(s2.GetThisTargetDirectory());
                    }
                }
            }
        }
        public void RunSingleCrossScenarioStep()
        {
            RunningConfig settings = RunningConfig.MakeDefaults();
            List <Stage>  ptr      = new List <Stage> {
                Stage.ScenarioCreation
//                Stage.ScenarioVisualisation,
            };

            settings.StagesToExecute.Clear();
            settings.StagesToExecute.AddRange(ptr);
            settings.MyOptions.Add(Options.ReadFromExcel);
            settings.MyOptions.Add(Options.AddPresent);
            settings.LimitToScenarios.Add(Scenario.FromEnum(ScenarioEnum.Utopia));
            settings.LimitToYears.Add(2017);
            settings.LimitToYears.Add(2050);

            settings.LimitToScenarios.Add(Scenario.Present());
            AnalysisRepository repo = new AnalysisRepository(settings);

            using (Logger logger = new Logger(_output, settings)) {
                settings.InitializeSlices(logger);
                using (var container = CreateBuilderContainer(_output, logger, settings)) {
                    using (var scope = container.BeginLifetimeScope()) {
                        List <RunableForSingleSliceWithBenchmark> stuffToRun = new List <RunableForSingleSliceWithBenchmark>();
                        var a1 = scope.Resolve <A02_CrossSliceProfileAnalysis>();
                        if (settings.Slices == null)
                        {
                            throw new FlaException("slices was not initalized");
                        }

                        a1.Run(settings.Slices.ToList(), repo);
                        var pm = scope.Resolve <PlotMaker>();
                        pm.Finish();
                        PngSvgConverter con = new PngSvgConverter(logger, Stage.Preparation);
                        con.ConvertAllSVG(settings);
                    }
                }
            }
        }
#pragma warning disable xUnit1013 // Public method should be marked as test
        public void RunBasedOnSettings([NotNull] RunningConfig settings, [NotNull] Logger logger)
#pragma warning restore xUnit1013 // Public method should be marked as test
        {
            Stopwatch sw = new Stopwatch();

            sw.Start();
            var container = CreateBuilderContainer(_output, logger, settings);
            Dictionary <string, double> secondsPerStep = new Dictionary <string, double>();

            using (var scope = container.BeginLifetimeScope()) {
                var allItems = container.Resolve <IEnumerable <IBasicRunner> >().ToList();
                logger.Info("#The following scenarios are going to be processed.", Stage.Preparation, nameof(MainBurgdorfStatisticsCreator));
                if (settings.Slices == null)
                {
                    throw new FlaException("slices was not initalized");
                }

                foreach (ScenarioSliceParameters scenarioSliceParameters in settings.Slices)
                {
                    logger.Info("\t" + scenarioSliceParameters, Stage.Preparation, nameof(MainBurgdorfStatisticsCreator));
                }

                logger.Info("#The following stages are going to be processed.", Stage.Preparation, nameof(MainBurgdorfStatisticsCreator));
                foreach (Stage stage in settings.StagesToExecute)
                {
                    logger.Info("\t" + stage, Stage.Preparation, nameof(MainBurgdorfStatisticsCreator));
                }

                for (int stageIdx = 0; stageIdx < settings.StagesToExecute.Count; stageIdx++)
                {
                    Stage currentStage = settings.StagesToExecute[stageIdx];
                    logger.Info("## Starting Stage " + currentStage, Stage.Preparation, nameof(MainBurgdorfStatisticsCreator));
                    var steps = allItems.Where(x => x.MyStage == currentStage).ToList();
                    steps.Sort((x, y) => x.SequenceNumber.CompareTo(y.SequenceNumber));
                    logger.Info("### The following steps in this stage are going to be processed.",
                                Stage.Preparation,
                                nameof(MainBurgdorfStatisticsCreator));
                    foreach (var step in steps)
                    {
                        logger.Info("\t" + step.SequenceNumber + " - " + step.Name, Stage.Preparation, nameof(MainBurgdorfStatisticsCreator));
                    }

                    CheckAndValidateSteps(steps, logger, currentStage, out var stepType);

                    switch (stepType)
                    {
                    case Steptype.Global: {
                        ProcessGlobalSteps(steps, secondsPerStep);
                        logger.SaveToDatabase(Constants.PresentSlice);
                        break;
                    }

                    case Steptype.SliceProcessors: {
                        ProcessSliceSteps(steps, logger, settings, secondsPerStep, currentStage);
                        break;
                    }

                    case Steptype.Scenario: {
                        List <RunnableForScenarioWithBenchmark> scenarioSteps = steps.Select(x => (RunnableForScenarioWithBenchmark)x).ToList();
                        var scenariosToProcess = settings.Slices.Select(x => x.DstScenario).Distinct().ToList();

                        if (scenariosToProcess.Contains(Scenario.Present()) && currentStage == Stage.ScenarioCreation)
                        {
                            scenariosToProcess.Remove(Scenario.Present());
                        }

                        foreach (var scenario in scenariosToProcess)
                        {
                            logger.Info("Processing " + scenario, Stage.Preparation, nameof(MainBurgdorfStatisticsCreator));
                            var slicesWithScenario = settings.Slices.Where(x => x.DstScenario == scenario).ToList();
                            foreach (var step in scenarioSteps)
                            {
                                Stopwatch stopwatch = Stopwatch.StartNew();
                                step.Run(settings.Slices.ToList());
                                logger.SaveToDatabase(slicesWithScenario.Last());
                                var stepname = currentStage + "-" + step.Name;
                                stopwatch.Stop();
                                if (!secondsPerStep.ContainsKey(stepname))
                                {
                                    secondsPerStep.Add(stepname, 0);
                                }

                                secondsPerStep[stepname] += stopwatch.ElapsedMilliseconds / 1000.0;
                            }

                            logger.Info("Finished processing " + scenario, Stage.Preparation, nameof(MainBurgdorfStatisticsCreator));
                        }
                    }

                    break;

                    case Steptype.AllScenarios: {
                        List <RunnableForAllScenarioWithBenchmark> crossScenarioSteps =
                            steps.Select(x => (RunnableForAllScenarioWithBenchmark)x).ToList();
                        AnalysisRepository analysisRepository = new AnalysisRepository(settings);
                        foreach (var step in crossScenarioSteps)
                        {
                            Stopwatch stopwatch = Stopwatch.StartNew();
                            step.Run(settings.Slices.ToList(), analysisRepository);
                            logger.SaveToDatabase(Constants.PresentSlice);
                            var stepname = currentStage + "-" + step.Name;
                            stopwatch.Stop();
                            if (!secondsPerStep.ContainsKey(stepname))
                            {
                                secondsPerStep.Add(stepname, 0);
                            }

                            secondsPerStep[stepname] += stopwatch.ElapsedMilliseconds / 1000.0;
                        }
                    }

                    break;

                    default:
                        throw new Exception("unknown steptype");
                    }

                    logger.Info("Finished Stage " + currentStage + ", waiting for the charts to finish.",
                                Stage.Preparation,
                                nameof(MainBurgdorfStatisticsCreator));
                    var plotMaker = scope.Resolve <PlotMaker>();
                    plotMaker.Finish();
                    logger.Info("Finished Stage " + currentStage, Stage.Preparation, nameof(MainBurgdorfStatisticsCreator));
                }

                logger.SaveToDatabase(Constants.PresentSlice);
                if (settings.MakeStageEntries)
                {
                    PngSvgConverter psc = new PngSvgConverter(logger, Stage.Preparation);
                    psc.ConvertAllSVG(settings);
                }

                sw.Stop();
                logger.Info("Finished everything after " + sw.Elapsed.TotalMinutes + " minutes",
                            Stage.Preparation,
                            nameof(MainBurgdorfStatisticsCreator));
                foreach (var pair in secondsPerStep)
                {
                    logger.Info(pair.Key + "\t" + pair.Value.ToString("F2"), Stage.Preparation, "Main");
                }

                logger.Info("Listing open threads before closing the logger", Stage.Preparation, nameof(MainBurgdorfStatisticsCreator));
                ThreadProvider.Get().DisplayRunningThreads();
                logger.Info("Listing open threads after closing the logger", Stage.Preparation, nameof(MainBurgdorfStatisticsCreator));
                logger.FinishSavingEverything();
                ThreadProvider.Get().DisplayRunningThreads();
            }

            container.Dispose();
        }