private void OnMultiConduitPlaced(MultiConduitInfo multiConduitInfo, MultiConduitPlaced @event) { multiConduitInfo.Id = @event.MultiConduitId; multiConduitInfo.Kind = ConduitKindEnum.MultiConduit; multiConduitInfo.WalkOfInterestId = @event.WalkOfInterestId; multiConduitInfo.AssetInfo = @event.AssetInfo; multiConduitInfo.Color = @event.ConduitInfo.Color; multiConduitInfo.Shape = @event.ConduitInfo.Shape; multiConduitInfo.ColorMarking = @event.ConduitInfo.ColorMarking; multiConduitInfo.TextMarking = @event.ConduitInfo.TextMarking; multiConduitInfo.Name = @event.ConduitInfo.Name; multiConduitInfo.InnerDiameter = @event.ConduitInfo.InnerDiameter; multiConduitInfo.OuterDiameter = @event.ConduitInfo.OuterDiameter; multiConduitInfo.Children = new List <ILine>(); // Create segment info (as is looks before any cuts or connections) var segment = new MultiConduitSegmentInfo(); segment.Id = Guid.NewGuid(); segment.ConduitId = @event.MultiConduitId; segment.SequenceNumber = 1; segment.FromRouteNodeId = routeNetworkQueryService.GetWalkOfInterestInfo(multiConduitInfo.WalkOfInterestId).StartNodeId; segment.ToRouteNodeId = routeNetworkQueryService.GetWalkOfInterestInfo(multiConduitInfo.WalkOfInterestId).EndNodeId; multiConduitInfo.Segments = new List <ISegment>() { segment }; conduitNetworkQueryService.UpdateMultiConduitInfo(multiConduitInfo); }
private void UpdateSegmentPassByIndex(ConduitInfo oldConduitInfo, ConduitInfo newConduitInfo) { var conduitWalkOfInterest = routeNetworkQueryService.GetWalkOfInterestInfo(newConduitInfo.GetRootConduit().WalkOfInterestId); if (oldConduitInfo != null) { // Remove old references foreach (var segment in oldConduitInfo.Segments.OfType <ConduitSegmentInfo>()) { var passThrougNodes = GetPassThroughNodes(segment, conduitWalkOfInterest); foreach (var passThroughNode in passThrougNodes) { _conduitSegmentPassByPointOfInterestId[passThroughNode].Remove(segment); } } } // Add new references foreach (var segment in newConduitInfo.Segments.OfType <ConduitSegmentInfo>()) { var passThrougNodes = GetPassThroughNodes(segment, conduitWalkOfInterest); foreach (var passThroughNode in passThrougNodes) { if (!_conduitSegmentPassByPointOfInterestId.ContainsKey(passThroughNode)) { _conduitSegmentPassByPointOfInterestId[passThroughNode] = new List <ISegment>(); } _conduitSegmentPassByPointOfInterestId[passThroughNode].Add(segment); } } }
private void OnFiberCablePlaced(FiberCableInfo fiberCableInfo, FiberCablePlaced @event) { fiberCableInfo.Id = @event.FiberCableId; fiberCableInfo.WalkOfInterestId = @event.WalkOfInterestId; // Create segment info (as is looks before any cuts or connections) var segment = new FiberCableSegmentInfo(); segment.Id = Guid.NewGuid(); segment.LineId = @event.FiberCableId; segment.SequenceNumber = 1; segment.FromRouteNodeId = routeNetworkQueryService.GetWalkOfInterestInfo(fiberCableInfo.WalkOfInterestId).StartNodeId; segment.ToRouteNodeId = routeNetworkQueryService.GetWalkOfInterestInfo(fiberCableInfo.WalkOfInterestId).EndNodeId; fiberCableInfo.Segments = new List <ISegment>() { segment }; // Create all the children fiberCableInfo.Children = new List <ILine>(); for (int i = 0; i < @event.NumberOfFibers; i++) { var fiber = new FiberCableFiberInfo() { Id = Guid.NewGuid(), Parent = fiberCableInfo, SequenceNumber = i + 1, WalkOfInterestId = fiberCableInfo.WalkOfInterestId }; var fiberSegment = new FiberCableSegmentInfo() { Id = Guid.NewGuid(), Line = fiber, FromNodeId = segment.FromNodeId, ToNodeId = segment.ToNodeId, LineId = fiber.Id, SequenceNumber = 1 }; fiber.Segments = new List <ISegment>() { fiberSegment }; fiberCableInfo.Children.Add(fiber); } fiberNetworkQueryService.UpdateFiberCableInfo(fiberCableInfo); }
public void CutInnerConduit(int sequenceNumber, Guid pointOfInterestId, IRouteNetworkState routeNetworkQueryService, IConduitNetworkQueryService conduitNetworkQueryService) { var multiConduitInfo = conduitNetworkQueryService.GetMultiConduitInfo(Id); // Point of interest id check if (pointOfInterestId == null || pointOfInterestId == Guid.Empty) { throw new ArgumentException("PointOfInterestId cannot be null or empty"); } // Inner conduit number check if (!multiConduitInfo.Children.OfType <ConduitInfo>().Any(i => i.SequenceNumber == sequenceNumber)) { throw new ArgumentException("Cannot find inner conduit number: " + sequenceNumber + " in multi conduit: " + Id); } var singleConduitInfo = conduitNetworkQueryService.GetSingleConduitInfo(multiConduitInfo.Children.OfType <ConduitInfo>().Single(i => i.SequenceNumber == sequenceNumber).Id); // Multi conduit cut check if (!multiConduitInfo.Segments.Exists(s => s.FromRouteNodeId == pointOfInterestId || s.ToRouteNodeId == pointOfInterestId)) { throw new ArgumentException("Multi conduit: " + Id + " is not cut at: " + pointOfInterestId + " You cannot cut a inner conduit before the outer conduit is cut."); } // Inner conduit cut check if (singleConduitInfo.Segments.Exists(s => s.FromRouteNodeId == pointOfInterestId || s.ToRouteNodeId == pointOfInterestId)) { throw new ArgumentException("Inner conduit number: " + sequenceNumber + " in multi conduit: " + Id + " is already cut at: " + pointOfInterestId); } // Check that conduit is cut at a node part of conduit walk of interest var walkOfInterest = routeNetworkQueryService.GetWalkOfInterestInfo(multiConduitInfo.WalkOfInterestId); if (!walkOfInterest.AllNodeIds.Contains(pointOfInterestId)) { throw new ArgumentException("The point of interest: " + pointOfInterestId + " was not found in walk of interest:" + multiConduitInfo.WalkOfInterestId + " of multi conduit: " + Id); } // Check that conduit is not cut at ends if (walkOfInterest.StartNodeId == pointOfInterestId || walkOfInterest.EndNodeId == pointOfInterestId) { throw new ArgumentException("The point of interest: " + pointOfInterestId + " is one of the ends in walk of interest:" + multiConduitInfo.WalkOfInterestId + " of multi conduit: " + Id + " This is not allowed. You cannot cut a conduit at its ends."); } RaiseEvent(new MultiConduitInnerConduitCut { MultiConduitId = Id, InnerConduitSequenceNumber = sequenceNumber, PointOfInterestId = pointOfInterestId }); }
public void InnerConduitCut(SingleConduitInfo singleConduitInfo, MultiConduitInnerConduitCut @event) { // Get the multi conduit var multiConduit = conduitNetworkQueryService.GetMultiConduitInfo(@event.MultiConduitId); // Get the walk of interest of the multi conduit var walkOfInterest = routeNetworkQueryService.GetWalkOfInterestInfo(multiConduit.WalkOfInterestId); // Get the node var nodeWhereToCut = routeNetworkQueryService.GetRouteNodeInfo(@event.PointOfInterestId); ConduitCutter.CutConduit(singleConduitInfo, walkOfInterest, nodeWhereToCut); conduitNetworkQueryService.UpdateSingleConduitInfo(singleConduitInfo); }
internal void Cut(Guid pointOfInterestId, IRouteNetworkState routeNetworkQueryService, IConduitNetworkQueryService conduitNetworkQueryService) { // Point of interest id check if (pointOfInterestId == null || pointOfInterestId == Guid.Empty) { throw new ArgumentException("PointOfInterestId cannot be null or empty"); } // Check if single conduit is already cut var singleConduitInfo = conduitNetworkQueryService.GetSingleConduitInfo(Id); if (singleConduitInfo.Segments.Exists(s => s.FromRouteNodeId == pointOfInterestId || s.ToRouteNodeId == pointOfInterestId)) { throw new ArgumentException("Single conduit: " + Id + " is already cut at: " + pointOfInterestId); } // Check that conduit is cut at a node part of conduit walk of interest var walkOfInterest = routeNetworkQueryService.GetWalkOfInterestInfo(singleConduitInfo.GetRootConduit().WalkOfInterestId); if (!walkOfInterest.AllNodeIds.Contains(pointOfInterestId)) { throw new ArgumentException("The point of interest: " + pointOfInterestId + " was not found in walk of interest:" + singleConduitInfo.WalkOfInterestId + " of single conduit: " + Id); } // Check that conduit is not cut at ends if (walkOfInterest.StartNodeId == pointOfInterestId || walkOfInterest.EndNodeId == pointOfInterestId) { throw new ArgumentException("The point of interest: " + pointOfInterestId + " is one of the ends in walk of interest:" + singleConduitInfo.WalkOfInterestId + " of single conduit: " + Id + " This is not allowed. You cannot cut a conduit at its ends."); } RaiseEvent(new SingleConduitCut { SingleConduitId = Id, PointOfInterestId = pointOfInterestId }); }
private void ResolveReferences(ConduitInfo condutiInfo) { var woi = routeNetworkQueryService.GetWalkOfInterestInfo(condutiInfo.GetRootConduit().WalkOfInterestId); // Resolve from node if (condutiInfo.FromRouteNode == null) { condutiInfo.FromRouteNode = routeNetworkQueryService.GetRouteNodeInfo(woi.StartNodeId); } // Resolve to node if (condutiInfo.ToRouteNode == null) { condutiInfo.ToRouteNode = routeNetworkQueryService.GetRouteNodeInfo(woi.EndNodeId); } // Resolve references inside segment foreach (var segment in condutiInfo.Segments.OfType <ConduitSegmentInfo>()) { // Resolve conduit reference segment.Conduit = condutiInfo; // Resolve conduit segment parent/child relationship if (segment.Conduit.Kind == ConduitKindEnum.InnerConduit) { // Create parents list if null if (segment.Parents == null) { segment.Parents = new List <ISegment>(); } var innerConduitSegmentWalkOfInterest = woi.SubWalk2(segment.FromRouteNodeId, segment.ToRouteNodeId); var multiConduit = segment.Conduit.Parent; // Go through each segment of the multi conduit to find if someone intersects with the inner conduit segment foreach (var multiConduitSegment in multiConduit.Segments) { // Create childre list if null if (multiConduitSegment.Children == null) { multiConduitSegment.Children = new List <ISegment>(); } var multiConduitSegmentWalkOfInterest = woi.SubWalk2(multiConduitSegment.FromRouteNodeId, multiConduitSegment.ToRouteNodeId); // Create hash set for quick lookup HashSet <Guid> multiConduitSegmentWalkOfInterestSegmetns = new HashSet <Guid>(); foreach (var segmentId in multiConduitSegmentWalkOfInterest.AllSegmentIds) { multiConduitSegmentWalkOfInterestSegmetns.Add(segmentId); } // check if overlap from segments of the inner conduit to the the multi conduit segment foreach (var innerConduitSegmentId in innerConduitSegmentWalkOfInterest.AllSegmentIds) { if (multiConduitSegmentWalkOfInterestSegmetns.Contains(innerConduitSegmentId)) { if (!multiConduitSegment.Children.Contains(segment)) { multiConduitSegment.Children.Add(segment); } if (!segment.Parents.Contains(multiConduitSegment)) { segment.Parents.Add(multiConduitSegment); } } } } } // From Junction if (segment.FromNodeId != Guid.Empty) { if (!_singleConduitJuncionInfos.ContainsKey(segment.FromNodeId)) { var newJunction = new SingleConduitSegmentJunctionInfo() { Id = segment.FromNodeId }; newJunction.AddToConduitSegment(segment); _singleConduitJuncionInfos.Add(newJunction.Id, newJunction); segment.FromNode = newJunction; } else { var existingJunction = _singleConduitJuncionInfos[segment.FromNodeId]; //existingJunction.ToConduitSegments = segment; existingJunction.AddToConduitSegment(segment); segment.FromNode = existingJunction; } } // To Junction if (segment.ToNodeId != Guid.Empty) { if (!_singleConduitJuncionInfos.ContainsKey(segment.ToNodeId)) { var newJunction = new SingleConduitSegmentJunctionInfo() { Id = segment.ToNodeId }; newJunction.AddFromConduitSegment(segment); _singleConduitJuncionInfos.Add(newJunction.Id, newJunction); segment.ToNode = newJunction; } else { var existingJunction = _singleConduitJuncionInfos[segment.ToNodeId]; existingJunction.AddFromConduitSegment(segment); segment.ToNode = existingJunction; } } } }
public ConduitSegment(IRouteNetworkState routeNetworkQueryService, IConduitNetworkQueryService conduitNetworkEqueryService, IDataLoaderContextAccessor dataLoader, IHttpContextAccessor httpContextAccessor) { this.routeNetworkQueryService = routeNetworkQueryService; this.conduitNetworkEqueryService = conduitNetworkEqueryService; var traversal = new TraversalHelper(routeNetworkQueryService); Description = "A conduit will initially contain one segment that spans the whole length of conduit that was originally placed in the route network. When the user starts to cut the conduit at various nodes, more conduit segments will emerge. However, the original conduit asset is the same, now just cut in pieces. The segment represent the pieces. The line represent the original asset. Graph connectivity is maintained on segment level. Use line field to access general asset information. Use the conduit field to access conduit specific asset information."; // Interface fields Interface <SegmentInterface>(); Field(x => x.Id, type: typeof(IdGraphType)).Description("Guid property"); Field <LineSegmentRelationTypeEnumType>( "RelationType", resolve: context => { Guid routeNodeId = (Guid)httpContextAccessor.HttpContext.Items["routeNodeId"]; return(context.Source.RelationType(routeNodeId)); }); Field(x => x.Line.LineKind, type: typeof(LineSegmentKindType)).Description("Type of line segment - i.e. multi conduit, single conduit, fiber cable etc."); Field(x => x.Line, type: typeof(LineInterface)).Description("Line that this segment belongs to."); Field(x => x.Parents, type: typeof(ListGraphType <SegmentInterface>)).Description("The parent segments of this segment, if this segment is contained within another segment network - i.e. a fiber cable segment running within one of more conduit segments."); Field(x => x.Children, type: typeof(ListGraphType <SegmentInterface>)).Description("The child segments of this segment. As an example, if this is multi conduit, then child segments might be fiber cable segments or inner conduit segments running inside the multi conduit."); Field <RouteNodeType>( "FromRouteNode", resolve: context => { return(routeNetworkQueryService.GetRouteNodeInfo(context.Source.FromRouteNodeId)); }); Field <RouteNodeType>( "ToRouteNode", resolve: context => { return(routeNetworkQueryService.GetRouteNodeInfo(context.Source.ToRouteNodeId)); }); Field <SegmentTraversalType>( "Traversal", resolve: context => { return(traversal.CreateTraversalInfoFromSegment(context.Source)); }); // Additional fields Field(x => x.Conduit, type: typeof(ConduitInfoType)).Description("The original conduit that this segment belongs to."); Field <SegmentTraversalType>( "Connectivity", resolve: context => { return(traversal.CreateTraversalInfoFromSegment(context.Source)); }); Field <ListGraphType <RouteSegmentType> >( "AllRouteSegments", resolve: context => { List <RouteSegmentInfo> result = new List <RouteSegmentInfo>(); var woi = routeNetworkQueryService.GetWalkOfInterestInfo(context.Source.Conduit.GetRootConduit().WalkOfInterestId).SubWalk2(context.Source.FromRouteNodeId, context.Source.ToRouteNodeId); foreach (var segmentId in woi.AllSegmentIds) { result.Add(routeNetworkQueryService.GetRouteSegmentInfo(segmentId)); } return(result); }); Field <ListGraphType <RouteNodeType> >( "AllRouteNodes", resolve: context => { List <RouteNodeInfo> result = new List <RouteNodeInfo>(); var woi = routeNetworkQueryService.GetWalkOfInterestInfo(context.Source.Conduit.GetRootConduit().WalkOfInterestId).SubWalk2(context.Source.FromRouteNodeId, context.Source.ToRouteNodeId); foreach (var nodeId in woi.AllNodeIds) { result.Add(routeNetworkQueryService.GetRouteNodeInfo(nodeId)); } return(result); }); }
public Fiber(IRouteNetworkState routeNetworkQueryService, IConduitNetworkQueryService conduitNetworkEqueryService, IDataLoaderContextAccessor dataLoader) { this.routeNetworkQueryService = routeNetworkQueryService; this.conduitNetworkEqueryService = conduitNetworkEqueryService; Description = "A fiber cable."; // Interface fields Interface <LineInterface>(); Field(x => x.Id, type: typeof(IdGraphType)).Description("Guid property"); Field(x => x.LineKind, type: typeof(LineSegmentKindType)).Description("Type of line - i.e. multi conduit, single conduit, fiber cable etc."); Field(x => x.FromRouteNode, type: typeof(NodeInterface)).Description("The node where this line equipment starts."); Field(x => x.ToRouteNode, type: typeof(NodeInterface)).Description("The node where this line equipment ends."); Field(x => x.Parent, type: typeof(LineInterface)).Description("The parent, if this object is part of a composite equipment structure - i.e. a fiber inside a fiber cable or an inner conduit inside a multi conduit. Notice that the parent-child relationship on line level only cover the relationship inside a single composite equipment such as a fiber cable or multi conduit. Containment relationships between different types of equipment is on segment level only."); //Field(x => x.Children, type: typeof(ListGraphType<LineInterface>)).Description("The children of a composite equipment structure - i.e. inner conduits part of a multi conduit. Notice that the parent-child relationship on line level only cover the relationship inside a composite equipment such as a fiber cable or multi conduit. Containment relationships between different types of equipment is on segment level only."); Field <ListGraphType <LineInterface> > ( "Children", resolve: context => { return(null); }); // Fiber specific fields Field(x => x.SequenceNumber, type: typeof(IdGraphType)).Description("The position of fiber cable inside of conduit or route."); Field <ListGraphType <RouteSegmentType> >( "AllRouteSegments", resolve: context => { List <RouteSegmentInfo> result = new List <RouteSegmentInfo>(); var woi = routeNetworkQueryService.GetWalkOfInterestInfo(context.Source.GetRoot().WalkOfInterestId); foreach (var segmentId in woi.AllSegmentIds) { result.Add(routeNetworkQueryService.GetRouteSegmentInfo(segmentId)); } return(result); }); Field <ListGraphType <RouteNodeType> >( "AllRouteNodes", resolve: context => { List <RouteNodeInfo> result = new List <RouteNodeInfo>(); var woi = routeNetworkQueryService.GetWalkOfInterestInfo(context.Source.GetRoot().WalkOfInterestId); foreach (var nodeId in woi.AllNodeIds) { result.Add(routeNetworkQueryService.GetRouteNodeInfo(nodeId)); } return(result); }); }
public ConduitInfoType(IRouteNetworkState routeNetworkQueryService, IConduitNetworkQueryService conduitNetworkEqueryService, IDataLoaderContextAccessor dataLoader) { this.routeNetworkQueryService = routeNetworkQueryService; this.conduitNetworkEqueryService = conduitNetworkEqueryService; Description = "A conduit. Can be a multi conduit (i.e. has inner ducts) or a single conduit."; // Interface fields //Interface<LineInterface>(); Field(x => x.Id, type: typeof(IdGraphType)).Description("Guid property"); Field(x => x.LineKind, type: typeof(LineSegmentKindType)).Description("Type of line - i.e. multi conduit, single conduit, fiber cable etc."); Field(x => x.FromRouteNode, type: typeof(NodeInterface)).Description("The node where this line equipment starts."); Field(x => x.ToRouteNode, type: typeof(NodeInterface)).Description("The node where this line equipment ends."); //Field(x => x.Parent, type: typeof(LineInterface)).Description("The parent, if this object is part of a composite equipment structure - i.e. a fiber inside a fiber cable or an inner conduit inside a multi conduit. Notice that the parent-child relationship on line level only cover the relationship inside a single composite equipment such as a fiber cable or multi conduit. Containment relationships between different types of equipment is on segment level only."); Field <ConduitInfoType>( "Parent", "The parent, if this object is part of a composite equipment structure - i.e. a fiber inside a fiber cable or an inner conduit inside a multi conduit. Notice that the parent-child relationship on line level only cover the relationship inside a single composite equipment such as a fiber cable or multi conduit. Containment relationships between different types of equipment is on segment level only.", resolve: context => { return(context.Source.Parent); }); // Additional fields, some for backwards compabtiblely Field <ConduitKindEnumType>("Kind", "Kind of conduit (multi or single conduit)"); Field(x => x.Name, type: typeof(IdGraphType)).Description("The uility might give each conduit a name/number"); Field <IdGraphType>( "Position", "The position of the conduit inside a multi conduit. Field only populated on inner conduits (conduits inside a multi conduit)", resolve: context => { return(context.Source.SequenceNumber); }); //Field(x => x.SequenceNumber, type: typeof(IdGraphType)).Description("The position of the conduit inside a multi conduit. Field only populated on inner conduits (conduits inside a multi conduit)"); Field <ConduitShapeKindEnumType>("Shape", "Shape of conduit - flat, round etc."); Field <ConduitColorEnumType>("Color", "Color of the conduit itself"); Field <ConduitColorEnumType>("ColorMarking", "Normally a colored stripe to distinguish between many conduits of same type in a trench"); Field(x => x.TextMarking, type: typeof(IdGraphType)).Description("Normally some text printed along the conduitto distinguish between many conduits of same type in a trench"); Field(x => x.InnerDiameter, type: typeof(IdGraphType)).Description("Inner diameter of the conduit"); Field(x => x.OuterDiameter, type: typeof(IdGraphType)).Description("Outer diameter of the conduit"); Field(x => x.AssetInfo, type: typeof(AssetInfoType)).Description("Asset info"); Field(x => x.Children, type: typeof(ListGraphType <ConduitInfoType>)).Description("Child conduits. Field only populated on multi conduits."); //Field(x => x.Parent, type: typeof(ConduitInfoType)).Description("The parent of an inner conduit. Not available on multi and single conduits."); /* * Field<RouteNodeType>( * "FromRouteNode", * resolve: context => * { * var woi = routeNetworkQueryService.GetWalkOfInterestInfo(context.Source.GetRootConduit().WalkOfInterestId); * return routeNetworkQueryService.GetRouteNodeInfo(woi.StartNodeId); * }); * * Field<RouteNodeType>( * "ToRouteNode", * resolve: context => * { * var woi = routeNetworkQueryService.GetWalkOfInterestInfo(context.Source.GetRootConduit().WalkOfInterestId); * return routeNetworkQueryService.GetRouteNodeInfo(woi.EndNodeId); * }); */ Field <ListGraphType <RouteSegmentType> >( "AllRouteSegments", resolve: context => { List <RouteSegmentInfo> result = new List <RouteSegmentInfo>(); var woi = routeNetworkQueryService.GetWalkOfInterestInfo(context.Source.GetRootConduit().WalkOfInterestId); foreach (var segmentId in woi.AllSegmentIds) { result.Add(routeNetworkQueryService.GetRouteSegmentInfo(segmentId)); } return(result); }); Field <ListGraphType <RouteNodeType> >( "AllRouteNodes", resolve: context => { List <RouteNodeInfo> result = new List <RouteNodeInfo>(); var woi = routeNetworkQueryService.GetWalkOfInterestInfo(context.Source.GetRootConduit().WalkOfInterestId); foreach (var nodeId in woi.AllNodeIds) { result.Add(routeNetworkQueryService.GetRouteNodeInfo(nodeId)); } return(result); }); }
public ConduitSegmentType(IRouteNetworkState routeNetworkQueryService, IConduitNetworkQueryService conduitNetworkEqueryService, IDataLoaderContextAccessor dataLoader) { this.routeNetworkQueryService = routeNetworkQueryService; this.conduitNetworkEqueryService = conduitNetworkEqueryService; var traversal = new TraversalHelper(routeNetworkQueryService); Description = "A conduit segment will initially be the original whole length piece of conduit. When the user starts to cut the conduit at various nodes, more conduit segments will emerge. Graph connectivity is maintained on segment level."; Field(x => x.Id, type: typeof(IdGraphType)).Description("Guid property"); Field(x => x.Conduit, type: typeof(ConduitInfoType)).Description("The original conduit that this segment is part of."); Field(x => x.Children, type: typeof(ListGraphType <ConduitSegmentType>)).Description("The children of a multi conduit segment."); Field(x => x.Parents, type: typeof(ListGraphType <ConduitSegmentType>)).Description("The parents of an inner conduit segment."); Field <ConduitLineType>( "Line", resolve: context => { var traversalInfo = traversal.CreateTraversalInfoFromSegment(context.Source); var cLineType = new ConduitLineInfo(); cLineType.AllSegments = traversalInfo.AllSegments.OfType <ConduitSegmentInfo>().ToList(); cLineType.AllRouteNodes = traversalInfo.AllRouteNodes.OfType <RouteNodeInfo>().ToList(); cLineType.AllRouteSegments = traversalInfo.AllRouteSegments.OfType <RouteSegmentInfo>().ToList(); cLineType.EndRouteNode = (RouteNodeInfo)traversalInfo.EndRouteNode; cLineType.StartRouteNode = (RouteNodeInfo)traversalInfo.StartRouteNode; cLineType.StartRouteSegment = (RouteSegmentInfo)traversalInfo.StartRouteSegment; cLineType.EndRouteSegment = (RouteSegmentInfo)traversalInfo.EndRouteSegment; return(cLineType); }); Field <RouteNodeType>( "FromRouteNode", resolve: context => { return(routeNetworkQueryService.GetRouteNodeInfo(context.Source.FromRouteNodeId)); }); Field <RouteNodeType>( "ToRouteNode", resolve: context => { return(routeNetworkQueryService.GetRouteNodeInfo(context.Source.ToRouteNodeId)); }); Field <ListGraphType <RouteSegmentType> >( "AllRouteSegments", resolve: context => { List <RouteSegmentInfo> result = new List <RouteSegmentInfo>(); var woi = routeNetworkQueryService.GetWalkOfInterestInfo(context.Source.Conduit.GetRootConduit().WalkOfInterestId).SubWalk2(context.Source.FromRouteNodeId, context.Source.ToRouteNodeId); foreach (var segmentId in woi.AllSegmentIds) { result.Add(routeNetworkQueryService.GetRouteSegmentInfo(segmentId)); } return(result); }); Field <ListGraphType <RouteNodeType> >( "AllRouteNodes", resolve: context => { List <RouteNodeInfo> result = new List <RouteNodeInfo>(); var woi = routeNetworkQueryService.GetWalkOfInterestInfo(context.Source.Conduit.GetRootConduit().WalkOfInterestId).SubWalk2(context.Source.FromRouteNodeId, context.Source.ToRouteNodeId); foreach (var nodeId in woi.AllNodeIds) { result.Add(routeNetworkQueryService.GetRouteNodeInfo(nodeId)); } return(result); }); Field(x => x.Line.LineKind, type: typeof(LineSegmentKindType)).Description("Type of line segment - i.e. conduit, power cable, signal cable etc."); //Interface<LineSegmentInterface>(); }
public ISegmentTraversal CreateTraversalInfoFromSegment(ISegment sourceSegment) { var result = new SegmentTraversalInfo(); HashSet <Guid> startNodesFound = new HashSet <Guid>(); HashSet <Guid> endNodesFound = new HashSet <Guid>(); Guid startNodeId = Guid.Empty; Guid endNodeId = Guid.Empty; Guid startSegmentId = Guid.Empty; Guid endSegmentId = Guid.Empty; List <Guid> allNodeIds = new List <Guid>(); List <Guid> allSegmentIds = new List <Guid>(); HashSet <ILine> alreadyChecked = new HashSet <ILine>(); // Get all segments related to the source segment var traceResult = sourceSegment.UndirectionalDFS <GraphElement, GraphElement>(); // Pull out the segments from the trace result var segments = traceResult.Where(t => t is ISegment).Select(t => t as ISegment); foreach (var segment in segments) { var rootConduit = segment.Line.GetRoot(); if (!alreadyChecked.Contains(rootConduit)) { alreadyChecked.Add(rootConduit); var walkOfInterest = routeNetworkQueryService.GetWalkOfInterestInfo(rootConduit.WalkOfInterestId).SubWalk2(segment.FromRouteNodeId, segment.ToRouteNodeId); // add node ids foreach (var nodeId in walkOfInterest.AllNodeIds) { if (!allNodeIds.Contains(nodeId)) { allNodeIds.Add(nodeId); } } // add segment ids foreach (var segmentId in walkOfInterest.AllSegmentIds) { if (!allSegmentIds.Contains(segmentId)) { allSegmentIds.Add(segmentId); } } if (!startNodesFound.Contains(walkOfInterest.StartNodeId)) { startNodesFound.Add(walkOfInterest.StartNodeId); startNodesFound.Add(walkOfInterest.EndNodeId); startNodeId = walkOfInterest.StartNodeId; startSegmentId = walkOfInterest.StartSegmentId; } if (!endNodesFound.Contains(walkOfInterest.EndNodeId)) { endNodesFound.Add(walkOfInterest.StartNodeId); endNodesFound.Add(walkOfInterest.EndNodeId); endNodeId = walkOfInterest.EndNodeId; endSegmentId = walkOfInterest.EndSegmentId; } } } result.StartRouteNode = routeNetworkQueryService.GetRouteNodeInfo(startNodeId); result.EndRouteNode = routeNetworkQueryService.GetRouteNodeInfo(endNodeId); result.StartRouteSegment = routeNetworkQueryService.GetRouteSegmentInfo(startSegmentId); result.EndRouteSegment = routeNetworkQueryService.GetRouteSegmentInfo(endSegmentId); result.AllRouteNodes = new List <INode>(); foreach (var nodeId in allNodeIds) { result.AllRouteNodes.Add(routeNetworkQueryService.GetRouteNodeInfo(nodeId)); } result.AllRouteSegments = new List <ISegment>(); foreach (var segmentId in allSegmentIds) { result.AllRouteSegments.Add(routeNetworkQueryService.GetRouteSegmentInfo(segmentId)); } result.AllSegments = segments.ToList(); return(result); }
internal void Connect(Guid pointOfInterestId, ConduitEndKindEnum endKind, Guid junctionId, IRouteNetworkState routeNetworkQueryService, IConduitNetworkQueryService conduitNetworkQueryService) { var singleConduitInfo = conduitNetworkQueryService.GetSingleConduitInfo(Id); // endKind check if (endKind == 0) { throw new ArgumentException("End kind must be specified. Otherwise the system don't know with end of the segment to connect, if a conduit has been cut into two pieces in a node."); } if (!singleConduitInfo.Segments.Exists(s => s.FromRouteNodeId == pointOfInterestId || s.ToRouteNodeId == pointOfInterestId)) { throw new ArgumentException("The single conduit: " + Id + " is not cut at: " + pointOfInterestId); } // Check that conduit is connected at a node part of conduit walk of interest var walkOfInterest = routeNetworkQueryService.GetWalkOfInterestInfo(singleConduitInfo.GetRootConduit().WalkOfInterestId); if (!walkOfInterest.AllNodeIds.Contains(pointOfInterestId)) { throw new ArgumentException("The point of interest: " + pointOfInterestId + " was not found in walk of interest:" + singleConduitInfo.WalkOfInterestId + " of single conduit: " + Id); } ISegment connectingSegment = null; // Check incomming if (endKind == ConduitEndKindEnum.Incomming) { if (!singleConduitInfo.Segments.Exists(s => s.ToRouteNodeId == pointOfInterestId)) { throw new ArgumentException("No segments are incomming to point of interest: " + pointOfInterestId + " in single conduit: " + Id); } connectingSegment = singleConduitInfo.Segments.Find(s => s.ToRouteNodeId == pointOfInterestId); // Check if already connect to a junction if (connectingSegment.ToNodeId != Guid.Empty) { throw new ArgumentException("the incomming segment: " + connectingSegment.Id + " is already connected to a junction: " + connectingSegment.ToNodeId); } } // Check outgoing else { if (!singleConduitInfo.Segments.Exists(s => s.FromRouteNodeId == pointOfInterestId)) { throw new ArgumentException("No segments are outgoing from point of interest: " + pointOfInterestId + " in single conduit: " + Id); } connectingSegment = singleConduitInfo.Segments.Find(s => s.FromRouteNodeId == pointOfInterestId); // Check if already connect to a junction if (connectingSegment.FromNodeId != Guid.Empty) { throw new ArgumentException("the outgoing segment: " + connectingSegment.Id + " is already connected to a junction: " + connectingSegment.FromNodeId); } } RaiseEvent(new SingleConduitConnected { SingleConduitId = Id, PointOfInterestId = pointOfInterestId, ConnectedEndKind = endKind, ConnectedJunctionId = junctionId }); }
internal void ConnectInnerConduit(Guid pointOfInterestId, int sequenceNumber, ConduitEndKindEnum endKind, Guid junctionId, IRouteNetworkState routeNetworkQueryService, IConduitNetworkQueryService conduitNetworkQueryService) { // Point of interest id check if (pointOfInterestId == null || pointOfInterestId == Guid.Empty) { throw new ArgumentException("PointOfInterestId cannot be null or empty"); } // endKind check if (endKind == 0) { throw new ArgumentException("End kind must be specified. Otherwise the system don't know with end of the segment to connect, if a conduit has been cut into two pieces in a node."); } var multiConduitInfo = conduitNetworkQueryService.GetMultiConduitInfo(Id); // Inner conduit number check if (!multiConduitInfo.Children.OfType <ConduitInfo>().Any(i => i.SequenceNumber == sequenceNumber)) { throw new ArgumentException("Cannot find inner conduit number: " + sequenceNumber + " in multi conduit: " + Id); } var singleConduitInfo = conduitNetworkQueryService.GetSingleConduitInfo(multiConduitInfo.Children.OfType <ConduitInfo>().Single(i => i.SequenceNumber == sequenceNumber).Id); if (!singleConduitInfo.Segments.Exists(s => s.FromRouteNodeId == pointOfInterestId || s.ToRouteNodeId == pointOfInterestId)) { throw new ArgumentException("Inner conduit number: " + sequenceNumber + " in multi conduit: " + Id + " is not cut at: " + pointOfInterestId); } // Check that conduit is connected at a node part of conduit walk of interest var walkOfInterest = routeNetworkQueryService.GetWalkOfInterestInfo(multiConduitInfo.WalkOfInterestId); if (!walkOfInterest.AllNodeIds.Contains(pointOfInterestId)) { throw new ArgumentException("The point of interest: " + pointOfInterestId + " was not found in walk of interest:" + multiConduitInfo.WalkOfInterestId + " of multi conduit: " + Id); } // Check incomming if (endKind == ConduitEndKindEnum.Incomming && !multiConduitInfo.Segments.Exists(s => s.ToRouteNodeId == pointOfInterestId)) { throw new ArgumentException("No segments are incomming to point of interest: " + pointOfInterestId + " in multi conduit: " + Id); } // Check outgoing if (endKind == ConduitEndKindEnum.Outgoing && !multiConduitInfo.Segments.Exists(s => s.FromRouteNodeId == pointOfInterestId)) { throw new ArgumentException("No segments are outgoing from point of interest: " + pointOfInterestId + " in multi conduit: " + Id); } ISegment connectingSegment = null; // Check incomming inner conduit if (endKind == ConduitEndKindEnum.Incomming) { if (!singleConduitInfo.Segments.Exists(s => s.ToRouteNodeId == pointOfInterestId)) { throw new ArgumentException("No inner conduit segments are incomming to point of interest: " + pointOfInterestId + " in single conduit: " + Id); } connectingSegment = singleConduitInfo.Segments.Find(s => s.ToRouteNodeId == pointOfInterestId); // Check if already connect to a junction if (connectingSegment.ToNodeId != Guid.Empty) { throw new ArgumentException("the incomming inner conduit segment: " + connectingSegment.Id + " is already connected to a junction: " + connectingSegment.ToNodeId); } } // Check outgoing inner conduit else { if (!singleConduitInfo.Segments.Exists(s => s.FromRouteNodeId == pointOfInterestId)) { throw new ArgumentException("No inner conduit segments are outgoing from point of interest: " + pointOfInterestId + " in single conduit: " + Id); } connectingSegment = singleConduitInfo.Segments.Find(s => s.FromRouteNodeId == pointOfInterestId); // Check if already connect to a junction if (connectingSegment.FromNodeId != Guid.Empty) { throw new ArgumentException("the outgoing inner conduit segment: " + connectingSegment.Id + " is already connected to a junction: " + connectingSegment.FromNodeId); } } RaiseEvent(new MultiConduitInnerConduitConnected { MultiConduitId = Id, PointOfInterestId = pointOfInterestId, InnerConduitSequenceNumber = sequenceNumber, ConnectedEndKind = endKind, ConnectedJunctionId = junctionId }); }
internal void AttachPassByConduitToClosure(Guid conduitId, ConduitClosureInfoSide incommingSide, ConduitClosureInfoSide outgoingSide, int incommingPortPosition, int outgoingPortPosition, int incommingTerminalPosition, int outgoingTerminalPosition, IRouteNetworkState routeNetworkQueryService, IConduitNetworkQueryService conduitNetworkQueryService, IConduitClosureRepository conduitClosureRepository) { // Check if multi conduit is passing by closure var conduit = conduitNetworkQueryService.GetMultiConduitInfo(conduitId); var walkOfInterest = routeNetworkQueryService.GetWalkOfInterestInfo(conduit.WalkOfInterestId); if (!walkOfInterest.AllNodeIds.Contains(_pointOfInterestId)) { throw new ArgumentException("Conduit: " + conduitId + " is not related to the point of interest: " + _pointOfInterestId + " where conduit closure: " + Id + " is placed at all."); } if (walkOfInterest.StartNodeId == _pointOfInterestId || walkOfInterest.EndNodeId == _pointOfInterestId) { throw new ArgumentException("Conduit: " + conduitId + " is ending in point of interest: " + _pointOfInterestId + " - but not pasing through it. Please use AttachConduitEndToClosure instead. The AttachPassByConduitToClosure can only be used on conduits that are passing through the point of interest (route node) where the conduit closure is placed."); } if (incommingSide == outgoingSide && incommingPortPosition == outgoingPortPosition) { throw new ArgumentException("A conduit is not allowed to enter and exit the same port on the same side."); } var conduitClosureInfo = conduitClosureRepository.GetConduitClosureInfo(Id); // Check if conduit is already attached to closure if (conduitClosureInfo.Sides.Exists(s => s.Ports.Exists(p => p.MultiConduitId == conduitId))) { throw new ArgumentException("The conduit: " + conduitId + " is already attached to the closure: " + this.Id); } if (conduitClosureInfo.Sides.Exists(s => s.Ports.Exists(p => p.Terminals.Exists(t => t.LineId == conduitId)))) { throw new ArgumentException("The conduit: " + conduitId + " is already attached to the closure: " + this.Id); } // If ports already exists on the side and outgoing port argument not set, find next available port if (incommingPortPosition == 0 && conduitClosureInfo.Sides.Find(s => s.Position == incommingSide).Ports.Count != 0) { incommingPortPosition = conduitClosureInfo.Sides.Find(s => s.Position == incommingSide).Ports.OrderByDescending(p => p.Position).First().Position + 1; } else { incommingPortPosition = 1; // No ports yet, so we put it on port 1 } // If ports already exists on the side and outgoing port argument not set, find next available port if (outgoingPortPosition == 0 && conduitClosureInfo.Sides.Find(s => s.Position == outgoingSide).Ports.Count != 0) { outgoingPortPosition = conduitClosureInfo.Sides.Find(s => s.Position == outgoingSide).Ports.OrderByDescending(p => p.Position).First().Position + 1; } else { outgoingPortPosition = 1; // No ports yet, so we put it on port 1 } // Check if port is the next in sequence. if (conduitClosureInfo.Sides.Find(s => s.Position == incommingSide).Ports.Count != 0) { if (conduitClosureInfo.Sides.Find(s => s.Position == incommingSide).Ports.OrderByDescending(p => p.Position).First().Position != (incommingPortPosition - 1)) { throw new ArgumentException("Incomming port: " + incommingPortPosition + "on side: " + incommingSide + " is not the next number in sequence. Last port number used on side: " + incommingSide + " is: " + conduitClosureInfo.Sides.Find(s => s.Position == incommingSide).Ports.OrderByDescending(p => p.Position).First().Position); } } else { if (incommingPortPosition != 1) { throw new ArgumentException("Incomming port: " + incommingPortPosition + "on side: " + incommingSide + " is not the next number in sequence. No ports currently added to side: " + incommingSide + ". Therefor port number = 1 was expected."); } } if (conduitClosureInfo.Sides.Find(s => s.Position == outgoingSide).Ports.Count != 0) { if (conduitClosureInfo.Sides.Find(s => s.Position == outgoingSide).Ports.OrderByDescending(p => p.Position).First().Position != (outgoingPortPosition - 1)) { throw new ArgumentException("Outgoing port: " + outgoingPortPosition + "on side: " + outgoingSide + " is not the next number in sequence. Last port number used on side: " + outgoingSide + " is: " + conduitClosureInfo.Sides.Find(s => s.Position == outgoingSide).Ports.OrderByDescending(p => p.Position).First().Position); } } else { if (outgoingPortPosition != 1) { throw new ArgumentException("Outgoing port: " + outgoingPortPosition + "on side: " + outgoingSide + " is not the next number in sequence. No ports currently added to side: " + outgoingSide + ". Therefor port number = 1 was expected."); } } /////////////////////////////////////////////////////////////// /// Finish checking. Now created the domain events var conduitAttached = new ConduitClosurePassingByConduitAttached() { ConduitClosureId = this.Id, ConduitId = conduitId, IncommingSide = incommingSide, OutgoingSide = outgoingSide, IncommingPortPosition = incommingPortPosition, OutgoingPortPosition = outgoingPortPosition, IncommingTerminalPosition = incommingTerminalPosition, OutgoingTerminalPosition = outgoingTerminalPosition }; RaiseEvent(conduitAttached); }
private void ResolveReferences(FiberCableInfo fiberCableInfo) { var woi = _routeNetworkQueryService.GetWalkOfInterestInfo(fiberCableInfo.GetRoot().WalkOfInterestId); // Resolve from node if (fiberCableInfo.FromRouteNode == null) { fiberCableInfo.FromRouteNode = _routeNetworkQueryService.GetRouteNodeInfo(woi.StartNodeId); } // Resolve to node if (fiberCableInfo.ToRouteNode == null) { fiberCableInfo.ToRouteNode = _routeNetworkQueryService.GetRouteNodeInfo(woi.EndNodeId); } // Resolve references inside segment foreach (var segment in fiberCableInfo.Segments.OfType <FiberSegmentInfo>()) { // Resolve fiber cable reference segment.Line = fiberCableInfo; // Resolve FromRouteNode if (segment.FromRouteNode == null && segment.FromRouteNodeId != Guid.Empty) { segment.FromRouteNode = _routeNetworkQueryService.GetRouteNodeInfo(segment.FromRouteNodeId); } // Resolve ToRouteNode if (segment.ToRouteNode == null && segment.ToRouteNodeId != Guid.Empty) { segment.ToRouteNode = _routeNetworkQueryService.GetRouteNodeInfo(segment.ToRouteNodeId); } } /* * // Resolve fiber to fiber cable parent/child relationship * if (segment.Line.LineKind == LineKindEnum.Fiber) * { * // Create parents list if null * if (segment.Parents == null) * segment.Parents = new List<ILineSegment>(); * * var fiberWalkOfInterest = conduitWalkOfInterest.SubWalk2(segment.FromRouteNodeId, segment.ToRouteNodeId); * * var fiberCable = segment.Line.Parent; * * // Go through each segment of the multi conduit to find if someone intersects with the inner conduit segment * foreach (var fiberCableSegment in fiberCable.Segments) * { * // Create childre list if null * if (fiberCableSegment.Children == null) * fiberCableSegment.Children = new List<ILineSegment>(); * * var fiberCableSegmentWalkOfInterest = conduitWalkOfInterest.SubWalk2(fiberCableSegment.FromRouteNodeId, fiberCableSegment.ToRouteNodeId); * * // Create hash set for quick lookup * HashSet<Guid> fiberCableSegmentWalkOfInterestSegments = new HashSet<Guid>(); * foreach (var segmentId in fiberCableSegmentWalkOfInterest.AllSegmentIds) * fiberCableSegmentWalkOfInterestSegments.Add(segmentId); * * // Check if overlap from segments of the inner conduit to the the multi conduit segment * foreach (var fiberSegmentId in fiberWalkOfInterest.AllSegmentIds) * { * if (fiberCableSegmentWalkOfInterestSegments.Contains(fiberSegmentId)) * { * if (!fiberCableSegment.Children.Contains(segment)) * fiberCableSegment.Children.Add(segment); * * if (!segment.Parents.Contains(fiberCableSegment)) * segment.Parents.Add(fiberCableSegment); * } * } * } * * // From Junction * if (segment.FromNodeId != Guid.Empty) * { * if (!_singleConduitJuncionInfos.ContainsKey(segment.FromNodeId)) * { * var newJunction = new SingleConduitSegmentJunctionInfo() { Id = segment.FromNodeId }; * newJunction.AddToConduitSegment(segment); * _singleConduitJuncionInfos.Add(newJunction.Id, newJunction); * segment.FromNode = newJunction; * } * else * { * var existingJunction = _singleConduitJuncionInfos[segment.FromNodeId]; * //existingJunction.ToConduitSegments = segment; * existingJunction.AddToConduitSegment(segment); * segment.FromNode = existingJunction; * } * } * * // To Junction * if (segment.ToNodeId != Guid.Empty) * { * if (!_singleConduitJuncionInfos.ContainsKey(segment.ToNodeId)) * { * var newJunction = new SingleConduitSegmentJunctionInfo() { Id = segment.ToNodeId }; * newJunction.AddFromConduitSegment(segment); * _singleConduitJuncionInfos.Add(newJunction.Id, newJunction); * segment.ToNode = newJunction; * } * else * { * var existingJunction = _singleConduitJuncionInfos[segment.ToNodeId]; * existingJunction.AddFromConduitSegment(segment); * segment.ToNode = existingJunction; * } * } */ }