} // MaxStringLength_Test_Case private static void MergeNewItemsIntoArray_Tests ( ) { int intTestNumber = MagicNumbers.ZERO; Console.WriteLine ( SharedUtl4_TestStand.Properties.Resources.IDS_MERGENEWITEMSINTOARRAY_BEGIN , Environment.NewLine ); string strInitialMasterFile = Path.Combine ( rs_strDataDirectory , Properties.Settings.Default.MergeNewItemsIntoArray_Master ); string strOutputFilenmetemplate = Properties.Settings.Default.MergeNewItemsIntoArray_Outputs; string strNewItemsListFileSpec = Properties.Settings.Default.MergeNewItemsIntoArray_Cases; int intMaxDigitsInCaseNumber = TestCaseMaxDigits ( strNewItemsListFileSpec ); string strSummaryFileFQFN = Path.Combine ( rs_strDataDirectory , Properties.Settings.Default.MergeNewItemsIntoArray_Summary ); string strOutputFileFQFN = null; string strInputFileName = null; string strReportLabels = MergeNewItemsIntoArray_Tester.ReportLabels.Replace ( SpecialCharacters.TAB_CHAR , SpecialCharacters.PIPE_CHAR ); List<string> lstReportDetails = new List<string> ( ); lstReportDetails.Add ( strReportLabels ); string strReportDetailTemplate = ReportHelpers.DetailTemplateFromLabels ( strReportLabels , SpecialCharacters.PIPE_CHAR ); foreach ( string strNewDataFile in Directory.GetFiles ( rs_strDataDirectory , strNewItemsListFileSpec , SearchOption.TopDirectoryOnly ) ) { strInputFileName = SelectInputFle ( intTestNumber , strInitialMasterFile , strOutputFileFQFN ); strOutputFileFQFN = MergeOutputFQFN ( strOutputFilenmetemplate , rs_strDataDirectory , intMaxDigitsInCaseNumber , ++intTestNumber ); MergeNewItemsIntoArray_Tester mergetester = new MergeNewItemsIntoArray_Tester ( strInputFileName , strNewDataFile , strOutputFileFQFN , lstReportDetails , strReportDetailTemplate ); MergeNewItemsIntoArray_Test_Case ( mergetester , ref intTestNumber ); } // foreach ( string strNewDataFile in Directory.GetFiles ( rs_strDataDirectory , strNewItemsListFileSpec , SearchOption.TopDirectoryOnly ) ) string [ ] astrSummaryReport = new string [ lstReportDetails.Count ]; lstReportDetails.CopyTo ( astrSummaryReport ); File.WriteAllLines ( strSummaryFileFQFN , astrSummaryReport ); Console.WriteLine ( SharedUtl4_TestStand.Properties.Resources.IDS_MERGENEWITEMSINTOARRAY_END , Environment.NewLine ); } // MergeNewItemsIntoArray_Tests
} // BeginTest method /// <summary> /// Create a report of the contents of the deserialized response in /// <paramref name="timeSeriesDailyResponse"/>. /// </summary> /// <param name="timeSeriesDailyResponse"> /// The populated TimeSeriesDailyResponse instance returned by the JSON /// deserializer. /// </param> internal static void ConsumeResponse ( string pstrReportFileName , TimeSeriesDailyResponse timeSeriesDailyResponse ) { Console.WriteLine ( Properties.Resources.MSG_RESPONSE_METADATA , // Format control string new object [ ] { timeSeriesDailyResponse.Meta_Data.Information , // Format item 0: Information = {0} timeSeriesDailyResponse.Meta_Data.Symbol , // Format Item 1: Symbol = {1} timeSeriesDailyResponse.Meta_Data.LastRefreshed , // Format Item 2: LastRefreshed = {2} timeSeriesDailyResponse.Meta_Data.OutputSize , // Format Item 3: OutputSize = {3} timeSeriesDailyResponse.Meta_Data.TimeZone , // Format Item 4: TimeZone = {4} timeSeriesDailyResponse.Time_Series_Daily.Length , // Format Item 5: Detail Count = {5} Environment.NewLine // Format Item 6: Platform-dependent newline } ); string strAbsoluteInputFileName = AssembleAbsoluteFileName ( pstrReportFileName ); using ( StreamWriter swTimeSeriesDetail = new StreamWriter ( strAbsoluteInputFileName , FileIOFlags.FILE_OUT_CREATE , System.Text.Encoding.ASCII , MagicNumbers.CAPACITY_08KB ) ) { string strLabelRow = Properties.Resources.MSG_RESPONSE_DETAILS_LABELS.ReplaceEscapedTabsInStringFromResX ( ); swTimeSeriesDetail.WriteLine ( strLabelRow ); string strDetailRowFormatString = ReportHelpers.DetailTemplateFromLabels ( strLabelRow ); for ( int intJ = ArrayInfo.ARRAY_FIRST_ELEMENT ; intJ < timeSeriesDailyResponse.Time_Series_Daily.Length ; intJ++ ) { Time_Series_Daily daily = timeSeriesDailyResponse.Time_Series_Daily [ intJ ]; swTimeSeriesDetail.WriteLine ( strDetailRowFormatString , new object [ ] { ArrayInfo.OrdinalFromIndex ( intJ ) , // Format Item 0: Item Beautify ( daily.Activity_Date) , // Format Item 1: Activity_Date Beautify ( daily.Open ) , // Format Item 2: Open Beautify ( daily.High ) , // Format Item 3: High Beautify ( daily.Low ) , // Format Item 4: Low Beautify ( daily.Close ) , // Format Item 5: Close Beautify ( daily.AdjustedClose ) , // Format Item 6: AdjustedClose Beautify ( daily.Volume ) , // Format Item 7: Volume Beautify ( daily.DividendAmount ) , // Format Item 8: DividendAmount Beautify ( daily.SplitCoefficient ) // Format Item 9: SplitCoefficient } ); } // for ( int intJ = ArrayInfo.ARRAY_FIRST_ELEMENT ; intJ < timeSeriesDailyResponse.Time_Series_Daily.Length ; intJ++ ) } // using ( StreamWriter swTimeSeriesDetail = new StreamWriter ( strAbsoluteInputFileName , FileIOFlags.FILE_OUT_CREATE , System.Text.Encoding.ASCII , MagicNumbers.CAPACITY_08KB ) ) Console.WriteLine ( ShowFileDetails ( // Print the returned string. Properties.Resources.FILE_LABEL_CONTENT_REPORT , // string pstrLabel strAbsoluteInputFileName , // string pstrFileName true , // bool pfPrefixWithNewline = false false ) ); // bool pfSuffixWithNewline = true } // private static void ConsumeResponse
} // private static string GetInternalResourceName /// <summary> /// Call this static method from a console program to list the resources /// defined in an assembly alphabetically by name. /// </summary> /// <param name="pasmInWhichEmbedded"> /// Specify the assembly that contains the resources to be enumerated. /// </param> /// <param name="pswReportFile"> /// Pass in a reference to an open StreamWriter to generate a /// tab-delimited report in addition to the console output. File output /// is suppressed when this parameter is null. /// </param> /// <remarks> /// This method creates and consumes a generic List of instances of the /// class that hosts it, and uses string padding to vertically align the /// list without resorting to composite format items. /// </remarks> public static void ListResourcesInAssemblyByName( Assembly pasmInWhichEmbedded, StreamWriter pswReportFile = null) { const string DEFAULT_STRING_RESOURCE_NAME = @"resources"; Console.WriteLine( Properties.Resources.MSG_RESOURCE_LIST_FQNAME, pasmInWhichEmbedded.FullName, Environment.NewLine); Console.WriteLine( Properties.Resources.MSG_RESOURCE_LIST_BASENAME, pasmInWhichEmbedded.Location); // ---------------------------------------------------------------- // Since they own unmanaged resources, ResourceSet are disposable. // Moreover, they must be enumerated (ForEach is unsupported.), and // they can't be sorted in place. Thankfully, it's fairly easy to // make copies of the parts that matter to us, sort them, and show // them. // ---------------------------------------------------------------- int intMaxNameLength = MagicNumbers.ZERO; int intMaxTypeNameLength = MagicNumbers.ZERO; List <SortableManagedResourceItem> lstResources = new List <SortableManagedResourceItem> ( ); // ---------------------------------------------------------------- // The list of SortableManagedResourceItem items is complete. Get a // count, initialize an item counter, and sort the list, then use a // standard ForEach loop to display them in order by name. The next // improvement is to apply dynamic formatting to the item numbers // and names. // ---------------------------------------------------------------- string [] astrNamedResources = pasmInWhichEmbedded.GetManifestResourceNames( ); Console.WriteLine( Properties.Resources.MSG_RESOURCE_LIST_ITEM_COUNT, // Format control string astrNamedResources.Length, // Format Item 0 = Item count Environment.NewLine); // Format Item 1 = Extra newline int intItemNumber = ListInfo.LIST_IS_EMPTY; int intItemNumberWidth = astrNamedResources.Length.ToString( ).Length; foreach (string strName in astrNamedResources) { // Though most assemblies contain but a single resource, named "resources," they may contain an unlimited number of them. I have at least one assembly that contains three. Console.WriteLine( Properties.Resources.MSG_RESOURCE_LIST_NAMED_ITEM, (++intItemNumber).ToString( ).PadRight(intItemNumberWidth), strName); } // foreach ( string strName in astrNamedResources) Console.WriteLine( Properties.Resources.MSG_RESOURCE_LIST_NAMES_END, Environment.NewLine); if (astrNamedResources.Length > ListInfo.LIST_IS_EMPTY) { using (Stream strOfResources = pasmInWhichEmbedded.GetManifestResourceStream(GetInternalResourceName(DEFAULT_STRING_RESOURCE_NAME, pasmInWhichEmbedded))) { if (strOfResources != null) { using (ResourceReader resReader4Embedded = new ResourceReader(strOfResources)) { IDictionaryEnumerator resourceEnumerator = resReader4Embedded.GetEnumerator( ); while (resourceEnumerator.MoveNext( )) { string strName = resourceEnumerator.Key.ToString( ); if (strName.Length > intMaxNameLength) { // Update length if longer than any yet seen. intMaxNameLength = strName.Length; } // if ( strName.Length > intMaxNameLength ) SortableManagedResourceItem resourceItem = new SortableManagedResourceItem( strName, resourceEnumerator.Value); if (resourceItem.TypeName.Length > intMaxTypeNameLength) { intMaxTypeNameLength = resourceItem.TypeName.Length; } // if ( item.TypeName.Length > intMaxTypeNameLength ) lstResources.Add(resourceItem); } // while ( resourceEnumerator.MoveNext ( ) ) } // using ( ResourceReader resReader4Embedded = new ResourceReader ( strOfResources ) ) } // TRUE (anticipated outcome) block, if ( strOfResources != null ) else { // There is nothing to report about string resources, because there aren't any. Console.WriteLine(Properties.Resources.MSG_RESOURCE_LIST_NO_STRINGS); } // FALSE (unanticipated outcome) block, if ( strOfResources != null ) } // using ( Stream strOfResources = pasmInWhichEmbedded.GetManifestResourceStream ( GetInternalResourceName ( DEFAULT_STRING_RESOURCE_NAME , pasmInWhichEmbedded ) ) ) } // TRUE (anticipated outcome) block, if ( astrNamedResources.Length > ListInfo.LIST_IS_EMPTY ) else { // The assembly is completely devoid of embedded resources of any kind, except the obligatory manifest. Console.WriteLine(Properties.Resources.MSG_RESOURCE_LIST_NONE); } // FALSE (unanticipated outcome) block, if ( astrNamedResources.Length > ListInfo.LIST_IS_EMPTY ) int intItemCount = lstResources.Count; intItemNumberWidth = intItemCount.ToString( ).Length; intItemNumber = ListInfo.LIST_IS_EMPTY; lstResources.Sort( ); string strReportDetailTemplate = null; if (pswReportFile != null) { string strLabelRow = Properties.Resources.RESOURCE_REPORT_LABELS.ReplaceEscapedTabsInStringFromResX( ); pswReportFile.WriteLine(strLabelRow); strReportDetailTemplate = ReportHelpers.DetailTemplateFromLabels(strLabelRow); } // if ( pswReportFile != null ) foreach (SortableManagedResourceItem resourceItem in lstResources) { // Padding to maximum width eliminates the need for composite format items. Console.WriteLine( Properties.Resources.MSG_RESOURCE_LIST_ITEM_DETAIL, // Format control string new string [] { resourceItem.TypeName.PadRight(intMaxTypeNameLength), // Format Item 0 = Item type (++intItemNumber).ToString( ).PadLeft(intItemNumberWidth), // Format Item 1 = Item number, left padded resourceItem.Name.PadRight(intMaxNameLength), // Format Item 2 = Name, right padded resourceItem.Value.ToString( ), // Format Item 3 = Value, as is }); if (pswReportFile != null) { pswReportFile.WriteLine( strReportDetailTemplate, intItemNumber, resourceItem.Name, resourceItem.Value); } // if ( pswReportFile != null ) } // foreach ( SortableManagedResourceItem resourceItem in lstResources ) } // ListResourcesInAssemblyByName
} // private static int ListEmbeddedResources /// <summary> /// Generate the format control string for the detail row from the label /// row, and write the label row into the output file before it boes out /// of scope. /// </summary> /// <param name="swAppSettings"> /// Pass in a reference to the StreamWriter that was created for the TSV /// report. /// </param> /// <returns> /// The return value is the string through which to write detail rows. /// </returns> private static string GenerateDetailFormatStringFromLabelRow ( StreamWriter swAppSettings ) { string strLabelRow = Properties.Resources.LBL_APP_SETTINGS_LIST.ReplaceEscapedTabsInStringFromResX ( ); swAppSettings.WriteLine ( strLabelRow ); return ReportHelpers.DetailTemplateFromLabels ( strLabelRow ); } // private static string GenerateDetailFormatStringFromLabelRow