} // static void Main private static void NeedMoreArgs ( string pstrMsg , int pintExitCode ) { Console.WriteLine ( pstrMsg ); _me.DisplayEOJMessage ( ); DisplayAids.WaitForCarbonUnit ( ); Environment.Exit ( pintExitCode ); } // private static void NeedMoreArgs
} // private static void NeedMoreArgs private static ExitRules EvaluateArguments ( string [ ] pastrArgs ) { const int ARG_EXIT_CODE = ArrayInfo.ARRAY_FIRST_ELEMENT; const int ARG_EXIT_ACTION = ARG_EXIT_CODE + MagicNumbers.PLUS_ONE; const int ARG_EXIT_DISPOSITION = ARG_EXIT_ACTION + MagicNumbers.PLUS_ONE; const string ENUM_NAME_EXIT_CODE_DISP = @"ExitCodeDisposition"; const string ENUM_NAME_EXIT_ACTION = @"NormalExitAction"; const string ERRMSG_INTERNAL_ERROR = @"An internal error has occurred."; const string ERRMSG_MUST_BE_NUMERIC = @"Argument {0} must be an integer. The specified value, {1}, is not."; const string ERRMSG_UNNECESSARY_ARG = @"Argument {0} value = {1} - SKIPPED"; const string ERRMSG_VALUE_OUT_OF_RANGE = @"Argument {0} value = {1} - Value must be in {2} enumeration."; ExitRules rutpExitRulesMap; rutpExitRulesMap.Action = 0; rutpExitRulesMap.Disposition = 0; rutpExitRulesMap.ExitCode = 0; bool fRequirementsMet = false; uint uintNArgs = ( uint ) pastrArgs.Length; for ( uint uintCurrArg = ArrayInfo.ARRAY_FIRST_ELEMENT ; uintCurrArg < uintNArgs ; uintCurrArg++ ) { uint uintToTest = MagicNumbers.ZERO; uint uintRealValue = MagicNumbers.ZERO; if ( uint.TryParse ( pastrArgs [ uintCurrArg ] , out uintToTest ) ) { switch ( uintCurrArg ) { case ARG_EXIT_CODE: rutpExitRulesMap.ExitCode = uintToTest; break; case ARG_EXIT_ACTION: uintRealValue = ( uint ) ( uintToTest - ArrayInfo.INDEX_FROM_ORDINAL ); switch ( ( ConsoleAppStateManager.NormalExitAction ) uintRealValue ) { case ConsoleAppStateManager.NormalExitAction.ExitImmediately: case ConsoleAppStateManager.NormalExitAction.HaltOnError: case ConsoleAppStateManager.NormalExitAction.WaitForOperator: case ConsoleAppStateManager.NormalExitAction.Silent: Console.WriteLine ( astrExitAction [ uintRealValue ] ); rutpExitRulesMap.Action = ( ConsoleAppStateManager.NormalExitAction ) uintRealValue; break; default: string strMessage = string.Format ( ERRMSG_VALUE_OUT_OF_RANGE , uintCurrArg + ArrayInfo.INDEX_FROM_ORDINAL , uintRealValue , ENUM_NAME_EXIT_ACTION ); throw new Exception ( strMessage ); } // switch ( ( ApplicationInstance.NormalExitAction ) uintToTest - ArrayInfo.INDEX_FROM_ORDINAL ) break; // case ARG_EXIT_ACTION of switch ( uintCurrArg ) case ARG_EXIT_DISPOSITION: uintRealValue = ( uint ) ( uintToTest - ArrayInfo.INDEX_FROM_ORDINAL ); switch ( ( ExitCodeDisposition ) uintRealValue ) { case ExitCodeDisposition.PassAsArg: case ExitCodeDisposition.StoreInMy: Console.WriteLine ( astrExitCodeDisposition [ uintRealValue ] ); rutpExitRulesMap.Disposition = ( ExitCodeDisposition ) uintRealValue; fRequirementsMet = true; break; default: string strMessage = string.Format ( ERRMSG_VALUE_OUT_OF_RANGE , uintCurrArg + ArrayInfo.INDEX_FROM_ORDINAL , uintRealValue , ENUM_NAME_EXIT_CODE_DISP ); throw new Exception ( strMessage ); } // switch ( ( ExitCodeDisposition ) uintToTest - ArrayInfo.INDEX_FROM_ORDINAL ) break; // case ARG_EXIT_DISPOSITION of switch ( uintCurrArg ) default: Console.WriteLine ( ERRMSG_UNNECESSARY_ARG , uintCurrArg + ArrayInfo.INDEX_FROM_ORDINAL , pastrArgs [ uintCurrArg ] ); break; } // switch ( uintCurrArg ) } // TRUE block, if ( uint.TryParse ( pastrArgs [ uintCurrArg ] , out uintToTest ) ) else { // Depending on their position, non-integral arguments are ignored, if extra, or provoke an exception. if ( uintCurrArg > ARG_EXIT_DISPOSITION ) { // It's extra. List it for the record, and discard it. Console.WriteLine ( ERRMSG_UNNECESSARY_ARG , uintCurrArg + ArrayInfo.INDEX_FROM_ORDINAL , pastrArgs [ uintCurrArg ] ); } // TRUE block, if ( uintCurrArg > ARG_EXIT_DISPOSITION ) else { // It's one of the required three. Die. string strMessage = string.Format ( ERRMSG_MUST_BE_NUMERIC , uintCurrArg + ArrayInfo.INDEX_FROM_ORDINAL , pastrArgs [ uintCurrArg ] ); throw new Exception ( strMessage ); } // FALSE block, if ( uintCurrArg > ARG_EXIT_DISPOSITION ) } // FALSE block, if ( uint.TryParse ( pastrArgs [ uintCurrArg ] , out uintToTest ) ) } // for ( uint uintCurrArg = StandardConstants.ARRAY_FIRST_ELEMENT ; uintCurrArg < uintNArgs ; uintCurrArg++ ) if ( fRequirementsMet ) { DisplayAids.WaitForCarbonUnit ( ); return rutpExitRulesMap; } else { throw new Exception ( ERRMSG_INTERNAL_ERROR ); } // if ( fRequirementsMet ) } // private static ExitRules EvaluateArguments