Exemplo n.º 1
0
        public static void Add()
        {
            Console.WriteLine("Enter printer name");
            string name = Console.ReadLine();

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


            if (!Printers.Where(p => p.Name == name).Any())
            {
                if (string.Compare(model, "Canon", StringComparison.OrdinalIgnoreCase) == 0)
                {
                    var p1 = new CanonPrinter(name, model);
                    Printers.Add(p1);
                    Console.WriteLine("Printer added");
                }
                else if (string.Compare(model, "Epson", StringComparison.OrdinalIgnoreCase) == 0)
                {
                    var p1 = new EpsonPrinter(name, model);
                    Printers.Add(p1);
                    Console.WriteLine("Printer added");
                }
                else
                {
                    Console.WriteLine("Unknown printer model");
                }
            }
        }
Exemplo n.º 2
0
        private static void CreatePrinter()
        {
            string  name = "RandomPrinter";
            Printer printer;

            Console.Clear();
            Console.WriteLine("Choose a model:\n1.Canon\n2.Epson\n3.Other");
            var key = Console.ReadKey();

            Console.Clear();

            try
            {
                if (key.Key == ConsoleKey.D3)
                {
                    Console.WriteLine("Enter printer name");
                    name = Console.ReadLine();
                }

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

                switch (key.Key)
                {
                case ConsoleKey.D1:
                {
                    printer = new CanonPrinter(model);
                    break;
                }

                case ConsoleKey.D2:
                {
                    printer = new EpsonPrinter(model);
                    break;
                }

                default:
                {
                    printer = new RandomPrinter(name, model);
                    break;
                }
                }

                try
                {
                    printerManager.Add(printer);
                    Console.WriteLine("Printer added.");
                }
                catch (InvalidOperationException)
                {
                    Console.WriteLine("Printer already exists.");
                }
            }
            catch (ArgumentNullException)
            {
                Console.WriteLine("Name or Model can't be empty!");
            }
        }
Exemplo n.º 3
0
        public static void Print(EpsonPrinter p1)
        {
            Log("Print started");
            var o = new OpenFileDialog();

            o.ShowDialog();
            var f = File.OpenRead(o.FileName);

            p1.Print(f);
            Log("Print finished");
        }
Exemplo n.º 4
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;
                }
            }
        }
        static void Main(string[] args)
        {
            var canon = new CanonPrinter("Canon", "1454");
            var epson = new EpsonPrinter("Epson", "1231");

            var manager = new PrinterManager();

            canon.Register(manager);
            epson.Register(manager);
            manager.SimulateNewPrint("Start");

            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)
            {
                CreatePrinter();
            }

            if (key.Key == ConsoleKey.D2)
            {
                Print(canon);
            }

            if (key.Key == ConsoleKey.D3)
            {
                Print(epson);
            }

            while (true)
            {
                // waiting
            }
        }
Exemplo n.º 6
0
 private static void Print(EpsonPrinter epsonPrinter)
 {
     PrinterManager.Print(epsonPrinter);
     PrinterManager.Log("Printed on Epson");
 }
Exemplo n.º 7
0
        private static void CreatePrinterEpson()
        {
            EpsonPrinter epsonPrinter = new EpsonPrinter();

            epsonPrinter.Register();
        }