/// <summary> /// ConvertFileFormat method that will call the appropriate class to perform /// file conversion, this class using the command line parser to parse /// command line options and then calls the FileFormatConverter.convertFile method /// which does the work /// </summary> /// <param name="args"></param> private static void ConvertFileFormat(string[] args) { var ffc = new FileFormatConverter(); var parser = new CommandLineArguments(); //add parameters parser.Parameter( ArgumentType.DefaultArgument, "FileList", ArgumentValueType.MultipleUniqueStrings, "", "Input and Output files."); if (args.Length > 0) { try { parser.Parse(args, ffc); } catch (ArgumentException ex) { Console.WriteLine(ex.Message); Console.WriteLine(Resources.UsageHelp); Environment.Exit(-1); } if (ffc.FileList.Length != 2) { Console.WriteLine(GetUsageMessage(ffc)); } else { ffc.InputFile = ffc.FileList[0]; ffc.OutputFile = ffc.FileList[1]; ffc.ConvertFile(); } } else { Console.WriteLine(GetUsageMessage(ffc)); } }
/// <summary> /// gets the usage message, if the FileFormatConverter class is available we can also write the /// available file extensions that we can parse and convert to otherwise just use static /// usage text /// </summary> /// <param name="ffc"></param> /// <returns></returns> private static string GetUsageMessage(FileFormatConverter ffc) { string usage = string.Empty; if (ffc != null) { usage = Resources.UsageHelp; usage += Environment.NewLine; usage += Environment.NewLine; usage += String.Format("File extensions for parsing:\n{0}", ffc.ListOfExtensionsToParse()); usage += Environment.NewLine; usage += Environment.NewLine; usage += String.Format("File extensions for conversion:\n{0}", ffc.ListOfExtensionsForConversion()); } else { usage = Resources.UsageHelp; } return(usage); }
/// <summary> /// ConvertFileFormat method that will call the appropriate class to perform /// file conversion, this class using the commandline parser to parse /// command line options and then calls the FileFormatConverter.convertFile method /// which does the work /// </summary> /// <param name="args"></param> private static void ConvertFileFormat(string[] args) { FileFormatConverter ffc = new FileFormatConverter(); CommandLineArguments parser = new CommandLineArguments(); //add parameters parser.Parameter(ArgumentType.Optional, "Help", ArgumentValueType.Bool, "h", "Print the help information."); parser.Parameter(ArgumentType.Optional, "OutputFile", ArgumentValueType.String, "o", "Output file formatted as specified."); parser.Parameter(ArgumentType.Optional, "InputFile", ArgumentValueType.String, "i", "Input file"); if (args.Length > 0) { try { parser.Parse(args, ffc); } catch (ArgumentException ex) { DisplayErrorMessage(ex.Message); DisplayErrorMessage(Resources.UsageHelp); Environment.Exit(-1); } if (ffc.Help) { string usage = GetUsageMessage(ffc); DisplayErrorMessage(usage); } else { ffc.ConvertFile(); } } else { string usage = GetUsageMessage(ffc); DisplayErrorMessage(usage); } }
/// <summary> /// gets the usage message, if the FileFormatConverter class is available we can also write the /// available file extensions that we can parse and convert to otherwise just use static /// usage text /// </summary> /// <param name="ffc"></param> /// <returns></returns> private static string GetUsageMessage(FileFormatConverter ffc) { string usage = string.Empty; if (ffc != null) { usage = Resources.UsageHelp; usage += Environment.NewLine; usage += Environment.NewLine; usage += String.Format("File extensions for parsing:\n{0}", ffc.ListOfExtensionsToParse()); usage += Environment.NewLine; usage += Environment.NewLine; usage += String.Format("File extensions for conversion:\n{0}", ffc.ListOfExtensionsForConversion()); } else { usage = Resources.UsageHelp; } return usage; }