예제 #1
0
        static void Main(string[] args)
        {
            Printer       printer       = new Printer();
            ColourPrinter colourPrinter = new ColourPrinter();
            PhotoPrinter  photoPrinter  = new PhotoPrinter();

            string[] strings = { "Message1", "Message2", "Message3" };

            Image[] images = { new Image()
                               {
                                   Name = "picture1.jpeg"
                               },
                               new Image()
                               {
                                   Name = "picture2.jpeg"
                               },
                               new Image()
                               {
                                   Name = "picture2.jpeg"
                               } };

            Console.WriteLine("Сalling a extension method of Printer!");
            printer.Print(strings);

            Console.WriteLine("\nСalling a extension method of ColourPrinter!");
            colourPrinter.Print(strings, ConsoleColor.DarkGreen);

            Console.WriteLine("\nСalling a extension method of PhotoPrinter!");
            photoPrinter.Print(images);

            Console.ReadLine();
        }
예제 #2
0
        static void Main(string[] args)
        {
            BlackAndWhitePrinter bawPrinter = new BlackAndWhitePrinter();
            Secretary            eva        = new Secretary(bawPrinter);

            eva.Print("Secretary's bill");

            Console.WriteLine();

            ColourPrinter cPrinter    = new ColourPrinter();
            Director      herrSchulte = new Director(cPrinter);

            herrSchulte.Print("Director's order");

            Console.WriteLine();

            MatrixPrinter mPrinter = new MatrixPrinter();
            Trainee       kevin    = new Trainee(mPrinter);

            kevin.Print("Trainee's project");

            Console.WriteLine();

            PDFPrinter pdfPrinter = new PDFPrinter();
            Developer  heiko      = new Developer(pdfPrinter);

            heiko.Print("Developer's source code");

            Console.ReadKey();
        }
예제 #3
0
 public CommandException(string message)
     : base(message)
 {
     // Write an error message on the screen.
     ColourPrinter.Print($"Error! {message}",
                         ConsoleColor.White, ConsoleColor.Red);
 }
예제 #4
0
 public static void Multiprint(this ColourPrinter cprinter, string[] messages, ConsoleColor color)
 {
     foreach (string message in messages)
     {
         cprinter.Print(message, color);
     }
 }
예제 #5
0
        static void Main(string[] args)
        {
            var stringsToDisplay = new [] { "Some information to display", "Another information to display" };

            Console.WriteLine("The printer prints information...");
            var printer = new Printer();

            printer.Print(stringsToDisplay);
            Console.WriteLine();

            var colorStrings = new ColorString[]
            {
                new ColorString("Some information to display", ConsoleColor.Yellow),
                new ColorString("Another information to display", ConsoleColor.Red)
            };

            Console.WriteLine("The colour printer prints information...");
            var colorPrinter = new ColourPrinter();

            colorPrinter.Print(colorStrings);
            Console.WriteLine();

            var images = new Bitmap[]
            {
                new Bitmap("C:\\Users\\eugen\\Documents\\ASPdotNET_logo.jpg"),
                new Bitmap("C:\\Users\\eugen\\Documents\\VeriSignLogo.jpg")
            };

            Console.WriteLine("The photo printer prints information...");
            var photoPrinter = new PhotoPrinter();

            photoPrinter.Print(images);
            Console.WriteLine();
        }
예제 #6
0
 public static void PrintColorArray(this ColourPrinter colourPrinter, string[] array, ConsoleColor[] color)
 {
     for (int i = 0; i < array.Length; i++)
     {
         colourPrinter.Print(array[i], color[i]);
     }
 }
예제 #7
0
 public static void Print(this ColourPrinter colorPrinter, ColorString[] colorStrings)
 {
     foreach (var colorString in colorStrings)
     {
         colorPrinter.Print(colorString.StringToDisplay, colorString.Color);
     }
 }
예제 #8
0
        static void Main(string[] args)
        {
            Printer printer = new Printer();

            ColourPrinter colourPrinter = new ColourPrinter();

            PhotoPrinter photoPrinter = new PhotoPrinter();


            printer.Print("My  printer");
            colourPrinter.Print("A1", Colour.Green);

            photoPrinter.Print("A1", Images.Sumssung);


            Printer[] prArr = new  Printer[10];
            prArr.HandleArrayPrinter();

            ColourPrinter [] cprArr = new ColourPrinter[2];
            cprArr.HandleArrayColourPrinter();

            PhotoPrinter[] phprArr = new PhotoPrinter[7];
            phprArr.HandleArrayPhotoPrinter();


            Console.ReadKey();
        }
예제 #9
0
        static void Main(string[] args)
        {
            ColourPrinter.Print("<==== Create Simplified Driver ====>", ConsoleColor.Green);
            ColourPrinter.Print("-- Enter the package in the format: P[COMMAND_CHARACTER][:][PARAMETERS][:]E", ConsoleColor.Green);

            // Buffer for entered characters in the console.
            StringBuilder       stringBuilder = new StringBuilder();
            Packet              packet;
            CommandValidator    commandValidator    = new CommandValidator(new Regex(@"^P[A-Za-z]+:.+:E$"));
            ConsoleEventHandler consoleEventHandler = new ConsoleEventHandler(commandValidator);

            while (true)
            {
                try
                {
                    ConsoleKeyInfo keyPress = Console.ReadKey(true);
                    char           input    = keyPress.KeyChar;

                    // We allow you to enter only characters from the table ASCII (32 - 127).
                    if ((int)input >= 32 && (int)input <= 127)
                    {
                        Console.Write(input);

                        stringBuilder.Append(input);
                    }
                    // When you press "Enter" - clear the buffer and throw the code "NACK".
                    if ((int)input == 13)
                    {
                        stringBuilder.Clear();
                        ColourPrinter.Print("\nNACK", ConsoleColor.Red);
                    }

                    // Check the validity of the entered package and process it.
                    if (commandValidator.IsValid(stringBuilder.ToString()))
                    {
                        packet = commandValidator.GetPacketFromStr(stringBuilder.ToString());

                        consoleEventHandler.HandlePacket(packet);

                        // We clear the buffer after processing the packet.
                        stringBuilder.Clear();
                    }
                }
                catch (CommandException cmdEx)
                {
                    // In the future - some kind of action.
                }
                catch (Exception ex)
                {
                    // In case of an error, we throw the code "NACK".
                    ColourPrinter.Print("\nNACK", ConsoleColor.Red);
                    // We clear the console buffer.
                    stringBuilder.Clear();
                    // Display error message.
                    ColourPrinter.Print(ex.Message, ConsoleColor.White, ConsoleColor.Red);
                }
            }
        }
예제 #10
0
        public static void Print(this List <ColourPrinterParams> colourPrinterParams)
        {
            var coloutPrinter = new ColourPrinter();

            foreach (var colourPrinterParam in colourPrinterParams)
            {
                coloutPrinter.Print(colourPrinterParam.Text, colourPrinterParam.Color);
            }
        }
예제 #11
0
 public static void WorkingWithArrayOfStringAndColors(this ColourPrinter colorPrinter, string[] list, ConsoleColor[] color)
 {
     for (var i = 0; i < list.Length; i++)
     {
         var j = i;
         j = j >= color.Length ? 0 : j;
         colorPrinter.Print(list[i], color[j]);
     }
 }
예제 #12
0
 public static void ExtendedColourPrint(this ColourPrinter colourPrinter, string[] arguments, ConsoleColor[] colors)
 {
     foreach (ConsoleColor col in colors)
     {
         foreach (string arg in arguments)
         {
             colourPrinter.Print(arg, col);
         }
     }
 }
예제 #13
0
        public static void ExtPrint(this ColourPrinter printer, string[] messages, ConsoleColor[] colors)
        {
            Console.WriteLine("Extention method for class ColourPrinter");

            for (int i = 0; i < colors.Length; i++)
            {
                Console.BackgroundColor = colors[i];
                Console.WriteLine(messages[i]);
                Console.ResetColor();
            }
        }
 public static void Print(ColourPrinter printer, string[] str, string[] colArr)
 {
     foreach (string msg in str)
     {
         foreach (string colour in colArr)
         {
             printer.Print(msg, colour);
         }
         Console.WriteLine();
     }
 }
예제 #15
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            ColourPrinter cprinter  = new ColourPrinter();
            PhotoPrinter  phprinter = new PhotoPrinter();

            string[] texttoprint   = new [] { "1", "2" };
            string[] textandcolour = new[] { "1", "red" };
            object[] photos        = new[] { "1", "2" };

            ExtensionMethods.PrintText(cprinter, texttoprint);
            ExtensionMethods.PrintTextAndColour(cprinter, textandcolour);
            ExtensionMethods.PrintPhoto(phprinter, photos);
        }
예제 #16
0
 public static void Print(this ColourPrinter colourPrinter, string[] text, ConsoleColor[] colors)
 {
     for (int i = 0; i < text.Length; i++)
     {
         if (i > colors.Length - 1)
         {
             colourPrinter.Print(text[i], colors[0]);
         }
         else
         {
             colourPrinter.Print(text[i], colors[i]);
         }
     }
 }
 public static void Print(this ColourPrinter colourPrinter, string[] strings, int[] colors)
 {
     if (strings.Length == colors.Length)
     {
         for (int i = 0; i < colors.Length; i++)
         {
             colourPrinter.Print(strings[i], colors[i]);
         }
     }
     else
     {
         Console.WriteLine("ERROR: Input arrays have different dimentions!");
     }
 }
예제 #18
0
 public static void PrintArrayOfColouredText(this ColourPrinter colourPrinter, string[] textArray, ConsoleColor[] colours)
 {
     for (var i = 0; i < textArray.Length; i++)
     {
         if (i < colours.Length)
         {
             colourPrinter.Print(textArray[i], colours[i]);
         }
         else
         {
             colourPrinter.Print(textArray[i]);
         }
     }
 }
예제 #19
0
        static void Main(string[] args)
        {
            Printer       mainPrinter   = new Printer();
            PhotoPrinter  photoPrinter  = new PhotoPrinter();
            ColourPrinter colourPrinter = new ColourPrinter();

            string[]       mainArguments   = { "First main test print", "Second main test print", "Third main test print" };
            Photo[]        photos          = { new Photo("100x100", true, 1), new Photo("200x200", false, 2), new Photo("300x300", true, 3) };
            string[]       colourArguments = { "First colour test print", "Second colour test print", "Third colour test print" };
            ConsoleColor[] colors          = { ConsoleColor.DarkGreen, ConsoleColor.DarkMagenta, ConsoleColor.DarkRed };

            mainPrinter.ExtendedPrint(mainArguments);
            photoPrinter.ExtendedPhotoPrint(photos);
            colourPrinter.ExtendedColourPrint(colourArguments, colors);
        }
예제 #20
0
        static void Main(string[] args)
        {
            var printer = new Printer.Printer();

            printer.Multiprint(new string[] { "message one", "message two" });

            var colourPrinter = new ColourPrinter();

            colourPrinter.Multiprint(new string[] { "colour message one", "colour message two" }, ConsoleColor.DarkCyan);

            var photoPrinter = new PhotoPrinter();

            photoPrinter.Multiprint(new Image[] { Image.FromFile("maidukov1.jpg"), Image.FromFile("capricorn.png") });

            Console.ReadLine();
        }
예제 #21
0
        static void Main(string[] args)
        {
            var printer = new Printer();

            printer.Multiprint(new string[] { "text1", "text2" });

            var cprinter = new ColourPrinter();

            cprinter.Multiprint(new string[] { "colortext1", "colortext2" }, ConsoleColor.DarkYellow);

            var pprinter = new PhotoPrinter();

            pprinter.Multiprint(new string[] { "photo printer text 1", "photo printer text 2" }, "PHOTO");

            Console.ReadLine();
        }
예제 #22
0
        static void Main(string[] args)
        {
            var printer       = new Printer();
            var colourPrinter = new ColourPrinter();
            var photoPrinter  = new PhotoPrinter();

            printer.PrintArrayOfText(new string[] { "hello ", "world" });

            colourPrinter.PrintArrayOfColouredText(new string[] { "colour ", "text", "example" },
                                                   new ConsoleColor[] { ConsoleColor.Blue, ConsoleColor.Red });

            photoPrinter.PrintArrayOfPhotos(new Image[] { new Image("Image1"), new Image("Image2") });


            Console.ReadLine();
        }
예제 #23
0
        static void Main(string[] args)
        {
            Printer.Printer printer       = new Printer.Printer();
            ColourPrinter   colourPrinter = new ColourPrinter();
            PhotoPrinter    photoPrinter  = new PhotoPrinter();

            string[]       message = { "message1", "message2", "message3" };
            ConsoleColor[] color   = { ConsoleColor.Blue, ConsoleColor.Yellow, ConsoleColor.Magenta };
            string[]       photo   = { "photo1", "photo2", "photo3" };

            printer.ExpansionToPrinter(message, 0);
            colourPrinter.ExpansionToColourPrinte(message, color, 1);
            colourPrinter.ExpansionToPrinter(message, 1);
            photoPrinter.ExpansionToPhotoPrinter(message, photo, 2);
            photoPrinter.ExpansionToPrinter(message, 2);

            Console.ReadKey();
        }
예제 #24
0
        static void Main(string[] args)
        {
            Printer printer = new Printer();

            printer.PrintAll("This", "is", "a", "long", "message");

            Console.WriteLine();

            ColourPrinter colPrinter = new ColourPrinter();

            colPrinter.PrintAll(new Tuple <string, ConsoleColor>("Colourful", ConsoleColor.DarkBlue), new Tuple <string, ConsoleColor>("message", ConsoleColor.Red));

            Console.WriteLine();

            PhotoPrinter photoPr = new PhotoPrinter();

            photoPr.PrintAll(new Photo(), new Photo("Custom photo"), new Photo());

            Console.ReadKey();
        }
예제 #25
0
        static void Main(string[] args)
        {
            var list = new string[5];

            for (var i = 0; i < 5; i++)
            {
                list[i] = $"Number {i}";
            }
            var colors  = new[] { ConsoleColor.Blue, ConsoleColor.Red, ConsoleColor.Magenta, ConsoleColor.DarkYellow };
            var imgs    = new Img[4];
            var printer = new Printer();

            printer.WorkingWithArrayOfString(list);
            var colorPrinter = new ColourPrinter();

            colorPrinter.WorkingWithArrayOfStringAndColors(list, colors);
            var photoPrinter = new PhotoPrinter();

            photoPrinter.WorkingWithArrayOfImg(imgs);
            Console.ReadKey();
        }
예제 #26
0
        static void Main(string[] args)
        {
            string[]       message = { "Message 1", " Message 2" };
            ConsoleColor[] color   = { ConsoleColor.DarkRed, ConsoleColor.Yellow };
            string[]       photos  = { "Small dog", "Fat cat" };
            var            printer = new Printer();

            printer.ExtPrint(message);

            Console.WriteLine();
            var colourPrinter = new ColourPrinter();

            colourPrinter.ExtPrint(message, color);

            Console.WriteLine();
            var photoPrinter = new PhotoPrinter();

            photoPrinter.ExtPrint(message, photos);

            Console.ReadLine();
        }
예제 #27
0
        static void Main(string[] args)
        {
            var p1 = new Printer();

            string[] str = new string[5];
            str[0] = "s0";
            str[1] = "s1";
            str[2] = "s2";
            str[3] = "s3";
            str[4] = "s4";
            ExtensionMethods.Print(p1, str);
            p1 = new PhotoPrinter();
            ExtensionMethods.Print(p1, str);
            string[] col = new string[5];
            col[0] = "Green";
            col[1] = "Yellow";
            col[2] = "Cyan";
            col[3] = "Red";
            col[4] = "Mayonnaise";
            var p2 = new ColourPrinter();

            ExtensionMethods.Print(p2, str, col);
        }
예제 #28
0
        static void Main(string[] args)
        {
            var printer       = new Printer();
            var colourPrinter = new ColourPrinter();
            var photoPrinter  = new PhotoPrinter();

            object photo = "Photo2", photo1 = "Photo1";

            Console.WriteLine("Printer");
            printer.PrintSomeArray("Some Text", "Some Text2", "Some Text3");

            Console.WriteLine("------------------");

            Console.WriteLine("Coluor Printer");
            colourPrinter.PrintColorArray(new string[] { "Some text", "Some Text1" }, new ConsoleColor[] { ConsoleColor.Red, ConsoleColor.DarkGreen });

            Console.WriteLine("------------------");

            Console.WriteLine("Photo Printer");
            photoPrinter.PrintPhotoArray(photo, photo1);

            Console.ReadLine();
        }
예제 #29
0
        static void Main(string[] args)
        {
            Printer       printer       = new Printer();
            ColourPrinter colourPrinter = new ColourPrinter();
            PhotoPrinter  photoPrinter  = new PhotoPrinter();

            string[] strings = { "string1", "string2", "string3", "string4", "string5" };
            int[]    colours = { 1, 2, 3, 4, 5 };
            Photo[]  photos  =
            {
                new Photo {
                    PhotoData = "photo string1"
                },
                new Photo {
                    PhotoData = "photo string2"
                },
                new Photo {
                    PhotoData = "photo string3"
                },
                new Photo {
                    PhotoData = "photo string4"
                },
                new Photo {
                    PhotoData = "photo string5"
                }
            };


            Console.WriteLine("Print string array:");
            printer.Print(strings);
            Console.WriteLine("\nPrint colored string array:");
            colourPrinter.Print(strings, colours);
            Console.WriteLine("\nPrint photo array:");
            photoPrinter.Print(photos);

            Console.ReadKey();
        }
예제 #30
0
 public Director(ColourPrinter printer)
 {
     this._Printer = printer;
 }