tbf/TBF/BenchControl/TestMethods/ChangeFlowDirection/ChangeFlowDirectionSeq.cs

112 lines
4.1 KiB
C#
Raw Normal View History

///
/// Copyright (c) 2018 Sensus Slovensko a.s.
///
using System;
using System.Collections.Generic;
using log4net;
using Config.Entities;
using TBF.UiBridge;
namespace TBF.BenchControl.TestMethods.ChangeFlowDirection
{
public class ChangeFlowDirectionSeq : Sequences.SequenceBase
{
private static readonly ILog log = LogManager.GetLogger(typeof(ChangeFlowDirectionSeq));
/// <summary>
/// Adjustment method sequence
/// </summary>
/// <param name="test">Test entity</param>
/// <returns>
/// Event.Done . . . . . . . OK
/// Event.UiCmdStop . . . . Stopped by the user using the on-screen button STOP
/// Event.OpArgumentError . Target flow is out of range
/// Event.Error . . . . . . Unspecified error
/// </returns>
public IList<Event> Execute(Test test, int repetitionNr, bool isLastRepetition, DebugMode mode)
{
///
/// Find purge suquences
///
TransitionSequence benchFillSeq = null;
TransitionSequence benchEmptySeq = null;
foreach (var transition in StateMachine.TransitionSequences)
{
if (transition.Name == StateMachine.Procedure.TransitionStart) benchFillSeq = transition;
if (transition.Name == StateMachine.Procedure.TransitionEnd) benchEmptySeq = transition;
}
IList<Event> e = new List<Event>(); /// Events from currently running operations
checkUiOp = new Operations.CheckUIOp(true); /// Runs in more then one state
/// Start the test, initialize test results
Bridge.OnTestSelected(this, new TestSelectedEventArgs(test, repetitionNr, inPath, benchPath, outPath, sensPath, 0));
string testName = Results.Utils.GetTestName(test.Name, test.Repeats, repetitionNr);
TestStartTime = DateTime.Now;
///
/// Empty the line
///
Bridge.OnTestProgress(this, new TestProgressEventArgs(test, repetitionNr, Config.Entities.Progress.TransitionBefore));
switch (Transition(benchEmptySeq, TransitionContext.PurgeEnd))
{
case Event.Error:
case Event.UiCmdStop:
goto stopTest;
default:
break;
}
///
/// Show a dialog with OK button and an appropriate message
///
Bridge.OnAdjustmentInProgress(this, new AdjustmentInProgressEventArgs(testName));
Bridge.OnTestProgress(this, new TestProgressEventArgs(test, repetitionNr, Config.Entities.Progress.Test));
Bridge.OnActivity(this, test.Method);
State.Create(string.Format("{0}({1}) : Turn the direction of watermeters", test.Method, test.Name))
.AddOperation(checkUiOp)
.AddOperation(new Operations.MessageBoxOp("Otočte iPerly prosím."))
.EnterState();
do
{
e = StateMachine.WaitRunDevsRunOps();
Bridge.OnTestProgress(this, new TestProgressEventArgs(test, 1, Config.Entities.Progress.Test));
if (e.Contains(Event.Error)) goto stopTest;
if (TestAndLogUiCmdStop(test, e)) goto stopTest;
}
while (!e.Contains(Event.OK));
///
/// Fill the line
///
Bridge.OnTestProgress(this, new TestProgressEventArgs(test, repetitionNr, Config.Entities.Progress.TransitionAfter));
switch (Transition(benchFillSeq, TransitionContext.PurgeBegin))
{
case Event.Error:
case Event.UiCmdStop:
goto stopTest;
default:
break;
}
/// Create a list with one item 'retVal' (default is Event.Done) and return it
IList<Event> retList = new List<Event>(1);
retList.Add(Event.Done);
return retList;
stopTest:
/// Create a list with one item 'retVal' (default is Event.Done) and return it
IList<Event> retList2 = new List<Event>(1);
retList2.Add(Event.UiCmdStop);
return retList2;
}
}
}