public void TestChangeGeneralSafetyLimit() { FlowDiagram fl = new FlowDiagram(); fl.ChangeSafetyLimitGeneral(120); Assert.AreEqual(fl.GeneralSafetyLimit, 120); }
public void TestClearDiagram() { FlowDiagram fl = new FlowDiagram(); fl.AddComponent(new Point(1, 1), ComponentType.Pump); fl.AddComponent(new Point(1, 1), ComponentType.AdjustableSplitter); fl.AddComponent(new Point(1, 1), ComponentType.Splitter); fl.AddComponent(new Point(1, 1), ComponentType.AdjustableSplitter); fl.AddComponent(new Point(1, 1), ComponentType.Sink); fl.AddComponent(new Point(1, 1), ComponentType.Sink); fl.AddComponent(new Point(1, 1), ComponentType.Sink); fl.AddComponent(new Point(1, 1), ComponentType.Sink); Component pump = fl.Components[0]; Component ads1 = fl.Components[1]; Component sp = fl.Components[2]; Component ads2 = fl.Components[3]; Component sink1 = fl.Components[4]; Component sink2 = fl.Components[5]; Component sink3 = fl.Components[6]; Component sink4 = fl.Components[7]; fl.ChangeSafetyLimitGeneral(200); fl.ClearFlowDiagram(); Assert.AreEqual(fl.Components.Count, 0); Assert.AreEqual(fl.Connections.Count, 0); Assert.AreEqual(fl.GeneralSafetyLimit, 200); }
public FlowDiagram BuildDiagram(Type requestType, Type responseType, IFlowDefinition flowDefinition, bool isOverride = false) { var requestInfo = new FlowRequestInfo { RequestType = requestType, Description = GetDescriptionAttributeValue(requestType), Properties = GetFlowPropertyInfos(requestType), }; var responseInfo = new FlowResponseInfo { ResponseType = responseType, Description = GetDescriptionAttributeValue(responseType), Properties = GetFlowPropertyInfos(responseType), }; var flowDiagram = new FlowDiagram(flowDefinition.Criteria, requestInfo, responseInfo, isOverride); var startNode = flowDiagram.AddNode(new FlowDiagramNode { NodeType = FlowDiagramNodeType.Start, Name = "Start" }); var endCount = AddFlowDiagramDefaultLink(startNode, -1, flowDefinition, flowDiagram, 0); var previousNode = startNode; for (var stepIndex = 0; stepIndex < flowDefinition.Steps.Count; stepIndex++) { previousNode = AddFlowDiagramNode(stepIndex, flowDefinition, previousNode, flowDiagram, ref endCount); } return(flowDiagram); }
private int AddFlowDiagramDefaultLink(FlowDiagramNode node, int stepIndex, IFlowDefinition flowDefinition, FlowDiagram flowDiagram, int endCount) { if (stepIndex + 1 == flowDefinition.Steps.Count) { var endNode = AddFlowDiagramEndNode(flowDiagram, ref endCount); node.Links.Add(new FlowDiagramLink { TargetNodeName = endNode.Name }); } else { var nextStep = flowDefinition.Steps[stepIndex + 1]; switch (nextStep) { case GotoFlowStep _: case EndFlowStep _: // These steps add a link to the previous node, so we don't add one here break; default: node.Links.Add(new FlowDiagramLink { TargetNodeName = nextStep.Name }); break; } } return(endCount); }
public void TestDeleteComponent() { FlowDiagram fl = new FlowDiagram(); fl.AddComponent(new Point(1, 1), ComponentType.Pump); fl.AddComponent(new Point(1, 1), ComponentType.AdjustableSplitter); fl.AddComponent(new Point(1, 1), ComponentType.Splitter); fl.AddComponent(new Point(1, 1), ComponentType.AdjustableSplitter); fl.AddComponent(new Point(1, 1), ComponentType.Sink); fl.AddComponent(new Point(1, 1), ComponentType.Sink); fl.AddComponent(new Point(1, 1), ComponentType.Sink); fl.AddComponent(new Point(1, 1), ComponentType.Sink); Component pump = fl.Components[0]; Component ads1 = fl.Components[1]; Component sp = fl.Components[2]; Component ads2 = fl.Components[3]; Component sink1 = fl.Components[4]; Component sink2 = fl.Components[5]; Component sink3 = fl.Components[6]; Component sink4 = fl.Components[7]; fl.ChangeCapacity(pump, 25); fl.ChangeCurrentFlow(pump, 50); fl.Connect(ads1, pump, null, null); fl.Connect(sp, ads1, null, "up"); fl.Connect(ads2, ads1, null, "down"); fl.Connect(sink1, sp, null, "up"); fl.Connect(sink2, sp, null, "down"); fl.Connect(sink3, ads2, null, "up"); fl.Connect(sink4, ads2, null, "down"); fl.DeleteComponent(ads1); Assert.AreEqual(fl.Connections.Count, 4); }
public void TestCalculateFlowWithAdjustableSplitter() { FlowDiagram fl = new FlowDiagram(); fl.AddComponent(new Point(1, 1), ComponentType.Pump); Component p = fl.Components[0]; fl.ChangeCapacity(p, 25); fl.ChangeCurrentFlow(p, 20); fl.AddComponent(new Point(1, 1), ComponentType.AdjustableSplitter); Component ads = fl.Components[1]; fl.Connect(ads, p, null, null); Assert.IsTrue(((AdjustableSplitter)ads).OtherConnected == p.GetId()); fl.AddComponent(new Point(1, 1), ComponentType.Sink); Component s = fl.Components[2]; fl.Connect(s, ads, null, "up"); Assert.IsTrue(((AdjustableSplitter)ads).UpperConnectedComponent == s.GetId()); fl.AddComponent(new Point(1, 1), ComponentType.Sink); Component sink = fl.Components[3]; fl.Connect(sink, ads, null, "down"); Assert.IsTrue(((AdjustableSplitter)ads).LowerConnectedComponent == sink.GetId()); double flow = fl.CalculateFlow(); Assert.AreEqual(flow, 20); Assert.AreEqual(((Sink)s).Input, 14); Assert.AreEqual(((Sink)sink).Input, 6); }
private void button1_Click(object sender, EventArgs e) { OpenFileDialog loadFileDialog = new OpenFileDialog(); loadFileDialog.Filter = "fld files (*.fld)|*.fld|All files (*.*)|*.*"; loadFileDialog.FilterIndex = 0; loadFileDialog.RestoreDirectory = true; try { if (loadFileDialog.ShowDialog() == DialogResult.OK) { textBox_FileName.Text = loadFileDialog.FileName; Stream TestFileStream = loadFileDialog.OpenFile(); BinaryFormatter serializer = new BinaryFormatter(); d = (FlowDiagram)serializer.Deserialize(TestFileStream); ff = new Form1(d); ff.Text = loadFileDialog.FileName; Filename = loadFileDialog.FileName; //ff.ShowDialog(); d = ff.d; ff.InterpretDiagram(); for (int i = 0; i < ff.max_n; i++) { asm_code[n] = ff.OCRCode[i]; n++; } } } catch (Exception e1) { MessageBox.Show("Load Error" + e1.Message); } }
public void TestLoadFromFile() { string pathNew = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName + "\\test.bin"; FlowDiagram fl = new FlowDiagram(); fl.LoadFromFile(pathNew); Assert.IsTrue(fl.Components.Count == 2); Assert.IsTrue(fl.Connections.Count == 1); }
public void TestSetPumpFlowMoreThanCapacity() { FlowDiagram fl = new FlowDiagram(); fl.AddComponent(new Point(1, 1), ComponentType.Pump); Component c = fl.Components[0]; fl.ChangeCapacity(c, 25); fl.ChangeCurrentFlow(c, 40); Assert.AreEqual(((Pump)c).Output, 0); }
private static FlowDiagramNode AddFlowDiagramEndNode(FlowDiagram flowDiagram, ref int endCount) { endCount += 1; var endNode = flowDiagram.AddNode(new FlowDiagramNode { NodeType = FlowDiagramNodeType.End, Name = "End_" + endCount }); return(endNode); }
public void TestConnectSplitter() { FlowDiagram fl = new FlowDiagram(); fl.AddComponent(new Point(1, 1), ComponentType.Splitter); fl.AddComponent(new Point(1, 1), ComponentType.Sink); Component splitter = fl.Components[0]; Component sink = fl.Components[1]; fl.Connect(sink, splitter, null, "up"); Assert.AreEqual(fl.Connections.Count, 1); fl.Connect(sink, splitter, null, "down"); Assert.AreEqual(fl.Connections.Count, 2); }
public void TestAddTwoSameConnections() { FlowDiagram fl = new FlowDiagram(); fl.AddComponent(new Point(1, 1), ComponentType.Pump); fl.AddComponent(new Point(1, 1), ComponentType.Sink); Component pump = fl.Components[0]; Component sink = fl.Components[1]; fl.ChangeCapacity(pump, 25); fl.ChangeCurrentFlow(pump, 50); fl.Connect(sink, pump, null, null); fl.Connect(sink, pump, null, null); Assert.AreEqual(fl.Connections.Count, 1); }
private void AssertDiagramFlow(FlowDiagram flowDiagram, IEnumerable <string> expectedFlowLines) { var dotNotation = flowDiagram.GetDotDiagram(); Assert.NotEmpty(dotNotation); _output.WriteLine(dotNotation); var actualLines = Regex.Split(dotNotation, "\r\n|\r|\n"); foreach (var expectedLine in expectedFlowLines) { Assert.True(actualLines.Any(al => al.Contains(expectedLine)), $"Actual diagram did not contain: {expectedLine}"); } }
public void TestChangePipeSafetyLimit() { FlowDiagram fl = new FlowDiagram(); fl.AddComponent(new Point(1, 1), ComponentType.Pump); Component c = fl.Components[0]; fl.ChangeCapacity(c, 25); fl.ChangeCurrentFlow(c, 20); fl.AddComponent(new Point(1, 1), ComponentType.Sink); Component c2 = fl.Components[1]; fl.Connect(c2, c, null, null); fl.ChangeSafetyLimit(160, fl.Connections[0]); Assert.AreEqual(fl.Connections[0].SafetyLimit, 160); }
public void TestCalculateFlowSimple() { FlowDiagram fl = new FlowDiagram(); fl.AddComponent(new Point(1, 1), ComponentType.Pump); Component c = fl.Components[0]; fl.ChangeCapacity(c, 25); fl.ChangeCurrentFlow(c, 20); fl.AddComponent(new Point(1, 1), ComponentType.Sink); Component c2 = fl.Components[1]; fl.Connect(c2, c, null, null); double flow = fl.CalculateFlow(); Assert.AreEqual(flow, 20); }
public void TestMakeConnection() { FlowDiagram fl = new FlowDiagram(); fl.AddComponent(new Point(1, 1), ComponentType.Pump); Component c = fl.Components[0]; fl.ChangeCapacity(c, 25); fl.ChangeCurrentFlow(c, 20); fl.AddComponent(new Point(1, 1), ComponentType.Sink); Component c2 = fl.Components[1]; fl.Connect(c2, c, null, null); Assert.AreEqual(fl.Connections.Count, 1); Assert.IsTrue(fl.Connections[0].InputElement == c2); Assert.IsTrue(fl.Connections[0].OutputElement == c); }
public void TestSaveToFile() { FlowDiagram fl = new FlowDiagram(); fl.AddComponent(new Point(1, 1), ComponentType.Pump); Component c = fl.Components[0]; fl.ChangeCapacity(c, 25); fl.ChangeCurrentFlow(c, 20); fl.AddComponent(new Point(1, 1), ComponentType.Sink); Component c2 = fl.Components[1]; fl.Connect(c2, c, null, null); string pathNew = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName + "\\test.bin"; fl.SaveToFile(pathNew); Assert.IsTrue(File.Exists(pathNew)); }
public void TestPipelineColor() { FlowDiagram fl = new FlowDiagram(); fl.AddComponent(new Point(1, 1), ComponentType.Pump); fl.AddComponent(new Point(1, 1), ComponentType.Sink); Component pump = fl.Components[0]; Component sink = fl.Components[1]; fl.ChangeCapacity(pump, 200); fl.ChangeCurrentFlow(pump, 199); fl.Connect(sink, pump, null, null); fl.CalculateFlow(); //red... Assert.AreEqual(fl.Connections[0].CheckColor(), 3); fl.ChangeCurrentFlow(pump, 95); fl.CalculateFlow(); //yellow.. Assert.AreEqual(fl.Connections[0].CheckColor(), 2); }
private FlowDiagramNode AddFlowDiagramNode(int stepIndex, IFlowDefinition flowDefinition, FlowDiagramNode previousNode, FlowDiagram flowDiagram, ref int endCount) { var flowStep = flowDefinition.Steps[stepIndex]; switch (flowStep) { case ActivityFlowStep _: var activityNode = AddFlowDiagramActivityNode(stepIndex, flowDefinition, flowDiagram, flowStep, ref endCount); previousNode = activityNode; break; case LabelFlowStep _: var labelNode = AddFlowDiagramLabelNode(stepIndex, flowDefinition, flowDiagram, flowStep, ref endCount); previousNode = labelNode; break; case EndFlowStep _: var endFlowNode = AddFlowDiagramEndNode(flowDiagram, ref endCount); previousNode.Links.Add(new FlowDiagramLink { TargetNodeName = endFlowNode.Name }); break; case GotoFlowStep gotoFlowStep: previousNode.Links.Add(new FlowDiagramLink { TargetNodeName = gotoFlowStep.NextStepName }); break; case DecisionFlowStepBase decisionFlowStep: var decisionNode = AddFlowDiagramDecisionNode(stepIndex, flowDefinition, flowDiagram, flowStep, decisionFlowStep, ref endCount); previousNode = decisionNode; break; default: throw new FlowException($"Unhandled flow step type: {flowStep.GetType().FullName}"); } return(previousNode); }
public void TestCalculateFlowWithNestedSplitters() { FlowDiagram fl = new FlowDiagram(); fl.AddComponent(new Point(1, 1), ComponentType.Pump); fl.AddComponent(new Point(1, 1), ComponentType.AdjustableSplitter); fl.AddComponent(new Point(1, 1), ComponentType.Splitter); fl.AddComponent(new Point(1, 1), ComponentType.AdjustableSplitter); fl.AddComponent(new Point(1, 1), ComponentType.Sink); fl.AddComponent(new Point(1, 1), ComponentType.Sink); fl.AddComponent(new Point(1, 1), ComponentType.Sink); fl.AddComponent(new Point(1, 1), ComponentType.Sink); Component pump = fl.Components[0]; Component ads1 = fl.Components[1]; Component sp = fl.Components[2]; Component ads2 = fl.Components[3]; Component sink1 = fl.Components[4]; Component sink2 = fl.Components[5]; Component sink3 = fl.Components[6]; Component sink4 = fl.Components[7]; fl.ChangeCapacity(pump, 50); fl.ChangeCurrentFlow(pump, 50); fl.Connect(ads1, pump, null, null); fl.Connect(sp, ads1, null, "up"); fl.Connect(ads2, ads1, null, "down"); fl.Connect(sink1, sp, null, "up"); fl.Connect(sink2, sp, null, "down"); fl.Connect(sink3, ads2, null, "up"); fl.Connect(sink4, ads2, null, "down"); double flow = fl.CalculateFlow(); Assert.AreEqual(((Sink)sink1).Input, 17.5); Assert.AreEqual(((Sink)sink2).Input, 17.5); Assert.AreEqual(((Sink)sink3).Input, 10.5); Assert.AreEqual(((Sink)sink4).Input, 4.5); Assert.AreEqual(flow, 50); }
public void TestAddComponent() { FlowDiagram fl = new FlowDiagram(); fl.AddComponent(new Point(1, 1), ComponentType.Pump); fl.AddComponent(new Point(1, 1), ComponentType.AdjustableSplitter); fl.AddComponent(new Point(1, 1), ComponentType.Splitter); fl.AddComponent(new Point(1, 1), ComponentType.AdjustableSplitter); fl.AddComponent(new Point(1, 1), ComponentType.Sink); fl.AddComponent(new Point(1, 1), ComponentType.Sink); fl.AddComponent(new Point(1, 1), ComponentType.Sink); fl.AddComponent(new Point(1, 1), ComponentType.Sink); Component pump = fl.Components[0]; Component ads1 = fl.Components[1]; Component sp = fl.Components[2]; Component ads2 = fl.Components[3]; Component sink1 = fl.Components[4]; Component sink2 = fl.Components[5]; Component sink3 = fl.Components[6]; Component sink4 = fl.Components[7]; Assert.AreEqual(fl.Components.Count, 8); }
public void TestCalculateFlowWithMerger() { FlowDiagram fl = new FlowDiagram(); fl.AddComponent(new Point(1, 1), ComponentType.Pump); fl.AddComponent(new Point(1, 1), ComponentType.Pump); Component p = fl.Components[0]; Component p1 = fl.Components[1]; fl.ChangeCapacity(p, 25); fl.ChangeCurrentFlow(p, 20); fl.ChangeCapacity(p1, 25); fl.ChangeCurrentFlow(p1, 20); fl.AddComponent(new Point(1, 1), ComponentType.Merger); Component m = fl.Components[2]; fl.Connect(m, p, "up", null); fl.Connect(m, p1, "down", null); Assert.IsTrue(((Merger)m).LowerConnectedComponent == p1.GetId()); Assert.IsTrue(((Merger)m).UpperConnectedComponent == p.GetId()); fl.AddComponent(new Point(1, 1), ComponentType.Sink); Component s = fl.Components[3]; fl.Connect(s, m, null, null); fl.AddComponent(new Point(1, 1), ComponentType.Pump); fl.AddComponent(new Point(1, 1), ComponentType.Sink); Component pomp = fl.Components[4]; Component sink = fl.Components[5]; fl.ChangeCapacity(pomp, 25); fl.ChangeCurrentFlow(pomp, 20); fl.Connect(sink, pomp, null, null); double flow = fl.CalculateFlow(); Assert.AreEqual(flow, 60); }
private FlowDiagramNode AddFlowDiagramActivityNode(int stepIndex, IFlowDefinition flowDefinition, FlowDiagram flowDiagram, FlowStep flowStep, ref int endCount) { var activityRequest = GetFlowStepRequest(flowStep.Definition); var activityNode = flowDiagram.AddNode(new FlowDiagramNode { NodeType = FlowDiagramNodeType.Activity, Name = flowStep.Name, Text = GetFlowDiagramNodeText(flowStep, activityRequest), OverrideKey = flowStep.OverrideKey?.Value, OverrideDescription = flowStep.OverrideKey?.Description, }); SetFlowDiagramNodeInputSummaries(flowStep, activityRequest, activityNode); activityNode.OutputBindings = GetBoundOutputSummary(flowStep, activityRequest); endCount = AddFlowDiagramDefaultLink(activityNode, stepIndex, flowDefinition, flowDiagram, endCount); return(activityNode); }
private FlowDiagramNode AddFlowDiagramLabelNode(int stepIndex, IFlowDefinition flowDefinition, FlowDiagram flowDiagram, FlowStep flowStep, ref int endCount) { var labelNode = flowDiagram.AddNode(new FlowDiagramNode { NodeType = FlowDiagramNodeType.Label, Name = flowStep.Name, Text = flowStep.Text ?? flowStep.Name }); endCount = AddFlowDiagramDefaultLink(labelNode, stepIndex, flowDefinition, flowDiagram, endCount); return(labelNode); }
private FlowDiagramNode AddFlowDiagramDecisionNode(int stepIndex, IFlowDefinition flowDefinition, FlowDiagram flowDiagram, FlowStep flowStep, DecisionFlowStepBase decisionFlowStep, ref int endCount) { var decisionRequest = GetFlowStepRequest(flowStep.Definition); var decisionNode = flowDiagram.AddNode(new FlowDiagramNode { NodeType = FlowDiagramNodeType.Decision, Name = flowStep.Name, Text = GetFlowDiagramNodeText(flowStep, decisionRequest), OverrideKey = flowStep.OverrideKey?.Value, OverrideDescription = flowStep.OverrideKey?.Description, }); SetFlowDiagramNodeInputSummaries(flowStep, decisionRequest, decisionNode); foreach (var branch in decisionFlowStep.Branches) { if (branch.IsUnhandled) { continue; } var linkCriteria = branch.Targets?.ToList().ConvertAll(c => c?.ToString()); if (branch.IsEnd) { var endNode = AddFlowDiagramEndNode(flowDiagram, ref endCount); decisionNode.Links.Add(new FlowDiagramLink { TargetNodeName = endNode.Name, Criteria = linkCriteria }); } else { if (string.IsNullOrEmpty(branch.NextStepName)) { endCount = AddFlowDiagramDefaultLink(decisionNode, stepIndex, flowDefinition, flowDiagram, endCount); } else { decisionNode.Links.Add(new FlowDiagramLink { TargetNodeName = branch.NextStepName, Criteria = linkCriteria }); } } } return(decisionNode); }