static void Map(
            this Dictionary <InstanceID, InstanceID> map,
            SegmentRecord segmentData,
            ushort nodeID,
            bool startNode,
            ushort targetSegmentID)
        {
            // node maps to it self.
            InstanceID instanceID = new InstanceID {
                NetNode = nodeID
            };

            map[instanceID] = instanceID;

            // map segment.
            InstanceID sourceSegment = new InstanceID {
                NetSegment = segmentData.SegmentID
            };
            InstanceID targetSegment = new InstanceID {
                NetSegment = targetSegmentID
            };

            map[sourceSegment] = targetSegment;

            // map segment end.
            InstanceID sourceInstanceID = InstanceIDExtension.SegmentEnd(segmentData.SegmentID, startNode);
            bool       targetStartNode  = targetSegmentID.ToSegment().IsStartNode(nodeID);
            InstanceID targetInstanceID = InstanceIDExtension.SegmentEnd(targetSegmentID, targetStartNode);

            map[sourceInstanceID] = targetInstanceID;
        }
 static void PasteSegmentEnd(
     object data, ushort nodeID1, ushort nodeID, ushort nodeID2, ushort targetSegmentID)
 {
     if (data != null)
     {
         if (nodeID == nodeID1 || nodeID == nodeID2)
         {
             //man_.PasteSegmentEnd(data, targetNodeID: nodeID, targetSegmentID: targetSegmentID);
             bool startNode        = targetSegmentID.ToSegment().IsStartNode(nodeID);
             var  targetInstanceID = InstanceIDExtension.SegmentEnd(targetSegmentID, startNode);
             man_.Paste(targetInstanceID, data, null);
         }
     }
 }
 public static void Prefix(ushort segment)
 {
     if (UpgradingSegmentData != null)
     {
         KianCommons.Log.Error("Unexpected UpgradingSegmentData != null");
         UpgradingSegmentData = null;
     }
     if (m_upgrading)
     {
         UpgradingSegmentData = SegmentRecord.Create(segment, man_);
     }
     Log.Debug($"ReleaseSegment.Prefix({segment})\n" + Environment.StackTrace);
     if (man_ is IReleaser releaser)
     {
         releaser.Release(new InstanceID {
             NetSegment = segment
         });
         releaser.Release(InstanceIDExtension.SegmentEnd(segment, true));
         releaser.Release(InstanceIDExtension.SegmentEnd(segment, false));
     }
 }
 internal static object CopySegmentEnd(this MoveItIntegrationBase man, ushort segmentID, bool start) =>
 man.Copy(InstanceIDExtension.SegmentEnd(segmentID, start));