static void Main(string[] args) { Initialize(); // Start interrogating try { // Get command line arguments CompressionCmdArguments cmdArguments = CompressionUserInputParser.GetCompressionCmdArguments(args); if (cmdArguments.Mode == "compress") { ShowProgress(); resizer.Compress(cmdArguments.FileName, cmdArguments.ArchiveName); } else if (cmdArguments.Mode == "decompress") { ShowProgress(); resizer.Decompress(cmdArguments.ArchiveName, cmdArguments.FileName); } System.Console.WriteLine("Operation finished successfully! Press Enter to exit"); System.Console.ReadLine(); } catch (Exception ex) { ShowException(ex); System.Console.WriteLine("Press Enter to exit."); System.Console.ReadLine(); } }
/// <summary> /// Returns CompressionCmdArguments object containing required command line arguments. /// </summary> /// <param name="args"></param> /// <returns></returns> public static CompressionCmdArguments GetCompressionCmdArguments(string[] args) { try { CompressionCmdArguments cmdArguments = new CompressionCmdArguments { Mode = args[0] }; if (cmdArguments.Mode == "compress") { cmdArguments.FileName = args[1]; cmdArguments.ArchiveName = args[2]; } else if (cmdArguments.Mode == "decompress") { cmdArguments.FileName = args[2]; cmdArguments.ArchiveName = args[1]; } else { throw new Exception(); } return(cmdArguments); } catch (Exception) { throw new ArgumentException(GetCommonInputValidationExceptionMessage()); } }