Exemplo n.º 1
0
        /// <summary>
        /// Creates the printer.
        /// </summary>
        private static void CreatePrinter()
        {
            Console.WriteLine("Creating new printer...\n");
            Console.WriteLine("Choose printer model:");
            Console.WriteLine("1. Canon");
            Console.WriteLine("2. Epson");
            var consoleKeyInfo = Console.ReadKey();

            Console.WriteLine("Enter printer model:");
            var model = Console.ReadLine();

            Printer newPrinter;
            var     manager = PrinterManager.Instance;

            if (consoleKeyInfo.Key == ConsoleKey.D1)
            {
                newPrinter = PrinterFactory.CreatePrinter("Canon", model);
            }
            else if (consoleKeyInfo.Key == ConsoleKey.D2)
            {
                newPrinter = PrinterFactory.CreatePrinter("Epson", model);
            }
            else
            {
                return;
            }

            manager.Add(newPrinter);
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            PrinterFactory factory = new PrinterFactory();

            while (true)
            {
                Console.WriteLine("Select your choice:");
                Console.WriteLine("1:Add new printer");
                Console.WriteLine("2:Print on Canon");
                Console.WriteLine("3:Print on Epson");

                var key = Console.ReadKey();

                if (key.Key == ConsoleKey.D1)
                {
                    Console.WriteLine("Enter printer model");
                    string model = Console.ReadLine();
                    Console.WriteLine("Enter printer name");
                    string name = Console.ReadLine();
                    factory.CreatePrinter(name, model);
                }

                if (key.Key == ConsoleKey.D2)
                {
                    Console.WriteLine("Enter printer name");
                    string name = Console.ReadLine();
                    PrinterManager.Instance.Print(new CanonPrinter(name, "Canon"));
                }

                if (key.Key == ConsoleKey.D3)
                {
                    Console.WriteLine("Enter printer name");
                    string name = Console.ReadLine();
                    PrinterManager.Instance.Print(new EpsonPrinter(name, "Epson"));
                }
            }
        }
Exemplo n.º 3
0
 private static void CreatePrinter(string name, string model)
 {
     PrinterManager.Manager.Logger = new DefaultLogger("log.txt");
     PrinterManager.Manager.Add(PrinterFactory.CreateNewPrinter(name, model));
 }
Exemplo n.º 4
0
        /// <summary>
        /// Analyze input.
        /// </summary>
        /// <param name="printerManager">The printer manager.</param>
        public static void Analyzer(PrinterManager printerManager)
        {
            var UserInput = Console.ReadKey();
            int bowl      = 0;

            if (char.IsNumber(UserInput.KeyChar))
            {
                bowl = int.Parse(UserInput.KeyChar.ToString());
                Console.WriteLine("\nВыбран пункт : {0}", bowl);
            }
            else
            {
                bowl = -1;
            }

            switch (bowl)
            {
            case -1:
            {
                Console.Clear();
                Console.WriteLine("Ошибка ввода");
                Console.ReadKey();
                break;
            }

            case 1:
            {
                Console.WriteLine("Enter printer name");
                string Name = Console.ReadLine();
                Console.WriteLine("Enter printer model");
                string Model = Console.ReadLine();
                printerManager.TryAdd(PrinterFactory.CreatePrinter(Name, Model));
                break;
            }

            case 2:
            {
                new CanonPrinter().Print(File.OpenRead(OpenFile()));
                Console.ReadKey();
                break;
            }

            case 3:
            {
                new EpsonPrinter().Print(File.OpenRead(OpenFile()));
                Console.ReadKey();
                break;
            }

            default:
            {
                bowl = bowl - 4;
                if (bowl <= printerManager.GetPrinters().Count)
                {
                    printerManager.Print(printerManager.GetPrinters().ElementAt(bowl), OpenFile());
                }
                else
                {
                    Console.WriteLine("Пункт меню отсутствует!" + printerManager.GetPrinters().Count);
                }
                Console.ReadKey();
                break;
            }
            }
        }