public SpanSegmentConnectHolder(SpanSegmentToSimpleTerminalConnectInfo connectInfo) { ConnectInfo = connectInfo; }
internal void ApplySegmentConnect(SpanEquipment spanEquipment, SpanSegmentToSimpleTerminalConnectInfo spanSegmentToConnect) { if (!_graphElementsById.TryGetValue(spanSegmentToConnect.SegmentId, out var existingSegmentGraphElement)) { throw new ApplicationException($"Cannot find span segment graph element with id: {spanSegmentToConnect.SegmentId} processing segment to terminal connection."); } if (!spanEquipment.TryGetSpanSegment(spanSegmentToConnect.SegmentId, out var spanSegmentWithIndexInfo)) { throw new ApplicationException($"Cannot find span segment with id: {spanSegmentToConnect.SegmentId} in span equipment with id: {spanEquipment.Id} "); } var version = _objectManager.GetLatestCommitedVersion(); var trans = _objectManager.CreateTransaction(); try { // Find or create terminal var terminalToConnect = _objectManager.GetObject(spanSegmentToConnect.TerminalId, version) as UtilityGraphConnectedTerminal; if (terminalToConnect == null) { var terminalNodeOfInterestId = spanSegmentToConnect.ConnectionDirection == SpanSegmentToTerminalConnectionDirection.FromSpanSegmentToTerminal ? spanEquipment.NodesOfInterestIds[spanSegmentWithIndexInfo.SpanSegment.ToNodeOfInterestIndex] : spanEquipment.NodesOfInterestIds[spanSegmentWithIndexInfo.SpanSegment.FromNodeOfInterestIndex]; terminalToConnect = new UtilityGraphConnectedTerminal(spanSegmentToConnect.TerminalId, terminalNodeOfInterestId); trans.Add(terminalToConnect); } // If segment has never been connected before if (existingSegmentGraphElement is UtilityGraphDisconnectedSegment) { var fromNodeToConnect = spanSegmentToConnect.ConnectionDirection == SpanSegmentToTerminalConnectionDirection.FromTerminalToSpanSegment ? terminalToConnect : null; var toNodeToConnect = spanSegmentToConnect.ConnectionDirection == SpanSegmentToTerminalConnectionDirection.FromSpanSegmentToTerminal ? terminalToConnect : null; var newSegmentGraphElement = new UtilityGraphConnectedSegment(spanSegmentToConnect.SegmentId, fromNodeToConnect, toNodeToConnect, spanEquipment.Id, spanSegmentWithIndexInfo.StructureIndex, spanSegmentWithIndexInfo.SegmentIndex); trans.Add(newSegmentGraphElement); UpdateDict(spanSegmentToConnect.SegmentId, newSegmentGraphElement); } // We're dealing with update to a segment already connected else { if (spanSegmentToConnect.ConnectionDirection == SpanSegmentToTerminalConnectionDirection.FromSpanSegmentToTerminal) { var existingFromTerminal = (UtilityGraphConnectedTerminal)((UtilityGraphConnectedSegment)existingSegmentGraphElement).InV(version); var newSegmentGraphElement = new UtilityGraphConnectedSegment(spanSegmentToConnect.SegmentId, existingFromTerminal, terminalToConnect, spanEquipment.Id, spanSegmentWithIndexInfo.StructureIndex, spanSegmentWithIndexInfo.SegmentIndex); trans.Update(newSegmentGraphElement); UpdateDict(spanSegmentToConnect.SegmentId, newSegmentGraphElement); } else { var existingToTerminal = (UtilityGraphConnectedTerminal)((UtilityGraphConnectedSegment)existingSegmentGraphElement).OutV(version); var newSegmentGraphElement = new UtilityGraphConnectedSegment(spanSegmentToConnect.SegmentId, terminalToConnect, existingToTerminal, spanEquipment.Id, spanSegmentWithIndexInfo.StructureIndex, spanSegmentWithIndexInfo.SegmentIndex); trans.Update(newSegmentGraphElement); UpdateDict(spanSegmentToConnect.SegmentId, newSegmentGraphElement); } } } finally { trans.Commit(); } }