Exemplo n.º 1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Select your choice:");
            Console.WriteLine("1:Add new printer");
            Console.WriteLine("2:Print on Canon");
            Console.WriteLine("3:Print on Epson");
            string         pathToFile = "D:\\Epam\\Epam.ASP.NET\\LabExam\\LabExam\\bin\\Debug\\log.txt";
            ILogger        logger     = new Logger(pathToFile);
            PrinterManager manager    = new PrinterManager(logger);

            while (true)
            {
                var key = Console.ReadKey();
                if (key.Key == ConsoleKey.D1)
                {
                    manager.CreatePrinter();
                }

                if (key.Key == ConsoleKey.D2)
                {
                    manager.Print(new Printer("1", "Canon"));
                }

                if (key.Key == ConsoleKey.D3)
                {
                    manager.Print(new Printer("2", "Epson"));
                }

                for (int i = 0; i < manager.Printers.Count; i++)
                {
                    Console.WriteLine("Printers " + i + ' ' + " Name: " + manager.Printers[i].Name + " Model: " + manager.Printers[i].Model);
                }
            }
        }
Exemplo n.º 2
0
        private static void Print(Printer printer)
        {
            ILogger standartLogger = new DefaultLogger();

            PrinterManager.Print(printer, standartLogger);
            standartLogger.Log($"Printed on {printer.Model} {printer.Name}");
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            Console.WriteLine("Select your choice:");
            Console.WriteLine("0:Add new Epson printer");
            Console.WriteLine("1:Add new Canon printer");
            Console.WriteLine("2:Print on Canon");
            Console.WriteLine("3:Print on Epson");

            DefaultLogger  logger         = new DefaultLogger();
            PrinterManager printerManager = new PrinterManager(logger, new PrinterRepository());

            var epsonPrinter = new EpsonPrinter("123x");
            var canonPrinter = new CanonPrinter("123x");

            while (true)
            {
                var key = Console.ReadKey();

                if (key.Key == ConsoleKey.D0)
                {
                    printerManager.Add(epsonPrinter);
                }

                if (key.Key == ConsoleKey.D1)
                {
                    printerManager.Add(canonPrinter);
                }

                if (key.Key == ConsoleKey.D2)
                {
                    printerManager.Print(canonPrinter, @"D:\1.txt");
                }

                if (key.Key == ConsoleKey.D3)
                {
                    printerManager.Print(epsonPrinter, @"D:\1.txt");
                }

                if (key.Key == ConsoleKey.E)
                {
                    break;
                }
            }
        }
Exemplo n.º 4
0
 private static void Print(Printer printer, PrinterManager manager)
 {
     if (manager.OnStartPrinting.Invoke(printer))
     {
         manager.Print(printer);
         manager.OnEndPrinting(printer);
     }
     else
     {
         Console.WriteLine("There is no such printer");
     }
 }
Exemplo n.º 5
0
        private static void Print(Printer printer)
        {
            string fileName = "";

            if (GetFile(ref fileName))
            {
                PrinterManager.Print(printer, fileName);
            }
            else
            {
                Console.WriteLine("Wrong FileName.");
            }
        }
Exemplo n.º 6
0
        private static void Print(this PrinterManager manager, Printer printer)
        {
            if (manager == null || printer == null)
            {
                throw new ArgumentNullException($"{(nameof(manager))} cant be a null");
            }
            if (printer == null)
            {
                throw new ArgumentNullException($"{(nameof(printer))} cant be a null");
            }

            Console.WriteLine(printer.GetType());
            manager.Print(printer);
        }
        private static void Process(PrinterManager printerManager)
        {
            var key = Console.ReadKey();

            if (key.Key == ConsoleKey.D1)
            {
                printerManager.CreatePrinter();
            }
            else
            {
                int choice = Convert.ToInt32(key.KeyChar.ToString()) - 2;


                printerManager.Print(printerManager.Printers[choice]);
            }
        }
Exemplo n.º 8
0
        private static void Print(Printer printer)
        {
            if (printer == null)
            {
                throw new ArgumentNullException("{0} is null.", nameof(printer));
            }

            string fileName = "";

            if (GetFile(ref fileName))
            {
                printerManager.Print(printer, fileName);
            }
            else
            {
                Console.WriteLine("Wrong FileName.");
            }
        }
Exemplo n.º 9
0
        private static void ProcessPrinting(PrinterManager pm)
        {
            while (true)
            {
                Console.WriteLine("Select your choice:");
                Console.WriteLine("0: Exit");
                Console.WriteLine("1: Add new printer");

                ShowListOfPrinters(pm);

                var key = Console.ReadKey();

                if (key.Key == ConsoleKey.D0)
                {
                    break;
                }

                if (key.Key == ConsoleKey.D1)
                {
                    Console.WriteLine();

                    try
                    {
                        pm.CreatePrinter();
                    }
                    catch (DuplicatedPrinterException e)
                    {
                        Console.WriteLine(e.Message);
                    }

                    continue;
                }

                if (key.Key >= ConsoleKey.D2 && key.Key <= ConsoleKey.D9)
                {
                    pm.Print((int)key.Key - 50);
                }

                Console.WriteLine();
            }
        }
Exemplo n.º 10
0
 private static void Print(Printer printer)
 {
     PrinterManager.Print(printer);
     PrinterManager.Log($"Printed on {printer.Name}");
 }
Exemplo n.º 11
0
 private void Print(CanonPrinter canonPrinter)
 {
     PrinterManager.Print(canonPrinter, logger);
     logger.Info("Printed on Canon");
 }
Exemplo n.º 12
0
 private static void Print(EpsonPrinter epsonPrinter)
 {
     PrinterManager.Print(epsonPrinter);
     PrinterManager.Log("Printed on Epson");
 }
Exemplo n.º 13
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;
            }
            }
        }
Exemplo n.º 14
0
 private static void Print(Printer printer)
 {
     PrinterManager.Print(printer);
     PrinterManager.Log($"Печатается на {printer.Name}");
 }
Exemplo n.º 15
0
 private static void Print(CanonPrinter canonPrinter)
 {
     PrinterManager.Print(canonPrinter);
     PrinterManager.Log("Printed on Canon");
 }
Exemplo n.º 16
0
 private void Print(BasePrinter epsonPrinter)
 {
     PrinterManager.Print(epsonPrinter, logger);
     logger.Info("Printed on Epson");
 }
Exemplo n.º 17
0
 private static void Print(Printer Printer)
 {
     PrinterManager.Print(Printer);
     Logger.Log($"Printed on {Printer.Name}{Printer.Model}");
 }
Exemplo n.º 18
0
 /// <summary>
 /// Print Method
 /// </summary>
 /// <param name="printer"></param>
 private static void Print(Printer printer)
 {
     printerManager.Print(printer);
     logger.Log($"Printed on :{printer.Name},{printer.Model}");
 }
Exemplo n.º 19
0
 private static void Print()
 {
     PrinterManager.Print();
 }