public void RemoveTaskAndMoveSequences(string eventId) { dynamic bpmnElement = null; if (TaskExists(eventId)) { bpmnElement = GetTask(eventId); } else if (ExclusiveGatewayExists(eventId)) { bpmnElement = GetExclusiveGateWay(eventId);; } else if (ParallelGatewayExists(eventId)) { bpmnElement = GetParallelGateWay(eventId); } if (bpmnElement != null) { string incId = bpmnElement.incoming.Count == 1 ? bpmnElement.incoming[0] : null; string outId = bpmnElement.outgoing.Count == 1 ? bpmnElement.outgoing[0] : null; SequenceFlow incSeq = GetSequenceFlow(incId); SequenceFlow outSeq = GetSequenceFlow(outId); if (incSeq != null && outSeq != null) { string source = incSeq.sourceRef; string target = outSeq.targetRef; RemoveEventWithSequences(eventId); AddSequenceFlow(incId, source, target); } return; } else if (EndEventExists(eventId)) { bpmnElement = GetEndEvent(eventId); string incId = bpmnElement.incoming.Count == 1 ? bpmnElement.incoming[0] : null; SequenceFlow incSeq = trail.process.sequenceFlows.Find(x => x.id.Equals(incId)); if (incSeq != null) { RemoveEventWithSequences(eventId); } } }
public void AddBackLoopingSequence(string mergeGateId, string eventId, string seqFlowBackLoopId) { Task task = GetTask(eventId); if (task != null) { string incId = task.incoming[0]; SequenceFlow incSeq = GetSequenceFlow(incId); if (incSeq != null) { string source = incSeq.sourceRef; if (ExclusiveGatewayExists(source)) { AddSequenceFlow(seqFlowBackLoopId, source, mergeGateId); } else if (TaskExists(source)) { InsertExclusiveGate(eventId, mergeGateId + eventId + seqFlowBackLoopId, seqFlowBackLoopId + mergeGateId + eventId); AddSequenceFlow(seqFlowBackLoopId, mergeGateId + eventId + seqFlowBackLoopId, mergeGateId); } } } }
public void AddSequenceFlow(string id, string sourceId, string targetId) { if (!trail.process.sequenceFlows.Exists(seq => seq.sourceRef.Equals(sourceId) && seq.targetRef.Equals(targetId) && seq.id.Equals(id))) { SequenceFlow sequenceFlow = new SequenceFlow { id = id, sourceRef = sourceId, targetRef = targetId }; trail.process.sequenceFlows.Add(sequenceFlow); string sourceType = ""; string targetType = ""; int x_target = 0, x_source = 0, y_target = 0, y_source = 0; Bounds b; if (StartEventExists(sourceId)) { StartEvent se = GetStartEvent(sourceId); se.outgoing.Add(id); sourceType = "se"; b = trail.diagram.bpmnPlane.bpmnShapes.Find(x => x.id.Equals(se.id + "_shape")).bounds; x_source = int.Parse(b.X); y_source = int.Parse(b.Y); } else if (StartEventExists(targetId)) { Console.Write("Cannot target start events"); } if (EndEventExists(targetId)) { EndEvent ee = GetEndEvent(targetId); ee.incoming.Add(id); targetType = "se"; b = trail.diagram.bpmnPlane.bpmnShapes.Find(x => x.id.Equals(ee.id + "_shape")).bounds; x_target = int.Parse(b.X); y_target = int.Parse(b.Y); } else if (EndEventExists(sourceId)) { Console.Write("Cannot use end events as source"); } if (TaskExists(sourceId)) { Task task = GetTask(sourceId); task.outgoing.Add(id); sourceType = "task"; b = trail.diagram.bpmnPlane.bpmnShapes.Find(x => x.id.Equals(task.id + "_shape")).bounds; x_source = int.Parse(b.X); y_source = int.Parse(b.Y); } else if (TaskExists(targetId)) { Task task = GetTask(targetId); task.incoming.Add(id); targetType = "task"; b = trail.diagram.bpmnPlane.bpmnShapes.Find(x => x.id.Equals(task.id + "_shape")).bounds; x_target = int.Parse(b.X); y_target = int.Parse(b.Y); } if (ParallelGatewayExists(sourceId)) { ParallelGateway par = GetParallelGateWay(sourceId); par.outgoing.Add(id); sourceType = "gate"; b = trail.diagram.bpmnPlane.bpmnShapes.Find(x => x.id.Equals(par.id + "_shape")).bounds; x_source = int.Parse(b.X); y_source = int.Parse(b.Y); } else if (ParallelGatewayExists(targetId)) { ParallelGateway par = GetParallelGateWay(targetId); par.incoming.Add(id); targetType = "gate"; b = trail.diagram.bpmnPlane.bpmnShapes.Find(x => x.id.Equals(par.id + "_shape")).bounds; x_target = int.Parse(b.X); y_target = int.Parse(b.Y); } if (ExclusiveGatewayExists(sourceId)) { ExclusiveGateway exc = GetExclusiveGateWay(sourceId); exc.outgoing.Add(id); sourceType = "gate"; b = trail.diagram.bpmnPlane.bpmnShapes.Find(x => x.id.Equals(exc.id + "_shape")).bounds; x_source = int.Parse(b.X); y_source = int.Parse(b.Y); } else if (ExclusiveGatewayExists(targetId)) { ExclusiveGateway exc = GetExclusiveGateWay(targetId); exc.incoming.Add(id); targetType = "gate"; b = trail.diagram.bpmnPlane.bpmnShapes.Find(x => x.id.Equals(exc.id + "_shape")).bounds; x_target = int.Parse(b.X); y_target = int.Parse(b.Y); } BPMNEdge bPMNEdge = new BPMNEdge { id = id + "_edge", bpmnElement = id }; Waypoint first = new Waypoint { X = "0", Y = "0" }; Waypoint second = new Waypoint { X = "0", Y = "0" }; switch (sourceType) { case "se": first.Y = SEHW / 2 + y_source + ""; first.X = x_source + ""; break; case "task": first.Y = TH / 2 + y_source + ""; first.X = x_source + ""; break; case "gate": first.Y = GHW / 2 + y_source + ""; first.X = x_source + ""; break; default: break; } switch (targetType) { case "se": second.Y = SEHW / 2 + y_target + ""; second.X = SEHW + x_target + ""; break; case "task": second.Y = TH / 2 + y_target + ""; second.X = TW + x_target + ""; break; case "gate": second.Y = GHW / 2 + y_target + ""; second.X = GHW + x_target + ""; break; default: break; } bPMNEdge.waypoint.Add(first); bPMNEdge.waypoint.Add(second); trail.diagram.bpmnPlane.bpmnEdges.Add(bPMNEdge); } }