public async void TestAffixConduitInHH_10()
        {
            // Affix 5x10 to west side
            var conduit1Id = TestUtilityNetwork.MultiConduit_12x7_HH_1_to_HH_10;

            var conduit1 = _eventStore.Projections.Get <UtilityNetworkProjection>().SpanEquipments[conduit1Id];

            var conduit1AffixCommand = new AffixSpanEquipmentToNodeContainer(Guid.NewGuid(), new UserContext("test", Guid.Empty),
                                                                             spanEquipmentOrSegmentId: conduit1.SpanStructures[0].SpanSegments[0].Id,
                                                                             nodeContainerId: TestUtilityNetwork.NodeContainer_HH_10,
                                                                             nodeContainerIngoingSide: NodeContainerSideEnum.West
                                                                             );

            var conduit1AffixResult = await _commandDispatcher.HandleAsync <AffixSpanEquipmentToNodeContainer, Result>(conduit1AffixCommand);

            // Act
            var getDiagramQueryResult = await _queryDispatcher.HandleAsync <GetDiagram, Result <GetDiagramResult> >(new GetDiagram(TestRouteNetwork.HH_10));

            if (System.Environment.OSVersion.Platform.ToString() == "Win32NT")
            {
                new GeoJsonExporter(getDiagramQueryResult.Value.Diagram).Export("c:/temp/diagram/test.geojson");
            }

            // Assert
            getDiagramQueryResult.IsSuccess.Should().BeTrue();
            var diagram = getDiagramQueryResult.Value.Diagram;

            diagram.DiagramObjects.Count(o => o.Label == "HH-1").Should().Be(18);
            diagram.DiagramObjects.Count(o => o.Label == "SP-1").Should().Be(1);
            diagram.DiagramObjects.Count(o => o.Label == "HH-10").Should().Be(0);
        }
Example #2
0
        public async void TestAffixConduitToContainer_ShouldSucceed()
        {
            var nodeContainerId = PlaceNodeContainer(TestRouteNetwork.HH_2);

            var testNetwork = new TestUtilityNetwork(_commandDispatcher, _queryDispatcher).Run();

            var testConduitId = TestUtilityNetwork.MultiConduit_5x10_HH_1_to_HH_10;

            var testConduit = _eventStore.Projections.Get <UtilityNetworkProjection>().SpanEquipments[testConduitId];

            var affixConduitToContainerCommand = new AffixSpanEquipmentToNodeContainer(
                spanEquipmentOrSegmentId: testConduit.SpanStructures[0].SpanSegments[0].Id,
                nodeContainerId: nodeContainerId,
                nodeContainerIngoingSide: NodeContainerSideEnum.West
                );

            var affixResult = await _commandDispatcher.HandleAsync <AffixSpanEquipmentToNodeContainer, Result>(affixConduitToContainerCommand);

            var equipmentQueryResult = await _queryDispatcher.HandleAsync <GetEquipmentDetails, Result <GetEquipmentDetailsResult> >(
                new GetEquipmentDetails(new EquipmentIdList()
            {
                testConduitId
            })
                );

            equipmentQueryResult.IsSuccess.Should().BeTrue();

            equipmentQueryResult.Value.SpanEquipment[testConduitId].NodeContainerAffixes.First(n => n.NodeContainerId == nodeContainerId).NodeContainerIngoingSide.Should().Be(NodeContainerSideEnum.West);

            // Check if an event is published to the notification.utility-network topic having an idlist containing the span equipment id we just created
            var utilityNetworkNotifications = _externalEventProducer.GetMessagesByTopic("notification.utility-network").OfType <RouteNetworkElementContainedEquipmentUpdated>();
            var utilityNetworkUpdatedEvent  = utilityNetworkNotifications.First(n => n.IdChangeSets != null && n.IdChangeSets.Any(i => i.IdList.Any(i => i == nodeContainerId) && i.ChangeType == Events.Changes.ChangeTypeEnum.Modification));

            utilityNetworkUpdatedEvent.AffectedRouteNetworkElementIds.Should().Contain(TestRouteNetwork.HH_2);
        }
Example #3
0
        public async void TestAffixConduitToContainerTwoTimes_ShouldFaild()
        {
            var nodeContainerId = PlaceNodeContainer(TestRouteNetwork.HH_10);

            var testConduits = new TestUtilityNetwork(_commandDispatcher, _queryDispatcher).Run();

            var testConduitId = TestUtilityNetwork.MultiConduit_5x10_HH_1_to_HH_10;

            var testConduit = _eventStore.Projections.Get <UtilityNetworkProjection>().SpanEquipments[testConduitId];

            var affixConduitToContainerCommand = new AffixSpanEquipmentToNodeContainer(
                spanEquipmentOrSegmentId: testConduit.SpanStructures[0].SpanSegments[0].Id,
                nodeContainerId: nodeContainerId,
                nodeContainerIngoingSide: NodeContainerSideEnum.West
                );

            var affixResult1 = await _commandDispatcher.HandleAsync <AffixSpanEquipmentToNodeContainer, Result>(affixConduitToContainerCommand);

            var affixResult2 = await _commandDispatcher.HandleAsync <AffixSpanEquipmentToNodeContainer, Result>(affixConduitToContainerCommand);


            affixResult1.IsSuccess.Should().BeTrue();
            affixResult2.IsSuccess.Should().BeFalse();
            ((AffixSpanEquipmentToNodeContainerError)affixResult2.Errors.First()).Code.Should().Be(AffixSpanEquipmentToNodeContainerErrorCodes.SPAN_EQUIPMENT_ALREADY_AFFIXED_TO_NODE_CONTAINER);
        }
Example #4
0
        private void AffixSpanEquipmentToContainer(Guid spanEquipmentId, Guid nodeContainerId, NodeContainerSideEnum side)
        {
            var affixConduitToContainerCommand = new AffixSpanEquipmentToNodeContainer(Guid.NewGuid(), new UserContext("test", Guid.Empty),
                                                                                       spanEquipmentOrSegmentId: spanEquipmentId,
                                                                                       nodeContainerId: nodeContainerId,
                                                                                       nodeContainerIngoingSide: side
                                                                                       );

            var affixResult = _commandDispatcher.HandleAsync <AffixSpanEquipmentToNodeContainer, Result>(affixConduitToContainerCommand).Result;

            if (affixResult.IsFailed)
            {
                throw new ApplicationException(affixResult.Errors.First().Message);
            }
        }
Example #5
0
        public async void TestAffixConduitToContainer_ShouldSucceed()
        {
            var testConduitId = TestUtilityNetwork.MultiConduit_12x7_SDU_1_to_J_1;

            var testConduit = _eventStore.Projections.Get <UtilityNetworkProjection>().SpanEquipments[testConduitId];

            var affixConduitToContainerCommand = new AffixSpanEquipmentToNodeContainer(
                spanEquipmentOrSegmentId: testConduit.SpanStructures[0].SpanSegments[0].Id,
                nodeContainerId: TestUtilityNetwork.NodeContainer_J_1,
                nodeContainerIngoingSide: NodeContainerSideEnum.West
                );

            var affixResult = await _commandDispatcher.HandleAsync <AffixSpanEquipmentToNodeContainer, Result>(affixConduitToContainerCommand);

            affixResult.IsSuccess.Should().BeTrue();
        }
        private Result AffixSpanEquipmentToContainer(Guid routeNodeId, Guid spanEquipmentId, Guid nodeContainerId, NodeContainerSideEnum side)
        {
            Guid correlationId = Guid.NewGuid();

            var commandUserContext = new UserContext("conversion", _workTaskId)
            {
                EditingRouteNodeId = routeNodeId
            };

            var affixConduitToContainerCommand = new AffixSpanEquipmentToNodeContainer(correlationId, commandUserContext,
                                                                                       spanEquipmentOrSegmentId: spanEquipmentId,
                                                                                       nodeContainerId: nodeContainerId,
                                                                                       nodeContainerIngoingSide: side
                                                                                       );

            var affixResult = _commandDispatcher.HandleAsync <AffixSpanEquipmentToNodeContainer, Result>(affixConduitToContainerCommand).Result;

            return(affixResult);
        }
        public async void TestAffixConduitInCC_1()
        {
            // Affix 5x10 to west side
            var conduit1Id = TestUtilityNetwork.MultiConduit_12x7_HH_1_to_HH_10;

            var conduit1 = _eventStore.Projections.Get <UtilityNetworkProjection>().SpanEquipments[conduit1Id];

            var conduit1AffixCommand = new AffixSpanEquipmentToNodeContainer(Guid.NewGuid(), new UserContext("test", Guid.Empty),
                                                                             spanEquipmentOrSegmentId: conduit1.SpanStructures[0].SpanSegments[0].Id,
                                                                             nodeContainerId: TestUtilityNetwork.NodeContainer_CC_1,
                                                                             nodeContainerIngoingSide: NodeContainerSideEnum.West
                                                                             );

            var conduit1AffixResult = await _commandDispatcher.HandleAsync <AffixSpanEquipmentToNodeContainer, Result>(conduit1AffixCommand);

            // Affix 3x10 to north side
            var conduit2Id = TestUtilityNetwork.MultiConduit_3x10_CC_1_to_SP_1;

            var conduit2 = _eventStore.Projections.Get <UtilityNetworkProjection>().SpanEquipments[conduit2Id];

            var conduit2AffixCommand = new AffixSpanEquipmentToNodeContainer(Guid.NewGuid(), new UserContext("test", Guid.Empty),
                                                                             spanEquipmentOrSegmentId: conduit2.SpanStructures[0].SpanSegments[0].Id,
                                                                             nodeContainerId: TestUtilityNetwork.NodeContainer_CC_1,
                                                                             nodeContainerIngoingSide: NodeContainerSideEnum.North
                                                                             );

            var conduit2AffixResult = await _commandDispatcher.HandleAsync <AffixSpanEquipmentToNodeContainer, Result>(conduit2AffixCommand);

            // Affix flex conduit to south side
            var conduit3Id = TestUtilityNetwork.FlexConduit_40_Red_CC_1_to_SP_1;

            var conduit3 = _eventStore.Projections.Get <UtilityNetworkProjection>().SpanEquipments[conduit3Id];

            var conduit3AffixCommand = new AffixSpanEquipmentToNodeContainer(Guid.NewGuid(), new UserContext("test", Guid.Empty),
                                                                             spanEquipmentOrSegmentId: conduit3.SpanStructures[0].SpanSegments[0].Id,
                                                                             nodeContainerId: TestUtilityNetwork.NodeContainer_CC_1,
                                                                             nodeContainerIngoingSide: NodeContainerSideEnum.South
                                                                             );

            var conduit3AffixResult = await _commandDispatcher.HandleAsync <AffixSpanEquipmentToNodeContainer, Result>(conduit3AffixCommand);

            // Act
            var getDiagramQueryResult = await _queryDispatcher.HandleAsync <GetDiagram, Result <GetDiagramResult> >(new GetDiagram(TestRouteNetwork.CC_1));

            if (System.Environment.OSVersion.Platform.ToString() == "Win32NT")
            {
                new GeoJsonExporter(getDiagramQueryResult.Value.Diagram).Export("c:/temp/diagram/test.geojson");
            }

            // Assert
            getDiagramQueryResult.IsSuccess.Should().BeTrue();
            var diagram = getDiagramQueryResult.Value.Diagram;

            diagram.DiagramObjects.Count(o => o.Style == "NodeContainer").Should().Be(1);
            diagram.DiagramObjects.Count(o => o.Style == "NodeContainerSideWest").Should().Be(1);

            diagram.DiagramObjects.Count(o => o.Style == "WestTerminalLabel" && o.IdentifiedObject.RefId == conduit1.SpanStructures[1].SpanSegments[0].Id).Should().Be(1);

            diagram.DiagramObjects.Count(o => o.Style == "SouthTerminalLabel" && o.IdentifiedObject.RefId == conduit3.SpanStructures[0].SpanSegments[0].Id).Should().Be(2);

            // Only one terminal connection should be shown in conduit 1 that is affixed to the node container
            diagram.DiagramObjects.Count(o => o.Style == "OuterConduitOrange" && o.IdentifiedObject.RefId == conduit1.SpanStructures[0].SpanSegments[0].Id).Should().Be(1);

            diagram.DiagramObjects.Any(d => d.DrawingOrder == 0).Should().BeFalse();
        }
Example #8
0
        public SpanEquipmentMutations(ICommandDispatcher commandDispatcher, IEventStore eventStore)
        {
            Description = "Span equipment mutations";

            FieldAsync <CommandResultType>(
                "placeSpanEquipmentInRouteNetwork",
                description: "Place a span equipment (i.e. conduit, cable whatwever) in the route network",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <IdGraphType> > {
                Name = "spanEquipmentId"
            },
                    new QueryArgument <NonNullGraphType <IdGraphType> > {
                Name = "spanEquipmentSpecificationId"
            },
                    new QueryArgument <NonNullGraphType <ListGraphType <IdGraphType> > > {
                Name = "routeSegmentIds"
            },
                    new QueryArgument <IdGraphType> {
                Name = "manufacturerId"
            },
                    new QueryArgument <MarkingInfoInputType> {
                Name = "markingInfo"
            },
                    new QueryArgument <NamingInfoInputType> {
                Name = "namingInfo"
            },
                    new QueryArgument <AddressInfoInputType> {
                Name = "addressInfo"
            }
                    ),
                resolve: async context =>
            {
                var spanEquipmentId = context.GetArgument <Guid>("spanEquipmentId");
                var spanEquipmentSpecificationId = context.GetArgument <Guid>("spanEquipmentSpecificationId");
                var routeSegmentIds = context.GetArgument <List <Guid> >("routeSegmentIds");
                var manufacturerId  = context.GetArgument <Guid>("manufacturerId");
                var markingInfo     = context.GetArgument <MarkingInfo>("markingInfo");
                var namingInfo      = context.GetArgument <NamingInfo>("namingInfo");
                var addressInfo     = context.GetArgument <AddressInfo>("addressInfo");

                // Name conduit span equipment
                // TODO: Refactor into som class responsible for span equipment naming
                var spec   = eventStore.Projections.Get <SpanEquipmentSpecificationsProjection>().Specifications[spanEquipmentSpecificationId];
                namingInfo = CalculateName(eventStore, namingInfo, spec);

                var correlationId = Guid.NewGuid();

                var userContext = context.UserContext as GraphQLUserContext;
                var userName    = userContext.Username;

                // TODO: Get from work manager
                var workTaskId         = Guid.Parse("54800ae5-13a5-4b03-8626-a63b66a25568");
                var commandUserContext = new UserContext(userName, workTaskId);

                var spanEquipments = eventStore.Projections.Get <UtilityNetworkProjection>().SpanEquipmentsByEquipmentId;

                // First register the walk in the route network where the client want to place the span equipment
                var walkOfInterestId = Guid.NewGuid();
                var walk             = new RouteNetworkElementIdList();
                walk.AddRange(routeSegmentIds);

                var registerWalkOfInterestCommand = new RegisterWalkOfInterest(correlationId, commandUserContext, walkOfInterestId, walk);

                var registerWalkOfInterestCommandResult = await commandDispatcher.HandleAsync <RegisterWalkOfInterest, Result <RouteNetworkInterest> >(registerWalkOfInterestCommand);

                if (registerWalkOfInterestCommandResult.IsFailed)
                {
                    return(new CommandResult(registerWalkOfInterestCommandResult));
                }

                // Now place the conduit in the walk
                var placeSpanEquipmentCommand = new PlaceSpanEquipmentInRouteNetwork(
                    correlationId, commandUserContext, spanEquipmentId, spanEquipmentSpecificationId, registerWalkOfInterestCommandResult.Value)
                {
                    ManufacturerId = manufacturerId,
                    NamingInfo     = namingInfo,
                    MarkingInfo    = markingInfo,
                    LifecycleInfo  = new LifecycleInfo(DeploymentStateEnum.InService, null, null),
                    AddressInfo    = addressInfo
                };

                var placeSpanEquipmentResult = await commandDispatcher.HandleAsync <PlaceSpanEquipmentInRouteNetwork, Result>(placeSpanEquipmentCommand);

                // Unregister interest if place span equipment failed
                if (placeSpanEquipmentResult.IsFailed)
                {
                    var unregisterCommandResult = await commandDispatcher.HandleAsync <UnregisterInterest, Result>(
                        new UnregisterInterest(correlationId, commandUserContext, walkOfInterestId));

                    if (unregisterCommandResult.IsFailed)
                    {
                        return(new CommandResult(unregisterCommandResult));
                    }
                }

                return(new CommandResult(placeSpanEquipmentResult));
            }
                );

            FieldAsync <CommandResultType>(
                "affixSpanEquipmentToNodeContainer",
                description: "Affix a span equipment to a node container - i.e. to some condult closure, man hole etc.",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <ListGraphType <IdGraphType> > > {
                Name = "spanSegmentIds"
            },
                    new QueryArgument <NonNullGraphType <IdGraphType> > {
                Name = "nodeContainerId"
            },
                    new QueryArgument <NonNullGraphType <NodeContainerSideEnumType> > {
                Name = "nodeContainerSide"
            }
                    ),
                resolve: async context =>
            {
                var spanSegmentIds  = context.GetArgument <List <Guid> >("spanSegmentIds");
                var nodeContainerId = context.GetArgument <Guid>("nodeContainerId");
                var side            = context.GetArgument <NodeContainerSideEnum>("nodeContainerSide");

                var correlationId = Guid.NewGuid();

                var userContext = context.UserContext as GraphQLUserContext;
                var userName    = userContext.Username;

                // TODO: Get from work manager
                var workTaskId = Guid.Parse("54800ae5-13a5-4b03-8626-a63b66a25568");

                var commandUserContext = new UserContext(userName, workTaskId);

                foreach (var spanSegmentId in spanSegmentIds)
                {
                    var affixCommand = new AffixSpanEquipmentToNodeContainer(correlationId, commandUserContext, spanSegmentId, nodeContainerId, side);

                    var affixCommandResult = await commandDispatcher.HandleAsync <AffixSpanEquipmentToNodeContainer, Result>(affixCommand);

                    if (affixCommandResult.IsFailed)
                    {
                        return(new CommandResult(affixCommandResult));
                    }
                }

                return(new CommandResult(Result.Ok()));
            }
                );

            FieldAsync <CommandResultType>(
                "detachSpanEquipmentFromNodeContainer",
                description: "Detach a span equipment from a node container - i.e. from some condult closure, man hole etc.",
                arguments: new QueryArguments(
                    new QueryArgument <ListGraphType <IdGraphType> > {
                Name = "spanSegmentIds"
            },
                    new QueryArgument <NonNullGraphType <IdGraphType> > {
                Name = "routeNodeId"
            }
                    ),
                resolve: async context =>
            {
                var spanSegmentIds = context.GetArgument <List <Guid> >("spanSegmentIds");
                var routeNodeId    = context.GetArgument <Guid>("routeNodeId");

                var correlationId = Guid.NewGuid();

                var userContext = context.UserContext as GraphQLUserContext;
                var userName    = userContext.Username;

                // TODO: Get from work manager
                var workTaskId = Guid.Parse("54800ae5-13a5-4b03-8626-a63b66a25568");

                var commandUserContext = new UserContext(userName, workTaskId)
                {
                    EditingRouteNodeId = routeNodeId
                };

                foreach (var spanSegmentId in spanSegmentIds)
                {
                    var detachCommand       = new DetachSpanEquipmentFromNodeContainer(correlationId, commandUserContext, spanSegmentId, routeNodeId);
                    var detachCommandResult = await commandDispatcher.HandleAsync <DetachSpanEquipmentFromNodeContainer, Result>(detachCommand);

                    if (detachCommandResult.IsFailed)
                    {
                        return(new CommandResult(detachCommandResult));
                    }
                }

                return(new CommandResult(Result.Ok()));
            }
                );

            FieldAsync <CommandResultType>(
                "cutSpanSegments",
                description: "Cut the span segments belonging to som span equipment at the route node specified",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <IdGraphType> > {
                Name = "routeNodeId"
            },
                    new QueryArgument <NonNullGraphType <ListGraphType <IdGraphType> > > {
                Name = "spanSegmentstoCut"
            }
                    ),
                resolve: async context =>
            {
                var routeNodeId      = context.GetArgument <Guid>("routeNodeId");
                var spanSegmentToCut = context.GetArgument <Guid[]>("spanSegmentstoCut");

                var correlationId = Guid.NewGuid();

                var userContext = context.UserContext as GraphQLUserContext;
                var userName    = userContext.Username;

                // TODO: Get from work manager
                var workTaskId = Guid.Parse("54800ae5-13a5-4b03-8626-a63b66a25568");

                var commandUserContext = new UserContext(userName, workTaskId)
                {
                    EditingRouteNodeId = routeNodeId
                };

                var cutCmd    = new CutSpanSegmentsAtRouteNode(correlationId, commandUserContext, routeNodeId, spanSegmentToCut);
                var cutResult = await commandDispatcher.HandleAsync <CutSpanSegmentsAtRouteNode, Result>(cutCmd);

                return(new CommandResult(cutResult));
            }
                );

            FieldAsync <CommandResultType>(
                "connectSpanSegments",
                description: "Connect the span segments belonging to two different span equipment at the route node specified",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <IdGraphType> > {
                Name = "routeNodeId"
            },
                    new QueryArgument <NonNullGraphType <ListGraphType <IdGraphType> > > {
                Name = "spanSegmentsToConnect"
            }
                    ),
                resolve: async context =>
            {
                var routeNodeId          = context.GetArgument <Guid>("routeNodeId");
                var spanSegmentToConnect = context.GetArgument <Guid[]>("spanSegmentsToConnect");

                var correlationId = Guid.NewGuid();

                var userContext = context.UserContext as GraphQLUserContext;
                var userName    = userContext.Username;

                // TODO: Get from work manager
                var workTaskId = Guid.Parse("54800ae5-13a5-4b03-8626-a63b66a25568");

                var commandUserContext = new UserContext(userName, workTaskId)
                {
                    EditingRouteNodeId = routeNodeId
                };

                var connectCmd    = new ConnectSpanSegmentsAtRouteNode(correlationId, commandUserContext, routeNodeId, spanSegmentToConnect);
                var connectResult = await commandDispatcher.HandleAsync <ConnectSpanSegmentsAtRouteNode, Result>(connectCmd);

                return(new CommandResult(connectResult));
            }
                );

            FieldAsync <CommandResultType>(
                "disconnectSpanSegments",
                description: "Disconnect two span segments belonging to two different span equipment at the route node specified",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <IdGraphType> > {
                Name = "routeNodeId"
            },
                    new QueryArgument <NonNullGraphType <ListGraphType <IdGraphType> > > {
                Name = "spanSegmentsToDisconnect"
            }
                    ),
                resolve: async context =>
            {
                var routeNodeId             = context.GetArgument <Guid>("routeNodeId");
                var spanSegmentToDisconnect = context.GetArgument <Guid[]>("spanSegmentsToDisconnect");

                var correlationId = Guid.NewGuid();

                var userContext = context.UserContext as GraphQLUserContext;
                var userName    = userContext.Username;

                // TODO: Get from work manager
                var workTaskId = Guid.Parse("54800ae5-13a5-4b03-8626-a63b66a25568");

                var commandUserContext = new UserContext(userName, workTaskId)
                {
                    EditingRouteNodeId = routeNodeId
                };

                var disconnectCmd    = new DisconnectSpanSegmentsAtRouteNode(correlationId, commandUserContext, routeNodeId, spanSegmentToDisconnect);
                var disconnectResult = await commandDispatcher.HandleAsync <DisconnectSpanSegmentsAtRouteNode, Result>(disconnectCmd);

                return(new CommandResult(disconnectResult));
            }
                );

            FieldAsync <CommandResultType>(
                "addAdditionalInnerSpanStructures",
                description: "Add inner span structures to an existing span equipment",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <IdGraphType> > {
                Name = "spanEquipmentOrSegmentId"
            },
                    new QueryArgument <NonNullGraphType <ListGraphType <IdGraphType> > > {
                Name = "spanStructureSpecificationIds"
            }
                    ),
                resolve: async context =>
            {
                var spanEquipmentOrSegmentId = context.GetArgument <Guid>("spanEquipmentOrSegmentId");
                var specificationsId         = context.GetArgument <Guid[]>("spanStructureSpecificationIds");

                var correlationId = Guid.NewGuid();

                var userContext = context.UserContext as GraphQLUserContext;
                var userName    = userContext.Username;

                // TODO: Get from work manager
                var workTaskId = Guid.Parse("54800ae5-13a5-4b03-8626-a63b66a25568");

                var commandUserContext = new UserContext(userName, workTaskId);

                var addStructure = new PlaceAdditionalStructuresInSpanEquipment(
                    correlationId: correlationId,
                    userContext: commandUserContext,
                    spanEquipmentId: spanEquipmentOrSegmentId,
                    structureSpecificationIds: specificationsId
                    );

                var addStructureResult = await commandDispatcher.HandleAsync <PlaceAdditionalStructuresInSpanEquipment, Result>(addStructure);

                return(new CommandResult(addStructureResult));
            }
                );

            FieldAsync <CommandResultType>(
                "removeSpanStructure",
                description: "Remove inner or outer span structure of a span equipment. When the outer span structure is removed the entire span equipment is removed from the network.",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <IdGraphType> > {
                Name = "spanSegmentId"
            }
                    ),
                resolve: async context =>
            {
                var spanSegmentId = context.GetArgument <Guid>("spanSegmentId");

                var correlationId = Guid.NewGuid();

                var userContext = context.UserContext as GraphQLUserContext;
                var userName    = userContext.Username;

                // TODO: Get from work manager
                var workTaskId = Guid.Parse("54800ae5-13a5-4b03-8626-a63b66a25568");

                var commandUserContext = new UserContext(userName, workTaskId);

                var removeStructure = new RemoveSpanStructureFromSpanEquipment(
                    correlationId: correlationId,
                    userContext: commandUserContext,
                    spanSegmentId: spanSegmentId
                    );

                var removeStructureResult = await commandDispatcher.HandleAsync <RemoveSpanStructureFromSpanEquipment, Result>(removeStructure);

                return(new CommandResult(removeStructureResult));
            }
                );

            FieldAsync <CommandResultType>(
                "move",
                description: "Move a span equipment / change its walk in the route network",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <IdGraphType> > {
                Name = "spanEquipmentOrSegmentId"
            },
                    new QueryArgument <NonNullGraphType <ListGraphType <IdGraphType> > > {
                Name = "routeSegmentIds"
            }
                    ),
                resolve: async context =>
            {
                var spanEquipmentOrSegmentId = context.GetArgument <Guid>("spanEquipmentOrSegmentId");

                var correlationId = Guid.NewGuid();

                var userContext = context.UserContext as GraphQLUserContext;
                var userName    = userContext.Username;

                // TODO: Get from work manager
                var workTaskId = Guid.Parse("54800ae5-13a5-4b03-8626-a63b66a25568");

                var commandUserContext = new UserContext(userName, workTaskId);

                Guid[] routeSegmentIds = context.GetArgument <Guid[]>("routeSegmentIds");

                RouteNetworkElementIdList newWalkIds = new();
                newWalkIds.AddRange(routeSegmentIds);

                var moveCmd = new MoveSpanEquipment(
                    correlationId: correlationId,
                    userContext: commandUserContext,
                    spanEquipmentId: spanEquipmentOrSegmentId,
                    newWalkIds: newWalkIds
                    );

                var moveCmdResult = await commandDispatcher.HandleAsync <MoveSpanEquipment, Result>(moveCmd);

                return(new CommandResult(moveCmdResult));
            }
                );

            FieldAsync <CommandResultType>(
                "updateProperties",
                description: "Mutation that can be used to change the span equipment specification, manufacturer and/or marking information",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <IdGraphType> > {
                Name = "spanEquipmentOrSegmentId"
            },
                    new QueryArgument <IdGraphType> {
                Name = "spanEquipmentSpecificationId"
            },
                    new QueryArgument <IdGraphType> {
                Name = "manufacturerId"
            },
                    new QueryArgument <MarkingInfoInputType> {
                Name = "markingInfo"
            },
                    new QueryArgument <AddressInfoInputType> {
                Name = "addressInfo"
            }
                    ),
                resolve: async context =>
            {
                var spanEquipmentOrSegmentId = context.GetArgument <Guid>("spanEquipmentOrSegmentId");

                var correlationId = Guid.NewGuid();

                var userContext = context.UserContext as GraphQLUserContext;
                var userName    = userContext.Username;

                // TODO: Get from work manager
                var workTaskId = Guid.Parse("54800ae5-13a5-4b03-8626-a63b66a25568");

                var commandUserContext = new UserContext(userName, workTaskId);

                var updateCmd = new UpdateSpanEquipmentProperties(correlationId, commandUserContext, spanEquipmentOrSegmentId: spanEquipmentOrSegmentId)
                {
                    SpecificationId = context.HasArgument("spanEquipmentSpecificationId") ? context.GetArgument <Guid>("spanEquipmentSpecificationId") : null,
                    ManufacturerId  = context.HasArgument("manufacturerId") ? context.GetArgument <Guid>("manufacturerId") : null,
                    MarkingInfo     = context.HasArgument("markingInfo") ? context.GetArgument <MarkingInfo>("markingInfo") : null,
                    AddressInfo     = context.HasArgument("addressInfo") ? context.GetArgument <AddressInfo>("addressInfo") : null
                };

                var updateResult = await commandDispatcher.HandleAsync <UpdateSpanEquipmentProperties, Result>(updateCmd);

                return(new CommandResult(updateResult));
            }
                );

            FieldAsync <CommandResultType>(
                "affixSpanEquipmentToParent",
                description: "Affix a span equipment to a parent span equipment - i.e. put a cable inside a conduit",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <IdGraphType> > {
                Name = "routeNodeId"
            },
                    new QueryArgument <NonNullGraphType <IdGraphType> > {
                Name = "spanSegmentId1"
            },
                    new QueryArgument <NonNullGraphType <IdGraphType> > {
                Name = "spanSegmentId2"
            }
                    ),
                resolve: async context =>
            {
                var routeNodeId    = context.GetArgument <Guid>("routeNodeId");
                var spanSegmentId1 = context.GetArgument <Guid>("spanSegmentId1");
                var spanSegmentId2 = context.GetArgument <Guid>("spanSegmentId2");

                var correlationId = Guid.NewGuid();

                var userContext = context.UserContext as GraphQLUserContext;
                var userName    = userContext.Username;

                // TODO: Get from work manager
                var workTaskId = Guid.Parse("54800ae5-13a5-4b03-8626-a63b66a25568");

                var commandUserContext = new UserContext(userName, workTaskId);

                var affixCommand       = new AffixSpanEquipmentToParent(correlationId, commandUserContext, routeNodeId, spanSegmentId1, spanSegmentId2);
                var affixCommandResult = await commandDispatcher.HandleAsync <AffixSpanEquipmentToParent, Result>(affixCommand);

                if (affixCommandResult.IsFailed)
                {
                    return(new CommandResult(affixCommandResult));
                }

                return(new CommandResult(Result.Ok()));
            }
                );

            FieldAsync <CommandResultType>(
                "connectToTerminalEquipment",
                description: "Connect one or more span segments inside a span equipment to terminals inside a terminal equipmment",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <IdGraphType> > {
                Name = "routeNodeId"
            },
                    new QueryArgument <NonNullGraphType <ListGraphType <ConnectSpanSegmentToTerminalOperationInputType> > > {
                Name = "connects"
            }
                    ),
                resolve: async context =>
            {
                var routeNodeId = context.GetArgument <Guid>("routeNodeId");
                var connects    = context.GetArgument <ConnectSpanSegmentToTerminalOperation[]>("connects");

                var correlationId = Guid.NewGuid();

                var userContext = context.UserContext as GraphQLUserContext;
                var userName    = userContext.Username;

                // TODO: Get from work manager
                var workTaskId = Guid.Parse("54800ae5-13a5-4b03-8626-a63b66a25568");

                var commandUserContext = new UserContext(userName, workTaskId);

                var connectCommand       = new ConnectSpanSegmentsWithTerminalsAtRouteNode(correlationId, commandUserContext, routeNodeId, connects);
                var connectCommandResult = await commandDispatcher.HandleAsync <ConnectSpanSegmentsWithTerminalsAtRouteNode, Result>(connectCommand);

                if (connectCommandResult.IsFailed)
                {
                    return(new CommandResult(connectCommandResult));
                }

                return(new CommandResult(Result.Ok()));
            }
                );

            FieldAsync <CommandResultType>(
                "disconnectFromTerminalEquipment",
                description: "Disconnect one or more span segments inside a span equipment from terminals inside a terminal equipmment",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <IdGraphType> > {
                Name = "routeNodeId"
            },
                    new QueryArgument <NonNullGraphType <ListGraphType <DisconnectSpanSegmentFromTerminalOperationInputType> > > {
                Name = "disconnects"
            }
                    ),
                resolve: async context =>
            {
                var routeNodeId = context.GetArgument <Guid>("routeNodeId");
                var connects    = context.GetArgument <DisconnectSpanSegmentFromTerminalOperation[]>("disconnects");

                var correlationId = Guid.NewGuid();

                var userContext = context.UserContext as GraphQLUserContext;
                var userName    = userContext.Username;

                // TODO: Get from work manager
                var workTaskId = Guid.Parse("54800ae5-13a5-4b03-8626-a63b66a25568");

                var commandUserContext = new UserContext(userName, workTaskId);
                var connectCommand     = new DisconnectSpanSegmentsFromTerminalsAtRouteNode(correlationId, commandUserContext, routeNodeId, connects);

                var connectCommandResult = await commandDispatcher.HandleAsync <DisconnectSpanSegmentsFromTerminalsAtRouteNode, Result>(connectCommand);

                if (connectCommandResult.IsFailed)
                {
                    return(new CommandResult(connectCommandResult));
                }

                return(new CommandResult(Result.Ok()));
            }
                );
        }
Example #9
0
        public async Task ConnectInnerDuct2In3x10sIn_HH_10()
        {
            var utilityNetwork = _eventStore.Projections.Get <UtilityNetworkProjection>();

            var nodeOfInterestId = Guid.NewGuid();
            var registerNodeOfInterestCommand       = new RegisterNodeOfInterest(Guid.NewGuid(), new UserContext("test", Guid.Empty), nodeOfInterestId, TestRouteNetwork.HH_10);
            var registerNodeOfInterestCommandResult = _commandDispatcher.HandleAsync <RegisterNodeOfInterest, Result <RouteNetworkInterest> >(registerNodeOfInterestCommand).Result;

            var placeNodeContainerCommand = new PlaceNodeContainerInRouteNetwork(Guid.NewGuid(), new UserContext("test", Guid.Empty), Guid.NewGuid(), TestSpecifications.Conduit_Closure_Emtelle_Branch_Box, registerNodeOfInterestCommandResult.Value)
            {
                ManufacturerId = TestSpecifications.Manu_Emtelle
            };

            // Place node container
            var placeNodeContainerResult = await _commandDispatcher.HandleAsync <PlaceNodeContainerInRouteNetwork, Result>(placeNodeContainerCommand);

            // Affix conduit 1
            var testConduitId1 = TestConduits.Conduit_3x10_HH_10_to_HH_11;

            var testConduit1 = _eventStore.Projections.Get <UtilityNetworkProjection>().SpanEquipmentsByEquipmentId[testConduitId1];

            var affixConduitToContainerCommand1 = new AffixSpanEquipmentToNodeContainer(Guid.NewGuid(), new UserContext("test", Guid.Empty),
                                                                                        spanEquipmentOrSegmentId: testConduit1.SpanStructures[0].SpanSegments[0].Id,
                                                                                        nodeContainerId: placeNodeContainerCommand.NodeContainerId,
                                                                                        nodeContainerIngoingSide: NodeContainerSideEnum.North
                                                                                        );

            var affixResult1 = await _commandDispatcher.HandleAsync <AffixSpanEquipmentToNodeContainer, Result>(affixConduitToContainerCommand1);

            affixResult1.IsSuccess.Should().BeTrue();

            // Affix conduit 2
            var testConduitId2 = TestConduits.Conduit_5x10_HH_1_to_HH_10;

            var testConduit2 = _eventStore.Projections.Get <UtilityNetworkProjection>().SpanEquipmentsByEquipmentId[testConduitId2];

            var affixConduitToContainerCommand2 = new AffixSpanEquipmentToNodeContainer(Guid.NewGuid(), new UserContext("test", Guid.Empty),
                                                                                        spanEquipmentOrSegmentId: testConduit2.SpanStructures[0].SpanSegments[0].Id,
                                                                                        nodeContainerId: placeNodeContainerCommand.NodeContainerId,
                                                                                        nodeContainerIngoingSide: NodeContainerSideEnum.South
                                                                                        );

            var affixResult2 = await _commandDispatcher.HandleAsync <AffixSpanEquipmentToNodeContainer, Result>(affixConduitToContainerCommand2);

            affixResult2.IsSuccess.Should().BeTrue();

            // Connect inner conduit 2
            var sutConnectFromSpanEquipment = TestConduits.Conduit_5x10_HH_1_to_HH_10;
            var sutConnectToSpanEquipment   = TestConduits.Conduit_3x10_HH_10_to_HH_11;

            utilityNetwork.TryGetEquipment <SpanEquipment>(sutConnectFromSpanEquipment, out var sutFromSpanEquipment);
            utilityNetwork.TryGetEquipment <SpanEquipment>(sutConnectToSpanEquipment, out var sutToSpanEquipment);

            // Connect inner conduit 2 in 3x10 with inner conduit 2 in the other 3x10 in node HH 10
            var connectCmd = new ConnectSpanSegmentsAtRouteNode(Guid.NewGuid(), new UserContext("test", Guid.Empty),
                                                                routeNodeId: TestRouteNetwork.HH_10,
                                                                spanSegmentsToConnect: new Guid[] {
                sutFromSpanEquipment.SpanStructures[2].SpanSegments[0].Id,
                sutToSpanEquipment.SpanStructures[2].SpanSegments[0].Id
            }
                                                                );

            var connectResult = await _commandDispatcher.HandleAsync <ConnectSpanSegmentsAtRouteNode, Result>(connectCmd);

            connectResult.IsSuccess.Should().BeTrue();
        }