public static void Main(string[] args) { var friendlyName = AppDomain.CurrentDomain.FriendlyName; var newLine = Environment.NewLine; var setter = new OptionSetter(); String fileName = null, outputFileName = null, payload = null; QRCodeGenerator.ECCLevel eccLevel = QRCodeGenerator.ECCLevel.L; SupportedImageFormat imageFormat = SupportedImageFormat.Png; int pixelsPerModule = 20; string foregroundColor = "#000000"; string backgroundColor = "#FFFFFF"; var showHelp = false; var optionSet = new OptionSet { { "e|ecc-level=", "error correction level", value => eccLevel = setter.GetECCLevel(value) }, { "f|output-format=", "Image format for outputfile. Possible values: png, jpg, gif, bmp, tiff, svg (default: png)", value => { Enum.TryParse(value, true, out imageFormat); } }, { "i|in=", "input file | alternative to parameter -p", value => fileName = value }, { "p|payload=", "payload string | alternative to parameter -i", value => payload = value }, { "o|out=", "output file", value => outputFileName = value }, { "s|pixel=", "pixels per module", value => { if (int.TryParse(value, out pixelsPerModule)) { if (pixelsPerModule < 1) { pixelsPerModule = 20; } } else { pixelsPerModule = 20; } } }, { "l|background=", "background color", value => backgroundColor = value }, { "d|foreground=", "foreground color", value => foregroundColor = value }, { "h|help", "show this message and exit.", value => showHelp = value != null } }; try { optionSet.Parse(args); if (showHelp) { ShowHelp(optionSet); } string text = null; if (fileName != null) { var fileInfo = new FileInfo(fileName); if (fileInfo.Exists) { text = GetTextFromFile(fileInfo); } else { Console.WriteLine($"{friendlyName}: {fileName}: No such file or directory"); } } else if (payload != null) { text = payload; } else { var stdin = Console.OpenStandardInput(); text = GetTextFromStream(stdin); } if (text != null) { GenerateQRCode(payload, eccLevel, outputFileName, imageFormat, pixelsPerModule, foregroundColor, backgroundColor); } } catch (Exception oe) { Console.Error.WriteLine( $"{friendlyName}:{newLine}{oe.GetType().FullName}{newLine}{oe.Message}{newLine}{oe.StackTrace}{newLine}Try '{friendlyName} --help' for more information"); Environment.Exit(-1); } }
public static void Main(string[] args) { var friendlyName = AppDomain.CurrentDomain.FriendlyName; var newLine = Environment.NewLine; var setter = new OptionSetter (); String fileName = null, outputFileName = null, payload = null; QRCodeGenerator.ECCLevel eccLevel = QRCodeGenerator.ECCLevel.L; ImageFormat imageFormat = ImageFormat.Png; var showHelp = false; var optionSet = new OptionSet { { "e|ecc-level=", "error correction level", value => eccLevel = setter.GetECCLevel(value) }, { "f|output-format=", "Image format for outputfile. Possible values: png, jpg, gif, bmp, tiff (default: png)", value => imageFormat = setter.GetImageFormat(value) }, { "i|in=", "input file | alternative to parameter -p", value => fileName = value }, { "p|payload=", "payload string | alternative to parameter -i", value => payload = value }, { "o|out=", "output file", value => outputFileName = value }, { "h|help", "show this message and exit.", value => showHelp = value != null } }; try { optionSet.Parse(args); if (showHelp) { ShowHelp(optionSet); } if (fileName != null) { var fileInfo = new FileInfo(fileName); if (fileInfo.Exists) { var text = GetTextFromFile(fileInfo); GenerateQRCode(text, eccLevel, outputFileName, imageFormat); } else { Console.WriteLine($"{friendlyName}: {fileName}: No such file or directory"); } } else if (payload != null) { GenerateQRCode(payload, eccLevel, outputFileName, imageFormat); } else { var stdin = Console.OpenStandardInput(); var text = GetTextFromStream(stdin); GenerateQRCode(text, eccLevel, outputFileName, imageFormat); } } catch (Exception oe) { Console.Error.WriteLine( $"{friendlyName}:{newLine}{oe.GetType().FullName}{newLine}{oe.Message}{newLine}{oe.StackTrace}{newLine}Try '{friendlyName} --help' for more information"); Environment.Exit(-1); } }
public static void Main(string[] args) { var friendlyName = AppDomain.CurrentDomain.FriendlyName; var newLine = Environment.NewLine; var setter = new OptionSetter(); String fileName = null, outputFileName = null, payload = null; QRCodeGenerator.ECCLevel eccLevel = QRCodeGenerator.ECCLevel.L; ImageFormat imageFormat = ImageFormat.Png; var showHelp = false; var optionSet = new OptionSet { { "e|ecc-level=", "error correction level", value => eccLevel = setter.GetECCLevel(value) }, { "f|output-format=", "Image format for outputfile. Possible values: png, jpg, gif, bmp, tiff (default: png)", value => imageFormat = setter.GetImageFormat(value) }, { "i|in=", "input file | alternative to parameter -p", value => fileName = value }, { "p|payload=", "payload string | alternative to parameter -i", value => payload = value }, { "o|out=", "output file", value => outputFileName = value }, { "h|help", "show this message and exit.", value => showHelp = value != null } }; try { optionSet.Parse(args); if (showHelp) { ShowHelp(optionSet); } if (fileName != null) { var fileInfo = new FileInfo(fileName); if (fileInfo.Exists) { var text = GetTextFromFile(fileInfo); GenerateQRCode(text, eccLevel, outputFileName, imageFormat); } else { Console.WriteLine($"{friendlyName}: {fileName}: No such file or directory"); } } else if (payload != null) { GenerateQRCode(payload, eccLevel, outputFileName, imageFormat); } else { var stdin = Console.OpenStandardInput(); var text = GetTextFromStream(stdin); GenerateQRCode(text, eccLevel, outputFileName, imageFormat); } } catch (Exception oe) { Console.Error.WriteLine( $"{friendlyName}:{newLine}{oe.GetType().FullName}{newLine}{oe.Message}{newLine}{oe.StackTrace}{newLine}Try '{friendlyName} --help' for more information"); Environment.Exit(-1); } }