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]); } } }
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 Multiprint(this ColourPrinter cprinter, string[] messages, ConsoleColor color) { foreach (string message in messages) { cprinter.Print(message, color); } }
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(); }
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(); }
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(); }
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]); } }
public CommandException(string message) : base(message) { // Write an error message on the screen. ColourPrinter.Print($"Error! {message}", ConsoleColor.White, ConsoleColor.Red); }
public static void Print(this ColourPrinter colorPrinter, ColorString[] colorStrings) { foreach (var colorString in colorStrings) { colorPrinter.Print(colorString.StringToDisplay, colorString.Color); } }
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); } } }
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]); } }
public static void Print(this List <ColourPrinterParams> colourPrinterParams) { var coloutPrinter = new ColourPrinter(); foreach (var colourPrinterParam in colourPrinterParams) { coloutPrinter.Print(colourPrinterParam.Text, colourPrinterParam.Color); } }
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); } } }
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(); } }
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!"); } }
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(); }