Beispiel #1
0
        private static IPrinterConnector _printSerialMenu()
        {
            var portName = ConsoleHelpers.PromptLine("Port name:");

            var baudRate        = 0;
            var baudRateIsValid = false;

            while (!baudRateIsValid)
            {
                baudRateIsValid = int.TryParse(ConsoleHelpers.PromptLine("Baud rate:"), out baudRate);

                if (!baudRateIsValid)
                {
                    ConsoleHelpers.WriteErrorLine("Baud rate must be an integer number, try again.");
                }
            }

            return(new SerialPortConnector(portName, baudRate));
        }
Beispiel #2
0
        private static IPrinterConnector _printNetworkMenu()
        {
            var       addressIsValid = false;
            IPAddress ipAddress      = null;

            while (!addressIsValid)
            {
                addressIsValid = IPAddress.TryParse(ConsoleHelpers.PromptLine("IP Address:"), out ipAddress);

                if (!addressIsValid)
                {
                    ConsoleHelpers.WriteErrorLine("IP Address is not valid, try again.");
                }
            }

            var portIsValid = false;
            int port        = 0;

            while (!portIsValid)
            {
                if (int.TryParse(ConsoleHelpers.PromptLine("TCP Port (ej 9100):"), out port))
                {
                    if (port >= 0 && port < 65535)
                    {
                        portIsValid = true;
                    }
                }

                if (!portIsValid)
                {
                    ConsoleHelpers.WriteErrorLine("Port number is not valid, try again.");
                }
            }

            return(new NetworkPrinterConnector(ipAddress, port));
        }