} // private static int ListAppSettings /// <summary> /// When called by the main routine, this routine generates two lists of /// the string resources embedded in the executing assembly. The first /// list is displayed on the console, while the second is written into a /// file as a set of tab delimited list of records. /// </summary> /// <param name="pintTestNumber"> /// The sequential test number is passed into this routine, which /// increments it, and returns the new value. /// </param> /// <returns> /// The return value is <paramref name="pintTestNumber"/> incremented by /// one. /// </returns> private static int ListEmbeddedResources ( int pintTestNumber ) { Utl.BeginTest ( Properties.Resources.MSG_TEST_3_PROLOGUE , ref pintTestNumber ); string strAppSettingsReportFileName = Utl.AssembleAbsoluteFileName ( Properties.Settings.Default.EMBEDDED_RESOURCES_REPORT_FILENAME ); using ( StreamWriter writer = new StreamWriter ( strAppSettingsReportFileName , FileIOFlags.FILE_OUT_CREATE , System.Text.Encoding.Unicode , MagicNumbers.CAPACITY_08KB ) ) { WizardWrx.AssemblyUtils.SortableManagedResourceItem.ListResourcesInAssemblyByName ( System.Reflection.Assembly.GetExecutingAssembly ( ) , writer ); } // using ( StreamWriter writer = new StreamWriter ( strAppSettingsReportFileName , FileIOFlags.FILE_OUT_CREATE , System.Text.Encoding.Unicode , MagicNumbers.CAPACITY_08KB ) ) Console.WriteLine ( Utl.ShowFileDetails ( Properties.Resources.FILE_LABEL_EMBEDD3ED_RESOUCES_REPORT , // string pstrLabel strAppSettingsReportFileName , // string pstrFileName true , // bool pfPrefixWithNewline = false false ) ); // bool pfSuffixWithNewline = true s_smThisApp.BaseStateManager.AppReturnCode = Utl.TestDone ( MagicNumbers.ERROR_SUCCESS , pintTestNumber ); return pintTestNumber; } // private static int ListEmbeddedResources
} // static void Main /// <summary> /// When called by the main routine, this routine generates two lists of /// the application settings defined in the application configuration /// file associated with the entry assembly. The first list is displayed /// on the console, while the second is written into a file as a set of /// tab delimited list of records. /// </summary> /// <param name="pintTestNumber"> /// The sequential test number is passed into this routine, which /// increments it, and returns the new value. /// </param> /// <returns> /// The return value is <paramref name="pintTestNumber"/> incremented by /// one. /// </returns> private static int ListAppSettings ( int pintTestNumber ) { Utl.BeginTest ( Properties.Resources.MSG_TEST_2_PROLOGUE , ref pintTestNumber ); // ---------------------------------------------------------------- // Load the settings into a SettingsPropertyCollection object, then // enumerate it with two objectives. // // 1) Show that the items returned by the enumerator are unsorted. // 2) Fill an array of SortableSettingsProperty objects. // ---------------------------------------------------------------- SettingsPropertyCollection spcMySettings = Properties.Settings.Default.Properties; int intTotalItems = spcMySettings.Count; Console.WriteLine ( Properties.Resources.MSG_SETTINGS_ENUMERATION_HEADING , // Format control string intTotalItems , // Format Item 0 Environment.NewLine ); // Format Item 1 SortableSettingsProperty [ ] asspSortableSettings = new SortableSettingsProperty [ intTotalItems ]; int intItenNumber = ListInfo.LIST_IS_EMPTY; foreach ( SettingsProperty setting in spcMySettings ) { // Do everything in one pass, using the third constructor, since the single-argument constructor left most of the fields uninitialized. asspSortableSettings [ intItenNumber ] = new SortableSettingsProperty ( setting.Name , // string name setting.PropertyType , // Type propertType setting.Provider , // SettingsProvider provider true , // bool isReadOnly setting.DefaultValue , // object defaultValue setting.SerializeAs , // SettingsSerializeAs serializeAs setting.Attributes , // SettingsAttributeDictionary attributes true , // bool throwOnErrorDeserializing true ); // bool throwOnErrorSerializing Console.WriteLine ( Properties.Resources.MSG_APP_SETTINGS_DETAIL_TEMPLATE , // Format control string ++intItenNumber , // Format Item 0: {0,2} of intTotalItems , // Format Item 1: of {1,2}: setting.Name , // Format Item 2: Name = {2} setting.DefaultValue ); // Format Item 3: Value = {3} } // foreach ( SettingsProperty setting in spcMySettings ) // ---------------------------------------------------------------- // Sort the array, then iterate it by way of a conventional FOR // loop, listing the name, type, and default value of each setting. // This listing is ordered by setting name. // ---------------------------------------------------------------- Array.Sort ( asspSortableSettings ); Console.WriteLine ( Properties.Resources.MSG_SORTED_APP_SETTINGS_LIST_HEADING , // Format control string intTotalItems , // Format Item 0: Enumerate the {0} Environment.NewLine ); // Format Item 1: sorted settings:{1} intItenNumber = ListInfo.LIST_IS_EMPTY; string strAppSettingsReportFileName = Utl.AssembleAbsoluteFileName ( Properties.Settings.Default.APP_SETTINGS_REPORT_FILENAME ); using ( StreamWriter swAppSettings = new StreamWriter ( strAppSettingsReportFileName , FileIOFlags.FILE_OUT_CREATE , System.Text.Encoding.ASCII , MagicNumbers.CAPACITY_08KB ) ) { string strDetailRowFormatString = GenerateDetailFormatStringFromLabelRow ( swAppSettings ); for ( int intIndex = ArrayInfo.ARRAY_FIRST_ELEMENT ; intIndex < intTotalItems ; intIndex++ ) { SortableSettingsProperty settingsProperty = asspSortableSettings [ intIndex ]; Console.WriteLine ( Properties.Resources.MSG_APP_SETTINGS_SORTED_ITEM , // Format control string ++intItenNumber , // Format Item 0: {0,2} of intTotalItems , // Format Item 1: of {1,2}: settingsProperty.Name , // Format Item 2: Name = {2} settingsProperty.PropertyType.FullName , // Format Item 3: Type = {2} settingsProperty.DefaultValue ); // Format Item 4: Value = {4} swAppSettings.WriteLine ( strDetailRowFormatString , // The generated format control string consists entirely of format items and TAB characters. intItenNumber , // The item number was incremented just before the console line was assembled. settingsProperty.Name , settingsProperty.PropertyType.FullName , settingsProperty.DefaultValue ); } // for ( int intIndex = ArrayInfo.ARRAY_FIRST_ELEMENT ; intIndex < intTotalItems ; intIndex++ ) } // using ( StreamWriter swAppSettings = new StreamWriter ( Utl.AssembleAbsoluteFileName ( Properties.Settings.Default.APP_SETTINGS_REPORT ) , FileIOFlags.FILE_OUT_CREATE , System.Text.Encoding.ASCII , MagicNumbers.CAPACITY_08KB ) ) Console.WriteLine ( Utl.ShowFileDetails ( Properties.Resources.FILE_LABEL_APP_SETTINGS_LIST , // string pstrLabel strAppSettingsReportFileName , // string pstrFileName true , // bool pfPrefixWithNewline = false false ) ); // bool pfSuffixWithNewline = true s_smThisApp.BaseStateManager.AppReturnCode = Utl.TestDone ( MagicNumbers.ERROR_SUCCESS , pintTestNumber ); return pintTestNumber; } // private static int ListAppSettings