Example #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");
                }
            }
        }
        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!");
            }
        }
Example #3
0
        public static void Print(CanonPrinter p1)
        {
            Log("Print started");
            var o = new OpenFileDialog();

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

            p1.Print(f);
            Log("Print finished");
        }
        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
            }
        }
 private void Print(CanonPrinter canonPrinter)
 {
     PrinterManager.Print(canonPrinter, logger);
     logger.Info("Printed on Canon");
 }
Example #7
0
 private static void Print(CanonPrinter canonPrinter)
 {
     PrinterManager.Print(canonPrinter);
     PrinterManager.Log("Printed on Canon");
 }
Example #8
0
        private static void CreatePrinterCanon()
        {
            CanonPrinter canonPrinter = new CanonPrinter();

            canonPrinter.Register();
        }