コード例 #1
0
        }                                                             // DisplayProperties method

        /// <summary>
        /// Enumerate the dependent assemblies.
        /// </summary>
        public void EnumerateDependents( )
        {
            string strDispCount = NumberFormatters.Integer(_lstNamesOfDependentAssemblies.Count);
            int    intMaxWidth  = strDispCount.Length;
            string strDtlFmt    = string.Concat("    {0,", intMaxWidth, "}: {1}");

            Console.WriteLine(
                Properties.Resources.MSG_ASM_DEPENDENTS_LIST_HEADER,                                    // Format Control String
                _asmRoot.FullName,                                                                      // Format Item 0 = Assembly Full Name
                strDispCount,                                                                           // Format Item 1 = Dependent Count
                Environment.NewLine);                                                                   // Format Item 2 = Embedded Newline
            int intOrdinal = ListInfo.LIST_IS_EMPTY;

            foreach (DependentAssemblyInfo dai in _lstNamesOfDependentAssemblies)
            {
                Console.WriteLine(
                    strDtlFmt,                              // Format Control String
                    NumberFormatters.Integer(++intOrdinal), // Format Item 0 = Item number
                    dai.FullName);                          // Format Item 1 = Assembly Full Name
            }                                               // foreach ( AssemblyName an in _lstNamesOfDependentAssemblies )

            Console.WriteLine(
                Properties.Resources.MSG_ASM_DEPENDENTS_LIST_TAIL, // Format Control String
                _asmRoot.FullName,                                 // Format Item 0 = Assembly Full Name
                Environment.NewLine);                              // Format Item 1 = Embedded Newline
        }                                                          // EnumerateDependents
コード例 #2
0
        }                                                             // DisplayProperties method

        /// <summary>
        /// Enumerate the dependent assemblies.
        /// </summary>
        public void EnumerateDependents( )
        {
            string strDispCount = NumberFormatters.Integer(_lstNamesOfDependentAssemblies.Count);
            int    intMaxWidth  = strDispCount.Length;
            string strDtlFmt    = string.Concat("    {0,", intMaxWidth, "}: {1}");

            Console.WriteLine(
                Properties.Resources.MSG_ASM_DEPENDENTS_LIST_HEADER,                    // Format Control String
                _asmRoot.FullName,                                                      // Format Item 0 = Assembly Full Name
                strDispCount,                                                           // Format Item 1 = Dependent Count
                Environment.NewLine);                                                   // Format Item 2 = Embedded Newline

            for (int intJ = ArrayInfo.ARRAY_FIRST_ELEMENT;
                 intJ < _lstNamesOfDependentAssemblies.Count;
                 intJ++)
            {
                Console.WriteLine(
                    strDtlFmt,                                       // Format Control String
                    NumberFormatters.Integer(                        // Format Item 0 = Item number
                        ArrayInfo.OrdinalFromIndex(                  // int pintAnyInteger
                            intJ)),                                  // int pintIndex
                    _lstNamesOfDependentAssemblies [intJ].FullName); // Format Item 1 = Assembly Full Name
            }                                                        // for ( int intJ = ArrayInfo.ARRAY_FIRST_ELEMENT ; intJ < _lstNamesOfDependentAssemblies.Count ; intJ++ )

            Console.WriteLine(
                Properties.Resources.MSG_ASM_DEPENDENTS_LIST_TAIL, // Format Control String
                _asmRoot.FullName,                                 // Format Item 0 = Assembly Full Name
                Environment.NewLine);                              // Format Item 1 = Embedded Newline
        }                                                          // EnumerateDependents
コード例 #3
0
 /// <summary>
 /// Override the base class ToString method, so that it renders the most
 /// critical properties of the underlying file.
 /// </summary>
 /// <returns>
 /// The returned string lists the name of the exporting class, as usual,
 /// but followed immediately by the key properties that a debugger will
 /// most likely need.
 /// </returns>
 public override string ToString( )
 {
     return(string.Format(
                Properties.Resources.AGED_FILES_INFO_TOSTRING_TEMPLATE,
                new string []
     {
         this.GetType( ).FullName,                // Format Item 0 = Fully qualified class name
         _fileInfo.Name,                          // Format Item 1 = Base Name        = {1},
         SysDateFormatters.FormatDateTimeForShow( // Format Item 2 = LastWriteTimeUTC = {2}
             _fileInfo.LastAccessTimeUtc),        // LastAccessTimeUtc is a System.DateTime structure, which FormatDateTimeForShow formats for display to carbon units.
         NumberFormatters.Integer(                // Format Item 3 = ({3 Ticks}),LastWriteTime
             _fileInfo.LastAccessTimeUtc.Ticks),  // LastAccessTimeUtc.Ticks is a long (64 bit) integer, which counts upwards from 01/01/0001 at Midnight UTC.
         SysDateFormatters.FormatDateTimeForShow( // Format Item 4 = LastWriteTime    = {4}
             _fileInfo.LastAccessTime),           // LastAccessTime, which reports the LastWriteTime, expressed as Local time is a System.DateTime structure, which FormatDateTimeForShow formats for display to carbon units.
         NumberFormatters.Integer(                // Format Item 5 = ({5 Ticks})
             _fileInfo.LastAccessTime.Ticks)      // LastAccessTime.Ticks is a long (64 bit) integer, which counts upwards from 01/01/0001 at Midnight local time,
     }));
 }                                                // public override string ToString ( )
コード例 #4
0
		internal static void Exercise_Base64_ToAndFrom ( )
		{
			string strInputFileName = Properties.Settings.Default.Base64EncodingSource;
			string strOutputFileName = Properties.Settings.Default.Base64EncodingRoundTrip;

			Console.WriteLine (
				@"{0}Exercise_Base64_ToAndFrom Begin:{0}" ,
				Environment.NewLine );

			//	--------------------------------------------------------------------------
			//	List input and output file names, both of which are absolute.
			//	--------------------------------------------------------------------------

			Console.WriteLine ( 
				@"    Absolute Input FileName                = {0}" , 
				strInputFileName );
			Console.WriteLine (
				@"    Absolute Output FileName               = {0}" ,
				strOutputFileName );

			try
			{
				FileInfo fiInputFile = new FileInfo ( strInputFileName );

				if ( fiInputFile.Exists )
                {
                    //	--------------------------------------------------------
                    //	List the siza and last modified date of the input file.
                    //	--------------------------------------------------------

                    Console.WriteLine (
                        @"{1}    Input File Size (bytes)                = {0}" ,
                        NumberFormatters.Integer ( fiInputFile.Length ) ,
                        Environment.NewLine );
                    Console.WriteLine (
                        @"    Input File Last Modified               = {0} ({1} UTC){2}" ,
                        SysDateFormatters.FormatDateTimeForShow ( fiInputFile.LastWriteTime ) ,
                        SysDateFormatters.FormatDateTimeForShow ( fiInputFile.CreationTimeUtc ) ,
                        Environment.NewLine );

                    //	--------------------------------------------------------
                    //	Read the input file into a byte array from which the
                    //	Base64 character array can be constructed, then report
                    //	its size, which should be equal to the length of the
                    //	input file reported above.
                    //	--------------------------------------------------------

                    byte [ ] abytInputBytes = File.ReadAllBytes ( strInputFileName );
                    Console.WriteLine (
                        @"    Input Byte Array Size                  = {0}" ,
                        NumberFormatters.Integer ( abytInputBytes.Length ) );

                    if ( fiInputFile.Length == abytInputBytes.Length )
                    {
                        Console.WriteLine ( $"{Environment.NewLine}    The input file and byte array lengths are equal.{Environment.NewLine}" );
                    }   // TRUE (expected outcome) block, if ( fiInputFile.Length == abytInputBytes.Length )
                    else
                    {
                        Console.WriteLine ( $"{Environment.NewLine}    The input file and byte array lengths DIFFER.{Environment.NewLine}" );
                    }   // FALSE (unexpected outcome) block, if ( fiInputFile.Length == abytInputBytes.Length )

                    //	--------------------------------------------------------
                    //	Construct a character array 4/3 as large as the input
                    //	array to hold the Base64 encoded characters created from
                    //	it, then call the Base64 encoder to create it.
                    //	--------------------------------------------------------

                    char [ ] achrOutputBytes = new char [ MoreMath2.MakeEvenlyDivisibleByFour ( MoreMath2.FractionalMultiply2Integer (
                        abytInputBytes.Length ,
                        ( double ) 4 / 3 ) ) ];
                    int intOutCount = Convert.ToBase64CharArray (
                        abytInputBytes ,
                        ArrayInfo.ARRAY_FIRST_ELEMENT ,
                        abytInputBytes.Length ,
                        achrOutputBytes ,
                        ArrayInfo.ARRAY_FIRST_ELEMENT );

                    //	--------------------------------------------------------
                    //	Creeate a Base64 encoded string from the same input, and
                    //	convert the character array into another string.
                    //	--------------------------------------------------------

                    string strBase64String = Convert.ToBase64String ( abytInputBytes );
                    string strBase64Array2String = new string ( achrOutputBytes );

                    //	--------------------------------------------------------
                    //	Show the lengths of both output strings, then report the
                    //	result of comparing them, which should report that they
                    //	are identical.
                    //	--------------------------------------------------------

                    Console.WriteLine (
                        @"    Output Byte Array Size                 = {0}" ,
                        NumberFormatters.Integer ( achrOutputBytes.Length ) );
                    Console.WriteLine (
                        @"    Convert.ToBase64CharArray Return Value = {0}" ,
                        NumberFormatters.Integer ( intOutCount ) );
                    Console.WriteLine (
                        @"    Convert.ToBase64String String Length   = {0}" ,
                        NumberFormatters.Integer ( strBase64String.Length ) );
                    Console.WriteLine (
                        @"    strBase64Array2String String Length    = {0}" ,
                        NumberFormatters.Integer ( strBase64Array2String.Length ) );

                    if ( strBase64String.Equals ( strBase64Array2String ) )
                    {
                        Console.WriteLine ( $"{Environment.NewLine}    Strings strBase64String and strBase64Array2String match.{Environment.NewLine}" );
                    }   // TRUE (expected outcome) block, if ( strBase64String.Equals ( strBase64Array2String ) )
                    else
                    {
                        Console.WriteLine ( $"{Environment.NewLine}    Strings strBase64String and strBase64Array2String DIFFER.{Environment.NewLine}" );
                    }   // FALSE (unexpected outcome) block, if ( strBase64String.Equals ( strBase64Array2String ) )

                    //	--------------------------------------------------------
                    //	Decodee the Base64 character array, which creates a new
                    //	array dynamically, and compare it byte for byte against
                    //	the input array. Both should match exactly.
                    //	--------------------------------------------------------

                    byte [ ] abytRoundTripBytes = Convert.FromBase64CharArray (
                        achrOutputBytes ,
                        ArrayInfo.ARRAY_FIRST_ELEMENT ,
                        achrOutputBytes.Length );

                    Console.WriteLine (
                        @"    Convert.FromBase64CharArray Array Size = {0}" ,
                        NumberFormatters.Integer ( abytRoundTripBytes.Length ) );

                    Compare2ArraysByte4Byte (
                        abytInputBytes ,
                        abytRoundTripBytes );

                    File.WriteAllBytes (
                        strOutputFileName ,
                        abytRoundTripBytes );
                    FileInfo fiRoundTripFile = new FileInfo ( strOutputFileName );
                    Console.WriteLine (
                        @"    Round Trip Output File Size            = {0}" ,
                        NumberFormatters.Integer ( fiRoundTripFile.Length ) );

                    if ( fiInputFile.Length == fiRoundTripFile.Length )
                    {
                        Console.WriteLine ( $"{Environment.NewLine}    Input and output file sizes match." );
                    }   // TRUE (expected outcome) block, if ( fiInputFile.Length == fiRoundTripFile.Length )
                    else
                    {
                        Console.WriteLine ( $"{Environment.NewLine}    Input and output file sizes DIFFER." );
                    }   // FALSE (unexpected outcome) block, if ( fiInputFile.Length == fiRoundTripFile.Length )

                    //	--------------------------------------------------------
                    //	Exercise new Base64 round trip converters.
                    //	--------------------------------------------------------

                    byte [ ] abytBase64Characters = WizardWrx.Core.ByteArrayBase64Converters.Base64EncodeBinaryFile ( strInputFileName );
                    byte [ ] abytDecodedBase64Characters = WizardWrx.Core.ByteArrayBase64Converters.Base64DecodeByteArray ( abytBase64Characters );

                    Compare2ArraysByte4Byte (
                        abytInputBytes ,
                        abytDecodedBase64Characters );
                }   // TRUE (anticipated outcome) block, if ( fiInputFile.Exists )
                else
				{
					Console.WriteLine ( @"FATAL ERROR: The specified input file cannot be found." );
				}   // FALSE (unanticipated outcome) block, if ( fiInputFile.Exists )
			}
			catch ( Exception exAllKinds )
			{
				Program.s_smTheApp.AppExceptionLogger.ReportException ( exAllKinds );
			}

			Console.WriteLine (
				@"{0}Exercise_Base64_ToAndFrom Done{0}" ,
				Environment.NewLine );
		}   // internal static void Exercise_Base64_ToAndFrom
コード例 #5
0
ファイル: Program.cs プロジェクト: txwizard/FixCSV
        }   // private static string CleanGuardedString


        /// <summary>
        /// Perform the core processing that is the mission of this program.
        /// </summary>
        /// <remarks>
        /// Everything this routine needs, including its error reporting
        /// mechanism, is the two static objects owned by the class.
        /// </remarks>
        private static void ProcessInputFile ( )
        {
            const char GUARD_CHARACTER = SpecialCharacters.DOUBLE_QUOTE;

            FileInfo outFileInfo = new FileInfo ( s_operatingParameters.InputFileNamePerCmd );
            FileInfo inFileInfo = new FileInfo ( s_operatingParameters.BackupFileName );

            Console.WriteLine (
                inFileInfo.ShowFileDetails (
                    FileInfoExtensionMethods.FileDetailsToShow.Everything ,
                    Properties.Resources.MSG_INPUT_FILE_DETAILS ) );

            if ( outFileInfo.Exists )
            {
                outFileInfo.FileAttributeClear ( FileAttributes.ReadOnly );
                Console.WriteLine (
                    outFileInfo.ShowFileDetails (
                        FileInfoExtensionMethods.FileDetailsToShow.Everything ,
                        Properties.Resources.MSG_OUTPUT_FILE_DETAILS ) );
            }   // TRUE block, if ( outFileInfo.Exists )
            else
            {
                Console.WriteLine ( Properties.Resources.MSG_OUTPUT_FILE_IS_NEW );
            }   // FALSE block, if ( outFileInfo.Exists )

            //  ----------------------------------------------------------------
            //  The real work begins here.
            //  ----------------------------------------------------------------

            string strInputFileContent = File.ReadAllText ( inFileInfo.FullName );

            int intInputCRCount = strInputFileContent.CountCharacterOccurrences ( SpecialCharacters.CARRIAGE_RETURN );
            int intInputLFCount = strInputFileContent.CountCharacterOccurrences ( SpecialCharacters.LINEFEED );

#pragma warning disable IDE0059 // Unnecessary assignment of a value
            int intNChars2Append = ListInfo.EMPTY_STRING_LENGTH;
            int intNInputChars = strInputFileContent.Length;
            int intPosCurrent = ListInfo.BEGINNING_OF_BUFFER;
            int intPosLeftGuardChar = ListInfo.INDEXOF_NOT_FOUND;
            int intPosRightGuardChar = ListInfo.INDEXOF_NOT_FOUND;
#pragma warning restore IDE0059 // Unnecessary assignment of a value

            bool fMoreChars2Process = true;
            bool fInsideGuardedBlock = false;
            bool fLastGuardAccountedFor = false;

            StringBuilder builder = new StringBuilder ( intNInputChars );

            while ( fMoreChars2Process )
            {
                if ( fInsideGuardedBlock )
                {
                    intPosRightGuardChar = ScanForNextGuardCharacter (
                        GUARD_CHARACTER ,
                        strInputFileContent ,
                        intPosCurrent );

                    if ( intPosRightGuardChar > ListInfo.INDEXOF_NOT_FOUND )
                    {
                        intNChars2Append = (   intPosRightGuardChar
                                             - intPosCurrent )
                                           + MagicNumbers.PLUS_ONE;
                        string strGuardedAndClean = CleanGuardedString (
                            strInputFileContent.Substring (
                                intPosCurrent ,
                                intNChars2Append ) ,
                            s_astrNewlineTokenList );
                        builder.Append ( strGuardedAndClean );
                        fInsideGuardedBlock = false;
                    }   // TRUE (anticipated outcome) block, if ( intPosRightGuardChar > ListInfo.INDEXOF_NOT_FOUND )
                    else
                    {
                        throw new Exception (
                            string.Format (
                                Properties.Resources.ERRMSG_MISSING_RIGHT_GUARD ,
                                intPosLeftGuardChar ,
                                intPosCurrent ,
                                intNInputChars ,
                                Environment.NewLine ) );
                    }   // FALSE (unanticipated outcome) block, if ( intPosRightGuardChar > ListInfo.INDEXOF_NOT_FOUND )
                }   // TRUE (intPosCurrent is WITHIN a guarded block.) block, if ( fInsideGuardedBlock )
                else
                {
                    intPosLeftGuardChar = ScanForNextGuardCharacter (
                        GUARD_CHARACTER ,
                        strInputFileContent ,
                        intPosCurrent );

                    if ( intPosLeftGuardChar > ListInfo.INDEXOF_NOT_FOUND )
                    {
                        intNChars2Append = (   intPosLeftGuardChar
                                             - intPosCurrent )
                                           + MagicNumbers.PLUS_ONE;
                        builder.Append (
                            strInputFileContent.Substring (
                                intPosCurrent ,
                                intNChars2Append ) );
                        fInsideGuardedBlock = true;
                    }   // TRUE (anticipated outcome, except perhaps for the last block), block, if ( intPosLeftGuardChar > ListInfo.INDEXOF_NOT_FOUND )
                    else
                    {   // Unless scanning for an opening guard character, this condition is invalid.
                        fLastGuardAccountedFor = true;
                        intNChars2Append = MagicNumbers.ZERO;
                    }   // FALSE (unanticipated outcome, except perhaps for the last block), block, if ( intPosLeftGuardChar > ListInfo.INDEXOF_NOT_FOUND )
                }   // FALSE (intPosCurrent is OUTSIDE a guarded block.) block, if ( fInsideGuardedBlock )

                //  ------------------------------------------------------------
                //  The less hand copying I do the sooner I can put this to bed.
                //  ------------------------------------------------------------

                intPosCurrent += intNChars2Append;

                if ( intPosCurrent > intNInputChars )
                {   // Bounds check the current position against the length of the input string.
                    throw new Exception (
                        string.Format (
                            Properties.Resources.ERRMSG_BAD_POSITION_INDEX ,
                            intPosCurrent ,                                     // Format Item 0: Position Index     = {0}
                            intNInputChars ,                                    // Format Item 1: Characters in File = {1}
                            Environment.NewLine ) );                            // Format Item 2: Line break
                }   // if ( intPosCurrent > intNInputChars )

                if ( fLastGuardAccountedFor )
                {   // If we've found the last guard character, check for remaining unguarded characters.
                    if ( intPosCurrent < intNInputChars )
                    {   // Append the trailing unguarded characters to the end of the string.
                        intNChars2Append = intNInputChars - intPosCurrent;
                        builder.Append (
                            strInputFileContent.Substring (
                                intPosCurrent ,
                                intNChars2Append ) );
                    }   // if ( intPosCurrent < intNInputChars )

                    fMoreChars2Process = false;
                }   // if ( fLastGuardAccountedFor )
            }   // while ( fMoreChars2Process )

            //  ----------------------------------------------------------------
            //  CSV files often contains quirky line breaks, such as a legacy
            //  Macintosh line break (a single line feed) followed by a standard
            //  Windows lime break (a carriage returne followed by a line feed).
            //  
            //  Method FindAndFixLimeBreakQuirks removes them, returning a count
            //  of such quirks removed. Unless the count is zero, it is reported
            //  on the 
            //  ----------------------------------------------------------------

            int intNQuirksFound = FindAndFixLimeBreakQuirks ( builder );

            if ( intNQuirksFound > MagicNumbers.ZERO )
            {
                Console.WriteLine (
                    Properties.Resources.MSG_QUIRKS_REPORT ,
                    intNQuirksFound.ToString (                                  // Format Control String
                        NumericFormats.NUMBER_PER_REG_SETTINGS_0D ) ,           // Format Item 0: {0} quirky line endings were found
                    Environment.NewLine );                                      // Format Item 1: and fixed.{1}
            }   // if ( intNQuirksFound > MagicNumbers.ZERO )

            string strOutputFileContent = builder.ToString ( );

            int intOutputCRCount = strOutputFileContent.CountCharacterOccurrences ( SpecialCharacters.CARRIAGE_RETURN );
            int intOutputLFCount = strOutputFileContent.CountCharacterOccurrences ( SpecialCharacters.LINEFEED );

            Console.WriteLine (
                Properties.Resources.MSG_LINE_BREAK_COUNTS_IN_AND_OUT ,         // Format Control String
                NumberFormatters.Integer ( intInputCRCount ) ,                  // Format Item 0: Input File:  CR Count = {0}
                NumberFormatters.Integer ( intInputLFCount ) ,                  // Format Item 1: LF Count = {1}
                NumberFormatters.Integer ( intOutputCRCount ) ,                 // Format Item 2: Output File: CR Count = {2}
                NumberFormatters.Integer ( intOutputLFCount ) ,                 // Format Item 3: LF Count = {3}
                Environment.NewLine );                                          // Format Item 4: Line break between each of the above
            File.WriteAllText (
                outFileInfo.FullName ,
                strOutputFileContent );
            System.Threading.Thread.Sleep ( MagicNumbers.MILLISECONDS_PER_SECOND );
            outFileInfo.Refresh ( );
            Console.WriteLine (
                outFileInfo.ShowFileDetails (
                    FileInfoExtensionMethods.FileDetailsToShow.Everything ,
                    Properties.Resources.MSG_OUTPUT_FILE_DETAILS ) );
        }   // private static void ProcessInputFile