Exemplo n.º 1
0
 public Step(string name = null, StepSettings stepSettings = null, IClock clock = null)
 {
     Name          = name ?? GetType().Name;
     Id            = Guid.NewGuid().ToString("N");
     _stepSettings = stepSettings;
     _clock        = clock ?? new Clock();
 }
Exemplo n.º 2
0
 public ForLoop(
     Func <T, Task <int> > setIterationCountAsync,
     string name = null,
     StepSettings stepSettings = null,
     List <Step <T> > steps    = null) : base(name, stepSettings, steps)
 {
     _setIterationCountAsync = setIterationCountAsync;
 }
Exemplo n.º 3
0
 public WhileLoop(
     Func <T, bool> shouldContinue,
     string name = null,
     StepSettings stepSettings = null,
     List <Step <T> > steps    = null) : base(name, stepSettings, steps)
 {
     _shouldContinue = shouldContinue;
 }
Exemplo n.º 4
0
 public Step(string name = null, string id = null, StepSettings stepSettings = null, IProcessor <T> processor = null, IClock clock = null)
 {
     Name = name ?? GetType().Name.ToString();
     Id   = id ?? Guid.NewGuid().ToString("N");
     _processorSettings = stepSettings ?? new StepSettings();
     _processor         = processor;
     _clock             = clock ?? new Clock();
 }
Exemplo n.º 5
0
 public AsyncStep(
     int delayMs,
     string name = null,
     StepSettings stepSettings = null,
     IClock clock = null) : base(name, stepSettings, clock)
 {
     _delayMs = delayMs;
 }
Exemplo n.º 6
0
 /// <summary>
 /// Удаляет указанный этапа для редактирования
 /// </summary>
 private void DeleteStepSettings(object obj)
 {
     if (!(obj is StepSettings))
     {
         return;
     }
     StepSettings.Remove(obj as StepSettings);
 }
Exemplo n.º 7
0
 public WhileLoop(
     Func <T, Task <bool> > shouldContinueAsync,
     string name = null,
     StepSettings stepSettings = null,
     List <Step <T> > steps    = null) : base(name, stepSettings, steps)
 {
     _shouldContinueAsync = shouldContinueAsync;
 }
Exemplo n.º 8
0
 public ForLoop(
     Func <T, int> setIterationCount,
     string name = null,
     StepSettings stepSettings = null,
     List <Step <T> > steps    = null) : base(name, stepSettings, steps)
 {
     _setIterationCount = setIterationCount;
 }
        public void CopyProjects()
        {
            StepSettings settings = new StepSettings(new string[] { StepSettings.COPY_PROJECTS });
            Assert.AreEqual(settings.DefaultSteps, settings.Steps);

            settings = new StepSettings(new string[] { StepSettings.COPY_PROJECTS, "destination path" });
            Assert.AreEqual(Steps.CopyDirs, settings.Steps);
        }
Exemplo n.º 10
0
 protected Instruction(
     StepSettings stepSettings,
     MainWorkflowManager mainWorkflowManager,
     ILogger logger,
     WorkflowDataValidator[] workflowDataValidators) : base(stepSettings, logger, workflowDataValidators)
 {
     MainWorkflowManager = mainWorkflowManager;
 }
Exemplo n.º 11
0
 public ForLoop(
     int iterations,
     string name = null,
     StepSettings stepSettings = null,
     List <Step <T> > steps    = null) : base(name, stepSettings, steps)
 {
     _iterationCount = iterations;
 }
Exemplo n.º 12
0
        /// <summary>
        /// Открыввает окно с параметрами этапа измерения
        /// </summary>
        private void AddStepSettings(object obj)
        {
            var stepViewModel = new StepSettingsViewModel();

            if (WindowService.ShowDialog(stepViewModel) ?? false)
            {
                StepSettings.Add(stepViewModel.StepSettigs);
            }
        }
Exemplo n.º 13
0
        public async void ProcessForkWithException()
        {
            // Arrange
            var settings = new StepSettings {
                TrackStateChanges = true, AutoProgress = true
            };

            const string firstStepName       = "first";
            const string forkStepName        = "fork";
            const string secondStepName      = "second";
            const string exceptionalStepName = "exceptionalStep";
            const string fourthStepName      = "fourth";

            var firstBaseStep   = new BaseStep(firstStepName, settings);
            var secondStepAsync = new AsyncStep(500, secondStepName);
            var exceptionalStep = new ExceptionalStep(exceptionalStepName);
            var fourthStepAsync = new AsyncStep(200, fourthStepName);

            firstBaseStep.Fork(
                name: forkStepName,
                stepSettings: settings,
                secondStepAsync,
                exceptionalStep,
                fourthStepAsync);

            var expectedExecutionStarted         = new[] { firstStepName, forkStepName, secondStepName, exceptionalStepName, fourthStepName };
            var expectedExecutionCompletionOrder = new[] { firstStepName, fourthStepName, secondStepName };
            var expectedFailedOrder = new[] { forkStepName, exceptionalStepName };

            // Actssert
            try
            {
                await firstBaseStep.Execute(_workflowState);
            }
            catch (WorkflowActionException <SimpleWorkflowState> ex)
            {
                var result = ex.WorkflowState;

                var orderedByStarted    = result.WorkflowChain.ToList().Select(x => x.StepName).ToArray();
                var orderedByCompletion = result.WorkflowChain.ToList()
                                          .Where(x => x.StepActivities.Any(y => y.Activity == StepActivityStages.ExecutionCompleted))
                                          .OrderBy(x => x.StepActivities.FirstOrDefault(y => y.Activity == StepActivityStages.ExecutionCompleted).DateTimeOffset)
                                          .Select(x => x.StepName)
                                          .ToArray();
                var failedStepNames = result.WorkflowChain.ToList()
                                      .Where(x => x.StepActivities.Any(y => y.Activity == StepActivityStages.ExecutionFailed))
                                      .Select(x => x.StepName)
                                      .ToArray();

                // Assert
                Assert.True(expectedExecutionStarted.SequenceEqual(orderedByStarted));
                Assert.True(expectedExecutionCompletionOrder.SequenceEqual(orderedByCompletion));
                Assert.True(expectedFailedOrder.SequenceEqual(failedStepNames));
            }
        }
Exemplo n.º 14
0
 public TestStep(
     TestStepDependency testStepDependency,
     StepSettings stepSettings,
     ILogger logger,
     IWorkflowManager workflowManager,
     IStepFactory stepFactory,
     WorkflowDataValidator[] workflowDataValidators) :
     base(stepSettings, logger, workflowManager, stepFactory, workflowDataValidators)
 {
     _testStepDependency = testStepDependency;
 }
Exemplo n.º 15
0
        public void InstructionHelper_IdentifiesTheFirstStep(StepSettings stepSettings)
        {
            var lines = new List <string> {
                "Step C must be finished before step A can begin.",
                "Step C must be finished before step F can begin.",
            };

            var steps             = new StepFactory(stepSettings).Create(lines);
            var instructionHelper = new InstructionHelper();

            var result = instructionHelper.Order(steps);

            Assert.Equal('C', result.First());
        }
Exemplo n.º 16
0
        /// <summary>
        /// Проверяет возможность удаления указанный этапа
        /// </summary>
        private bool CanDeleteStepSettings(object obj)
        {
            if (!(obj is StepSettings))
            {
                return(false);
            }
            var step = obj as StepSettings;

            if (StepSettings.SelectedItem != step && StepSettings.Contains(step))
            {
                return(true);
            }
            return(false);
        }
        public void CompatibleSteps() {

            string[] compatibleSteps = new string[] {
                StepSettings.ENV_INIT,
                StepSettings.REMOVE_PROJECTS,
                StepSettings.GET_PROJECTS,
                StepSettings.BUILD_PROJECTS,
                StepSettings.TEST_PROJECTS,
                StepSettings.COLLECT_ARTIFATCS,
                StepSettings.COPY_PROJECTS, "destination path"
            };

            StepSettings settings = new StepSettings(compatibleSteps);
            Assert.AreEqual(settings.AllSteps, settings.Steps);
        }
Exemplo n.º 18
0
        public void InstructionHelper_PicksNextStepAlpabeticallyFromAllAvailable(StepSettings stepSettings)
        {
            var lines = new List <string> {
                "Step C must be finished before step A can begin.",
                "Step C must be finished before step F can begin.",
                "Step A must be finished before step B can begin.",
            };

            var steps             = new StepFactory(stepSettings).Create(lines);
            var instructionHelper = new InstructionHelper();

            var result = instructionHelper.Order(steps);

            Assert.Equal("CABF", result);
        }
Exemplo n.º 19
0
        public void InstructionHelper_TimeToAssemble_TwoWorkersSolvesThreeSteps(StepSettings stepSettings, WorkerSettings workerSettings)
        {
            stepSettings.DurationOffset = 0;
            workerSettings.WorkerCount  = 2;
            var lines = new List <string> {
                "Step C must be finished before step B can begin.",
                "Step C must be finished before step F can begin.",
            };

            var steps             = new StepFactory(stepSettings).Create(lines);
            var instructionHelper = new InstructionHelper();

            var result = instructionHelper.TimeToAssemble(steps, workerSettings.WorkerCount);

            Assert.Equal(9, result);
        }
Exemplo n.º 20
0
        public void Step_ParsesTwoLinesWithThreeSteps(StepSettings stepSettings)
        {
            var lines = new List <string> {
                "Step C must be finished before step A can begin.",
                "Step C must be finished before step F can begin.",
            };

            var steps = new StepFactory(stepSettings).Create(lines);

            Assert.Equal(3, steps.Count);

            Assert.Contains(steps.First(x => x.Name == 'A').PrerequisiteSteps, x => x.Name == 'C');
            Assert.Contains(steps.First(x => x.Name == 'F').PrerequisiteSteps, x => x.Name == 'C');

            Assert.Contains(steps.First(x => x.Name == 'C').NextSteps, x => x.Name == 'A');
            Assert.Contains(steps.First(x => x.Name == 'C').NextSteps, x => x.Name == 'F');
        }
Exemplo n.º 21
0
        public async void ProcessSequenceAfterAdd()
        {
            // Arrange
            var settings = new StepSettings {
                TrackStateChanges = true
            };

            var sequencer      = new Sequencer <SimpleWorkflowState>(stepSettings: settings);
            var firstStepName  = "first";
            var secondStepName = "second";

            var firstStep  = new BaseStep(name: firstStepName, settings);
            var secondStep = new BaseStep(name: secondStepName, settings);

            sequencer.AddStep(firstStep);
            sequencer.AddStep(secondStep);

            var expectedSequence = new List <Step <SimpleWorkflowState> > {
                firstStep, secondStep
            };

            // Act
            var result = await sequencer.Execute(_workflowState);

            // Assert
            Assert.Equal(_originalWorfklowState.MyInteger + 2, result.State.MyInteger);
            Assert.Equal(3, result.WorkflowChain.Count);
            Assert.True(expectedSequence.SequenceEqual(sequencer.GetSequence()));

            var sequencerStepLink = result.WorkflowChain.First.Value;
            var firstStepLink     = result.WorkflowChain.First.Next.Value;
            var secondStepLink    = result.WorkflowChain.Last.Value;

            Assert.Equal(sequencer.Id, sequencerStepLink.StepIdentifier);

            var something = sequencerStepLink.GetUncompressedStateSnapshot <SimpleWorkflowState>();

            Assert.Equal(0, sequencerStepLink.GetUncompressedStateSnapshot <SimpleWorkflowState>().MyInteger);
            Assert.Equal(firstStep.Id, firstStepLink.StepIdentifier);
            Assert.Equal(1, firstStepLink.GetUncompressedStateSnapshot <SimpleWorkflowState>().MyInteger);
            Assert.Equal(secondStep.Id, secondStepLink.StepIdentifier);
            Assert.Equal(2, secondStepLink.GetUncompressedStateSnapshot <SimpleWorkflowState>().MyInteger);
        }
Exemplo n.º 22
0
        public async void ProcessFork()
        {
            // Arrange
            var settings = new StepSettings {
                TrackStateChanges = true, AutoProgress = true
            };

            const string firstStepName  = "first";
            const string forkStepName   = "fork";
            const string secondStepName = "second";
            const string thirdStepName  = "third";
            const string fourthStepName = "fourth";

            var firstBaseStep   = new BaseStep(firstStepName, settings);
            var secondStepAsync = new AsyncStep(500, secondStepName);
            var thirdStepAsync  = new AsyncStep(0, thirdStepName);
            var fourthStepAsync = new AsyncStep(200, fourthStepName);

            firstBaseStep.Fork(
                name: forkStepName,
                stepSettings: settings,
                secondStepAsync,
                thirdStepAsync,
                fourthStepAsync);

            var expectedExecutionStarted         = new[] { firstStepName, forkStepName, secondStepName, thirdStepName, fourthStepName };
            var expectedExecutionCompletionOrder = new[] { firstStepName, thirdStepName, fourthStepName, secondStepName, forkStepName };

            // Act
            var result = await firstBaseStep.Execute(_workflowState);

            var orderedByStarted    = result.WorkflowChain.ToList().Select(x => x.StepName).ToArray();
            var orderedByCompletion = result.WorkflowChain.ToList()
                                      .OrderBy(x => x.StepActivities.FirstOrDefault(y => y.Activity == StepActivityStages.ExecutionCompleted).DateTimeOffset)
                                      .Select(x => x.StepName)
                                      .ToArray();

            // Assert
            Assert.True(expectedExecutionStarted.SequenceEqual(orderedByStarted));
            Assert.True(expectedExecutionCompletionOrder.SequenceEqual(orderedByCompletion));
        }
Exemplo n.º 23
0
        public async void WorkflowChainUpdated()
        {
            // Arrange
            var baseStepName = "base";
            var settings     = new StepSettings {
                TrackStateChanges = true
            };
            var originStep = new BaseStep(name: baseStepName, settings);

            // Act
            var result = await originStep.Execute(_workflowState);

            var link = result.WorkflowChain.First.Value;

            // Assert
            Assert.Single(result.WorkflowChain);
            Assert.Equal(baseStepName, link.StepName);
            Assert.Equal(originStep.Id, link.StepIdentifier);
            Assert.Equal(0, link.SequenceNumber);
            Assert.Equal(_originalWorfklowState.MyInteger + 1, link.GetUncompressedStateSnapshot <SimpleWorkflowState>().MyInteger);
            Assert.Equal(StepActivityStages.Executing, link.StepActivities.First().Activity);
            Assert.Equal(StepActivityStages.ExecutionCompleted, link.StepActivities.Last().Activity);
        }
Exemplo n.º 24
0
        public async void AutoProgressSetting()
        {
            // Arrange
            var baseStepName = "base";
            var nextStepName = "next";
            var settings     = new StepSettings()
            {
                AutoProgress = true, TrackStateChanges = true
            };

            var originStep = new BaseStep(name: baseStepName, stepSettings: settings);
            var nextStep   = new BaseStep(name: nextStepName, stepSettings: settings);

            originStep.SetNext(nextStep);

            // Act
            var result = await originStep.Execute(_workflowState);

            // Assert
            Assert.Equal(_originalWorfklowState.MyInteger + 2, result.State.MyInteger);
            Assert.Equal(2, result.WorkflowChain.Count);

            var firstLink  = result.WorkflowChain.First.Value;
            var secondLink = result.WorkflowChain.Last.Value;

            Assert.Equal(originStep.Id, firstLink.StepIdentifier);
            Assert.Equal(1, firstLink.GetUncompressedStateSnapshot <SimpleWorkflowState>().MyInteger);
            Assert.Equal(nextStep.Id, secondLink.StepIdentifier);
            Assert.Equal(2, secondLink.GetUncompressedStateSnapshot <SimpleWorkflowState>().MyInteger);

            Assert.Equal(StepActivityStages.Executing, firstLink.StepActivities.First().Activity);
            Assert.Equal(StepActivityStages.ExecutionCompleted, firstLink.StepActivities.Last().Activity);

            Assert.Equal(StepActivityStages.Executing, secondLink.StepActivities.First().Activity);
            Assert.Equal(StepActivityStages.ExecutionCompleted, secondLink.StepActivities.Last().Activity);
        }
Exemplo n.º 25
0
        private void StepCollection_SelectionChanged(WSICollection <StepSettings> collection, ChangedEventArgs <StepSettings> args)
        {
            isDone = false;
            _step  = collection.SelectedItem;

            //Установка текущего индекса в -1 означает, что достигли конца коллекции
            // или был вызван метод ResetSelection(), т.е. перезапустили этапы
            if (collection.SelectedIndex == -1)
            {
                isDone = true;
                return;
            }

            switch (collection.SelectedItem.Type)
            {
            //TODO: необходимо ли проверять на два этих типа?
            case StepType.NotAssigned:
            case StepType.Done:
                return;

            case StepType.Waiting:
            case StepType.Heating:
                _coeff = 1;
                break;

            case StepType.Cooling:
                _coeff = -1;
                break;
            }

            NextTemperature = _step.From;
            while (_coeff * NextTemperature < _coeff * CurrentTemperature)
            {
                NextTemperature += _coeff * _step.Step;
            }
        }
 public void CollectArtifacts()
 {
     StepSettings settings = new StepSettings(new string[] { StepSettings.COLLECT_ARTIFATCS });
     Assert.AreEqual(settings.DefaultSteps | Steps.CollectArtifacts, settings.Steps);
 }
Exemplo n.º 27
0
 protected Loop(string name = null, StepSettings stepSettings = null, List <Step <T> > steps = null) : base(name, stepSettings)
 {
     _steps = steps ?? new List <Step <T> >();
 }
Exemplo n.º 28
0
        public static Fork <TState> Fork <TState>(this Step <TState> source, List <Step <TState> > steps, string name = null, StepSettings stepSettings = null) where TState : class
        {
            var fork = new Fork <TState>(steps, name, stepSettings);

            source.SetNextStep(fork);
            return(fork);
        }
 public void DefaultSettings()
 {
     StepSettings settings = new StepSettings(null);
     Assert.AreEqual(settings.DefaultSteps, settings.Steps);
 }
Exemplo n.º 30
0
 public LoopStep(string name = null, StepSettings stepSettings = null, IClock clock = null)
     : base(name, stepSettings, clock)
 {
 }
 public void BuildProjects()
 {
     StepSettings settings = new StepSettings(new string[] { StepSettings.BUILD_PROJECTS });
     Assert.AreEqual(Steps.Build, settings.Steps);
 }
 public void GetProjects()
 {
     StepSettings settings = new StepSettings(new string[] { StepSettings.GET_PROJECTS });
     Assert.AreEqual(Steps.GetProjectsFromDXVCS, settings.Steps);
 }
 public void RemoveProjects()
 {
     StepSettings settings = new StepSettings(new string[] { StepSettings.REMOVE_PROJECTS });
     Assert.AreEqual(Steps.RemoveProjectsDirectories, settings.Steps);
 }
Exemplo n.º 34
0
        public static Fork <TState> Fork <TState>(this Step <TState> source, string name = null, StepSettings stepSettings = null, params Step <TState>[] steps) where TState : class
        {
            var fork = new Fork <TState>(name, stepSettings, steps);

            source.SetNextStep(fork);
            return(fork);
        }
 public void RunTests()
 {
     StepSettings settings = new StepSettings(new string[] { StepSettings.TEST_PROJECTS });
     Assert.AreEqual(Steps.RunTests, settings.Steps);
 }
Exemplo n.º 36
0
 public StepSettingsViewModel(StepSettings step)
 {
     StepSettigs = step;
 }
Exemplo n.º 37
0
        public async void TestAutomatedFlow()
        {
            // Arrange
            var firstStepName  = "firstStepName";
            var secondStepName = "secondStepName";
            var thirdStepName  = "thirdStepName";

            var firstStepId  = "firstStepId";
            var secondStepId = "secondStepId";
            var thirdStepId  = "thirdStepId";

            var stepSettings = new StepSettings()
            {
                AutoProgress = true
            };

            var firstStep  = new Step <SimpleWorkflowState>(name: firstStepName, id: firstStepId, stepSettings: stepSettings, processor: _testProcessor, clock: _mockClock.Object);
            var secondStep = new Step <SimpleWorkflowState>(name: secondStepName, id: secondStepId, stepSettings: stepSettings, processor: _testProcessor, clock: _mockClock.Object);
            var thirdStep  = new Step <SimpleWorkflowState>(name: thirdStepName, id: thirdStepId, stepSettings: stepSettings, processor: _testProcessor, clock: _mockClock.Object);

            firstStep
            .SetNext(secondStep)
            .SetNext(thirdStep);

            var workflowState = new WorkflowState <SimpleWorkflowState>()
            {
                State = new SimpleWorkflowState()
            };

            var expectedWorkflowChain = new LinkedList <WorkflowChainLink>();

            var firstexpectedLink = new WorkflowChainLink()
            {
                StepIdentifier = firstStepId,
                StepName       = firstStepName,
                SequenceNumber = 0,
                StepActivities = new List <StepActivity>()
                {
                    new StepActivity(StepActivityStages.Executing, clock: _mockClock.Object), new StepActivity(StepActivityStages.ExecutionCompleted, clock: _mockClock.Object)
                }
            };

            firstexpectedLink.SetStateSnapshot(1);

            var secondExpectedLink = new WorkflowChainLink()
            {
                StepIdentifier = secondStepId,
                StepName       = secondStepName,
                SequenceNumber = 1,
                StepActivities = new List <StepActivity>()
                {
                    new StepActivity(StepActivityStages.Executing, clock: _mockClock.Object), new StepActivity(StepActivityStages.ExecutionCompleted, clock: _mockClock.Object)
                }
            };

            secondExpectedLink.SetStateSnapshot(2);

            var thirdExpectedLink = new WorkflowChainLink()
            {
                StepIdentifier = thirdStepId,
                StepName       = thirdStepName,
                SequenceNumber = 2,
                StepActivities = new List <StepActivity>()
                {
                    new StepActivity(StepActivityStages.Executing, clock: _mockClock.Object), new StepActivity(StepActivityStages.ExecutionCompleted, clock: _mockClock.Object)
                }
            };

            thirdExpectedLink.SetStateSnapshot(3);

            expectedWorkflowChain.AddLast(firstexpectedLink);
            expectedWorkflowChain.AddLast(secondExpectedLink);
            expectedWorkflowChain.AddLast(thirdExpectedLink);

            var expectedWorkflowState = new WorkflowState <SimpleWorkflowState>()
            {
                State = new SimpleWorkflowState()
                {
                    MyInteger = 3
                },
                WorkflowChain = expectedWorkflowChain
            };

            // Act
            var result = await firstStep.Process(workflowState);

            // Assert
            Assert.Equal(expectedWorkflowState.State.MyInteger, result.State.MyInteger);

            var currentExpectedLink = expectedWorkflowChain.First;

            foreach (var resultLink in result.WorkflowChain)
            {
                Assert.Equal(JsonSerializer.Serialize(currentExpectedLink.Value), JsonSerializer.Serialize(resultLink));

                currentExpectedLink = currentExpectedLink.Next;
            }
        }
Exemplo n.º 38
0
 public StepSettingsViewModel()
 {
     StepSettigs = new StepSettings();
 }
 public void EnvironmentInitialization()
 {
     StepSettings settings = new StepSettings(new string[] { StepSettings.ENV_INIT });
     Assert.AreEqual(Steps.EnvironmentInitialization, settings.Steps);
 }