Ejemplo n.º 1
0
        /// <summary>
        /// Returns a printer instance using the specified printer type.
        /// </summary>
        /// <param name="printerName">The name of the printer.</param>
        /// <param name="printerType">The type of the printer.</param>
        /// <returns>The printer instance.</returns>
        public static PrinterBase GetPrinter(string printerName, PrinterType printerType)
        {
            if (string.IsNullOrWhiteSpace(printerName))
            {
                throw new ArgumentException("The name of the printer cannot be null, empty nor contain only white-spaces.", nameof(printerName));
            }

            if (printer != null)
            {
                if (printer.PrinterName == printerName && printer.PrinterType == printerType)
                {
                    return(printer);
                }
            }

            if (printerType == PrinterType.Nii)
            {
                printer             = new NiiPrinter();
                printer.PrinterName = printerName;
                printer.PrinterType = printerType;
            }
            else if (printerType == PrinterType.TUP900)
            {
                printer             = new StarIOPrinter();
                printer.PrinterName = printerName;
                printer.PrinterType = printerType;
            }
            else
            {
                throw new InvalidOperationException("The printer type is not supported.");
            }

            return(printer);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Returns a printer instance.
        /// </summary>
        /// <param name="printerName">The name of the printer.</param>
        /// <returns>The printer instance.</returns>
        public static PrinterBase GetPrinter(string printerName)
        {
            if (string.IsNullOrWhiteSpace(printerName))
            {
                throw new ArgumentException("The name of the printer cannot be null, empty nor contain only white-spaces.", nameof(printerName));
            }

            if (printer != null)
            {
                if (printer.PrinterName == printerName)
                {
                    return(printer);
                }
            }

            if (printerName.Contains("NII"))
            {
                printer             = new NiiPrinter();
                printer.PrinterName = printerName;
                printer.PrinterType = PrinterType.Nii;
            }
            else if (printerName.Contains("TUP900"))
            {
                printer             = new StarIOPrinter();
                printer.PrinterName = printerName;
                printer.PrinterType = PrinterType.TUP900;
            }
            else
            {
                throw new InvalidOperationException("The printer type could not be guessed. Specify it manually.");
            }

            return(printer);
        }