Ejemplo n.º 1
0
        private Result PlaceTerminalEquipment(NpgsqlCommand logCmd, TerminalEquipmentForConversion terminalEquipment, Guid specId, RelatedEquipmentInfo relatedInfo)
        {
            Guid correlationId = Guid.NewGuid();

            var commandUserContext = new UserContext("conversion", _workTaskId)
            {
                EditingRouteNodeId = terminalEquipment.NodeId
            };

            // Check if node container already exists
            if (relatedInfo.NodeContainer == null)
            {
                if (_utilityNetwork.TryGetEquipment <NodeContainer>(relatedInfo.NodeContainer.Id, out var existingNodeContainer))
                {
                    System.Diagnostics.Debug.WriteLine($"No container exists in node: {terminalEquipment.NodeId}");
                    return(Result.Fail(new Error($"No container exists in node: {terminalEquipment.NodeId}")));
                }
            }


            var terminalEquipmentSpecificationId = GetTerminalEquipmentSpecificationIdFromName(terminalEquipment.Specification);

            if (terminalEquipmentSpecificationId == null)
            {
                return(Result.Fail(new Error($"Cannot find terminal equipment specfication: {terminalEquipment.Specification}")));
            }


            // Stand-alone splice equipment in node
            if (terminalEquipment.RackId == Guid.Empty)
            {
                var placeEqCmd = new PlaceTerminalEquipmentInNodeContainer(
                    correlationId: Guid.NewGuid(),
                    userContext: commandUserContext,
                    nodeContainerId: relatedInfo.NodeContainer.Id,
                    terminalEquipmentId: terminalEquipment.TerminalEquipmentId,
                    terminalEquipmentSpecificationId: terminalEquipmentSpecificationId.Value,
                    numberOfEquipments: 1,
                    startSequenceNumber: 1,
                    namingMethod: TerminalEquipmentNamingMethodEnum.NameOnly,
                    namingInfo: new NamingInfo(terminalEquipment.Name, null)
                    )
                {
                    AddressInfo = terminalEquipment.AccessAddressId == null ? null : new AddressInfo(terminalEquipment.AccessAddressId, terminalEquipment.UnitAddressId, null)
                };

                var placeEqResult = _commandDispatcher.HandleAsync <PlaceTerminalEquipmentInNodeContainer, Result>(placeEqCmd).Result;

                LogStatus((NpgsqlCommand)logCmd, _terminalEquipmentTableName, "external_id", terminalEquipment.ExternalId, placeEqResult);

                return(placeEqResult);
            }
            else
            {
                // Rack equipment
                var placeEqCmd = new PlaceTerminalEquipmentInNodeContainer(
                    correlationId: Guid.NewGuid(),
                    userContext: commandUserContext,
                    nodeContainerId: relatedInfo.NodeContainer.Id,
                    terminalEquipmentId: terminalEquipment.TerminalEquipmentId,
                    terminalEquipmentSpecificationId: terminalEquipmentSpecificationId.Value,
                    numberOfEquipments: 1,
                    startSequenceNumber: 80 - terminalEquipment.RackPosition,
                    namingMethod: TerminalEquipmentNamingMethodEnum.NumberOnly,
                    namingInfo: null
                    )
                {
                    SubrackPlacementInfo = new SubrackPlacementInfo(terminalEquipment.RackId, terminalEquipment.RackPosition, SubrackPlacmentMethod.BottomUp)
                };

                var placeEqResult = _commandDispatcher.HandleAsync <PlaceTerminalEquipmentInNodeContainer, Result>(placeEqCmd).Result;

                LogStatus((NpgsqlCommand)logCmd, _terminalEquipmentTableName, "external_id", terminalEquipment.ExternalId, placeEqResult);

                return(placeEqResult);
            }
        }
Ejemplo n.º 2
0
        private Result PlaceRack(NpgsqlCommand logCmd, RackForConversion rack, Guid specId, RelatedEquipmentInfo relatedInfo)
        {
            Guid correlationId = Guid.NewGuid();

            var commandUserContext = new UserContext("conversion", _workTaskId)
            {
                EditingRouteNodeId = rack.NodeId
            };

            // Check if node container already exists
            if (relatedInfo.NodeContainer == null)
            {
                if (_utilityNetwork.TryGetEquipment <NodeContainer>(relatedInfo.NodeContainer.Id, out var existingNodeContainer))
                {
                    System.Diagnostics.Debug.WriteLine($"No container exists in node: {rack.NodeId}");
                    return(Result.Fail(new Error($"No container exists in node: {rack.NodeId}")));
                }
            }

            var rackSpecId = GetRackSpecificationIdFromName(rack.Specification);

            if (rackSpecId == null)
            {
                return(Result.Fail(new Error($"Cannot find rack specfication: {rack.Specification}")));
            }

            // Place rack
            var placeRackCmd = new PlaceRackInNodeContainer(
                correlationId,
                commandUserContext,
                relatedInfo.NodeContainer.Id,
                rack.RackId,
                rackSpecId.Value,
                rack.Name,
                rack.HeightInUnits
                );

            var placeRackResult = _commandDispatcher.HandleAsync <PlaceRackInNodeContainer, Result>(placeRackCmd).Result;


            LogStatus((NpgsqlCommand)logCmd, _rackTableName, "external_id", rack.ExternalId, placeRackResult);

            return(placeRackResult);
        }
        private void ConnectSpanEquipmentsInNodeContainer(NpgsqlCommand logCmd, NodeContainerForConversion nodeContainer, RelatedEquipmentInfo relatedInfo)
        {
            foreach (var connectivity in nodeContainer.Connectivity)
            {
                if (!relatedInfo.SpanEquipmentById.ContainsKey(connectivity.FromSpanEquipmentId))
                {
                    LogStatus(logCmd, _connectivityTableName, "ogc_fid", connectivity.Key, $"Span equipment with id: {connectivity.FromSpanEquipmentId} not found in route node with id: {nodeContainer.NodeId}");
                    continue;
                }

                if (!relatedInfo.SpanEquipmentById.ContainsKey(connectivity.ToSpanEquipmentId))
                {
                    LogStatus(logCmd, _connectivityTableName, "ogc_fid", connectivity.Key, $"Span equipment with id: {connectivity.ToSpanEquipmentId} not found in route node with id: {nodeContainer.NodeId}");
                    continue;
                }

                // We need adjust index 1 to index 0 on single conduits
                var fromSpanEquipment = relatedInfo.SpanEquipmentById[connectivity.FromSpanEquipmentId];
                var toSpanEquipment   = relatedInfo.SpanEquipmentById[connectivity.ToSpanEquipmentId];

                int fromStructureIndex = fromSpanEquipment.SpanStructures.Length == 1 ? connectivity.FromStructureIndex - 1 : connectivity.FromStructureIndex;
                int toStructureIndex   = toSpanEquipment.SpanStructures.Length == 1 ? connectivity.ToStructureIndex - 1 : connectivity.ToStructureIndex;

                var connectResult = ConnectSpanEquipments(nodeContainer.NodeId, connectivity.FromSpanEquipmentId, connectivity.ToSpanEquipmentId, (ushort)fromStructureIndex, (ushort)toStructureIndex, connectivity.NumberOfUnits);

                if (connectResult.IsFailed)
                {
                    LogStatus((NpgsqlCommand)logCmd, _connectivityTableName, "ogc_fid", connectivity.Key, connectResult.Errors.First().Message);
                }

                LogStatus(logCmd, _connectivityTableName, "ogc_fid", connectivity.Key, connectResult);
            }
        }
        private Result PlaceNodeContainer(NpgsqlCommand logCmd, NodeContainerForConversion nodeContainer, Guid specId, RelatedEquipmentInfo relatedInfo)
        {
            Guid correlationId = Guid.NewGuid();

            var commandUserContext = new UserContext("conversion", _workTaskId)
            {
                EditingRouteNodeId = nodeContainer.NodeId
            };

            // Check if node container already exists
            if (relatedInfo.NodeContainer != null)
            {
                if (_utilityNetwork.TryGetEquipment <NodeContainer>(relatedInfo.NodeContainer.Id, out var existingNodeContainer))
                {
                    System.Diagnostics.Debug.WriteLine($"Node container alreadu exists in node: {nodeContainer.NodeId}");
                    return(Result.Ok());
                }
            }

            // First register the node of interest where to place the node container
            var nodeOfInterestId = Guid.NewGuid();

            var registerNodeOfInterestCommand = new RegisterNodeOfInterest(correlationId, commandUserContext, nodeOfInterestId, nodeContainer.NodeId);

            var registerNodeOfInterestCommandResult = _commandDispatcher.HandleAsync <RegisterNodeOfInterest, Result <RouteNetworkInterest> >(registerNodeOfInterestCommand).Result;

            if (registerNodeOfInterestCommandResult.IsFailed)
            {
                LogStatus((NpgsqlCommand)logCmd, _nodeContainerTableName, registerNodeOfInterestCommandResult.Errors.First().Message, nodeContainer.ExternalId);
                return(registerNodeOfInterestCommandResult);
            }

            // Now place the node container in the walk
            var placeNodeContainerCommand = new PlaceNodeContainerInRouteNetwork(correlationId, commandUserContext, nodeContainer.NodeContainerId, specId, registerNodeOfInterestCommandResult.Value)
            {
                ManufacturerId = null,
                LifecycleInfo  = new LifecycleInfo(DeploymentStateEnum.InService, null, null)
            };

            var placeNodeContainerResult = _commandDispatcher.HandleAsync <PlaceNodeContainerInRouteNetwork, Result>(placeNodeContainerCommand).Result;

            // Unregister interest if place node container failed
            if (placeNodeContainerResult.IsFailed)
            {
                LogStatus((NpgsqlCommand)logCmd, _nodeContainerTableName, placeNodeContainerResult.Errors.First().Message, nodeContainer.ExternalId);

                var unregisterCommandResult = _commandDispatcher.HandleAsync <UnregisterInterest, Result>(new UnregisterInterest(correlationId, commandUserContext, nodeOfInterestId)).Result;

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

            LogStatus((NpgsqlCommand)logCmd, _nodeContainerTableName, "external_id", nodeContainer.ExternalId, placeNodeContainerResult);

            return(placeNodeContainerResult);
        }
        private void AffixSpanEquipmentsToNodeContainer(NpgsqlCommand logCmd, NodeContainerForConversion nodeContainer, RelatedEquipmentInfo relatedInfo)
        {
            if (!relatedInfo.SingleConduitsOnly)
            {
                foreach (var ingoingSpanEquipment in relatedInfo.IngoingSpanEquipments)
                {
                    if (ingoingSpanEquipment.SpanStructures.Length == 1)
                    {
                        AffixSpanEquipmentToContainer(nodeContainer.NodeId, ingoingSpanEquipment.Id, nodeContainer.NodeContainerId, NodeContainerSideEnum.North);
                    }
                    else
                    {
                        AffixSpanEquipmentToContainer(nodeContainer.NodeId, ingoingSpanEquipment.Id, nodeContainer.NodeContainerId, NodeContainerSideEnum.West);
                    }
                }

                foreach (var outgoingSpanEquipment in relatedInfo.OutgoingSpanEquipments)
                {
                    if (outgoingSpanEquipment.SpanStructures.Length == 1)
                    {
                        AffixSpanEquipmentToContainer(nodeContainer.NodeId, outgoingSpanEquipment.Id, nodeContainer.NodeContainerId, NodeContainerSideEnum.North);
                    }
                    else
                    {
                        AffixSpanEquipmentToContainer(nodeContainer.NodeId, outgoingSpanEquipment.Id, nodeContainer.NodeContainerId, NodeContainerSideEnum.East);
                    }
                }
            }
            else
            {
                foreach (var ingoingSpanEquipment in relatedInfo.IngoingSpanEquipments)
                {
                    AffixSpanEquipmentToContainer(nodeContainer.NodeId, ingoingSpanEquipment.Id, nodeContainer.NodeContainerId, NodeContainerSideEnum.West);
                }

                foreach (var outgoingSpanEquipment in relatedInfo.OutgoingSpanEquipments)
                {
                    AffixSpanEquipmentToContainer(nodeContainer.NodeId, outgoingSpanEquipment.Id, nodeContainer.NodeContainerId, NodeContainerSideEnum.East);
                }
            }
        }