コード例 #1
0
ファイル: Program.cs プロジェクト: txwizard/ConsoleAppAids2
        static void Main ( string [ ] args )
        {
            const int ERR_NO_ARGS = 999;
            const int ERR_ONE_ARG = 998;
            const int ERR_TWO_ARG = 997;

            const string ERRMSG_INTERNAL = @"An internal error has occurred in the NormalExit testing block.";
            const string ERRMSG_NO_ARGS = @"    Called without arguments. Two are required.";
            const string ERRMSG_ONE_ARG = @"    Called with one argument. We need three of them.";
            const string ERRMSG_TWO_ARG = @"    Called with two argument. We need three of them.";

            _me.DisplayBOJMessage ( );

			WizardWrx.DLLServices2.Util.ShowKeyAssemblyProperties ( System.Reflection.Assembly.GetAssembly ( _me.GetType ( ) ) );

            try
            {
                switch ( args.Length )
                {
                    case MagicNumbers.ZERO:
                        NeedMoreArgs ( ERRMSG_NO_ARGS , ERR_NO_ARGS );
                        break;

					case MagicNumbers.PLUS_ONE:
                        NeedMoreArgs ( ERRMSG_ONE_ARG , ERR_ONE_ARG );
                        break;

					case MagicNumbers.PLUS_TWO:
                        NeedMoreArgs ( ERRMSG_TWO_ARG , ERR_TWO_ARG );
                        break;

                    default:
                        ShowArgs ( args );
                        ExitRules utpExitRulesMap = EvaluateArguments ( args );

                        switch ( utpExitRulesMap.Disposition )
                        {
                            case ExitCodeDisposition.PassAsArg:
                                _me.NormalExit (
                                    utpExitRulesMap.ExitCode ,
                                    utpExitRulesMap.Action );
                                break;

                            case ExitCodeDisposition.StoreInMy:
                                _me.BaseStateManager.AppReturnCode = ( int ) utpExitRulesMap.ExitCode;
                                _me.NormalExit ( utpExitRulesMap.Action );
                                break;

                            default:
                                throw new Exception ( ERRMSG_INTERNAL );
                        }   // switch ( utpExitRulesMap.Disposition )
                        break;
                }   // switch ( args.Length )
            }   // The normal execution path ends here.
            catch ( Exception errAllKinds )
            {
				_me.BaseStateManager.AppExceptionLogger.ReportException ( errAllKinds );
                _me.DisplayEOJMessage ( );
            }
        }   // static void Main
コード例 #2
0
        }   //private static void ReportScenarioOutcome


        private static void ExitWithError (
            OutputFormat penmOutputFormat ,
            uint puintStatusCode )
        {
            if ( penmOutputFormat == OutputFormat.Quiet )
                s_theApp.NormalExit (
                    puintStatusCode ,
                    ConsoleAppStateManager.NormalExitAction.Silent );
            else
                s_theApp.NormalExit (
                    puintStatusCode ,
                    ConsoleAppStateManager.NormalExitAction.ExitImmediately );
        }   // private static void ExitWithError
コード例 #3
0
ファイル: Program.cs プロジェクト: txwizard/TimeSpanLab
        static void Main ( string [ ] args )
        {
            s_stateManager.DisplayBOJMessage ( );

            s_stateManager.BaseStateManager.AppExceptionLogger.OptionFlags = s_stateManager.BaseStateManager.AppExceptionLogger.OptionFlags
                                                                             | WizardWrx.DLLConfigurationManager.ExceptionLogger.OutputOptions.NBSpaceForNewlines
                                                                             | WizardWrx.DLLConfigurationManager.ExceptionLogger.OutputOptions.StandardError
                                                                             | WizardWrx.DLLConfigurationManager.ExceptionLogger.OutputOptions.Stack
                                                                             | WizardWrx.DLLConfigurationManager.ExceptionLogger.OutputOptions.Source
                                                                             | WizardWrx.DLLConfigurationManager.ExceptionLogger.OutputOptions.Method
                                                                             | WizardWrx.DLLConfigurationManager.ExceptionLogger.OutputOptions.EventLog;

            try
			{
                DateTime dateTime1 = new DateTime ( 2020 , 6 , 12 , 1 , 23 , 0 );
                DateTime dateTime2 = new DateTime ( 2020 , 6 , 12 , 4 , 44 , 0 );

                TimeSpan timeSpan1 = new TimeSpan ( dateTime2.TimeOfDay.Ticks - dateTime1.TimeOfDay.Ticks );

                ShowDateTime (
                    dateTime1 ,
                    nameof ( dateTime1 ) );
                ShowDateTime (
                    dateTime2 ,
                    nameof ( dateTime2 ) );
                ShowTimeOfDay (
                    timeSpan1 ,
                    nameof ( timeSpan1 ) );
			}
            catch ( Exception exAll )
            {
                s_stateManager.BaseStateManager.AppExceptionLogger.ReportException ( exAll );
                s_stateManager.BaseStateManager.AppReturnCode = MagicNumbers.ERROR_RUNTIME;
            }

            if ( s_stateManager.BaseStateManager.AppReturnCode == MagicNumbers.ERROR_SUCCESS )
            {
                s_stateManager.NormalExit ( ConsoleAppStateManager.NormalExitAction.WaitForOperator );
            }   // TRUE (anticipated outcome) block, if ( s_stateManager.BaseStateManager.AppReturnCode == MagicNumbers.ERROR_SUCCESS )
            else
            {
                s_stateManager.ErrorExit ( ( uint ) s_stateManager.BaseStateManager.AppReturnCode );
            }   // FALSE (unanticipated outcome) block, if ( s_stateManager.BaseStateManager.AppReturnCode == MagicNumbers.ERROR_SUCCESS )
        }   // static void Main
コード例 #4
0
		static void Main ( string [ ] args )
		{
			const int EXTRA_LEADING_CHARACTERS = 19;

			const string INTERNAL_ERROR_OO2_PREFIX = @"INTERNAL PROCESSING ERROR 002:";
			const string INTERNAL_ERROR_OO3_PREFIX = @"INTERNAL PROCESSING ERROR 003:";
			const string INTERNAL_ERROR_OO4_PREFIX = @"INTERNAL PROCESSING ERROR 004:";
			const string INTERNAL_ERROR_OO5_PREFIX = @"INTERNAL PROCESSING ERROR 005:";

			s_theApp = ConsoleAppStateManager.GetTheSingleInstance ( );
			s_theApp.DisplayBOJMessage ( );
			s_theApp.BaseStateManager.AppExceptionLogger.OptionFlags = s_theApp.BaseStateManager.AppExceptionLogger.OptionFlags
																	   | ExceptionLogger.OutputOptions.Stack
																	   | ExceptionLogger.OutputOptions.EventLog
																	   | ExceptionLogger.OutputOptions.StandardError;
			s_theApp.BaseStateManager.LoadErrorMessageTable ( s_astrErrorMessages );

			try
			{
				Console.WriteLine ( 
					"Namespace of Entry Point Routine {0} = {1} " ,
					System.Reflection.MethodBase.GetCurrentMethod ( ).Name ,
					System.Reflection.Assembly.GetEntryAssembly ( ).EntryPoint.DeclaringType.Namespace );

				Type typeCmdArgsBasic = typeof ( CmdLneArgsBasic );
				System.Reflection.Assembly asmClassLibrary = System.Reflection.Assembly.GetAssembly ( typeCmdArgsBasic );

				Console.WriteLine (
					"Namespace of Entry Point Routine of the assembly that exports class {0} = {1} " ,
					typeCmdArgsBasic.FullName ,
					asmClassLibrary.EntryPoint == null
						? Properties.Resources.RENDERED_STRING_IS_NULL
						: asmClassLibrary.EntryPoint.DeclaringType.Namespace );

				Utl.ListInternalResourceNames ( System.Reflection.Assembly.GetExecutingAssembly ( ) );
				AppSettingsForEntryAssembly appSettingsForEntryAssembly = AppSettingsForEntryAssembly.GetTheSingleInstance ( Properties.Settings.Default.Properties);

				string strAppSettingMane = @"OperatingParameter1";

				{   // Constrain the scope of objAppSettingValue.
					object objAppSettingValue = appSettingsForEntryAssembly.GetAppSettingByName ( strAppSettingMane );
					Console.WriteLine (
						"Application Setting {0} = {1}" ,
						strAppSettingMane ,
						objAppSettingValue == null
							? Properties.Resources.RENDERED_STRING_IS_NULL
							: objAppSettingValue );
				}   // Let objAppSettingValue go out of scope.

				strAppSettingMane = @"OperatingParameter2";

				{   // Constrain the scope of objAppSettingValue.
					object objAppSettingValue = appSettingsForEntryAssembly.GetAppSettingByName ( strAppSettingMane );
					Console.WriteLine (
						"Application Setting {0} = {1}" ,
						strAppSettingMane ,
						objAppSettingValue == null
							? Properties.Resources.RENDERED_STRING_IS_NULL
							: objAppSettingValue );
				}   // Let objAppSettingValue go out of scope.

				appSettingsForEntryAssembly.ListAllAppSettings ( );
				OperatingParametersCollection<ParameterType , ParameterSource> operatingParametersColl = OperatingParametersCollection<ParameterType , ParameterSource>.GetTheSingleInstance (
					Properties.Settings.Default.Properties ,
					Properties.Resources.PARAMETER_DISPLAY_NAME_TEMPLATE ,
					ParameterSource.ApplicationSettings );
				CmdLneArgsBasic cmdArgs = new CmdLneArgsBasic (
					operatingParametersColl.GetParameterNames ( ) ,
					CmdLneArgsBasic.ArgMatching.CaseInsensitive );
				operatingParametersColl.SetFromCommandLineArguments (
					cmdArgs ,
					ParameterSource.CommandLine );

				int intTotalParameters = operatingParametersColl.GetCount ( );
				Console.WriteLine (
					Properties.Resources.MSG_PARAMETER_LIST_HEADER ,            // Format Control String: The {0} application has {1} parameters.
					s_theApp.BaseStateManager.AppRootAssemblyFileBaseName ,     // Format Item 0: The {0} application
					intTotalParameters ,                                        // Format Item 1: has {1} parameters.
					Environment.NewLine );                                      // Format Item 2: platform-dependent newline
				int intParameterNumber = ListInfo.LIST_IS_EMPTY;

				foreach ( string strParamName in operatingParametersColl.GetParameterNames ( ) )
				{
					Console.WriteLine (
						Properties.Resources.MESSAGE_PARAMETER_NAME ,           // Format Control String: "    Parameter # {0}: {1}" (excluding the quotation marks, of course!)
						++intParameterNumber ,                                  // Format Item 0: Parameter # {0}:
						Utl.ListPropertiesPerDefaultToString (                  // Format Item 1: Property Details listed by its ToString method
							operatingParametersColl.GetParameterByName ( strParamName ) ,
							EXTRA_LEADING_CHARACTERS ) );
				}   // foreach ( string strParamName in operatingParametersColl.GetParameterNames ( ) )

				Console.WriteLine (
					Properties.Resources.MSG_PARAMETER_LIST_FOOTER ,            // Format Control String: End of {0} parameter list.
					s_theApp.BaseStateManager.AppRootAssemblyFileBaseName ,     // Format Item 0: End of {0} parameter
					Environment.NewLine );                                      // Format Item 1: platform-dependent newline

				Console.WriteLine (
					Properties.Resources.MSG_VALIDATION_BEGIN ,                 // Format Control String
					Environment.NewLine );                                      // Format Item 0: platform-dependent newline

				foreach ( string strParamName in operatingParametersColl.GetParameterNames ( ) )
				{
					OperatingParameter<ParameterType , ParameterSource> operatingParameter = operatingParametersColl.GetParameterByName ( strParamName );
					bool fParamIsValid = operatingParameter.IsValueValid<ParameterType> ( );
					Console.WriteLine (
						Properties.Resources.MSG_VALIDATION_DETAIL ,            // Format Control String: Parameter {0} value of {1} is {2}.
						operatingParameter.DisplayName ,                        // Format Item 0: Parameter {0}
						Utl.RenderStringValue (
							operatingParameter.ParamValue ) ,                   // Format Item 1: value of {1}
						fParamIsValid );                                        // Format Item 2: is {2}
				}   // foreach ( string strParamName in operatingParametersColl.GetParameterNames ( ) )

				Console.WriteLine (
					Properties.Resources.MSG_VALIDATION_END ,                   // Format Control String
					Environment.NewLine );                                      // Format Item 0: platform-dependent newline
			}	// try block
			catch ( Exception exAllKinds )
			{   // Theere must be a lower-maintenance way to do this.
				if ( exAllKinds.Message.StartsWith ( INTERNAL_ERROR_OO2_PREFIX ) )
				{
					s_theApp.BaseStateManager.AppReturnCode = ERROR_INTERNAL_PROCESSING_ERROR_002;
				}   // TRUE block, if ( exAllKinds.Message.StartsWith ( INTERNAL_ERROR_OO2_PREFIX ) )
				else if ( exAllKinds.Message.StartsWith ( INTERNAL_ERROR_OO3_PREFIX ) )
				{
					s_theApp.BaseStateManager.AppReturnCode = ERROR_INTERNAL_PROCESSING_ERROR_003;
				}   // TRUE block, else if ( exAllKinds.Message.StartsWith ( INTERNAL_ERROR_OO3_PREFIX ) )
				else if ( exAllKinds.Message.StartsWith ( INTERNAL_ERROR_OO4_PREFIX ) )
				{
					s_theApp.BaseStateManager.AppReturnCode = ERROR_INTERNAL_PROCESSING_ERROR_004;
				}   // TRUE block, else if ( exAllKinds.Message.StartsWith ( INTERNAL_ERROR_OO4_PREFIX ) )
				else if ( exAllKinds.Message.StartsWith ( INTERNAL_ERROR_OO5_PREFIX ) )
				{
					s_theApp.BaseStateManager.AppReturnCode = ERROR_INTERNAL_PROCESSING_ERROR_005;
				}   // TRUE block, else if ( exAllKinds.Message.StartsWith ( INTERNAL_ERROR_OO4_PREFIX ) )
				else
				{   // If all else fails, call it a run-of-the-mill runtime error.
					s_theApp.BaseStateManager.AppReturnCode = WizardWrx.MagicNumbers.ERROR_RUNTIME;
				}   // FALSE block, if ( exAllKinds.Message.StartsWith ( INTERNAL_ERROR_OO2_PREFIX ) ) ...

				s_theApp.BaseStateManager.AppExceptionLogger.ReportException ( exAllKinds );
			}   // catch ( Exception exAllKinds ) block

			if ( s_theApp.BaseStateManager.AppReturnCode == WizardWrx.MagicNumbers.ERROR_SUCCESS )
			{
				s_theApp.NormalExit ( ConsoleAppStateManager.NormalExitAction.Timed );
			}   // TRUE (anticipated outcome) block, if ( s_theApp.BaseStateManager.AppReturnCode == WizardWrx.MagicNumbers.ERROR_SUCCESS )
			else
			{
				s_theApp.ErrorExit ( ( uint ) s_theApp.BaseStateManager.AppReturnCode );
			}   // FALSE (unanticipated outcome) block, if ( s_theApp.BaseStateManager.AppReturnCode == WizardWrx.MagicNumbers.ERROR_SUCCESS )
		}   // static void Main
コード例 #5
0
        internal static int s_intNArgs;						// This gets the count of command line arguments.


        static void Main ( string [ ] args )
        {
            rs_appThis.DisplayBOJMessage ( );
            Console.WriteLine (
                SharedUtl4_TestStand.Properties.Resources.IDS_DATA_DIRECTORY_NAME ,
                rs_strDataDirectory );
            rs_appThis.BaseStateManager.LoadErrorMessageTable (
                new string [ ]
                {
                    Properties.Resources.ERRMSG_SUCCESS ,
                    Properties.Resources.ERRMSG_RUNTIME
                } );
            rs_appThis.BaseStateManager.AppExceptionLogger.OptionFlags =
                rs_appThis.BaseStateManager.AppExceptionLogger.OptionFlags
                | ExceptionLogger.OutputOptions.EventLog
                | ExceptionLogger.OutputOptions.Stack
                | ExceptionLogger.OutputOptions.StandardOutput;
            InitializeTestSelections ( args );

            try
            {
                if ( DoThisTest ( CHOICE_MAXSTRINGLENGTH ) )
                    MaxStringLength_Tests ( );

                if ( DoThisTest ( CHOICE_MERGENEWITEMSINTOARRAY ) )
                    MergeNewItemsIntoArray_Tests ( );

                if ( DoThisTest ( CHOICE_DIGESTFILE ) )
                    DigestFileTests ( );

                if ( DoThisTest ( CHOICE_REPORTDETAILS ) )
                {
                    ReportDetailsTests ( TEST_UNSORTED );
                    ReportDetailsTests ( TEST_SORTED );
                }   // if ( DoThisTest ( CHOICE_REPORTDETAILS ) )

                if ( DoThisTest ( CHOICE_REPORTHELPERS ) )
                    ReportHelpersTests ( );

                if ( DoThisTest ( CHOICE_FORMAT_ITEM_GEN ) )
                    FormatStringParsing_Drills.TestFormatItemBuilders ( );

				if ( DoThisTest ( CHOICE_ASCII_TABLE_GEN ) )
					FormatStringParsing_Drills.ASCII_Table_Gen ( );
            }
            catch ( Exception errAllKinds )
            {
				rs_appThis.BaseStateManager.AppExceptionLogger.ReportException ( errAllKinds );
                rs_appThis.BaseStateManager.AppReturnCode = ERR_RUNTIME;
            }
            finally
            {
                if ( rs_appThis.BaseStateManager.AppReturnCode == MagicNumbers.ERROR_SUCCESS )
                {
                    rs_appThis.NormalExit (
                        ConsoleAppStateManager.NormalExitAction.WaitForOperator );
                }   // TRUE (expected outcome) block, if ( rs_appThis.BaseStateManager.AppReturnCode == MagicNumbers.ERROR_SUCCESS )
                else
                {
                    rs_appThis.ErrorExit (
                        ( uint ) rs_appThis.BaseStateManager.AppReturnCode );
                }   // FALSE (exception) block, if ( rs_appThis.BaseStateManager.AppReturnCode == MagicNumbers.ERROR_SUCCESS )
            }
        }   // static void Main
コード例 #6
0
        };  // static char [ ] s_achrValidSwitches

        static void Main ( string [ ] args )
        {

            s_theApp = ConsoleAppStateManager.GetTheSingleInstance ( );

            CmdLneArgsBasic cmdArgs = new CmdLneArgsBasic (
                s_achrValidSwitches ,
                CmdLneArgsBasic.ArgMatching.CaseInsensitive )
            {
                AllowEmptyStringAsDefault = CmdLneArgsBasic.BLANK_AS_DEFAULT_ALLOWED
            };

            //  ----------------------------------------------------------------
            //  The default value of the AppSubsystem property is GUI, which
            //  disables output to the console. Since ReportException returns
            //  the message that would have been written, you still have the
            //  option of displaying or discarding it. If EventLoggingState is
            //  set to Enabled, the message is written into the Application
            //  Event log, where it is preserved until the event log record is
            //  purged by the aging rules or some other method.
            //  ----------------------------------------------------------------

            s_theApp.BaseStateManager.AppExceptionLogger.OptionFlags =
                s_theApp.BaseStateManager.AppExceptionLogger.OptionFlags
                | ExceptionLogger.OutputOptions.EventLog
                | ExceptionLogger.OutputOptions.Stack
                | ExceptionLogger.OutputOptions.StandardError;
            s_theApp.BaseStateManager.LoadErrorMessageTable ( s_astrErrorMessages );

            string strDeferredMessage = null;

            OutputFormat enmOutputFormat = SetOutputFormat (
                cmdArgs ,
                ref strDeferredMessage );

            if ( enmOutputFormat != OutputFormat.None )
            {   // Unless output is suppressed, display the standard BOJ message.
                s_theApp.DisplayBOJMessage ( );
            }   // if ( enmOutputFormat != OutputFormat.None )

            if ( !string.IsNullOrEmpty ( strDeferredMessage ) )
            {   // SetOutputFormat saves its error message, if any, in SetOutputFormat. 
                Console.WriteLine ( strDeferredMessage );
            }   // if ( !string.IsNullOrEmpty ( s_strDeferredMessage ) )

            if ( cmdArgs.PositionalArgsInCmdLine < CmdLneArgsBasic.FIRST_POSITIONAL_ARG )
            {   // Required input is missing. Report and bug out.
                s_theApp.ErrorExit ( ERR_NEED_INPUT_FILENAME );
            }   // if ( cmdArgs.PositionalArgsInCmdLine < CmdLneArgsBasic.FIRST_POSITIONAL_ARG )

            string strTestFileName = cmdArgs.GetArgByPosition ( CmdLneArgsBasic.FIRST_POSITIONAL_ARG );
            Console.WriteLine (
                Properties.Resources.MSG_INPUT_FILENAME ,
                s_theApp.BaseStateManager.InitialWorkingDirectoryName ,
                strTestFileName ,
                Environment.NewLine );

            try
            {
#if ANYCSV
                int intNCases = System.IO.File.ReadAllLines (
                    strTestFileName , 
                    Encoding.ASCII ).Length;
                int intCurrCase = MagicNumbers.ZERO;

                WizardWrx.AnyCSV.Parser ReusableParser = new WizardWrx.AnyCSV.Parser (
                    WizardWrx.AnyCSV.CSVParseEngine.DelimiterChar.Comma ,
                    WizardWrx.AnyCSV.CSVParseEngine.GuardChar.DoubleQuote ,
                    WizardWrx.AnyCSV.CSVParseEngine.GuardDisposition.Strip );
                Console.WriteLine (
                    Properties.Resources.MSG_TOSTRING_CONSTRUCTED_FROM_ENUMS ,          // Format control string
                    Properties.Resources.MSG_TOSTRING_JUST_CONSTRUCTED ,                // Format Item 0: {0}, the ToString method
                    nameof ( ReusableParser ) ,                                         // Format Item 1: the ToString method on {1} reports
                    ReusableParser.ToString ( ) );                                      // Format Item 2: reports as follows: {2}.

                using ( System.IO.StreamReader srTestData = new System.IO.StreamReader (
                        strTestFileName ,
                        Encoding.ASCII ,
                        IGNORE_BOM ,
                        MagicNumbers.CAPACITY_08KB ) )
                {
                    do
                    {
                        string strTestCase = srTestData.ReadLine ( );

                        string [ ] astrInstanceTestOutput = ReusableParser.Parse ( strTestCase );

                        if ( intCurrCase == MagicNumbers.ZERO )
                        {   // On the first iteration, intCurrCase is zero.
                            Console.WriteLine (
                                Properties.Resources.MSG_TOSTRING_CONSTRUCTED_FROM_ENUMS ,          // Format control string
                                Properties.Resources.MSG_TOSTRING_POST_FIRST_USE ,                  // Format Item 0: {0}, the ToString method
                                nameof ( ReusableParser ) ,                                         // Format Item 1: the ToString method on {1} reports
                                ReusableParser.ToString ( ) );                                      // Format Item 2: reports as follows: {2}.
                        }   // if ( intCurrCase == MagicNumbers.ZERO )

                        string [ ] astrStaticTestOutput1 = WizardWrx.AnyCSV.Parser.Parse (
                            strTestCase ,                                                           // Input string
                            WizardWrx.AnyCSV.Parser.COMMA ,                                         // Field delimiter character
                            WizardWrx.AnyCSV.Parser.DOUBLE_QUOTE );                                 // Delimiter guard character

                        //  ----------------------------------------------------
                        //  Identify the case number, and show the input string.
                        //  ----------------------------------------------------

                        intCurrCase++;
                        int intNFields = astrStaticTestOutput1.Length;
                        Console.WriteLine (
                            Properties.Resources.MSG_CASE_LABEL ,
                            new string [ ]
                            {
                                intCurrCase.ToString ( ) ,
                                intNCases.ToString ( ) ,
                                intNFields.ToString ( ) ,
                                strTestCase ,
                                Environment.NewLine } );

                        ReportScenarioOutcome (
                            Properties.Resources.INSTANCE_SCENARIO_1 ,
                            astrInstanceTestOutput ,
                            astrInstanceTestOutput.Length );
                        ReportScenarioOutcome (
                            Properties.Resources.STATIC_SCENARIO_1 ,
                            astrStaticTestOutput1 ,
                            intNFields );

                        string [ ] astrStaticTestOutput2 = WizardWrx.AnyCSV.Parser.Parse (
                            strTestCase ,                                                           // Input string
                            WizardWrx.AnyCSV.Parser.COMMA ,                                         // Field delimiter character
                            WizardWrx.AnyCSV.Parser.DOUBLE_QUOTE ,                                  // Delimiter guard character
                            WizardWrx.AnyCSV.Parser.GuardDisposition.Keep );                        // Override to keep.

                        intNFields = astrStaticTestOutput2.Length;
                        ReportScenarioOutcome (
                            Properties.Resources.STATIC_SCENARIO_2 ,
                            astrStaticTestOutput2 ,
                            intNFields );

                        string [ ] astrStaticTestOutput3 = WizardWrx.AnyCSV.Parser.Parse (
                            strTestCase ,                                                           // Input string
                            WizardWrx.AnyCSV.Parser.COMMA ,                                         // Field delimiter character
                            WizardWrx.AnyCSV.Parser.DOUBLE_QUOTE ,                                  // Delimiter guard character
                            WizardWrx.AnyCSV.Parser.GuardDisposition.Strip ,                        // Override to keep.
                            WizardWrx.AnyCSV.Parser.TrimWhiteSpace.TrimLeading );
                        intNFields = astrStaticTestOutput3.Length;
                        ReportScenarioOutcome (
                            Properties.Resources.STATIC_SCENARIO_3 ,
                            astrStaticTestOutput3 ,
                            intNFields );
                    } while ( !srTestData.EndOfStream );
                }   // using ( System.IO.StreamReader srTestData = new System.IO.StreamReader (
#else
                CsvParser engine = new CsvParser ( );
                string [ ] [ ] astrParsedStrings = engine.Parse ( 
                    new System.IO.StreamReader (
                        strTestFileName ,
                        Encoding.ASCII ,
                        IGNORE_BOM ,
                        StandardConstants.FILE_BUFSIZE_STANDARD_08KB ) );
                int intNCases = astrParsedStrings.Length;

                for ( int intCurrCase = StandardConstants.ARRAY_FIRST_ELEMENT ; intCurrCase < intNCases ; intCurrCase++ )
                {
                    int intNFields = astrParsedStrings [ intCurrCase ].Length;
                    Console.WriteLine (
                        Properties.Resources.MSG_CASE_LABEL ,
                        new string [ ]
                        {
                            OrdinalFromSubscript ( intCurrCase ).ToString(),
                            intNCases.ToString() ,
                            intNFields.ToString() ,
                            Environment.NewLine
                        } );
                    
                    for ( int intCurrField = StandardConstants.ARRAY_FIRST_ELEMENT ;
                              intCurrField < astrParsedStrings [ intCurrCase ].Length ;
                              intCurrField++ )
                    {
                        Console.WriteLine (
                            Properties.Resources.MSG_CASE_DETAIL ,
                            OrdinalFromSubscript ( intCurrField ) ,
                            intNFields ,
                            astrParsedStrings [ intCurrCase ] [ intCurrField ] );
                    }   // for ( int intCurrField = StandardConstants.ARRAY_FIRST_ELEMENT ; intCurrField < astrParsedStrings [ intCurrCase ].Length ; intCurrField++ )
                }   // for ( int intCurrCase = StandardConstants.ARRAY_FIRST_ELEMENT ; intCurrCase < intNCases ; intNCases++ )
#endif
            }
            catch ( Exception exAll )
            {   // The Message string is displayed, but the complete exception goes to the event log.
                s_theApp.BaseStateManager.AppExceptionLogger.ReportException ( exAll );
                Console.WriteLine ( exAll.Message );

                ExitWithError (
                    enmOutputFormat ,
                    ERR_RUNTIME );
            }   // Providing a catch block is enough to cause the program to fall through.

#if DEBUG
            if ( enmOutputFormat == OutputFormat.None )
            {   // Suppress all output.
                s_theApp.NormalExit (  ConsoleAppStateManager.NormalExitAction.Silent );
            }   // TRUE block, if ( enmOutputFormat == OutputFormat.None )
            else
            {   // Display the standard exit banner.
                s_theApp.NormalExit ( ConsoleAppStateManager.NormalExitAction.WaitForOperator );
            }   // FALSE block, if ( enmOutputFormat == OutputFormat.None )
#else
            if ( enmOutputFormat == OutputFormat.None )
            {   // Suppress all output.
                s_theApp.NormalExit ( ConsoleAppStateManager.NormalExitAction.Silent );
            }   // TRUE block, if ( enmOutputFormat == OutputFormat.None )
            else
            {   // Display the standard exit banner.
                s_theApp.NormalExit(ConsoleAppStateManager.NormalExitAction.WaitForOperator);
            }   // FALSE block, if ( enmOutputFormat == OutputFormat.None )
#endif
        }   // static void Main
コード例 #7
0
        };  // static JSONDeserializationUseCase [ ] s_aDeserializationUseCases


        /// <summary>
        /// This routine is the entry point of the entry assembly.
        /// </summary>
        /// <param name="args">
        /// When specified, the args array contains a single entry, which must
        /// match the string representation of a member of the SelectedTest
        /// enumeration. When the string corresponds to the string
        /// representation of a SelectedTest member, the corresponding test is
        /// performed. When no argument is given, all tests are performed. When
        /// the specified argument is invalid, the error is reported, and
        /// nothing else happens.
        /// </param>
        static void Main ( string [ ] args )
        {
            int intTestNumber = ListInfo.LIST_IS_EMPTY;

            s_smThisApp.DisplayBOJMessage ( );
            s_smThisApp.BaseStateManager.AppExceptionLogger.OptionFlags = s_smThisApp.BaseStateManager.AppExceptionLogger.OptionFlags | WizardWrx.DLLConfigurationManager.ExceptionLogger.OutputOptions.Stack;

            var varAppSettings = Properties.Settings.Default;
            var varAppStrings = Properties.Resources.ResourceManager.GetResourceSet (
                System.Globalization.CultureInfo.CurrentCulture ,               // System.Globalization.CultureInfo culture
                false ,                                                         // bool                             createIfNotExists
                true );                                                         // bool                             tryParents

            try
            {
                if ( RunThisTest ( SelectedTest.LineBreaks , args ) )
                {
                    s_smThisApp.BaseStateManager.AppReturnCode = LineEndingFixupTests.Exercise ( ref intTestNumber );
                }   // if ( RunThisTest ( SelectedTest.LineBreaks , args ) )

                if ( RunThisTest ( SelectedTest.AppSettingsList , args ) )
                {
                    intTestNumber = ListAppSettings ( intTestNumber );
                }   // if ( RunThisTest ( SelectedTest.AppSettingsList , args ) )

                if ( RunThisTest ( SelectedTest.StringResourceList , args ) )
                {
                    intTestNumber = ListEmbeddedResources ( intTestNumber );
                }   // if ( RunThisTest ( SelectedTest.StringResourceList , args ) )

                if ( RunThisTest ( SelectedTest.TransformJSONString , args ) )
                {
                    for ( int intUseCaseIndex = ArrayInfo.ARRAY_FIRST_ELEMENT ;
                          intUseCaseIndex < s_aDeserializationUseCases.Length ;
                          intUseCaseIndex++ )
                    {
                        try
                        {
                            JSONDeserializationUseCase deserializationUseCase = s_aDeserializationUseCases [ intUseCaseIndex ];
                            intTestNumber = PerformJSONTransofmration (
                                intTestNumber ,                                             // int    pintTestNumber                OK
                                deserializationUseCase.ConvertLineEndings ,                 // bool   pfConvertLineEndings          OK
                                deserializationUseCase.TestReportLabel ,                    // string pstrTestReportLabel           OK
                                deserializationUseCase.RESTResponseFileName ,               // string pstrRESTResponseFileName      OK
                                deserializationUseCase.IntermediateFileName ,               // string pstrIntermediateFileName      OK
                                deserializationUseCase.FinalOutputFileName ,                // string pstrFinalOutputFileName       OK
                                deserializationUseCase.ResponseObjectFileName );            // string pstrResponseObjectFileName    OK
                        }
                        catch ( Exception exAll )
                        {
                            s_smThisApp.BaseStateManager.AppExceptionLogger.ReportException ( exAll );
                        }
                    }   // for ( int intUseCaseIndex = ArrayInfo.ARRAY_FIRST_ELEMENT ; intUseCaseIndex < s_aDeserializationUseCases.Length ; intUseCaseIndex++ )
                }   // if ( RunThisTest ( SelectedTest.TransformJSONString , args ) )
            }
            catch ( InvalidOperationException exInvOp )
            {
                if ( exInvOp.Message == Properties.Resources.ERRMSG_CMDARG_IS_INVALID )
                {
                    s_smThisApp.ErrorExit ( MagicNumbers.ERROR_RUNTIME + MagicNumbers.PLUS_ONE );
                }   // TRUE (anticpated outcome) block, if ( exInvOp.Message == Properties.Resources.ERRMSG_CMDARG_IS_INVALID )
                else
                {
                    s_smThisApp.BaseStateManager.AppExceptionLogger.ReportException ( exInvOp );
                    s_smThisApp.ErrorExit ( MagicNumbers.ERROR_RUNTIME );
                }   // FALSE (unanticpated outcome) block, if ( exInvOp.Message == Properties.Resources.ERRMSG_CMDARG_IS_INVALID )
            }
            catch ( Exception exAll )
            {
                s_smThisApp.BaseStateManager.AppExceptionLogger.ReportException ( exAll );
                s_smThisApp.ErrorExit ( MagicNumbers.ERROR_RUNTIME );
            }

            //s_smThisApp.DisplayEOJMessage ( );            // Since s_smThisApp.NormalExit displays this message, this statement is redundant.
            s_smThisApp.NormalExit ( ConsoleAppStateManager.NormalExitAction.WaitForOperator );
        }   // static void Main
コード例 #8
0
ファイル: Program.cs プロジェクト: txwizard/FixCSV
        static void Main ( string [ ] args )
        {
            s_exLogger.OptionFlags = s_exLogger.OptionFlags
                                     | ExceptionLogger.OutputOptions.Stack
                                     | ExceptionLogger.OutputOptions.EventLog;
            s_theApp.BaseStateManager.LoadErrorMessageTable (
                new string [ ]
                {
                    null ,														// ERROR_SUCCESS
                    Properties.Resources.MSG_ERROR_RUNTIME_EXCEPTION ,			// ERR_RUNTIME
                    Properties.Resources.MSG_ERROR_FILE_TO_PROCESS_OMITTED ,	// ERR_FILENAME_MISSING
                    Properties.Resources.MSG_ERROR_FILE_TO_PROCESS_NOT_FOUND ,	// ERR_FNF
                    Properties.Resources.MSG_ERROR_BACKUP_OF_BACKUP				// WRM_NAME_COLLISION
                } );
            s_theApp.DisplayBOJMessage ( );
            CmdLneArgsBasic cmdLneArgs = new CmdLneArgsBasic (
                new string [ ]
                {
                    Properties.Resources.CMD_ARG_INPUT_FILENAME,
                    Properties.Resources.CMD_ARG_NEWLINE_REPL_TOKEN
                } );
            s_operatingParameters.InputFileNamePerCmd = cmdLneArgs.GetArgByName (
                Properties.Resources.CMD_ARG_INPUT_FILENAME );

            //  ----------------------------------------------------------------
            //  Evaluate the sole required command line argument. Unless it has
            //  a value, there is no point proceeding with anything more.
            //  ----------------------------------------------------------------

            if ( !string.IsNullOrEmpty ( s_operatingParameters.InputFileNamePerCmd ) )
            {
                s_operatingParameters.NewlineReplacementToken = SetEmbeddedNewlineReplacementValue ( cmdLneArgs );
                s_operatingParameters.BackupFileName = string.Concat (
                    s_operatingParameters.InputFileNamePerCmd ,
                    Properties.Resources.MSG_BACKUP_FILE_EXTENSION );
                Console.WriteLine (
                    Properties.Resources.MSG_INFO_INPUT_FILENAME ,              // Format control string
                    s_operatingParameters.InputFileNamePerCmd ,                 // Name of event log export file to process
                    s_operatingParameters.BackupFileName ,                      // Name of backup file to create
                    Environment.NewLine );                                      // Embedded newline

                //  ------------------------------------------------------------
                //  From here to almost the end involves interacting with the
                //  file system, so the majority of the main routine runs inside
                //  a try/catch block.
                //  ------------------------------------------------------------

                try
                {
                    if ( File.Exists ( s_operatingParameters.InputFileNamePerCmd ) )
                    {
                        if ( MakeBackup ( s_operatingParameters.InputFileNamePerCmd , s_operatingParameters.BackupFileName ) )
                        {
                            ProcessInputFile ( );
                        }   // if ( MakeBackup ( s_operatingParameters.InputFileNamePerCmd , s_operatingParameters.BackupFileName ) )
                    }   // TRUE (anticipated outcome) block, if ( File.Exists ( s_operatingParameters.InputFileNamePerCmd ) )
                    else
                    {
                        s_theApp.BaseStateManager.AppReturnCode = ERR_FNF;
                    }   // FALSE (unanticipated outcome) block, if ( File.Exists ( s_operatingParameters.InputFileNamePerCmd ) )
                }
                catch ( Exception exAll )
                {
                    s_theApp.BaseStateManager.AppExceptionLogger.ReportException ( exAll );
                    s_theApp.BaseStateManager.AppReturnCode = ERR_RUNTIME;
                }
            }   // TRUE (anticipated outcome) block, if ( !string.IsNullOrEmpty ( s_operatingParameters.InputFileNamePerCmd ) )
            else
            {
                s_theApp.BaseStateManager.AppReturnCode = ERR_FILENAME_MISSING;
                Console.WriteLine (
                    Properties.Resources.MSG_SYNTAX_HELP ,                      // Format Control String, presently "{1}Minimum command line:{1}{1}{0} InputFileName=CSVFileName{1}where CSVFileName = Name of CSV to process{1}"
                    s_theApp.BaseStateManager.AppRootAssemblyFileName ,         // Format Token 0: {0} InputFileName=CSVFileName
                    Environment.NewLine );                                      // Format Token 1: Newlines everywhere else
            }   // FALSE (unanticipated outcome) block, if ( !string.IsNullOrEmpty ( s_operatingParameters.InputFileNamePerCmd ) )

            //  ----------------------------------------------------------------
            //  Summarize and wrap up takes one of two turns, depending on the
            //  value of the return code stored in the application manager.
            //  ----------------------------------------------------------------

            if ( s_theApp.BaseStateManager.AppReturnCode == MagicNumbers.ERROR_SUCCESS )
            {
                s_theApp.NormalExit ( ConsoleAppStateManager.NormalExitAction.Timed );
            }   // TRUE (desired outcome) block, if ( s_theApp.BaseStateManager.AppReturnCode == MagicNumbers.ERROR_SUCCESS )
            else
            {   // Strictly speaking, one of the outcomes is just a warning.
                Console.WriteLine ( );
                s_theApp.ErrorExit ( ( uint ) s_theApp.BaseStateManager.AppReturnCode );
            }	// false (undesired outcome) block, if ( s_theApp.BaseStateManager.AppReturnCode == MagicNumbers.ERROR_SUCCESS )
        }   // static void Main