示例#1
0
 public static void Main(string[] args) {
     try {
         options = CheckArguments(args);
         string inputFileContent = ReadInputFile(options.InputFileName);
         string outputFileContent = Process(inputFileContent);
         WriteOutputFile(outputFileContent);
         DisplaySuccess();
     }
     catch(Exception e) {
         Console.WriteLine("\nUnhandled exception.  Program will terminate.\n");
         Console.WriteLine(e.Source);
         Console.WriteLine(e.TargetSite);
         Console.WriteLine(e.Message);
         Console.WriteLine(e.InnerException);
         Console.WriteLine(e.StackTrace);
         Console.ReadLine();
     }
 }
示例#2
0
        // --- Private Methods ---
        #region Options CheckArguments(string[] args)
        /// <summary>
        ///     Checks commandline arguments.
        /// </summary>
        /// <param name="args">
        ///     The commandline arguments.
        /// </param>
        /// <returns>
        ///     The selected options.
        /// </returns>
        private static Options CheckArguments(string[] args) {
            Options selectedOptions = new Options();

            if(args.Length < 2) {
                ExitWithError("You must supply input and output files.");
            }
            else {
                bool isDebugBuild = false;
                bool isOverwriteSilent = false;
                string inputFileName = args[0];
                string outputFileName = args[1];

                if(args.Length > 2) {
                    for(int i = 2; i < args.Length; i++) {
                        switch(args[i].ToUpper()) {
                            case "/D":
                                isDebugBuild = true;
                                break;
                            case "/R":
                                isDebugBuild = false;
                                break;
                            case "/Y":
                                isOverwriteSilent = true;
                                break;
                            default:
                                ExitWithError(args[i].ToUpper() + " is an invalid argument.");
                                break;
                        }
                    }
                }
                selectedOptions = new Options(inputFileName, outputFileName, isDebugBuild, isOverwriteSilent);
            }

            return selectedOptions;
        }