/// /// 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)); /// /// Adjustment method sequence /// /// Test entity /// /// 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 /// public IList 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 e = new List(); /// 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, heatMetersPath, 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(StateMachine.BenchWaitingOp) .AddOperation(new Operations.MessageBoxOp("iPerly jsou otočeny")) .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)); /// /// Change direction of expected flow in iPerl heads /// foreach (var rr in sensPath.RegisterReaders) { if (rr is TestMethods.iPerlCommunication.iPerlHead.IperlHead) { (rr as TestMethods.iPerlCommunication.iPerlHead.IperlHead).ChangeFlowDirection(); } } /// /// 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; } return new List { Event.Done }; stopTest: return new List { Event.UiCmdStop }; } } }