private IProcess BuildProcess(IReadOnlyCollection <IInitializer> initializers, InitializerExtractor extractor)
        {
            var result = _validator.Validate(initializers);

            if (!result.IsValid)
            {
                throw new ValidationException(result);
            }

            var firstInitializer      = initializers.SingleOrDefault(x => extractor.WhereModeEquals(x, RunModes.First));
            var lastInitializer       = initializers.SingleOrDefault(x => extractor.WhereModeEquals(x, RunModes.Last));
            var beginningInitializers = initializers.Where(x => extractor.WhereModeEquals(x, RunModes.Beginning)).ToArray();
            var endingInitializers    = initializers.Where(x => extractor.WhereModeEquals(x, RunModes.Ending)).ToArray();

            var mainProcess = new SequentialProcess();

            if (firstInitializer != null)
            {
                mainProcess.Add(extractor.AsSingleProcess(firstInitializer));
            }

            var sequence = BuildSequence(beginningInitializers, extractor);

            if (sequence != null)
            {
                mainProcess.Add(sequence);
            }

            sequence = BuildSequence(endingInitializers, extractor);
            if (sequence != null)
            {
                mainProcess.Add(sequence);
            }

            if (lastInitializer != null)
            {
                mainProcess.Add(extractor.AsSingleProcess(lastInitializer));
            }

            var optimizedProcess = _optimizer.OptimizeProcess(mainProcess);

            return(optimizedProcess);
        }
Exemple #2
0
        private IProcess BuildComplexProcess(IReadOnlyCollection <IInitializer> initializers, InitializerConverter converter)
        {
            var firstInitializer      = initializers.SingleOrDefault(x => converter.WhereModeEquals(x, RunModes.First));
            var lastInitializer       = initializers.SingleOrDefault(x => converter.WhereModeEquals(x, RunModes.Last));
            var beginningInitializers = initializers.Where(x => converter.WhereModeEquals(x, RunModes.Beginning)).ToArray();
            var endingInitializers    = initializers.Where(x => converter.WhereModeEquals(x, RunModes.Ending)).ToArray();

            var mainProcess = new SequentialProcess();

            if (firstInitializer != null)
            {
                mainProcess.Add(converter.AsSingleProcess(firstInitializer));
            }

            var sequence = BuildSequence(beginningInitializers, converter);

            if (sequence != null)
            {
                mainProcess.Add(sequence);
            }

            sequence = BuildSequence(endingInitializers, converter);
            if (sequence != null)
            {
                mainProcess.Add(sequence);
            }

            if (lastInitializer != null)
            {
                mainProcess.Add(converter.AsSingleProcess(lastInitializer));
            }

            var optimizedProcess = _optimizer.OptimizeProcess(mainProcess);

            return(optimizedProcess);
        }