Exemplo n.º 1
0
        public void SimplifyEnvironments(
            [ItemNotNull, NotNull] IEnumerable <ScenarioModel> scenarios,
            [ItemNotNull, NotNull] IEnumerable <ProductSetModel> productsSets)
        {
            var scenarioModels = scenarios
                                 .Where(scenario => scenario.Environments.Count > 1)
                                 .ToArray();

            Logger.Info($"merging duplicated environments {scenarioModels.Length}");

            var environmentsProcessor = new EnvironmentProcessor();
            var counter = 1;

            foreach (var scenarioModel in scenarioModels)
            {
                Logger.Info($"checking {counter++}/{scenarioModels.Count()}:{scenarioModel.Name}");
                Logger.Trace($"{scenarioModel.Name} old env: {string.Join(", ", scenarioModel.Environments.Select(env => env.Print()))}");
                var mergedEnvironments
                    = environmentsProcessor.MergeEnvironments(scenarioModel.Environments, productsSets);
                scenarioModel.Environments.Clear();
                scenarioModel.Environments.AddRange(mergedEnvironments);
                Logger.Trace($"{scenarioModel.Name} new env: {string.Join(", ", scenarioModel.Environments.Select(env => env.Print()))}");
            }

            Logger.Info("merging duplicated environments finished");
        }
Exemplo n.º 2
0
        public void ReplaceDuplicates(
            [ItemNotNull, NotNull] IEnumerable <ScenarioModel> scenarios,
            [NotNull] Func <ScenarioModel, ScenarioModel, bool> equalityPredicate)
        {
            Logger.Info($"removing duplicated scenarios total {scenarios.Count()}");
            var processed             = new List <int>();
            var environmentsProcessor = new EnvironmentProcessor();
            var counter = 1;

            foreach (var scenarioModel in scenarios)
            {
                counter++;
                if (processed.Any(id => id == scenarioModel.Id))
                {
                    continue;
                }

                Logger.Info($"checking {counter}/{scenarios.Count()}:{scenarioModel.Name}");
                processed.Add(scenarioModel.Id);
                var duplicates = scenarios
                                 .Where(scenario =>
                                        equalityPredicate(scenarioModel, scenario))
                                 .ToList();

                if (duplicates.Any())
                {
                    var mergedEnvironments = environmentsProcessor.ConcatenateEnvironments(
                        duplicates
                        .SelectMany(dup => dup.Environments)
                        .Concat(scenarioModel.Environments));
                    scenarioModel.Environments.Clear();
                    scenarioModel.Environments.AddRange(mergedEnvironments);

                    processed.AddRange(duplicates.Select(scenario => scenario.Id));
                    Logger.Info($"dupes of {scenarioModel.Name} : {string.Join(", ", duplicates.Select(dup => dup.Name))}");

                    Logger.Trace(scenarioModel.Print());
                    foreach (var dup in duplicates)
                    {
                        Logger.Trace(dup.Print());
                    }

                    ReplaceDuplicateScenarios(scenarioModel, duplicates);
                }
            }

            Logger.Info("removing duplicated finished");
        }