}   // private static long LineCountToDisplay


        private string [ ] LoadInputList (
            string pstrLabel ,
            string pstrInputFileName )
        {
            if ( File.Exists ( pstrInputFileName ) )
            {
                FileInfo fiMasterFile = new FileInfo ( pstrInputFileName );
                string [ ] rastrMasterFile = File.ReadAllLines ( pstrInputFileName );
                string [ ] astrReportDetails = new string [ ]
                {
                    pstrLabel ,
                    FileNameToDisplay ( fiMasterFile ) ,
                    SysDateFormatters.ReformatSysDate
                    (
                        fiMasterFile.LastWriteTime ,
                        SysDateFormatters.RFD_YYYY_MM_DD_HH_MM_SS
                    ) ,
                    fiMasterFile.Length.ToString ( NumericFormats.NUMBER_PER_REG_SETTINGS_0D ) ,
                    LineCountToDisplay ( rastrMasterFile ).ToString ( NumericFormats.NUMBER_PER_REG_SETTINGS_0D )
                };

                _lstReportDetails.Add (
                    string.Format
                        (
                            _strReportDetailTemplate ,
                            astrReportDetails
                        )
                    );
                Console.WriteLine (
                    sr_strReportDetail ,
                    astrReportDetails );

                return rastrMasterFile;
            }   // TRUE (normal) block, if ( File.Exists ( pstrInputFileName ) )
            else
            {
                Console.WriteLine (
                    sr_strReportDetail ,
                    new string [ ]
                    {
                        pstrLabel , 
                        FileNameToDisplay ( pstrInputFileName ) ,
                        Properties.Resources.IDS_MSG_FILE_NOT_FOUND ,
                        string.Empty ,
                        string.Empty
                    } );

                return null;
            }   // FALSE (exception) block, if ( File.Exists ( pstrInputFileName ) )
        }   //private string [ ] LoadInputList
Exemplo n.º 2
0
        }   // private static void ConsumeResponse


        /// <summary>
        /// Format date/time and integral types for printing, passing all other
        /// types through as is, by way of their ToString methods.
        /// </summary>
        /// <param name="pstrStringFromJSON">
        /// The string from the deserialized JSON object is converted to a safer
        /// type, then fed through its ToString method.
        /// </param>
        /// <returns>
        /// The return value is a formatted string, suitable for display on a
        /// report.
        /// </returns>
        internal static string Beautify ( string pstrStringFromJSON )
        {
            object objOfType = ConvertToAppropriateType ( pstrStringFromJSON );

            if ( objOfType is DateTime )
            {
                DateTime dtmObjAsDate = ( DateTime ) objOfType;
                return SysDateFormatters.ReformatSysDate ( dtmObjAsDate , SysDateFormatters.RFD_YYYY_MM_DD );
            }   // TRUE (The input is a DateTime.) block, if ( objOfType is DateTime )
            else if ( objOfType is long )
            {
                long lngObjAsLongInteger = ( long ) objOfType;
                return lngObjAsLongInteger.ToString ( NumericFormats.NUMBER_PER_REG_SETTINGS_0D );
            }   // TRUE (The input is a Long Integer.) block, else if ( objOfType is long )
            else
            {
                return objOfType.ToString ( );
            }   // FALSE block covering if ( objOfType is DateTime ) AND else if ( objOfType is long )
        }   // internal static string Beautify
        public void Go ( )
        {
            Console.WriteLine ( sr_strReportLabels );
            string [ ] astrMasterFile = LoadInputList (
                Properties.Resources.IDS_DESCR_MASTER_FILE ,
                _strMasterFileName );

            string [ ] astrNewItems = LoadInputList (
                Properties.Resources.IDS_DESCR_NEWITEMS_FILE ,
                _strNewItemsFileName );

            if ( astrMasterFile.LongLength > MagicNumbers.ZERO && astrNewItems.LongLength > MagicNumbers.ZERO )
            {
                TestItemSortByString [ ] atiMasterList = LoadList ( astrMasterFile );
                TestItemSortByString [ ] atiNewItems = LoadList ( astrNewItems );
                TestItemSortByString [ ] atiMergedList = WizardWrx.ListHelpers.MergeNewItemsIntoArray (
                    atiMasterList ,
                    atiNewItems );

                string [ ] astrMergedList = new string [ atiMergedList.LongLength + ArrayInfo.ORDINAL_FROM_INDEX ];
                long lngCurrentSlot = ArrayInfo.ARRAY_FIRST_ELEMENT;
                astrMergedList [ lngCurrentSlot ] = s_Labels;

                foreach ( TestItemSortByString tiCurrentItem in atiMergedList )
                {
                    astrMergedList [ ++lngCurrentSlot ] = string.Join (
                        SpecialCharacters.TAB_CHAR.ToString ( ) ,
                        new string [ ]
                        {
                            tiCurrentItem.Key.ToString ( NumericFormats.GENERAL_UC ) ,
                            tiCurrentItem.Data
                        } );
                }   // foreach ( TestItemSortByString tiCurrentItem in atiMergedList )

                File.WriteAllLines ( 
                    _strOutputFileName ,
                    astrMergedList );
                FileInfo fiOutputFile = new FileInfo ( _strOutputFileName );

                //  ------------------------------------------------------------
                //  Stash this for the other test.
                //  ------------------------------------------------------------
                string [ ] astrDetails = new string [ ]
                {
                    Properties.Resources.IDS_DESCR_OUTPUT_FILE ,
                    FileNameToDisplay ( fiOutputFile ) ,
                    SysDateFormatters.ReformatSysDate (
                        fiOutputFile.LastWriteTime ,
                        SysDateFormatters.RFD_YYYY_MM_DD_HH_MM_SS ) ,
                    fiOutputFile.Length.ToString ( NumericFormats.NUMBER_PER_REG_SETTINGS_0D ) ,
                    atiMergedList.LongLength.ToString ( NumericFormats.NUMBER_PER_REG_SETTINGS_0D )
                };

                Console.WriteLine (
                    sr_strReportDetail ,
                    astrDetails );
                _lstReportDetails.Add ( 
                    string.Format (
                        _strReportDetailTemplate ,
                        astrDetails ) );
            }   // TRUE (normal) block, if ( astrMasterFile.LongLength > MagicNumbers.ZERO && astrNewItems.LongLength > MagicNumbers.ZERO )
            else
            {
                Console.WriteLine ( @"Error!" );
            }   // FALSE (exception) block, if ( astrMasterFile.LongLength > MagicNumbers.ZERO && astrNewItems.LongLength > MagicNumbers.ZERO )
        }   // public void Go
Exemplo n.º 4
0
        }   // private static string [ ] MakePaddedLabels


        private ReportDetails UseInputFromFile ( )
        {
            ReportDetails rptDetails = new ReportDetails ( s_astrPaddedLbels.Length );
            int intItemIndex = ArrayInfo.ARRAY_INVALID_INDEX;
            string strInputFQFN = Path.Combine (
                Program.rs_strDataDirectory ,
                _strTestDataFileName );
            FileInfo fiInputFile = new FileInfo ( strInputFQFN );
            string [ ] astrLinesFromFile = File.ReadAllLines ( strInputFQFN );
            int intLogestLine = WizardWrx.ReportHelpers.MaxStringLength ( new List<string> ( astrLinesFromFile ) );

            foreach ( string strLabel in s_astrPaddedLbels )
            {
                switch ( s_enmDetailItem [ ++intItemIndex ] )
                {
                    case DetailItem.DataSource:
                        rptDetails.Add ( new ReportDetail ( 
                            strLabel ,
                            _enmDataSource.ToString ( ) ) );
                        break;  // case DetailItem.DataSource

                    case DetailItem.SourceFQFN:
                        if ( fiInputFile.DirectoryName == Program.rs_strDataDirectory )
                            rptDetails.Add ( new ReportDetail (
                                strLabel ,
                                fiInputFile.Name ) );
                        else
                            rptDetails.Add ( new ReportDetail (
                                strLabel ,
                                fiInputFile.FullName ) );

                        break;  // case DetailItem.SourceFQFN

                    case DetailItem.ModDate:
                        rptDetails.Add ( new ReportDetail (
                            strLabel ,
                            SysDateFormatters.ReformatSysDate (
                                fiInputFile.LastWriteTime , 
                                SysDateFormatters.RFD_YYYY_MM_DD_HH_MM_SS ) ) );
                        break;  // case DetailItem.ModDate

                    case DetailItem.FileSize:
                        rptDetails.Add ( new ReportDetail (
                            strLabel , 
                            fiInputFile.Length.ToString ( NumericFormats.NUMBER_PER_REG_SETTINGS_0D ) ) );
                        break;  // case DetailItem.FileSize

                    case DetailItem.LineCount:
                        rptDetails.Add ( new ReportDetail (
                            strLabel ,
                            astrLinesFromFile.LongLength.ToString ( NumericFormats.NUMBER_PER_REG_SETTINGS_0D ) ) );
                        break;  // case DetailItem.LineCount

                    case DetailItem.LongestLine:
                        rptDetails.Add ( new ReportDetail (
                            strLabel ,
                            intLogestLine.ToString ( NumericFormats.NUMBER_PER_REG_SETTINGS_0D ) ) );
                        break;  // case DetailItem.LongestLine
                }   // switch ( s_enmDetailItem [ ++intItemIndex ] )                
            }   // foreach ( string strLabel in s_astrPaddedLbels )

            return rptDetails;
        }   // private void UseInputFromFile