static int Main() { var commandLineParser = new clsParseCommandLine(); try { mProcessingMode = eProcessingMode.TaskParallelLibrary4_5; // Set this to 1 for now // If argument /Threads is present, it will be set to that // Otherwise, it will be set to value returned by GetCoreCount() mThreadCount = 1; mRuntimeSeconds = 15; mUseTieredRuntimes = false; var success = false; if (commandLineParser.ParseCommandLine()) { if (SetOptionsUsingCommandLineParameters(commandLineParser)) { success = true; } } else { if (commandLineParser.NonSwitchParameterCount + commandLineParser.ParameterCount == 0 && !commandLineParser.NeedToShowHelp) { // No arguments were provided; that's OK success = true; } } if (!success || commandLineParser.NeedToShowHelp) { ShowProgramHelp(); return(-1); } StartProcessing(); } catch (Exception ex) { ShowErrorMessage("Error occurred in Program->Main", ex); return(-1); } return(0); }
private static bool SetOptionsUsingCommandLineParameters(clsParseCommandLine commandLineParser) { // Returns True if no problems; otherwise, returns false var lstValidParameters = new List <string> { "Mode", "Runtime", "Threads", "UseTiered", "Preview" }; try { // Make sure no invalid parameters are present if (commandLineParser.InvalidParametersPresent(lstValidParameters)) { var badArguments = new List <string>(); foreach (var item in commandLineParser.InvalidParameters(lstValidParameters)) { badArguments.Add("/" + item); } ShowErrorMessage("Invalid command line parameters", badArguments); return(false); } // Could query commandLineParser to see if various parameters are present //if (commandLineParser.NonSwitchParameterCount > 0) //{ // mFileName = commandLineParser.RetrieveNonSwitchParameter(0); //} var modeValue = 0; if (!GetParamInt(commandLineParser, "Mode", ref modeValue)) { return(false); } try { if (modeValue > 0) { mProcessingMode = (eProcessingMode)(modeValue - 1); } } catch (Exception ex) { ShowErrorMessage("Invalid value for /Mode; should be /Mode:1 or /Mode:2 or /Mode:3 or /Mode:4", ex); } if (!GetParamInt(commandLineParser, "Runtime", ref mRuntimeSeconds)) { return(false); } if (commandLineParser.IsParameterPresent("Threads")) { if (!GetParamInt(commandLineParser, "Threads", ref mThreadCount)) { return(false); } } else { mThreadCount = GetCoreCount(); } mUseTieredRuntimes = commandLineParser.IsParameterPresent("UseTiered"); mPreviewMode = commandLineParser.IsParameterPresent("Preview"); return(true); } catch (Exception ex) { ShowErrorMessage("Error parsing the command line parameters: " + Environment.NewLine + ex.Message); } return(false); }