Esempio n. 1
0
        private Dictionary <Guid, TerminalEquipmentForConversion> LoadTerminalEquipmentsToBeImportedFromDatabase()
        {
            Dictionary <Guid, TerminalEquipmentForConversion> termianEquipmentsForConversions = new();

            using var dbConn = GetConnection();

            // Load terminal equipments
            using var terminalEquipmentSelectCmd   = dbConn.CreateCommand();
            terminalEquipmentSelectCmd.CommandText = "SELECT external_id, external_spec, route_node_id, terminal_equipment_id, specification, name, rack_id, rack_position, access_address_id, unit_address_id FROM " + _terminalEquipmentTableName + " WHERE status is null ORDER BY external_id";

            using var terminalEquipmentReader = terminalEquipmentSelectCmd.ExecuteReader();

            while (terminalEquipmentReader.Read())
            {
                var terminalEquipment = new TerminalEquipmentForConversion();

                var externalSpec = terminalEquipmentReader.GetString(1).Trim();

                terminalEquipment.ExternalId          = terminalEquipmentReader.GetString(0).Trim();
                terminalEquipment.NodeId              = Guid.Parse(terminalEquipmentReader.GetString(2));
                terminalEquipment.TerminalEquipmentId = Guid.Parse(terminalEquipmentReader.GetString(3));
                terminalEquipment.Specification       = terminalEquipmentReader.GetString(4).Trim();
                terminalEquipment.Name            = terminalEquipmentReader.GetString(5).Trim();
                terminalEquipment.RackId          = Guid.Parse(terminalEquipmentReader.GetString(6));
                terminalEquipment.RackPosition    = Int32.Parse(terminalEquipmentReader.GetString(7).Trim());
                terminalEquipment.AccessAddressId = terminalEquipmentReader.IsDBNull(8) || terminalEquipmentReader.GetString(8) == "" ? null : Guid.Parse(terminalEquipmentReader.GetString(8));
                terminalEquipment.UnitAddressId   = terminalEquipmentReader.IsDBNull(9) || terminalEquipmentReader.GetString(9) == "" ? null : Guid.Parse(terminalEquipmentReader.GetString(9));

                termianEquipmentsForConversions.Add(terminalEquipment.TerminalEquipmentId, terminalEquipment);
            }

            dbConn.Close();

            return(termianEquipmentsForConversions);
        }
Esempio n. 2
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);
            }
        }