예제 #1
0
        public static void Run(IConduitNetworkQueryService conduitNetworkQueryService, IMediator CommandBus)
        {
            Dictionary <string, ConduitBuildInfo> conduitBuildInfos = new Dictionary <string, ConduitBuildInfo>();


            // First find all main conduits.
            // Format ConduitSpecCode-ConduitNumber-(Marking) - i.e. "G10F-1-BL"
            // Having no underscores (which are used on single conduits that must connected to multi conduits)
            foreach (var segmentBuildCode in RouteNetworkBuilder._segmentBuildCodes)
            {
                var segmentId  = segmentBuildCode.Key;
                var buildCodes = segmentBuildCode.Value;

                foreach (var buildCode in buildCodes)
                {
                    // Single conduits (that is connected to a multi conduit) have "_" in spec code
                    if (buildCode.Contains("_"))
                    {
                        var newConduitBuildInfo = new ConduitBuildInfo();
                        newConduitBuildInfo.BuildCode    = buildCode;
                        newConduitBuildInfo.MultiConduit = false;
                        newConduitBuildInfo.BuildCodeSpecificationCode = "Ø12";

                        // Create build conduit info object, if not exists
                        if (!conduitBuildInfos.ContainsKey(buildCode))
                        {
                            conduitBuildInfos.Add(buildCode, newConduitBuildInfo);
                        }

                        var conduitBuildInfo = conduitBuildInfos[buildCode];

                        // Add segment id to build info object
                        conduitBuildInfo.AddRelatedRouteSegmentIdBuildInfo(segmentId);
                    }
                    else
                    // We're delaing with a multi conduit or single conduit not connected
                    {
                        var newConduitBuildInfo = new ConduitBuildInfo();
                        newConduitBuildInfo.BuildCode = buildCode;
                        string[] buildCodeSplit = buildCode.Split('-');
                        newConduitBuildInfo.BuildCodeSpecificationCode = buildCodeSplit[0];
                        newConduitBuildInfo.BuildCodeConduitId         = Int32.Parse(buildCodeSplit[1]);

                        if (buildCode.StartsWith("S"))
                        {
                            newConduitBuildInfo.MultiConduit = false;
                        }
                        else
                        {
                            newConduitBuildInfo.MultiConduit = true;
                        }

                        if (buildCodeSplit.Length > 2)
                        {
                            newConduitBuildInfo.BuildCodeMarking = buildCodeSplit[2];
                        }

                        // Create build conduit info object, if not exists
                        if (!conduitBuildInfos.ContainsKey(buildCode))
                        {
                            conduitBuildInfos.Add(buildCode, newConduitBuildInfo);
                        }

                        var conduitBuildInfo = conduitBuildInfos[buildCode];

                        // Add segment id to build info object
                        conduitBuildInfo.AddRelatedRouteSegmentIdBuildInfo(segmentId);
                    }
                }
            }



            // Sort and validate all conduit build infos
            foreach (var conduitBuildInfo in conduitBuildInfos)
            {
                conduitBuildInfo.Value.Prepare(RouteNetworkBuilder._routeGraph);

                var registerWalkOfInterestCmd = new RegisterWalkOfInterestCommand();
                registerWalkOfInterestCmd.WalkOfInterestId = conduitBuildInfo.Value.WalkOfInterestId;

                // First create walk of interest
                registerWalkOfInterestCmd.RouteElementIds = RouteNetworkBuilder._routeGraph.GetNodeLinkPathFromLinkPath(conduitBuildInfo.Value.relatedRouteSegmentIds);
                CommandBus.Send(registerWalkOfInterestCmd).Wait();

                // Create multi conduit
                if (conduitBuildInfo.Value.MultiConduit)
                {
                    var placeMultiConduitCommand = new PlaceMultiConduitCommand()
                    {
                        MultiConduitId   = conduitBuildInfo.Value.Id,
                        WalkOfInterestId = conduitBuildInfo.Value.WalkOfInterestId,
                        DemoDataSpec     = conduitBuildInfo.Key
                    };

                    CommandBus.Send(placeMultiConduitCommand).Wait();
                }
                // Create single conduit
                else
                {
                    var placeSingleConduitCommand = new PlaceSingleConduitCommand()
                    {
                        SingleConduitId  = conduitBuildInfo.Value.Id,
                        WalkOfInterestId = conduitBuildInfo.Value.WalkOfInterestId,
                        DemoDataSpec     = conduitBuildInfo.Key
                    };

                    CommandBus.Send(placeSingleConduitCommand).Wait();
                }
            }

            // Do the cuts and connections

            HashSet <string> cutAlreadDone = new HashSet <string>();

            foreach (var segmentBuildCode in RouteNetworkBuilder._segmentBuildCodes)
            {
                var segmentId  = segmentBuildCode.Key;
                var buildCodes = segmentBuildCode.Value;

                foreach (var buildCode in buildCodes)
                {
                    // Build codes containing _, is where conduits should be connected to each other
                    if (buildCode.Contains("_") && !cutAlreadDone.Contains(buildCode))
                    {
                        cutAlreadDone.Add(buildCode);

                        // Extract the different values from build code string
                        string[] buildCodeSplit = buildCode.Split('_');

                        int innerConduitNumberToCut = Int32.Parse(buildCodeSplit[1]);

                        // Find multi conduit to breakout/connect
                        var multiConduitBuildInfo      = conduitBuildInfos[buildCodeSplit[0]];
                        var multiConduitWalkOfInterest = RouteNetworkBuilder._routeGraph.GetNodeLinkPathFromLinkPath(multiConduitBuildInfo.relatedRouteSegmentIds);

                        // Find single conduit that has to be connected to the multi conduit
                        var singleConduitBuildInfo = conduitBuildInfos[buildCode];
                        var singleConduitSegments  = RouteNetworkBuilder._segmentBuildCodes.Where(n => n.Value.Contains(buildCode)).ToList();

                        // Find segment that har start or end in multi conduit
                        Link singleConduitLink = null;

                        foreach (var singleConduitSegmentId in singleConduitSegments)
                        {
                            singleConduitLink = RouteNetworkBuilder._routeGraph.Links[singleConduitSegmentId.Key];

                            if (multiConduitWalkOfInterest.Contains(Guid.Parse(singleConduitLink.StartNode.Id)))
                            {
                                break;
                            }

                            if (multiConduitWalkOfInterest.Contains(Guid.Parse(singleConduitLink.EndNode.Id)))
                            {
                                break;
                            }
                        }


                        // find the point of interest (the node where the single conduit connected witht the multi conduit)
                        Guid pointOfInterest = Guid.Empty;

                        ConduitEndKindEnum customerConduitConnectKind = ConduitEndKindEnum.Outgoing;

                        if (multiConduitWalkOfInterest.Contains(Guid.Parse(singleConduitLink.StartNode.Id)))
                        {
                            pointOfInterest = Guid.Parse(singleConduitLink.StartNode.Id);
                        }
                        else if (multiConduitWalkOfInterest.Contains(Guid.Parse(singleConduitLink.EndNode.Id)))
                        {
                            pointOfInterest            = Guid.Parse(singleConduitLink.EndNode.Id);
                            customerConduitConnectKind = ConduitEndKindEnum.Outgoing;
                        }


                        if (buildCode == "G12F-1-BL_3")
                        {
                        }

                        // Cut the inner conduit in the multi conduit, if not end
                        if (!(multiConduitWalkOfInterest[0] == pointOfInterest || multiConduitWalkOfInterest[multiConduitWalkOfInterest.Count - 1] == pointOfInterest))
                        {
                            // First cut the outer conduit, if not already cut
                            if (!conduitNetworkQueryService.CheckIfConduitIsCut(multiConduitBuildInfo.Id, pointOfInterest))
                            {
                                var cutOuterConduitCommand = new CutOuterConduitCommand()
                                {
                                    MultiConduitId    = multiConduitBuildInfo.Id,
                                    PointOfInterestId = pointOfInterest,
                                };

                                CommandBus.Send(cutOuterConduitCommand).Wait();
                            }

                            // Cut the inner conduit
                            var cutInnerConduitCommand = new CutInnerConduitCommand()
                            {
                                MultiConduitId             = multiConduitBuildInfo.Id,
                                PointOfInterestId          = pointOfInterest,
                                InnerConduitSequenceNumber = innerConduitNumberToCut
                            };

                            CommandBus.Send(cutInnerConduitCommand).Wait();
                        }

                        // Junction
                        Guid newJunctionId = Guid.NewGuid();

                        // Connect inner conduit in the multi conduit
                        var connectInnerConduitCommand = new ConnectInnerConduitToJunction()
                        {
                            MultiConduitId             = multiConduitBuildInfo.Id,
                            PointOfInterestId          = pointOfInterest,
                            InnerConduitSequenceNumber = innerConduitNumberToCut,
                            ConnectedJunctionId        = newJunctionId,
                            ConnectedEndKind           = ConduitNetwork.Events.Model.ConduitEndKindEnum.Incomming
                        };

                        CommandBus.Send(connectInnerConduitCommand).Wait();

                        // Connect customer conduit to the multi conduit
                        var connectCustomerConduitCommand = new ConnectSingleConduitToJunction()
                        {
                            SingleConduitId     = singleConduitBuildInfo.Id,
                            PointOfInterestId   = pointOfInterest,
                            ConnectedJunctionId = newJunctionId,
                            ConnectedEndKind    = customerConduitConnectKind
                        };

                        CommandBus.Send(connectCustomerConduitCommand).Wait();
                    }
                }
            }



            /*
             *  RouteWalkRelationTypeEnum type = RouteWalkRelationTypeEnum.StartNode;
             *
             * // Create conduit walk of interests objects
             * foreach (var networkElementId in nodeLinkIds)
             * {
             *  migrationBuilder.InsertData(
             *      table: "RouteElementWalkOfInterestRelations",
             *      columns: new[] { "RouteElementId", "WalkOfInterestId", "SeqNo", "Type" },
             *      values: new object[] {
             *          networkElementId,
             *          walkOfInterestId,
             *          seqNo,
             *          (int)type
             *      }
             *  );
             *
             *  if (type == RouteWalkRelationTypeEnum.IntermediateSegment && (seqNo == (nodeLinkIds.Count - 1)))
             *      type = RouteWalkRelationTypeEnum.EndNode;
             *  else if (type == RouteWalkRelationTypeEnum.IntermediateSegment)
             *      type = RouteWalkRelationTypeEnum.IntermediateNode;
             *  else if (type == RouteWalkRelationTypeEnum.StartNode || type == RouteWalkRelationTypeEnum.IntermediateNode)
             *      type = RouteWalkRelationTypeEnum.IntermediateSegment;
             *  else if (type == RouteWalkRelationTypeEnum.EndNode)
             *  {
             *      // do nothing we're finish
             *  }
             *  else
             *  {
             *      throw new NotSupportedException("Something went wrong in route walk relation write logic. Code broken!");
             *  }
             *
             *  seqNo++;
             */
        }
        public ConduitClosureBasicTests(ConduitClosureBasicTestsContainerFixture serviceContext)
        {
            this.serviceContext = serviceContext;

            // Create basic route test network, if not already created
            if (_testNetwork != null)
            {
                return;
            }

            _testNetwork = new TestRouteNetworkType1(serviceContext);


            // Now we're going to put two multi conduits from HH-1 to HH-10
            // And two single conduits between CC-1 and SP-1

            var fixture = new Fixture();

            // Walk of interest for placing the two multi conduits
            var registerMultiConduitWalk = fixture.Build <RegisterWalkOfInterestCommand>()
                                           .With(x => x.RouteElementIds, new List <Guid> {
                _testNetwork.GetNodeByName("HH-1").Id,
                _testNetwork.GetSegmentByName("HH-1_HH-2").Id,
                _testNetwork.GetNodeByName("HH-2").Id,
                _testNetwork.GetSegmentByName("HH-2_CC-1").Id,
                _testNetwork.GetNodeByName("CC-1").Id,
                _testNetwork.GetSegmentByName("CC-1_HH-10").Id,
                _testNetwork.GetNodeByName("HH-10").Id
            })
                                           .Create();

            serviceContext.CommandBus.Send(registerMultiConduitWalk).Wait();

            // Create first multi conduit: GM Plast Flatliner with 12 inner conduits
            _flatlinerCmd = fixture.Build <PlaceMultiConduitCommand>()
                            .With(x => x.WalkOfInterestId, registerMultiConduitWalk.WalkOfInterestId)
                            .With(x => x.Name, string.Empty)
                            .With(x => x.DemoDataSpec, "G12F-1-RD") // Flatliner with 12 inner conduits, conduit name = 1, red marking
                            .Create();

            serviceContext.CommandBus.Send(_flatlinerCmd);


            // Create second multi conduit: Emetelle round conduit with 7 inner conduits
            _emetelleCmd = fixture.Build <PlaceMultiConduitCommand>()
                           .With(x => x.WalkOfInterestId, registerMultiConduitWalk.WalkOfInterestId)
                           .With(x => x.Name, string.Empty)
                           .With(x => x.DemoDataSpec, "E7R-2-BK") // Emetelle with 7 inner conduits, conduit name = 2, black marking
                           .Create();

            serviceContext.CommandBus.Send(_emetelleCmd);


            // Walk of interest for placing the two singe conduits
            var registerSingleConduitWalk = fixture.Build <RegisterWalkOfInterestCommand>()
                                            .With(x => x.RouteElementIds, new List <Guid> {
                _testNetwork.GetNodeByName("CC-1").Id,
                _testNetwork.GetSegmentByName("CC-1_SP-1").Id,
                _testNetwork.GetNodeByName("SP-1").Id
            })
                                            .Create();

            serviceContext.CommandBus.Send(registerSingleConduitWalk).Wait();


            // Create first single conduit
            var createSingleConduit1Cmd = fixture.Build <PlaceSingleConduitCommand>()
                                          .With(x => x.WalkOfInterestId, registerSingleConduitWalk.WalkOfInterestId)
                                          .With(x => x.Name, "R3")
                                          .With(x => x.DemoDataSpec, "�")
                                          .Create();

            serviceContext.CommandBus.Send(createSingleConduit1Cmd).Wait();

            // Create second single conduit
            var createSingleConduit2Cmd = fixture.Build <PlaceSingleConduitCommand>()
                                          .With(x => x.WalkOfInterestId, registerSingleConduitWalk.WalkOfInterestId)
                                          .With(x => x.Name, "R4")
                                          .With(x => x.DemoDataSpec, "�")
                                          .Create();

            serviceContext.CommandBus.Send(createSingleConduit2Cmd).Wait();
        }
예제 #3
0
        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);
            });
        }