예제 #1
0
        public static void AddPort(this Computer comp, string protocol, int portNum, string displayName)
        {
            var record = PortManager.GetPortRecordFromProtocol(protocol);

            if (record == null)
            {
                record = new PortRecord(protocol, displayName, portNum);
            }
            comp.AddPort(record.CreateState(null, displayName, portNum));
        }
예제 #2
0
        public static void AddPort(this Computer comp, PortRecord record)
        {
            record.ThrowNull(nameof(record));
            if (!PortManager.IsPortRecordRegistered(record))
            {
                Logger.Log(LogLevel.Warning, $"Protocol '{record.Protocol}' not registered, please correct, this will crash in 6.0.0");
                PortManager.RegisterPort(record);
            }

            comp.AddPort(record.CreateState(comp));
        }
예제 #3
0
        public static void LoadPortsFromChildren(Computer comp, IEnumerable <ElementInfo> children, bool clearAll)
        {
            if (clearAll)
            {
                comp.ClearPorts();
            }
            foreach (var element in children)
            {
                var protocol = element.Name;
                if (element.Attributes.GetString("Remove")?.ToLower() == "true")
                {
                    comp.RemovePort(protocol);
                    continue;
                }
                var portNumString = element.Attributes.GetString("Number", null);
                var displayName   = element.Attributes.GetString("Display", null);
                if (element.Content != null)
                {
                    displayName = element.Content;
                }
                var numElement     = element.Children.GetElement("Number");
                var displayElement = element.Children.GetElement("Display");
                if (numElement != null)
                {
                    portNumString = numElement.Content;
                }
                if (displayElement != null)
                {
                    displayName = displayElement.Content;
                }
                var record  = GetPortRecordFromProtocol(protocol);
                int portNum = -1;
                if (record == null)
                {
                    if (portNumString == null || displayName == null)
                    {
                        throw new ArgumentException($"Protocol '{protocol}' does not exist");
                    }

                    if (!int.TryParse(portNumString, out portNum))
                    {
                        throw new FormatException($"Unable to parse port number for protocol '{protocol}'");
                    }

                    PortManager.RegisterPort(protocol, displayName, portNum);
                }
                else if (portNumString != null && !int.TryParse(portNumString, out portNum))
                {
                    throw new FormatException($"Unable to parse port number for protocol '{protocol}'");
                }

                var state = comp.GetPortState(protocol);
                if (state != null)
                {
                    if (displayName != null)
                    {
                        state.DisplayName = displayName;
                    }
                    if (portNumString != null)
                    {
                        state.PortNumber = portNum;
                    }
                    continue;
                }

                comp.AddPort(protocol, portNum, displayName);
            }
        }
예제 #4
0
 private static bool LoadPortsIntoComputerReplacement(string portsList, object computer_obj)
 {
     PortManager.LoadPortsFromStringVanilla((Computer)computer_obj, portsList);
     return(false);
 }