public void ThreeStepWithInputPoint() { List <string> results = new List <string>(); InputPoint <int> s = new InputPoint <int>(); TaskNode <int, string> filter = Helpers.GetFilter(); EndPoint <string> n = Helpers.GetEndpoint(results); Flow flow = Helpers.ConnectStartFilterEnd(s, filter, n); flow.Start(); s.Send(1, 2, 3, 4, 5, 6, 7, 8); s.Send(new int[] { 9, 10, 11, 12, 13, 14, 15 }); flow.RunToCompletion(); Assert.AreEqual(4, results.Count); Assert.AreEqual(15, filter.ItemsProcessed); Assert.AreEqual(RunStatus.Running, n.Status); s.CloseEntrance(); flow.RunToCompletion(); // at this point, the flow and some nodes may still be running or stopping, // the data items have left the flow, but the nodes can still be in the process of stopping Assert.Contains(n.Status, new List <RunStatus>() { RunStatus.Running, RunStatus.Stopping, RunStatus.Stopped }); // after a small wait, everything should be in the Stopped status Thread.Sleep(100); Assert.AreEqual(RunStatus.Stopped, n.Status); }
public void ThreeStepWithInputAndOutputPoints() { List <string> results = new List <string>(); InputPoint <int> s = new InputPoint <int>(); TaskNode <int, string> filter = Helpers.GetFilter(); OutputPoint <string> outpoint = new OutputPoint <string>(); Flow flow = Helpers.ConnectStartFilterEnd(s, filter, outpoint); flow.Start(); s.Send(1, 2, 3, 4, 5, 6, 7, 8); s.Send(new int[] { 9, 10, 11, 12, 13, 14, 15 }); string firstResult = outpoint.Output.Receive(); Assert.AreEqual("3.00", firstResult); }
public void StopRightInTheMiddle() { InputPoint <int> inp = new InputPoint <int>(); TaskNode <int, int> process = new TaskNode <int, int>( (input, output) => output.Send(input) ); process.ThreadNumber = 2; process.KeepOrder = true; Collector <int> coll = new Collector <int>(); Flow flow = Flow.FromAsciiArt("a->b->c", inp, process, coll ); coll.ItemProcessed += (o, a) => { if ((int)a.Item == 0) { flow.Stop(); } var state = flow.GetStateSnapshot(); Console.WriteLine(state.ToStringAsciiArt()); }; flow.Start(); for (int i = 1; i < 100; i++) { inp.Send(i); } inp.Send(0); inp.Send(1); inp.Send(1); inp.Send(1); inp.Send(1); inp.Send(1); inp.Send(1); //for (int i = 1; i < 1000; i++) //{ // inp.Send(i); //} flow.RunToCompletion(); Assert.AreEqual(coll.Items.Count, 100); }
public void StopRightInTheMiddle() { InputPoint<int> inp = new InputPoint<int>(); TaskNode<int,int> process = new TaskNode<int, int>( (input, output) => output.Send(input) ); process.ThreadNumber = 2; process.KeepOrder = true; Collector<int> coll = new Collector<int>(); Flow flow = Flow.FromAsciiArt("a->b->c", inp, process, coll ); coll.ItemProcessed += (o,a) => { if ((int)a.Item == 0) { flow.Stop(); } var state = flow.GetStateSnapshot(); Console.WriteLine(state.ToStringAsciiArt()); }; flow.Start(); for (int i = 1; i < 100; i++) { inp.Send(i); } inp.Send(0); inp.Send(1); inp.Send(1); inp.Send(1); inp.Send(1); inp.Send(1); inp.Send(1); //for (int i = 1; i < 1000; i++) //{ // inp.Send(i); //} flow.RunToCompletion(); Assert.AreEqual(coll.Items.Count,100); }
public void SortingValues() { InputPoint <int> entry = new InputPoint <int>(); TaskNode <int, int> sorter = StandardTasks.GetSortingFilter <int>(); Collector <int> collect = new Collector <int>(); sorter.ItemProcessed += new EventHandler <TaskNode.ItemEventArgs>(sorter_ItemProcessed); Flow f = Flow.FromAsciiArt("a-->b-->c", entry, sorter, collect); f.Start(); entry.Send(3, 7, 1, 9, 123, 2, 5, 3); entry.CloseEntrance(); f.RunToCompletion(); //Thread.Sleep(1000); Console.WriteLine("Last:" + f.GetStateSnapshot()); Assert.AreEqual(8, collect.Items.Count); Assert.AreEqual(1, collect.Items[0]); Assert.AreEqual(3, collect.Items[3]); }
private void SetRow(DataGridViewRow row, InputPoint point) { if (row == null || point == null) { return; } row.SetValue(DescriptionColumn, point.Description); row.SetValue(AutoManualColumn, point.AutoManual); row.SetCell(ValueColumn, TViewUtilities.GetValueCellForUnit( point.Value.ToString(), point.Value.Unit)); row.SetValue(UnitColumn, point.Value.Unit); row.SetValue(RangeColumn, point.Value.Value); row.SetValue(RangeTextColumn, point.Value.Unit); row.SetValue(CalibrationColumn, point.CalibrationL); row.SetValue(SignColumn, point.CalibrationSign); row.SetValue(FilterColumn, point.Filter); row.SetValue(StatusColumn, point.Status); row.SetValue(JumperColumn, point.Jumper); row.SetValue(LabelColumn, point.Label); }
public static Point[] GetSubmarineEdgePoints(Submarine submarine, Square[,] matrix, string message = null) { Point[] endPoints = new Point[2]; Console.WriteLine(message + "\n"); Console.WriteLine("Place the following Submarine:\t"); PrintObject.Submarine(submarine.Size); PrintObject.Board(matrix); for (int i = 0; i < 2; i++) { endPoints[i] = new Point(); InputPoint.GetPoint(ref endPoints[i]); if (endPoints[0] == endPoints[1] && endPoints[0] != null) { Console.WriteLine("Choose 2 different points from each other"); i = 0; } } return(endPoints); }
/// <summary> /// Add a Input control point info /// </summary> /// <param name="input">Input Point</param> /// <param name="index">Index</param> public void Add(InputPoint input, int index) { try { ControlPointInfo newCPInfo = new ControlPointInfo { ControlPointName = "IN" + index, Label = input.Label, FullLabel = input.Description, Type = IdentifierTypes.INS, Value = input.Value.ToString(), Units = input.Value.Unit.GetUnitsNames(null).OffOnName, AutoManual = input.AutoManual == 0 ? "Auto" : "Manual", Index = (short)index }; Inputs.Add(newCPInfo); } catch (Exception ex) { ExceptionHandler.Show(ex, "Addition of new Input to ControlPointsInfo"); } }
public void Prg_BTUMeter() { var path = TestUtilities.GetFullPathForPrgFile("BTUMeter.prg"); var prg = Prg.Load(path); ObjectAssert.AreEqual(new CustomDigitalUnitsPoint(false, "TANK1", "TANK2"), prg.CustomUnits.Digital[0]); //Inputs { //IN1 var expected = new InputPoint { Description = "TANK2 TOP", AutoManual = AutoManual.Automatic, Value = new VariableValue(0.683, Unit.PercentsVolts5), CalibrationH = 0.0, CalibrationL = 0.0, CalibrationSign = Sign.Negative, Control = OffOn.On, CustomUnits = null, DigitalAnalog = DigitalAnalog.Analog, FileVersion = FileVersion.Rev6, Filter = 1, Status = InputStatus.Normal, Jumper = Jumper.To5V, Label = "T2_TOP", SubNumber = 0.1, //Decom = 32 }; ObjectAssert.AreEqual(expected, prg.Inputs[0]); //IN2 expected = new InputPoint { Description = "TANK2 BOT", AutoManual = AutoManual.Automatic, Value = new VariableValue(true, Unit.LowHigh, null, 1000), CalibrationH = 0.0, CalibrationL = 0.0, CalibrationSign = Sign.Negative, Control = OffOn.On, CustomUnits = null, DigitalAnalog = DigitalAnalog.Digital, FileVersion = FileVersion.Rev6, Filter = 1, Status = InputStatus.Normal, Jumper = Jumper.Thermistor, Label = "T2_BOT", SubNumber = 0.1 }; ObjectAssert.AreEqual(expected, prg.Inputs[1]); //IN3 expected = new InputPoint { Description = "IN 3", AutoManual = AutoManual.Automatic, Value = new VariableValue(19.824, Unit.Psi20), CalibrationH = 0.0, CalibrationL = 0.0, CalibrationSign = Sign.Negative, Control = OffOn.On, CustomUnits = null, DigitalAnalog = DigitalAnalog.Analog, FileVersion = FileVersion.Rev6, Filter = 32, Status = InputStatus.Normal, Jumper = Jumper.Thermistor, Label = "IN3", SubNumber = 0.1 }; ObjectAssert.AreEqual(expected, prg.Inputs[2]); } //Outputs { //OUT1 var expected = new OutputPoint() { Description = "VALVE LEFT", AutoManual = AutoManual.Manual, HwSwitchStatus = SwitchStatus.Auto, Value = new VariableValue(true, Unit.OffOn, null, 1000), LowVoltage = 0, HighVoltage = 0, PwmPeriod = 0, Control = OffOn.On, CustomUnits = null, DigitalAnalog = DigitalAnalog.Digital, FileVersion = FileVersion.Rev6, Label = "VAL_LEFT", SubNumber = 0.1 }; ObjectAssert.AreEqual(expected, prg.Outputs[0]); //OUT2 expected = new OutputPoint() { Description = "VALVE RIGHT", AutoManual = AutoManual.Automatic, HwSwitchStatus = SwitchStatus.Auto, Value = new VariableValue(true, Unit.OffOn, null, 1000), LowVoltage = 0, HighVoltage = 0, PwmPeriod = 0, Control = OffOn.On, CustomUnits = null, DigitalAnalog = DigitalAnalog.Digital, FileVersion = FileVersion.Rev6, Label = "VAL_RIT", SubNumber = 0.1 }; ObjectAssert.AreEqual(expected, prg.Outputs[1]); } //Variables { //VAR1 var expected = new VariablePoint() { Description = "START TEST FLAG", AutoManual = AutoManual.Automatic, Value = new VariableValue(false, Unit.OffOn, null, 1000), Control = OffOn.Off, DigitalAnalog = DigitalAnalog.Digital, FileVersion = FileVersion.Rev6, Label = "INIT" }; ObjectAssert.AreEqual(expected, prg.Variables[0]); //VAR10 expected = new VariablePoint() { Description = "NOW FILLING", AutoManual = AutoManual.Automatic, Value = new VariableValue(false, Unit.CustomDigital1, null, 2000), Control = OffOn.Off, DigitalAnalog = DigitalAnalog.Digital, FileVersion = FileVersion.Rev6, Label = "FILLTANK", }; ObjectAssert.AreEqual(expected, prg.Variables[9]); } //Program codes { //var expected = new ProgramCode() //{ // Code = new byte[2000], // FileVersion = FileVersion.Rev6 //}; //ObjectAssert.AreEqual(expected, prg.ProgramCodes[0]); //Console.WriteLine(prg.ProgramCodes[0].PropertiesText()); //foreach (var line in prg.ProgramCodes[0].Lines) //{ //Console.WriteLine(line.GetString()); //} //Console.WriteLine(DebugUtilities.CompareBytes(prg.ProgramCodes[0].Code, // prg.ProgramCodes[0].Code, onlyDif: false)); } }
public void ThreeStepWithInputAndOutputPoints() { List<string> results = new List<string>(); InputPoint<int> s = new InputPoint<int>(); TaskNode<int, string> filter = Helpers.GetFilter(); OutputPoint<string> outpoint = new OutputPoint<string>(); Flow flow = Helpers.ConnectStartFilterEnd(s, filter, outpoint); flow.Start(); s.Send(1, 2, 3, 4, 5, 6, 7, 8); s.Send(new int[] { 9, 10, 11, 12, 13, 14, 15 }); string firstResult = outpoint.Output.Receive(); Assert.AreEqual("3.00", firstResult); }
public void ThreeStepWithInputPoint() { List<string> results = new List<string>(); InputPoint<int> s = new InputPoint<int>(); TaskNode<int, string> filter = Helpers.GetFilter(); EndPoint<string> n = Helpers.GetEndpoint(results); Flow flow = Helpers.ConnectStartFilterEnd(s, filter, n); flow.Start(); s.Send(1,2,3,4,5,6,7,8); s.Send(new int[]{9,10,11,12,13,14,15}); flow.RunToCompletion(); Assert.AreEqual(4, results.Count); Assert.AreEqual(15, filter.ItemsProcessed); Assert.AreEqual(RunStatus.Running, n.Status); s.CloseEntrance(); flow.RunToCompletion(); // at this point, the flow and some nodes may still be running or stopping, // the data items have left the flow, but the nodes can still be in the process of stopping Assert.Contains(n.Status, new List<RunStatus>(){RunStatus.Running , RunStatus.Stopping, RunStatus.Stopped}); // after a small wait, everything should be in the Stopped status Thread.Sleep(100); Assert.AreEqual(RunStatus.Stopped, n.Status); }