public async void TestDrawingCableThrowSingleConduitInWellInsideNodeContainerCC1()
        {
            var utilityNetwork = _eventStore.Projections.Get <UtilityNetworkProjection>();

            var sutRouteNetworkElement = TestRouteNetwork.CC_1;

            // The span equipment/segment where to route the child span equipment
            var routeThroughSpanEquipmentId  = TestUtilityNetwork.MultiConduit_12x7_HH_1_to_HH_10;
            var routeThroughSpanEquipmentId2 = TestUtilityNetwork.CustomerConduit_CC_1_to_SDU_1;

            utilityNetwork.TryGetEquipment <SpanEquipment>(routeThroughSpanEquipmentId, out var routeThoughSpanEquipment);
            utilityNetwork.TryGetEquipment <SpanEquipment>(routeThroughSpanEquipmentId2, out var routeThoughSpanEquipment2);

            var routeThroughSpanSegmentId  = routeThoughSpanEquipment.SpanStructures[6].SpanSegments[0].Id;
            var routeThroughSpanSegmentId2 = routeThoughSpanEquipment2.SpanStructures[0].SpanSegments[0].Id;

            // Setup command
            var specs = new TestSpecifications(_commandDispatcher, _queryDispatcher).Run();

            var routingHops = new RoutingHop[]
            {
                new RoutingHop(TestRouteNetwork.HH_1, routeThroughSpanSegmentId)
            };

            var placeSpanEquipmentCommand = new PlaceSpanEquipmentInUtilityNetwork(Guid.NewGuid(), new UserContext("test", Guid.Empty), Guid.NewGuid(), TestSpecifications.FiberCable_288Fiber, routingHops)
            {
                NamingInfo     = new NamingInfo("K999922222", null),
                ManufacturerId = Guid.NewGuid()
            };

            // Act
            var placeSpanEquipmentResult = await _commandDispatcher.HandleAsync <PlaceSpanEquipmentInUtilityNetwork, Result>(placeSpanEquipmentCommand);

            var getDiagramQueryResult = await _queryDispatcher.HandleAsync <GetDiagram, Result <GetDiagramResult> >(new GetDiagram(sutRouteNetworkElement));

            // Assert
            placeSpanEquipmentResult.IsSuccess.Should().BeTrue();

            var diagram = getDiagramQueryResult.Value.Diagram;

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

            // Assert
            diagram.DiagramObjects.Count(o => o.Style == "FiberCable" && o.Geometry is LineString).Should().Be(7);

            diagram.DiagramObjects.Count(o => o.Style == "OuterConduitOrange" && o.Geometry is Polygon).Should().Be(9);
        }
        public async void TestDrawingCableInsideConduitPassingThrougRouteSegment()
        {
            var utilityNetwork = _eventStore.Projections.Get <UtilityNetworkProjection>();

            var sutRouteNetworkElement = TestRouteNetwork.S2;

            // The span equipment/segment where to route the child span equipment
            var routeThroughSpanEquipmentId = TestUtilityNetwork.MultiConduit_10x10_HH_1_to_HH_10;

            utilityNetwork.TryGetEquipment <SpanEquipment>(routeThroughSpanEquipmentId, out var routeThoughSpanEquipment);

            var routeThroughSpanSegmentId = routeThoughSpanEquipment.SpanStructures[10].SpanSegments[0].Id;

            // Setup command
            var specs = new TestSpecifications(_commandDispatcher, _queryDispatcher).Run();

            var routingHops = new RoutingHop[]
            {
                new RoutingHop(TestRouteNetwork.HH_1, routeThroughSpanSegmentId)
            };

            var placeSpanEquipmentCommand = new PlaceSpanEquipmentInUtilityNetwork(Guid.NewGuid(), new UserContext("test", Guid.Empty), Guid.NewGuid(), TestSpecifications.FiberCable_72Fiber, routingHops)
            {
                NamingInfo     = new NamingInfo("K11112222", null),
                ManufacturerId = Guid.NewGuid()
            };

            // Act
            var placeSpanEquipmentResult = await _commandDispatcher.HandleAsync <PlaceSpanEquipmentInUtilityNetwork, Result>(placeSpanEquipmentCommand);

            var getDiagramQueryResult = await _queryDispatcher.HandleAsync <GetDiagram, Result <GetDiagramResult> >(new GetDiagram(sutRouteNetworkElement));


            var diagram = getDiagramQueryResult.Value.Diagram;

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

            // Assert
            diagram.DiagramObjects.Count(o => o.Style == "FiberCable" && o.Geometry is LineString).Should().Be(2);
            diagram.DiagramObjects.Count(o => o.Label != null && o.Label.Contains("K11112222")).Should().Be(1);
        }
        public async void TestDrawingCableEndOutsideConduitInRouteNode()
        {
            var utilityNetwork = _eventStore.Projections.Get <UtilityNetworkProjection>();

            var sutRouteNetworkElement = TestRouteNetwork.CC_1;

            // Setup
            var specs = new TestSpecifications(_commandDispatcher, _queryDispatcher).Run();

            // Cable directly in route network from HH_1 to CC_1
            var routingHops = new RoutingHop[]
            {
                new RoutingHop(
                    new Guid[] { TestRouteNetwork.HH_1, TestRouteNetwork.S2, TestRouteNetwork.HH_2, TestRouteNetwork.S4, TestRouteNetwork.CC_1 }
                    ),
            };

            var placeSpanEquipmentCommand = new PlaceSpanEquipmentInUtilityNetwork(Guid.NewGuid(), new UserContext("test", Guid.Empty), Guid.NewGuid(), TestSpecifications.FiberCable_192Fiber, routingHops)
            {
                NamingInfo     = new NamingInfo("K12345678", null),
                ManufacturerId = Guid.NewGuid()
            };

            // Act
            var placeSpanEquipmentResult = await _commandDispatcher.HandleAsync <PlaceSpanEquipmentInUtilityNetwork, Result>(placeSpanEquipmentCommand);

            utilityNetwork.TryGetEquipment <SpanEquipment>(placeSpanEquipmentCommand.SpanEquipmentId, out var placedSpanEquipment);


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

            var diagram = getDiagramQueryResult.Value.Diagram;

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

            // Assert
            diagram.DiagramObjects.Count(o => o.Style == "FiberCable" && o.Geometry is LineString).Should().Be(1);
            diagram.DiagramObjects.Count(o => o.Label != null && o.Label.Contains("K12345678")).Should().Be(1);
        }
Exemple #4
0
        public Result PlaceCableSpanEquipment(NpgsqlCommand logCmd, Guid spanEquipmentId, string externalId, Guid specificationId, List <Guid> routeSegmentIds, List <CableConduitRel> conduitRels)
        {
            Guid correlationId = Guid.NewGuid();

            RouteNetworkElementIdList walkIds = new RouteNetworkElementIdList();

            walkIds.AddRange(routeSegmentIds);

            // Cable name
            var nextConduitSeqStr = _eventStore.Sequences.GetNextVal("cable").ToString();
            var conduitName       = "K" + nextConduitSeqStr.PadLeft(6, '0');
            var namingInfo        = new NamingInfo(conduitName, null);

            // HACK use NE id
            var neIdSplit = externalId.Split(':');

            namingInfo = new NamingInfo("K" + neIdSplit.Last(), null);

            System.Diagnostics.Debug.WriteLine("---------------------------------------------------------------------------------------------------------------------------------------");
            System.Diagnostics.Debug.WriteLine($"*** Place cable: {externalId} ***");
            System.Diagnostics.Debug.WriteLine("---------------------------------------------------------------------------------------------------------------------------------------");

            // Get validated walk of interest
            var walk = new RouteNetworkElementIdList();

            walk.AddRange(routeSegmentIds);

            var validateInterestCommand = new ValidateWalkOfInterest(correlationId, new UserContext("conversion", _workTaskId), walk);

            var validateInterestResult = _commandDispatcher.HandleAsync <ValidateWalkOfInterest, Result <ValidatedRouteNetworkWalk> >(validateInterestCommand).Result;

            if (validateInterestResult.IsFailed)
            {
                return(Result.Fail(validateInterestResult.Errors.First()));
            }

            // trace all conduits
            var conduitsTraceResult = TraceAllConduits(conduitRels);

            foreach (var conduitTrace in conduitsTraceResult)
            {
                System.Diagnostics.Debug.WriteLine($"NE conduit path found starting in {conduitTrace.ConduitName} node {conduitTrace.OriginalTrace.FromRouteNodeName} ({conduitTrace.OriginalTrace.FromRouteNodeId}) <-> {conduitTrace.OriginalTrace.ToRouteNodeName} ({conduitTrace.OriginalTrace.ToRouteNodeId}) span segment id: {conduitTrace.SpanSegmentId}");
            }

            var routingHops = BuildRouteHops(validateInterestResult.Value, conduitsTraceResult, externalId);

            System.Diagnostics.Debug.WriteLine("---------------------------------------------------------------------------------------------------------------------------------------");

            foreach (var hop in routingHops)
            {
                System.Diagnostics.Debug.WriteLine($"Routing hop: start route node id: {hop.StartRouteNode} span equipment id: {hop.StartSpanSegmentId}");
            }

            // Place cable
            var placeSpanEquipmentCommand = new PlaceSpanEquipmentInUtilityNetwork(correlationId, new UserContext("conversion", _workTaskId), spanEquipmentId, specificationId, routingHops.ToArray())
            {
                NamingInfo = namingInfo,
            };


            var placeSpanEquipmentResult = _commandDispatcher.HandleAsync <PlaceSpanEquipmentInUtilityNetwork, Result>(placeSpanEquipmentCommand).Result;

            if (placeSpanEquipmentResult.IsFailed)
            {
                var errorMsg = "Failed to route cable: " + externalId + " through conduit network: " + placeSpanEquipmentResult.Errors.First().Message;

                System.Diagnostics.Debug.WriteLine("---------------------------------------------------------------------------------------------------------------------------------------");
                System.Diagnostics.Debug.WriteLine(errorMsg);

                _logger.LogInformation(errorMsg);

                // Try place cable directly in route network
                var placeSpanEquipmentDirectlyInRouteNetworkCmd = new PlaceSpanEquipmentInUtilityNetwork(correlationId, new UserContext("conversion", _workTaskId), spanEquipmentId, specificationId,
                                                                                                         new RoutingHop[] { new RoutingHop(validateInterestResult.Value.RouteNetworkElementRefs.ToArray()) }
                                                                                                         )
                {
                    NamingInfo = namingInfo,
                };

                var placeSpanEquipmentDirectlyInRouteNetworkResult = _commandDispatcher.HandleAsync <PlaceSpanEquipmentInUtilityNetwork, Result>(placeSpanEquipmentDirectlyInRouteNetworkCmd).Result;

                if (placeSpanEquipmentDirectlyInRouteNetworkResult.IsFailed)
                {
                    errorMsg = "GENERAL FAILURE PLACING DIRECTLY IN ROUTE NETWORK: " + placeSpanEquipmentResult.Errors.First().Message + " " + errorMsg;
                }

                LogStatus((NpgsqlCommand)logCmd, _tableName, errorMsg, externalId);
                return(placeSpanEquipmentResult);
            }

            return(Result.Ok());
        }
        public async void TestDrawingCableThroughWellInsideNodeContainerHH2()
        {
            var utilityNetwork = _eventStore.Projections.Get <UtilityNetworkProjection>();

            var sutRouteNetworkElement = TestRouteNetwork.HH_2;


            // The span equipment/segment where to route the child span equipment
            var routeThroughSpanEquipmentId  = TestUtilityNetwork.MultiConduit_12x10_5x10_HH_1_to_HH_2;
            var routeThroughSpanEquipmentId2 = TestUtilityNetwork.FlexConduit_40_Red_HH_2_to_FP_2;

            utilityNetwork.TryGetEquipment <SpanEquipment>(routeThroughSpanEquipmentId, out var routeThoughSpanEquipment);
            utilityNetwork.TryGetEquipment <SpanEquipment>(routeThroughSpanEquipmentId2, out var routeThoughSpanEquipment2);

            var cable1RouteThroughSpanSegmentId1 = routeThoughSpanEquipment.SpanStructures[1].SpanSegments[0].Id;
            var cable1RouteThroughSpanSegmentId2 = routeThoughSpanEquipment2.SpanStructures[0].SpanSegments[0].Id;

            var cable2RouteThroughSpanSegmentId1 = routeThoughSpanEquipment.SpanStructures[2].SpanSegments[0].Id;
            var cable2RouteThroughSpanSegmentId2 = routeThoughSpanEquipment2.SpanStructures[0].SpanSegments[0].Id;


            // Cable 1
            var routingHops = new RoutingHop[]
            {
                new RoutingHop(TestRouteNetwork.HH_1, cable1RouteThroughSpanSegmentId1),
                new RoutingHop(TestRouteNetwork.HH_2, cable1RouteThroughSpanSegmentId2)
            };

            var placeSpanEquipmentCommand = new PlaceSpanEquipmentInUtilityNetwork(Guid.NewGuid(), new UserContext("test", Guid.Empty), Guid.NewGuid(), TestSpecifications.FiberCable_288Fiber, routingHops)
            {
                NamingInfo     = new NamingInfo("K66600000", null),
                ManufacturerId = Guid.NewGuid()
            };

            var placeSpanEquipmentResult1 = await _commandDispatcher.HandleAsync <PlaceSpanEquipmentInUtilityNetwork, Result>(placeSpanEquipmentCommand);

            // Cable 2
            var routingHops2 = new RoutingHop[]
            {
                new RoutingHop(TestRouteNetwork.HH_1, cable2RouteThroughSpanSegmentId1),
                new RoutingHop(TestRouteNetwork.HH_2, cable2RouteThroughSpanSegmentId2)
            };

            var placeSpanEquipmentCommand2 = new PlaceSpanEquipmentInUtilityNetwork(Guid.NewGuid(), new UserContext("test", Guid.Empty), Guid.NewGuid(), TestSpecifications.FiberCable_288Fiber, routingHops2)
            {
                NamingInfo     = new NamingInfo("K66700000", null),
                ManufacturerId = Guid.NewGuid()
            };

            var placeSpanEquipmentResult2 = await _commandDispatcher.HandleAsync <PlaceSpanEquipmentInUtilityNetwork, Result>(placeSpanEquipmentCommand2);

            // Assert
            placeSpanEquipmentResult1.IsSuccess.Should().BeTrue();
            placeSpanEquipmentResult2.IsSuccess.Should().BeTrue();

            var getDiagramQueryResult = await _queryDispatcher.HandleAsync <GetDiagram, Result <GetDiagramResult> >(new GetDiagram(sutRouteNetworkElement));


            var diagram = getDiagramQueryResult.Value.Diagram;

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

            // Assert
            diagram.DiagramObjects.Count(o => o.Style == "FiberCable" && o.Geometry is LineString).Should().Be(9);
        }