public ConduitClosureCommandHandler(IAggregateRepository aggregateRepository, IRouteNetworkState routeNetworkQueryService, IConduitNetworkQueryService conduitNetworkQueryService, IConduitClosureRepository conduitClosureRepository) { this.repo = aggregateRepository; this.routeNetworkQueryService = routeNetworkQueryService; this.conduitNetworkQueryService = conduitNetworkQueryService; this.conduitClosureRepository = conduitClosureRepository; }
public RouteSegmentGraphFunctions(IRouteNetworkState routeNetworkQueryService, IConduitNetworkQueryService conduitNetworkEqueryService, IConduitClosureRepository conduitClosureRepository, IDataLoaderContextAccessor dataLoader) { this.routeNetworkQueryService = routeNetworkQueryService; this.conduitNetworkEqueryService = conduitNetworkEqueryService; this.conduitClosureRepository = conduitClosureRepository; Description = "Route segment graph functions"; Field <ListGraphType <RouteNodeType> >( "neighborNodes", resolve: context => { List <RouteNodeInfo> result = new List <RouteNodeInfo>(); var routeSegment = context.Source as RouteSegmentInfo; foreach (var neighbor in routeSegment.NeighborElements) { result.Add((RouteNodeInfo)neighbor); } return(result); }); Field <ListGraphType <RouteSegmentType> >( "neighborSegments", resolve: context => { List <RouteSegmentInfo> result = new List <RouteSegmentInfo>(); var routeSegment = context.Source as RouteSegmentInfo; foreach (var neighbor in routeSegment.NeighborElements) { var neighborNeighbors = neighbor.NeighborElements; foreach (var neighborNeighbor in neighborNeighbors) { if (neighborNeighbor != routeSegment) { result.Add((RouteSegmentInfo)neighborNeighbor); } } } return(result); }); }
public SingleConduitCommandHandler(IMediator commandBus, IConduitClosureRepository conduitClosureRepository, IRouteNetworkState routeNetwork, IConduitNetworkQueryService conduitNetwork) { Description = "API for sending commands to the single conduit aggregate root"; Field <ConduitInfoType>( "connectSingleConduitToJunction", description: "Connect the single conduit to a junction (single conduit connector). The junction/connector will be created automatically.", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <IdGraphType> > { Name = "pointOfInterestId" }, new QueryArgument <NonNullGraphType <IdGraphType> > { Name = "singleConduitId" }, new QueryArgument <NonNullGraphType <ConduitEndKindEnumType> > { Name = "conduitEndKind" }, new QueryArgument <NonNullGraphType <IdGraphType> > { Name = "junctionConnectorId" } ), resolve: context => { var connectToJunction = new ConnectSingleConduitToJunction() { SingleConduitId = context.GetArgument <Guid>("singleConduitId"), ConnectedEndKind = context.GetArgument <ConduitEndKindEnum>("conduitEndKind"), PointOfInterestId = context.GetArgument <Guid>("pointOfInterestId"), ConnectedJunctionId = context.GetArgument <Guid>("junctionConnectorId") }; try { commandBus.Send(connectToJunction).Wait(); } catch (Exception ex) { context.Errors.Add(new ExecutionError(ex.Message, ex)); return(null); } return(conduitNetwork.GetSingleConduitInfo(connectToJunction.SingleConduitId)); } ); }
public ConduitClosureAttachmentProjection(IRouteNetworkState routeNetworkQueryService, IConduitNetworkQueryService conduitNetworkQueryService, IConduitClosureRepository conduitClosureRepository) { this.routeNetworkQueryService = routeNetworkQueryService; this.conduitNetworkQueryService = conduitNetworkQueryService; this.conduitClosureRepository = conduitClosureRepository; // Conduit passing by attached to closure ProjectEvent <ConduitClosurePassingByConduitAttached>( (session, multiConduitEndAttached) => { return(multiConduitEndAttached.ConduitClosureId); }, OnConduitClosurePassingByConduitAttached); // Conduit end attached to closure ProjectEvent <ConduitClosureConduitEndAttached>( (session, e) => { return(e.ConduitClosureId); }, OnConduitClosureConduitEndAttached); // Inner conduit added to multi conduit ProjectEvent <MultiConduitInnerConduitAdded>((session, e) => { // Try find conduit closure affected by inner conduit addition if (conduitClosureRepository.CheckIfConduitClosureIsRelatedToLine(e.MultiConduitId)) { var conduitClosure = conduitClosureRepository.GetConduitClosureInfoByRelatedLineId(e.MultiConduitId); if (conduitClosure.Sides.Exists(s => s.Ports.Exists(p => p.MultiConduitId == e.MultiConduitId))) { return(conduitClosure.Id); } } return(Guid.Empty); }, OnMultiConduitInnerConduitAdded); }
public ConduitClosureLifecyleEventProjection(IRouteNetworkState routeNetworkQueryService, IConduitNetworkQueryService conduitNetworkQueryService, IConduitClosureRepository conduitClosureRepository) { this.routeNetworkQueryService = routeNetworkQueryService; this.conduitNetworkQueryService = conduitNetworkQueryService; this.conduitClosureRepository = conduitClosureRepository; // Conduits closure placed ProjectEvent <ConduitClosurePlaced>( (session, e) => { return(e.ConduitClosureId); }, OnConduitClosurePlaced); // Conduit closure removed DeleteEvent <ConduitClosureRemoved>( (session, e) => { return(e.ConduitClosureId); }, OnConduitClosureRemoved); }
public DemoNetwork(IHostingEnvironment env, IDocumentStore documentStore, IMediator commandBus, IConduitClosureRepository conduitClosureRepository, IRouteNetworkState routeNetwork, IConduitNetworkQueryService conduitNetwork, IFiberNetworkQueryService fiberNetworkQueryService) { Description = "API for invoking the demo/test data builder"; Field <StringGraphType>( "rebuild", description: "Deletes the database and rebuild the demo data from the GeoJson files created using QGIS", resolve: context => { try { // First delete everything in the database documentStore.Advanced.Clean.CompletelyRemoveAll(); // Clean everything in projected in-memory read models routeNetwork.Clean(); conduitNetwork.Clean(); conduitClosureRepository.Clean(); fiberNetworkQueryService.Clean(); var iisExpressFolder = AppDomain.CurrentDomain.BaseDirectory; var pathToData = env.ContentRootPath; if (iisExpressFolder.Contains("Debug\\netcoreapp")) { pathToData = iisExpressFolder; } pathToData += Path.DirectorySeparatorChar.ToString() + "Data" + Path.DirectorySeparatorChar.ToString(); // Rebuild demo data RouteNetworkBuilder.Run(pathToData, commandBus); ConduitBuilder.Run(conduitNetwork, commandBus); EquipmentBuilder.Run(routeNetwork, conduitNetwork, commandBus); // Reload everything again routeNetwork.Clean(); conduitNetwork.Clean(); conduitClosureRepository.Clean(); fiberNetworkQueryService.Clean(); return("Read models cleaned and test data was rebuilt."); } catch (Exception ex) { context.Errors.Add(new ExecutionError(ex.Message, ex)); return("Failed"); } } ); }
public ConduitClosureCommandHandler(IMediator commandBus, IConduitClosureRepository conduitClosureRepository, IRouteNetworkState routeNetwork, IConduitNetworkQueryService conduitNetwork) { Description = "API for sending commands to the conduit closure aggregate root"; Field <ConduitClosureType>( "placeConduitClosure", description: "Place a new conduit clousure in a point of interest (route node)", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <IdGraphType> > { Name = "pointOfInterestId" }, new QueryArgument <IdGraphType> { Name = "conduitClosureId" } ), resolve: context => { var conduitClosureId = context.GetArgument <Guid>("conduitClosureId"); var createConduitClosureCmd = new PlaceConduitClosureCommand() { ConduitClosureId = Guid.NewGuid(), PointOfInterestId = context.GetArgument <Guid>("pointOfInterestId") }; if (conduitClosureId != Guid.Empty) { createConduitClosureCmd.ConduitClosureId = conduitClosureId; } try { commandBus.Send(createConduitClosureCmd).Wait(); } catch (Exception ex) { context.Errors.Add(new ExecutionError(ex.Message, ex)); return(null); } return(conduitClosureRepository.GetConduitClosureInfo(createConduitClosureCmd.ConduitClosureId)); } ); Field <ConduitClosureType>( "removeConduitClosure", description: "Remove a new conduit clousure from its point of interest (route node)", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <IdGraphType> > { Name = "conduitClosureId" } ), resolve: context => { var removeConduitClosureCmd = new RemoveConduitClosureCommand() { ConduitClosureId = context.GetArgument <Guid>("conduitClosureId") }; try { commandBus.Send(removeConduitClosureCmd).Wait(); } catch (Exception ex) { context.Errors.Add(new ExecutionError(ex.Message, ex)); return(null); } return(null); } ); Field <ConduitClosureType>( "attachPassByConduitToClosure", description: "Attach a conduit that is passing by to the conduit closure", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <IdGraphType> > { Name = "conduitClosureId", Description = "Id of the conduit closure where the passing conduit should be attached to" }, new QueryArgument <NonNullGraphType <IdGraphType> > { Name = "conduitId", Description = "Id of the conduit to be attached to the conduit closure" }, new QueryArgument <NonNullGraphType <ConduitClosureSideEnumType> > { Name = "incommingSide", Description = "The side where the conduit should enter the closure. This argument is mandatory." }, new QueryArgument <NonNullGraphType <ConduitClosureSideEnumType> > { Name = "outgoingSide", Description = "The side where the conduit should leav the closure. This argument is mandatory." }, new QueryArgument <IntGraphType> { Name = "incommingPortPosition", Description = "The position where the port should be placed. If not specified, the system will position the new port after eventually existing ports. If specified, and the port number references an existing occupied port, the system will move the existing and following ports one position, and place the new port on the specified position." }, new QueryArgument <IntGraphType> { Name = "outgoingPortPosition", Description = "The position where the port should be placed. If not specified, the system will position the new port after eventually existing ports. If specified, and the port number references an existing occupied port, the system will move the existing and following ports one position, and place the new port on the specified position." }, new QueryArgument <IntGraphType> { Name = "incommingTerminalPosition", Description = "The position where the new terminal should be placed. Only used when attaching single conduits to closures. If specified the single conduit will be attached to a new terminal with the specified position on an existing port. If this argument is specified, you must also specify the port argument." }, new QueryArgument <IntGraphType> { Name = "outgoingTerminalPosition", Description = "The position where the new terminal should be placed. Only used when attaching single conduits to closures. If specified the single conduit will be attached to a new terminal with the specified position on an existing port. If this argument is specified, you must also specify the port argument." } ), resolve: context => { var routeConduitThroughClosureCmd = new AttachPassByConduitToClosureCommand() { ConduitClosureId = context.GetArgument <Guid>("conduitClosureId"), ConduitId = context.GetArgument <Guid>("conduitId"), IncommingSide = context.GetArgument <ConduitClosureInfoSide>("incommingSide"), OutgoingSide = context.GetArgument <ConduitClosureInfoSide>("outgoingSide"), IncommingPortPosition = context.GetArgument <int>("incommingPortPosition"), OutgoingPortPosition = context.GetArgument <int>("outgoingPortPosition"), IncommingTerminalPosition = context.GetArgument <int>("incommingPortPosition"), OutgoingTerminalPosition = context.GetArgument <int>("outgoingPortPosition"), }; try { commandBus.Send(routeConduitThroughClosureCmd).Wait(); } catch (Exception ex) { context.Errors.Add(new ExecutionError(ex.Message, ex)); return(null); } return(conduitClosureRepository.GetConduitClosureInfo(routeConduitThroughClosureCmd.ConduitClosureId)); } ); Field <ConduitClosureType>( "attachConduitEndToClosure", description: "Attach a conduit to the conduit closure, that is ending in the point of interest (node) where the conduit closure is also located.", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <IdGraphType> > { Name = "conduitClosureId", Description = "Id of the ending conduit that should be attached to the conduit closure." }, new QueryArgument <NonNullGraphType <IdGraphType> > { Name = "conduitId", Description = "Id of the conduit to be attached to the conduit closure" }, new QueryArgument <NonNullGraphType <ConduitClosureSideEnumType> > { Name = "side", Description = "The side where the conduit should enter the closure. This argument is mandatory." }, new QueryArgument <IntGraphType> { Name = "portPosition", Description = "The position where the port should be placed. If not specified, the system will position the new port after eventually existing ports. If specified, and the port number references an existing occupied port, the system will move the existing and following ports one position, and place the new port on the specified position." }, new QueryArgument <IntGraphType> { Name = "terminalPosition", Description = "The position where the new terminal should be placed. Only used when attaching single conduits to closures. If specified the single conduit will be attached to a new terminal with the specified position on an existing port. If this argument is specified, you must also specify the port argument." } ), resolve: context => { var attachConduitEndCmd = new AttachConduitEndToClosureCommand() { ConduitClosureId = context.GetArgument <Guid>("conduitClosureId"), ConduitId = context.GetArgument <Guid>("conduitId"), Side = context.GetArgument <ConduitClosureInfoSide>("side"), PortPosition = context.GetArgument <int>("portPosition"), TerminalPosition = context.GetArgument <int>("terminalPosition"), }; try { commandBus.Send(attachConduitEndCmd).Wait(); } catch (Exception ex) { context.Errors.Add(new ExecutionError(ex.Message, ex)); return(null); } return(conduitClosureRepository.GetConduitClosureInfo(attachConduitEndCmd.ConduitClosureId)); } ); }
public RouteSegmentType(IConduitNetworkQueryService conduitNetworkEqueryService, IConduitClosureRepository conduitClosureRepository, IDataLoaderContextAccessor dataLoader) { this.routeNetworkQueryService = routeNetworkQueryService; this.conduitNetworkEqueryService = conduitNetworkEqueryService; this.conduitClosureRepository = conduitClosureRepository; Description = "A route segment in a route network."; Field(x => x.Id, type: typeof(IdGraphType)).Description("Guid property"); Field <RouteSegmentKindEnumType>("SegmentKind", "Kind of segment"); Field <GeometryType>( "geometry", resolve: context => { return(new Geometry(context.Source.Geometry.GeoJsonType, context.Source.Geometry.GeoJsonCoordinates)); }); Field <FloatGraphType>("length", resolve: x => x.Source.Length); Field <ListGraphType <ConduitRelationType> >( "relatedConduits", arguments: new QueryArguments( new QueryArgument <BooleanGraphType> { Name = "includeMultiConduits" }, new QueryArgument <BooleanGraphType> { Name = "includeSingleConduits" }, new QueryArgument <BooleanGraphType> { Name = "includeInnerConduits" }, new QueryArgument <StringGraphType> { Name = "conduitSegmentId" } ), resolve: context => { var includeMultiConduits = context.GetArgument <Boolean>("includeMultiConduits", true); var includeSingleConduits = context.GetArgument <Boolean>("includeSingleConduits", true); var includeInnerConduits = context.GetArgument <Boolean>("includeInnerConduits", true); var conduitSegmentIdParam = context.GetArgument <string>("conduitSegmentId"); var conduitSegmentId = Guid.Empty; if (conduitSegmentIdParam != null) { if (!Guid.TryParse(conduitSegmentIdParam, out conduitSegmentId)) { context.Errors.Add(new ExecutionError("Wrong value for guid")); return(null); } } List <ConduitRelation> result = new List <ConduitRelation>(); var conduitSegmentRels = conduitNetworkEqueryService.GetConduitSegmentsRelatedToRouteSegment(context.Source.Id, conduitSegmentIdParam); foreach (var conduitSegmentRel in conduitSegmentRels) { ConduitRelation rel = new ConduitRelation() { RelationType = conduitSegmentRel.Type, Conduit = conduitSegmentRel.Segment.Conduit, ConduitSegment = conduitSegmentRel.Segment }; if (includeMultiConduits && conduitSegmentRel.Segment.Conduit.Kind == ConduitKindEnum.MultiConduit) { result.Add(rel); } if (includeInnerConduits && conduitSegmentRel.Segment.Conduit.Kind == ConduitKindEnum.InnerConduit) { result.Add(rel); } if (includeSingleConduits && conduitSegmentRel.Segment.Conduit.Kind == ConduitKindEnum.SingleConduit) { result.Add(rel); } } return(result); } ); Field <RouteSegmentGraphFunctions>("graph", resolve: context => context.Source); }
public ConduitClosureConduitCutAndConnectionProjection(IRouteNetworkState routeNetworkQueryService, IConduitNetworkQueryService conduitNetworkQueryService, IConduitClosureRepository conduitClosureRepository) { this.routeNetworkQueryService = routeNetworkQueryService; this.conduitNetworkQueryService = conduitNetworkQueryService; this.conduitClosureRepository = conduitClosureRepository; // Outer conduit cut ProjectEvent <MultiConduitOuterConduitCut>((session, e) => { // Try find conduit closure affected by cut if (conduitClosureRepository.CheckIfRouteNodeContainsConduitClosure(e.PointOfInterestId)) { var conduitClosure = conduitClosureRepository.GetConduitClosureInfoByRouteNodeId(e.PointOfInterestId); if (conduitClosure.Sides.Exists(s => s.Ports.Exists(p => p.MultiConduitId == e.MultiConduitId))) { return(conduitClosure.Id); } } return(Guid.Empty); }, OnMultiConduitOuterConduitCut); // Inner conduit cut ProjectEvent <MultiConduitInnerConduitCut>((session, e) => { // Try find conduit closure affected by cut if (conduitClosureRepository.CheckIfRouteNodeContainsConduitClosure(e.PointOfInterestId)) { var conduitClosure = conduitClosureRepository.GetConduitClosureInfoByRouteNodeId(e.PointOfInterestId); if (conduitClosure.Sides.Exists(s => s.Ports.Exists(p => p.MultiConduitId == e.MultiConduitId))) { return(conduitClosure.Id); } } return(Guid.Empty); }, OnMultiConduitInnerConduitCut); // Single conduit connected ProjectEvent <SingleConduitConnected>((session, e) => { // Try find conduit closure affected by connection if (conduitClosureRepository.CheckIfRouteNodeContainsConduitClosure(e.PointOfInterestId)) { var conduitClosure = conduitClosureRepository.GetConduitClosureInfoByRouteNodeId(e.PointOfInterestId); if (conduitClosure.Sides.Exists(s => s.Ports.Exists(p => p.Terminals.Exists(t => t.LineId == e.SingleConduitId)))) { return(conduitClosure.Id); } } return(Guid.Empty); }, OnSingleConduitConnected); // Inner conduit connected ProjectEvent <MultiConduitInnerConduitConnected>((session, e) => { // Try find conduit closure affected by connection if (conduitClosureRepository.CheckIfRouteNodeContainsConduitClosure(e.PointOfInterestId)) { var conduitClosure = conduitClosureRepository.GetConduitClosureInfoByRouteNodeId(e.PointOfInterestId); if (conduitClosure.Sides.Exists(s => s.Ports.Exists(p => p.MultiConduitId == e.MultiConduitId))) { return(conduitClosure.Id); } } return(Guid.Empty); }, OnInnerConduitConnected); }
public Diagram Build(Guid nodeId, IRouteNetworkState routeNetworkQueryService, IConduitNetworkQueryService conduitNetworkEqueryService, IFiberNetworkQueryService fiberNetworkService, IConduitClosureRepository conduitClosureRepository) { _routeNetworkQueryService = routeNetworkQueryService; _conduitNetworkQueryService = conduitNetworkEqueryService; _traversalHelper = new TraversalHelper(_routeNetworkQueryService); DiagramBuilder builder = new DiagramBuilder(); double minWidth = 300; double offsetY = 0; ConduitClosureInfo conduitClosureInfo = null; if (conduitClosureRepository.CheckIfRouteNodeContainsConduitClosure(nodeId)) { conduitClosureInfo = conduitClosureRepository.GetConduitClosureInfoByRouteNodeId(nodeId); } // Add cables passing through var cableSegmentRels = fiberNetworkService.GetLineSegmentsRelatedToPointOfInterest(nodeId); offsetY += AddCablePassThroughBlock(builder, cableSegmentRels, offsetY, 300); // Add multi conduit passing through var conduitSegmentRels = conduitNetworkEqueryService.GetConduitSegmentsRelatedToPointOfInterest(nodeId); foreach (var conduitSegmentRel in conduitSegmentRels) { // pass by multi conduit if (conduitSegmentRel.RelationType == SegmentRelationTypeEnum.PassThrough && conduitSegmentRel.Segment.Line.LineKind == LineKindEnum.MultiConduit) { // check if outside conduit closure if (conduitClosureInfo != null && conduitClosureInfo.Sides.Exists(s => s.Ports.Exists(p => p.MultiConduitId == conduitSegmentRel.Segment.Line.Id))) { } else { offsetY += AddMultiConduitPassThroughBlock(builder, (ConduitSegmentInfo)conduitSegmentRel.Segment, minWidth, offsetY); } } } // Add conduit closure offsetY += 20; if (conduitClosureInfo != null) { offsetY += AddConduitClosureBlock(builder, conduitClosureInfo, minWidth, offsetY); } Diagram diagram = builder.CreateDiagram(); return(diagram); LineBlock junctionBlock = new LineBlock(30, 0); junctionBlock.MinWidth = 300; // Add first vest port with 5 terminal AddMultiConduitPort(junctionBlock, BlockSideEnum.Vest, 10, "Orange"); // Add second vest port with 7 terminal AddMultiConduitPort(junctionBlock, BlockSideEnum.Vest, 7, "Orange"); // Add fist east port with 10 terminal AddMultiConduitPort(junctionBlock, BlockSideEnum.East, 10, "Orange"); // Add second east port with 7 terminal AddMultiConduitPort(junctionBlock, BlockSideEnum.East, 7, "Orange"); // Add north big conduit port 1 with 3 terminal AddBigConduitPort(junctionBlock, BlockSideEnum.North, 3, "Red"); // Add north big conduit port 2 with 5 terminal AddBigConduitPort(junctionBlock, BlockSideEnum.North, 5, "Red"); junctionBlock.AddTerminalConnection(BlockSideEnum.Vest, 1, 1, BlockSideEnum.East, 1, 1, null, "InnerConduitBlue", LineShapeTypeEnum.Polygon); junctionBlock.AddTerminalConnection(BlockSideEnum.Vest, 1, 2, BlockSideEnum.North, 1, 1, null, "InnerConduitBlue", LineShapeTypeEnum.Polygon); /* * * // Feeder calbe from central office * junctionBlock.AddConnection(BlockSideEnum.Vest, 2, 5, BlockSideEnum.North, 1, 1, "192", "CableInsideWell"); * * // Transit feeder cable to other flex points * junctionBlock.AddConnection(BlockSideEnum.Vest, 1, 4, BlockSideEnum.North, 1, 2, "96", "CableInsideWell"); * junctionBlock.AddConnection(BlockSideEnum.East, 1, 10, BlockSideEnum.North, 1, 3, "96", "CableInsideWell"); * * // Sp connections * junctionBlock.AddConnection(BlockSideEnum.East, 1, 1, BlockSideEnum.North, 2, 2, "24", "CableInsideWell"); * junctionBlock.AddConnection(BlockSideEnum.East, 1, 2, BlockSideEnum.North, 2, 3, "48", "CableInsideWell"); * junctionBlock.AddConnection(BlockSideEnum.East, 1, 3, BlockSideEnum.North, 2, 4, "48", "CableInsideWell"); * junctionBlock.AddConnection(BlockSideEnum.East, 1, 4, BlockSideEnum.North, 2, 5, "48", "CableInsideWell"); * junctionBlock.AddConnection(BlockSideEnum.Vest, 2, 2, BlockSideEnum.North, 2, 1, "48", "CableInsideWell"); * */ builder.ContentObjects.Add(junctionBlock); junctionBlock.Measure(new Layout.Size()); ////////////////////////////////////////////////////////// /// well north label block LineBlock wellNorthLabelBlock = new LineBlock(30, junctionBlock.DesiredSize.Height, LineBlockTypeEnum.Simple); wellNorthLabelBlock.MinHeight = 30; // Add north port with 3 terminal AddBigConduitPort(wellNorthLabelBlock, BlockSideEnum.North, 3); // Add north port with 5 terminal AddBigConduitPort(wellNorthLabelBlock, BlockSideEnum.North, 5); // Add south port with 3 terminal AddBigConduitPort(wellNorthLabelBlock, BlockSideEnum.South, 3); // Add south port with 5 terminal AddBigConduitPort(wellNorthLabelBlock, BlockSideEnum.South, 5); wellNorthLabelBlock.AddTerminalConnection(BlockSideEnum.North, 1, 1, BlockSideEnum.South, 1, 1, "GSS 1 (1-16)", "CableOutsideWell"); wellNorthLabelBlock.AddTerminalConnection(BlockSideEnum.North, 1, 2, BlockSideEnum.South, 1, 2, "GSS 1 (1-8)", "CableOutsideWell"); wellNorthLabelBlock.AddTerminalConnection(BlockSideEnum.North, 1, 3, BlockSideEnum.South, 1, 3, "GSS 1 (9-16)", "CableOutsideWell"); wellNorthLabelBlock.AddTerminalConnection(BlockSideEnum.North, 2, 1, BlockSideEnum.South, 2, 1, "GPS 1", "CableOutsideWell"); wellNorthLabelBlock.AddTerminalConnection(BlockSideEnum.North, 2, 2, BlockSideEnum.South, 2, 2, "GPS 1", "CableOutsideWell"); wellNorthLabelBlock.AddTerminalConnection(BlockSideEnum.North, 2, 3, BlockSideEnum.South, 2, 3, "GPS 2", "CableOutsideWell"); wellNorthLabelBlock.AddTerminalConnection(BlockSideEnum.North, 2, 4, BlockSideEnum.South, 2, 4, "GPS 2", "CableOutsideWell"); wellNorthLabelBlock.AddTerminalConnection(BlockSideEnum.North, 2, 5, BlockSideEnum.South, 2, 5, "GPS 2 & 3", "CableOutsideWell"); builder.ContentObjects.Add(wellNorthLabelBlock); wellNorthLabelBlock.Measure(new Layout.Size()); ////////////////////////////////////////////////////////// /// well vest label block LineBlock wellVestLabelBlock = new LineBlock(0, 0, LineBlockTypeEnum.Simple); wellVestLabelBlock.MinWidth = 30; // Add vest port with 5 terminal AddBigConduitPort(wellVestLabelBlock, BlockSideEnum.Vest, 5); // Add vest port with 7 terminal AddBigConduitPort(wellVestLabelBlock, BlockSideEnum.Vest, 7); // Add east port with 5 terminal AddBigConduitPort(wellVestLabelBlock, BlockSideEnum.East, 5); // Add east port with 7 terminal AddBigConduitPort(wellVestLabelBlock, BlockSideEnum.East, 7); wellVestLabelBlock.AddTerminalConnection(BlockSideEnum.Vest, 1, 4, BlockSideEnum.East, 1, 4, "PF-4200", "CableOutsideWell"); wellVestLabelBlock.AddTerminalConnection(BlockSideEnum.Vest, 2, 2, BlockSideEnum.East, 2, 2, "SP-5420", "CableOutsideWell"); wellVestLabelBlock.AddTerminalConnection(BlockSideEnum.Vest, 2, 5, BlockSideEnum.East, 2, 5, "CO-1010", "CableOutsideWell"); wellVestLabelBlock.Measure(new Layout.Size()); builder.ContentObjects.Add(wellVestLabelBlock); ////////////////////////////////////////////////////////// /// east label block LineBlock wellEastLabelBlock = new LineBlock(junctionBlock.DesiredSize.Width + 30, 0, LineBlockTypeEnum.Simple); wellEastLabelBlock.MinWidth = 30; wellEastLabelBlock.MinHeight = junctionBlock.DesiredSize.Height; // Add vest port with 10 terminal AddBigConduitPort(wellEastLabelBlock, BlockSideEnum.Vest, 10); // Add east port with 10 terminal AddBigConduitPort(wellEastLabelBlock, BlockSideEnum.East, 10); wellEastLabelBlock.AddTerminalConnection(BlockSideEnum.Vest, 1, 1, BlockSideEnum.East, 1, 1, "SP-5010", "CableOutsideWell"); wellEastLabelBlock.AddTerminalConnection(BlockSideEnum.Vest, 1, 2, BlockSideEnum.East, 1, 2, "SP-5011", "CableOutsideWell"); wellEastLabelBlock.AddTerminalConnection(BlockSideEnum.Vest, 1, 3, BlockSideEnum.East, 1, 3, "SP-5013", "CableOutsideWell"); wellEastLabelBlock.AddTerminalConnection(BlockSideEnum.Vest, 1, 4, BlockSideEnum.East, 1, 4, "SP-6002", "CableOutsideWell"); wellEastLabelBlock.AddTerminalConnection(BlockSideEnum.Vest, 1, 10, BlockSideEnum.East, 1, 10, "FP-4203", "CableOutsideWell"); wellEastLabelBlock.Measure(new Layout.Size()); builder.ContentObjects.Add(wellEastLabelBlock); ////////////////////////////////////////////////////////// /// well north corner 1 LineBlock wellNorthCorner1 = new LineBlock(30, junctionBlock.DesiredSize.Height + wellNorthLabelBlock.DesiredSize.Height, LineBlockTypeEnum.Simple); wellNorthCorner1.MinHeight = 20; // Add south port with 3 terminal AddBigConduitPort(wellNorthCorner1, BlockSideEnum.South, 3); // Add east port with 3 terminal AddBigConduitPort(wellNorthCorner1, BlockSideEnum.East, 3, null, 1, 1); wellNorthCorner1.AddTerminalConnection(BlockSideEnum.South, 1, 1, BlockSideEnum.East, 1, 1, "", "CableOutsideWell"); wellNorthCorner1.AddTerminalConnection(BlockSideEnum.South, 1, 2, BlockSideEnum.East, 1, 2, "", "CableOutsideWell"); wellNorthCorner1.AddTerminalConnection(BlockSideEnum.South, 1, 3, BlockSideEnum.East, 1, 3, "", "CableOutsideWell"); // Set margin on east side to 0 wellNorthCorner1.SetSideMargin(BlockSideEnum.East, 0); //builder.ContentObjects.Add(wellNorthCorner1); Diagram sdiagram = builder.CreateDiagram(); return(diagram); }
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); }
public ConduitClosure(Guid conduitClosureId, Guid pointOfInterestId, IRouteNetworkState routeNetworkQueryService, IConduitNetworkQueryService conduitNetworkQueryService, IConduitClosureRepository conduitClosureRepository) : this() { // Id check if (conduitClosureId == null || conduitClosureId == Guid.Empty) { throw new ArgumentException("ConduitClosureId cannot be null or empty"); } // Point of interest id check if (pointOfInterestId == null || pointOfInterestId == Guid.Empty) { throw new ArgumentException("PointOfInterestId cannot be null or empty"); } // Check that point of interest (node) exists if (!routeNetworkQueryService.CheckIfRouteNodeIdExists(pointOfInterestId)) { throw new ArgumentException("PointOfInterestId: " + pointOfInterestId + " not found in the route network."); } // Check that conduit closure do not already exists if (conduitClosureRepository.CheckIfConduitClosureAlreadyExists(conduitClosureId)) { throw new ArgumentException("A conduit closure with id: " + conduitClosureId + " already exists."); } // Check that a conduit closure is not already added to point of interest. This is not allowed, each conduit closure must be placed in its own node. if (conduitClosureRepository.CheckIfRouteNodeContainsConduitClosure(pointOfInterestId)) { throw new ArgumentException("A conduit closure: " + conduitClosureRepository.GetConduitClosureInfoByRouteNodeId(pointOfInterestId).Id + " is already placed in the specified point of interest (route node): " + pointOfInterestId + " Only one conduit closure is allowed per point of interest (route node)."); } var conduitClosurePlaced = new ConduitClosurePlaced() { ConduitClosureId = conduitClosureId, PointOfInterestId = pointOfInterestId }; RaiseEvent(conduitClosurePlaced); }
public MultiConduitCommandHandler(IMediator commandBus, IConduitClosureRepository conduitClosureRepository, IRouteNetworkState routeNetwork, IConduitNetworkQueryService conduitNetwork) { Description = "API for sending commands to the multi conduit aggregate root"; Field <ConduitInfoType>( "cutOuterConduitCommand", description: "Cut the outer conduit of a multi conduit", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <IdGraphType> > { Name = "pointOfInterestId" }, new QueryArgument <NonNullGraphType <IdGraphType> > { Name = "multiConduitId" } ), resolve: context => { var cutOuterConduitCmd = new CutOuterConduitCommand() { MultiConduitId = context.GetArgument <Guid>("multiConduitId"), PointOfInterestId = context.GetArgument <Guid>("pointOfInterestId") }; try { commandBus.Send(cutOuterConduitCmd).Wait(); } catch (Exception ex) { context.Errors.Add(new ExecutionError(ex.Message, ex)); return(null); } return(conduitNetwork.GetMultiConduitInfo(cutOuterConduitCmd.MultiConduitId)); } ); Field <ConduitInfoType>( "cutInnerConduitCommand", description: "Cut the outer conduit of a multi conduit", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <IdGraphType> > { Name = "pointOfInterestId" }, new QueryArgument <IdGraphType> { Name = "innerConduitId" }, new QueryArgument <IdGraphType> { Name = "multiConduitId" }, new QueryArgument <IntGraphType> { Name = "innerConduitNumber" } ), resolve: context => { var cutInnerConduitCmd = new CutInnerConduitCommand() { MultiConduitId = context.GetArgument <Guid>("multiConduitId"), InnerConduitId = context.GetArgument <Guid>("innerConduitId"), PointOfInterestId = context.GetArgument <Guid>("pointOfInterestId"), InnerConduitSequenceNumber = context.GetArgument <int>("innerConduitNumber") }; try { commandBus.Send(cutInnerConduitCmd).Wait(); } catch (Exception ex) { context.Errors.Add(new ExecutionError(ex.Message, ex)); return(null); } return(conduitNetwork.GetMultiConduitInfo(cutInnerConduitCmd.MultiConduitId)); } ); Field <ConduitInfoType>( "connectInnerConduitToJunction", description: "Connect an inner conduit of the multi conduit to a junction (single conduit connector). The junction/connector will be created automatically.", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <IdGraphType> > { Name = "pointOfInterestId" }, new QueryArgument <NonNullGraphType <IdGraphType> > { Name = "multiConduitId" }, new QueryArgument <NonNullGraphType <ConduitEndKindEnumType> > { Name = "conduitEndKind" }, new QueryArgument <NonNullGraphType <IntGraphType> > { Name = "innerConduitNumber" }, new QueryArgument <NonNullGraphType <IdGraphType> > { Name = "junctionConnectorId" } ), resolve: context => { var connectToJunction = new ConnectInnerConduitToJunction() { MultiConduitId = context.GetArgument <Guid>("multiConduitId"), ConnectedEndKind = context.GetArgument <ConduitEndKindEnum>("conduitEndKind"), PointOfInterestId = context.GetArgument <Guid>("pointOfInterestId"), InnerConduitSequenceNumber = context.GetArgument <int>("innerConduitNumber"), ConnectedJunctionId = context.GetArgument <Guid>("junctionConnectorId") }; try { commandBus.Send(connectToJunction).Wait(); } catch (Exception ex) { context.Errors.Add(new ExecutionError(ex.Message, ex)); return(null); } return(conduitNetwork.GetMultiConduitInfo(connectToJunction.MultiConduitId)); } ); Field <ConduitInfoType>( "connectConduitSegmentToConduitSegment", description: "A convenience function for connecting conduits together. It will automatically create junctions. Also, if the to conduit segment is a multi conduit, the function will automatically create an inner conduit in the to multi conduit of same type as the from single conduit.", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <IdGraphType> > { Name = "pointOfInterestId" }, new QueryArgument <NonNullGraphType <IdGraphType> > { Name = "fromConduitSegmentId" }, new QueryArgument <NonNullGraphType <IdGraphType> > { Name = "toConduitSegmentId" } ), resolve: context => { var connectConduitSegmentCmd = new ConnectConduitSegmentCommand() { PointOfInterestId = context.GetArgument <Guid>("pointOfInterestId"), FromConduitSegmentId = context.GetArgument <Guid>("fromConduitSegmentId"), ToConduitSegmentId = context.GetArgument <Guid>("toConduitSegmentId") }; try { commandBus.Send(connectConduitSegmentCmd).Wait(); } catch (Exception ex) { context.Errors.Add(new ExecutionError(ex.Message, ex)); return(null); } return(null); } ); }
public ConduitServiceCommandHandler(IMediator commandBus, IConduitClosureRepository conduitClosureRepository, IConduitNetworkQueryService conduitNetworkQueryService, IRouteNetworkState routeNetwork, IConduitNetworkQueryService conduitNetwork, IConduitSpecificationRepository conduitSpecificationRepository) { Description = "API for sending commands to the conduit service"; Field <ConduitClosureCommandHandler>("conduitClosure", resolve: context => new { }); Field <MultiConduitCommandHandler>("multiConduit", resolve: context => new { }); Field <SingleConduitCommandHandler>("singleConduit", resolve: context => new { }); Field <ConduitInfoType>( "placeConduit", description: "Place a multi or single conduit in the route network", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <IdGraphType> > { Name = "conduitSpecificationId" }, new QueryArgument <NonNullGraphType <ListGraphType <IdGraphType> > > { Name = "walkOfInterest", Description = "Route network walk specified as a list of route element ids (route-node-id, route-segment-id, route-node-id...)" }, new QueryArgument <IdGraphType> { Name = "conduitId", Description = "If not specified, a new guid will automatically be created" }, new QueryArgument <StringGraphType> { Name = "name" }, new QueryArgument <ConduitColorEnumType> { Name = "markingColor" }, new QueryArgument <StringGraphType> { Name = "markingText" } ), resolve: context => { try { var conduitSpec = conduitSpecificationRepository.GetConduitSpecification(context.GetArgument <Guid>("conduitSpecificationId")); // Check that conduit not already exists // First create walk of interest var walkOfInterestCmd = new RegisterWalkOfInterestCommand() { WalkOfInterestId = Guid.NewGuid(), RouteElementIds = context.GetArgument <List <Guid> >("walkOfInterest") }; commandBus.Send(walkOfInterestCmd).Wait(); var conduitId = context.GetArgument <Guid>("conduitId"); // Multi conduit if (conduitSpec.Kind == ConduitKindEnum.MultiConduit) { var placeConduitCommand = new PlaceMultiConduitCommand() { MultiConduitId = Guid.NewGuid(), ConduitSpecificationId = context.GetArgument <Guid>("conduitSpecificationId"), WalkOfInterestId = walkOfInterestCmd.WalkOfInterestId, Name = context.GetArgument <string>("name"), MarkingColor = context.GetArgument <ConduitColorEnum>("markingColor"), MarkingText = context.GetArgument <string>("markingText") }; if (conduitId != Guid.Empty) { placeConduitCommand.MultiConduitId = conduitId; } commandBus.Send(placeConduitCommand).Wait(); return(conduitNetworkQueryService.GetMultiConduitInfo(placeConduitCommand.MultiConduitId)); } // Single conduit else { var placeConduitCommand = new PlaceSingleConduitCommand() { SingleConduitId = Guid.NewGuid(), ConduitSpecificationId = context.GetArgument <Guid>("conduitSpecificationId"), WalkOfInterestId = walkOfInterestCmd.WalkOfInterestId, Name = context.GetArgument <string>("name"), MarkingColor = context.GetArgument <ConduitColorEnum>("markingColor"), MarkingText = context.GetArgument <string>("markingText") }; if (conduitId != Guid.Empty) { placeConduitCommand.SingleConduitId = conduitId; } commandBus.Send(placeConduitCommand).Wait(); return(conduitNetworkQueryService.GetSingleConduitInfo(placeConduitCommand.SingleConduitId)); } } catch (Exception ex) { context.Errors.Add(new ExecutionError(ex.Message, ex)); } return(null); }); Field <StringGraphType>( "placeFiberCableWithinConduit", description: "Place a fiber cable inside a conduit", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <IdGraphType> > { Name = "cableSegmentId", Description = "Id of the cable segment to be placed inside a conduit" }, new QueryArgument <NonNullGraphType <IdGraphType> > { Name = "conduitSegmentId1", Description = "Id of the conduit segment where the cable should be placed" }, new QueryArgument <IdGraphType> { Name = "conduitSegmentId2", Description = "Used when placing cables into a conduit that is cut and not connected in a well. The you must specify both the incomming and outgoing conduit segment in the well, because otherwise the cable has an unknown route." } ), resolve: context => { return(null); }); }
public DiagramServiceQuery(IRouteNetworkState routeNetworkQueryService, IConduitNetworkQueryService conduitNetworkEqueryService, IConduitClosureRepository conduitClosureRepository, IFiberNetworkQueryService fiberNetworkService, IDataLoaderContextAccessor dataLoader) { Description = "GraphQL API for generating fiber equiment diagrams."; Field <DiagramType>( "buildRouteNodeDiagram", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <IdGraphType> > { Name = "routeNodeId" }, new QueryArgument <StringGraphType> { Name = "exportGeojsonFileName" } ), resolve: context => { var routeNodeId = context.GetArgument <Guid>("routeNodeId"); var jsonFilename = context.GetArgument <string>("exportGeojsonFileName"); var diagram = new ConduitClosureBuilder().Build(routeNodeId, routeNetworkQueryService, conduitNetworkEqueryService, fiberNetworkService, conduitClosureRepository); if (jsonFilename != null) { var export = new GeoJsonExporter(diagram); export.Export(jsonFilename); } return(diagram); } ); }
public RouteNodeGraphFunctions(IRouteNetworkState routeNetworkQueryService, IConduitNetworkQueryService conduitNetworkEqueryService, IConduitClosureRepository conduitClosureRepository, IDataLoaderContextAccessor dataLoader) { this.routeNetworkQueryService = routeNetworkQueryService; this.conduitNetworkEqueryService = conduitNetworkEqueryService; this.conduitClosureRepository = conduitClosureRepository; Description = "Route node graph functions"; Field<ListGraphType<IdGraphType>>( "shortestPath", arguments: new QueryArguments(new QueryArgument<NonNullGraphType<IdGraphType>> { Name = "ToNodeId" }), resolve: context => { var startNode = context.Source as RouteNodeInfo; Guid endNodeId = context.GetArgument<Guid>("toNodeId"); List<Guid> result = new List<Guid>(); List<IGraphElement> graphElements = new List<IGraphElement>(); graphElements.AddRange(routeNetworkQueryService.GetAllRouteNodes()); graphElements.AddRange(routeNetworkQueryService.GetAllRouteSegments()); var graph = new Graph(graphElements); var shortestPathResult = graph.ShortestPath(startNode.Id.ToString(), endNodeId.ToString()).Select(s => s.Id); return shortestPathResult; }); Field<ListGraphType<RouteNodeType>>( "neighborNodes", resolve: context => { List<RouteNodeInfo> result = new List<RouteNodeInfo>(); var routeNode = context.Source as RouteNodeInfo; foreach (var neighbor in routeNode.NeighborElements) { var neighborNeighbors = neighbor.NeighborElements; foreach (var neighborNeighbor in neighborNeighbors) { if (neighborNeighbor != routeNode) result.Add((RouteNodeInfo)neighborNeighbor); } } return result; }); Field<ListGraphType<RouteSegmentType>>( "neighborSegments", resolve: context => { List<RouteSegmentInfo> result = new List<RouteSegmentInfo>(); var routeNode = context.Source as RouteNodeInfo; foreach (var neighbor in routeNode.NeighborElements) { result.Add((RouteSegmentInfo)neighbor); } return result; }); }
public RouteNodeType(IRouteNetworkState routeNetworkQueryService, IConduitNetworkQueryService conduitNetworkEqueryService, IFiberNetworkQueryService fiberNetworkQueryService, IConduitClosureRepository conduitClosureRepository, IDataLoaderContextAccessor dataLoader, IHttpContextAccessor httpContextAccessor) { this.routeNetworkQueryService = routeNetworkQueryService; this.conduitNetworkEqueryService = conduitNetworkEqueryService; this.conduitClosureRepository = conduitClosureRepository; Description = "A route node in a route network."; // Interface fields Interface <NodeInterface>(); Field(x => x.Id, type: typeof(IdGraphType)).Description("Guid property"); Field(x => x.Name, type: typeof(IdGraphType)).Description("Name of node managed by the utility"); // Additional fields Field <RouteNodeKindEnumType>("NodeKind", "Kind of node"); Field <RouteNodeFunctionKindEnumType>("NodeFunctionKind", "Function that the node do/provides"); Field <GeometryType>( "geometry", resolve: context => { return(new Geometry(context.Source.Geometry.GeoJsonType, context.Source.Geometry.GeoJsonCoordinates)); }); Field <LocationInfoType>( "locationInfo", resolve: context => { return(context.Source.LocationInfo); }); Field <ListGraphType <ConduitRelationType> >( "relatedConduits", arguments: new QueryArguments( new QueryArgument <BooleanGraphType> { Name = "includeMultiConduits" }, new QueryArgument <BooleanGraphType> { Name = "includeSingleConduits" }, new QueryArgument <BooleanGraphType> { Name = "includeInnerConduits" }, new QueryArgument <StringGraphType> { Name = "conduitSegmentId", Description = "Will be deleted. Use conduit id instead" }, new QueryArgument <StringGraphType> { Name = "conduitId", Description = "Id of conduit of conduit segment" } ), resolve: context => { var includeMultiConduits = context.GetArgument <Boolean>("includeMultiConduits", true); var includeSingleConduits = context.GetArgument <Boolean>("includeSingleConduits", true); var includeInnerConduits = context.GetArgument <Boolean>("includeInnerConduits", true); var conduitSegmentIdParam = context.GetArgument <string>("conduitSegmentId"); var conduitIdParam = context.GetArgument <string>("conduitId"); var conduitSegmentId = Guid.Empty; if (conduitSegmentIdParam != null) { if (!Guid.TryParse(conduitSegmentIdParam, out conduitSegmentId)) { context.Errors.Add(new ExecutionError("Wrong value for guid")); return(null); } } if (conduitIdParam != null) { if (!Guid.TryParse(conduitIdParam, out conduitSegmentId)) { context.Errors.Add(new ExecutionError("Wrong value for guid")); return(null); } } List <ConduitRelation> result = new List <ConduitRelation>(); var conduitSegmentRels = conduitNetworkEqueryService.GetConduitSegmentsRelatedToPointOfInterest(context.Source.Id, conduitSegmentId == Guid.Empty ? null : conduitSegmentId.ToString()); foreach (var conduitSegmentRel in conduitSegmentRels) { ConduitRelation rel = new ConduitRelation() { RelationType = Convert(conduitSegmentRel.RelationType), Conduit = ((ConduitSegmentInfo)conduitSegmentRel.Segment).Conduit, ConduitSegment = (ConduitSegmentInfo)conduitSegmentRel.Segment }; // Check if segment is related to a conduit closure { if (conduitClosureRepository.CheckIfRouteNodeContainsConduitClosure(context.Source.Id)) { var conduitClosureInfo = conduitClosureRepository.GetConduitClosureInfoByRouteNodeId(context.Source.Id); // If conduit closure contains a port or terminal related to the conduit segment, then it's related to the conduit closure if ( conduitClosureInfo.Sides.Exists(s => s.Ports.Exists(p => p.MultiConduitSegmentId == conduitSegmentRel.Segment.Id)) || conduitClosureInfo.Sides.Exists(s => s.Ports.Exists(p => p.Terminals.Exists(t => t.LineSegmentId == conduitSegmentRel.Segment.Id))) ) { rel.CanBeAttachedToConduitClosure = false; } else { rel.CanBeAttachedToConduitClosure = true; } } } // Check if segment is cut at node if (conduitSegmentRel.Segment.Line.Segments.Exists(s => s.FromRouteNodeId == context.Source.Id || s.ToRouteNodeId == context.Source.Id)) { rel.CanBeCutAtNode = false; } else { rel.CanBeCutAtNode = true; } if (includeMultiConduits && conduitSegmentRel.Segment.Line.LineKind == LineKindEnum.MultiConduit) { result.Add(rel); } if (includeInnerConduits && conduitSegmentRel.Segment.Line.LineKind == LineKindEnum.InnerConduit) { result.Add(rel); } if (includeSingleConduits && conduitSegmentRel.Segment.Line.LineKind == LineKindEnum.SingleConduit) { result.Add(rel); } } return(result); } ); Field <ConduitClosureType>( "conduitClosure", resolve: context => { if (conduitClosureRepository.CheckIfRouteNodeContainsConduitClosure(context.Source.Id)) { return(conduitClosureRepository.GetConduitClosureInfoByRouteNodeId(context.Source.Id)); } else { return(null); } }); Field <RouteNodeGraphFunctions>("graph", resolve: context => context.Source); Field <ListGraphType <SegmentInterface> >( "relatedSegments", arguments: new QueryArguments( new QueryArgument <StringGraphType> { Name = "lineId", Description = "Id of specific line og line segment to fetch" } ), resolve: context => { httpContextAccessor.HttpContext.Items.Add("routeNodeId", context.Source.Id); var lineIdParam = context.GetArgument <Guid>("lineId"); List <ISegment> result = new List <ISegment>(); var allSegments = new List <SegmentWithRouteNodeRelationInfo>(); // Add multi conduits and single conduits segments allSegments.AddRange(conduitNetworkEqueryService.GetConduitSegmentsRelatedToPointOfInterest(context.Source.Id).Where(c => c.Segment.Line.LineKind == LineKindEnum.MultiConduit || c.Segment.Line.LineKind == LineKindEnum.SingleConduit)); // Add fiber cable segments allSegments.AddRange(fiberNetworkQueryService.GetLineSegmentsRelatedToPointOfInterest(context.Source.Id).Where(c => c.Segment.Line.LineKind == LineKindEnum.FiberCable)); // Create fast lookup table to be used for parent check HashSet <Guid> segmentExistsLookup = new HashSet <Guid>(); foreach (var segmentWithRel in allSegments) { segmentExistsLookup.Add(segmentWithRel.Segment.Id); } // Iterate through all segments and decided if to return or not depending on if they are roots of the node or not foreach (var segmentWithRel in allSegments) { // Now check if the segment has a parent that is also related to the node. // If so, the segment is contained within another segment, and should not be returned as a root element to the node bool isContained = false; if (segmentWithRel.Segment.Parents != null) { foreach (var parent in segmentWithRel.Segment.Parents) { if (segmentExistsLookup.Contains(parent.Id)) { isContained = true; } } } if (!isContained) { if (lineIdParam != Guid.Empty) { if (segmentWithRel.Segment.Id == lineIdParam || segmentWithRel.Segment.Line.Id == lineIdParam) { result.Add(segmentWithRel.Segment); } } else { result.Add(segmentWithRel.Segment); } } } return(result); }); }