示例#1
0
        /// <summary>
        /// Populate All tables in the 'DataDictionary' DataSet with data extracted from the specified project PTU configuration database and the specified engineering
        /// data dictionary database and then write this data to the specified XML file. 
        /// </summary>
        /// <param name="oleDbPTUConfigurationConnection">The 'OleDbConnection' connection to a valid Microsoft Access project PTU configuration database.</param>
        /// <param name="oleDbConnection">The 'OleDbConnection' connection to a valid Microsoft Access engineering data dictionary database (.e1).</param>
        /// <param name="fullFilename">The fully qualified filename of the output XML file.</param>
        public static void WriteDataSetToXml(OleDbConnection oleDbPTUConfigurationConnection, OleDbConnection oleDbConnection, string fullFilename)
        {

            // Instantiate an empty DataSet into which the data is to be loaded.
            DataDictionary dataDictionary = new DataDictionary();

            // --------------------------------------------------------------------------------------------------------
            // Instantiate and fill those tables that are automatically created by the data dictionary builder utility.
            // --------------------------------------------------------------------------------------------------------

            ANNBITSTableAdapter annBitsTableAdapter = new ANNBITSTableAdapter();
            annBitsTableAdapter.Connection = oleDbConnection;
            annBitsTableAdapter.Fill(dataDictionary.ANNBITS);

            ANNIDSTableAdapter annIdsTableAdapter = new ANNIDSTableAdapter();
            annIdsTableAdapter.Connection = oleDbConnection;
            annIdsTableAdapter.Fill(dataDictionary.ANNIDS);

            ANNLIGHTTableAdapter annLightTableAdapter = new ANNLIGHTTableAdapter();
            annLightTableAdapter.Connection = oleDbConnection;
            annLightTableAdapter.Fill(dataDictionary.ANNLIGHT);

            ANNLISTTableAdapter annListTableAdapter = new ANNLISTTableAdapter();
            annListTableAdapter.Connection = oleDbConnection;
            annListTableAdapter.Fill(dataDictionary.ANNLIST);

            ANNUNENUMBITTableAdapter annEnumBitTableAdapter = new ANNUNENUMBITTableAdapter();
            annEnumBitTableAdapter.Connection = oleDbConnection;
            annEnumBitTableAdapter.Fill(dataDictionary.ANNUNENUMBIT);

            EVENTENUMBITTableAdapter eventEnumBitTableAdapter = new EVENTENUMBITTableAdapter();
            eventEnumBitTableAdapter.Connection = oleDbConnection;
            eventEnumBitTableAdapter.Fill(dataDictionary.EVENTENUMBIT);

            EVENTSTableAdapter eventsTableAdapter = new EVENTSTableAdapter();
            eventsTableAdapter.Connection = oleDbConnection;
            eventsTableAdapter.Fill(dataDictionary.EVENTS);

            EVENTVARIABLESTableAdapter eventVariablesTableAdapter = new EVENTVARIABLESTableAdapter();
            eventVariablesTableAdapter.Connection = oleDbConnection;
            eventVariablesTableAdapter.Fill(dataDictionary.EVENTVARIABLES);

            FILEINFOTableAdapter fileInfoTableAdapter = new FILEINFOTableAdapter();
            fileInfoTableAdapter.Connection = oleDbConnection;
            fileInfoTableAdapter.Fill(dataDictionary.FILEINFO);

            GROUPLISTTableAdapter groupListTableAdapter = new GROUPLISTTableAdapter();
            groupListTableAdapter.Connection = oleDbConnection;
            groupListTableAdapter.Fill(dataDictionary.GROUPLIST);

            GROUPLISTIDSTableAdapter groupListIdsTableAdapter = new GROUPLISTIDSTableAdapter();
            groupListIdsTableAdapter.Connection = oleDbConnection;
            groupListIdsTableAdapter.Fill(dataDictionary.GROUPLISTIDS);

            MACROCMDSTableAdapter macroCmdsTableAdapter = new MACROCMDSTableAdapter();
            macroCmdsTableAdapter.Connection = oleDbConnection;
            macroCmdsTableAdapter.Fill(dataDictionary.MACROCMDS);

            MACROSTableAdapter macrosTableAdapter = new MACROSTableAdapter();
            macrosTableAdapter.Connection = oleDbConnection;
            macrosTableAdapter.Fill(dataDictionary.MACROS);

            MAINTENANCETableAdapter maintenanceTableAdapter = new MAINTENANCETableAdapter();
            maintenanceTableAdapter.Connection = oleDbConnection;
            maintenanceTableAdapter.Fill(dataDictionary.MAINTENANCE);

            SELFTESTTableAdapter selfTestTableAdapter = new SELFTESTTableAdapter();
            selfTestTableAdapter.Connection = oleDbConnection;
            selfTestTableAdapter.Fill(dataDictionary.SELFTEST);

            SELFTESTENUMBITTableAdapter selfTestEnumBitTableAdapter = new SELFTESTENUMBITTableAdapter();
            selfTestEnumBitTableAdapter.Connection = oleDbConnection;
            selfTestEnumBitTableAdapter.Fill(dataDictionary.SELFTESTENUMBIT);

            SELFTESTERRMESSTableAdapter selfTestTerrMessTableAdapter = new SELFTESTERRMESSTableAdapter();
            selfTestTerrMessTableAdapter.Connection = oleDbConnection;
            selfTestTerrMessTableAdapter.Fill(dataDictionary.SELFTESTERRMESS);

            SELFTESTIDSTableAdapter selfTestIdsTableAdapter = new SELFTESTIDSTableAdapter();
            selfTestIdsTableAdapter.Connection = oleDbConnection;
            selfTestIdsTableAdapter.Fill(dataDictionary.SELFTESTIDS);

            SELFTESTVARIABLESTableAdapter selfTestVariablesTableAdapter = new SELFTESTVARIABLESTableAdapter();
            selfTestVariablesTableAdapter.Connection = oleDbConnection;
            selfTestVariablesTableAdapter.Fill(dataDictionary.SELFTESTVARIABLES);

            STRUCTTableAdapter structTableAdapter = new STRUCTTableAdapter();
            structTableAdapter.Connection = oleDbConnection;
            structTableAdapter.Fill(dataDictionary.STRUCT);

            TASKSTableAdapter tasksTableAdapter = new TASKSTableAdapter();
            tasksTableAdapter.Connection = oleDbConnection;
            tasksTableAdapter.Fill(dataDictionary.TASKS);

            TESTLISTTableAdapter testListTableAdapter = new TESTLISTTableAdapter();
            testListTableAdapter.Connection = oleDbConnection;
            testListTableAdapter.Fill(dataDictionary.TESTLIST);

            TESTLISTIDSTableAdapter testListIdsTableAdapter = new TESTLISTIDSTableAdapter();
            testListIdsTableAdapter.Connection = oleDbConnection;
            testListIdsTableAdapter.Fill(dataDictionary.TESTLISTIDS);

            TESTMESSAGESTableAdapter testMessagesTableAdapter = new TESTMESSAGESTableAdapter();
            testMessagesTableAdapter.Connection = oleDbConnection;
            testMessagesTableAdapter.Fill(dataDictionary.TESTMESSAGES);

            WATCHENUMBITTableAdapter watchEnumBitTableAdapter = new WATCHENUMBITTableAdapter();
            watchEnumBitTableAdapter.Connection = oleDbConnection;
            watchEnumBitTableAdapter.Fill(dataDictionary.WATCHENUMBIT);

            WATCHVARIABLESTableAdapter watchVariablesTableAdapter = new WATCHVARIABLESTableAdapter();
            watchVariablesTableAdapter.Connection = oleDbConnection;
            watchVariablesTableAdapter.Fill(dataDictionary.WATCHVARIABLES);

            // ----------------------------------------------------------------------------------------------------------------------
            // Include try/catch blocks on those tables that are not automatically created using the data dictionary builder utility. 
            // If an OleDbException is thrown, the XML generation process will be terminated and the user will be informed which table
            // threw the exception. These tables are populated from the project PTU configuration database, <project-id>.PTU Configuration.mdb,
            // rather than the engineering data dictionary database generated from the Database Builder Utility.
            // ----------------------------------------------------------------------------------------------------------------------

            // --------------------------------------------------------------------------------------------------------
            // Instantiate and fill those tables that are derived from the project PTU configuration database.
            // --------------------------------------------------------------------------------------------------------
            try
            {
                CONFIGUREPTUTableAdapter configurePTUTableAdapter = new CONFIGUREPTUTableAdapter();
                configurePTUTableAdapter.Connection = oleDbPTUConfigurationConnection;
                configurePTUTableAdapter.Fill(dataDictionary.CONFIGUREPTU);
            }
            catch (OleDbException)
            {
                throw new Exception(string.Format(Resources.MBTTableColumnMissing, "CONFIGUREPTU"));
            }

            try
            {
                DataStreamTypesTableAdapter dataStreamTypesTableAdapter = new DataStreamTypesTableAdapter();
                dataStreamTypesTableAdapter.Connection = oleDbPTUConfigurationConnection;
                dataStreamTypesTableAdapter.Fill(dataDictionary.DataStreamTypes);
            }
            catch (OleDbException)
            {
                throw new Exception(string.Format(Resources.MBTTableColumnMissing, "DataStreamTypes"));
            }

            try
            {
                // TODO - DataDictionary.WriteDataSetToXml(). Include code to create and fill a standard LOGSTableAdapter if an exception is thrown.
                LOGSTableAdapter logsTableAdapter = new LOGSTableAdapter();
                logsTableAdapter.Connection = oleDbPTUConfigurationConnection;
                logsTableAdapter.Fill(dataDictionary.LOGS);
            }
            catch (OleDbException)
            {
                throw new Exception(string.Format(Resources.MBTTableColumnMissing, "LOGS"));
            }

            try
            {
                SecurityTableAdapter securityTableAdapter = new SecurityTableAdapter();
                securityTableAdapter.Connection = oleDbPTUConfigurationConnection;
                securityTableAdapter.Fill(dataDictionary.Security);
            }
            catch (OleDbException)
            {
                throw new Exception(string.Format(Resources.MBTTableColumnMissing, "Security"));
            }

            try
            {
                URITableAdapter uRITableAdapter = new URITableAdapter();
                uRITableAdapter.Connection = oleDbPTUConfigurationConnection;
                uRITableAdapter.Fill(dataDictionary.URI);
            }
            catch (OleDbException)
            {
                throw new Exception(string.Format(Resources.MBTTableColumnMissing, "URI"));
            }
            
            // Write the DataSet containing the data to the specified XML file.
            dataDictionary.WriteXml(fullFilename, XmlWriteMode.WriteSchema);
        }
        /// <summary>
        /// Populate All tables in the 'DataDictionary' DataSet with data extracted from the specified project PTU configuration database and the specified engineering
        /// data dictionary database and then write this data to the specified XML file.
        /// </summary>
        /// <param name="oleDbPTUConfigurationConnection">The 'OleDbConnection' connection to a valid Microsoft Access project PTU configuration database.</param>
        /// <param name="oleDbConnection">The 'OleDbConnection' connection to a valid Microsoft Access engineering data dictionary database (.e1).</param>
        /// <param name="fullFilename">The fully qualified filename of the output XML file.</param>
        public static void WriteDataSetToXml(OleDbConnection oleDbPTUConfigurationConnection, OleDbConnection oleDbConnection, string fullFilename)
        {
            // Instantiate an empty DataSet into which the data is to be loaded.
            DataDictionary dataDictionary = new DataDictionary();

            // --------------------------------------------------------------------------------------------------------
            // Instantiate and fill those tables that are automatically created by the data dictionary builder utility.
            // --------------------------------------------------------------------------------------------------------

            ANNBITSTableAdapter annBitsTableAdapter = new ANNBITSTableAdapter();

            annBitsTableAdapter.Connection = oleDbConnection;
            annBitsTableAdapter.Fill(dataDictionary.ANNBITS);

            ANNIDSTableAdapter annIdsTableAdapter = new ANNIDSTableAdapter();

            annIdsTableAdapter.Connection = oleDbConnection;
            annIdsTableAdapter.Fill(dataDictionary.ANNIDS);

            ANNLIGHTTableAdapter annLightTableAdapter = new ANNLIGHTTableAdapter();

            annLightTableAdapter.Connection = oleDbConnection;
            annLightTableAdapter.Fill(dataDictionary.ANNLIGHT);

            ANNLISTTableAdapter annListTableAdapter = new ANNLISTTableAdapter();

            annListTableAdapter.Connection = oleDbConnection;
            annListTableAdapter.Fill(dataDictionary.ANNLIST);

            ANNUNENUMBITTableAdapter annEnumBitTableAdapter = new ANNUNENUMBITTableAdapter();

            annEnumBitTableAdapter.Connection = oleDbConnection;
            annEnumBitTableAdapter.Fill(dataDictionary.ANNUNENUMBIT);

            EVENTENUMBITTableAdapter eventEnumBitTableAdapter = new EVENTENUMBITTableAdapter();

            eventEnumBitTableAdapter.Connection = oleDbConnection;
            eventEnumBitTableAdapter.Fill(dataDictionary.EVENTENUMBIT);

            EVENTSTableAdapter eventsTableAdapter = new EVENTSTableAdapter();

            eventsTableAdapter.Connection = oleDbConnection;
            eventsTableAdapter.Fill(dataDictionary.EVENTS);

            EVENTVARIABLESTableAdapter eventVariablesTableAdapter = new EVENTVARIABLESTableAdapter();

            eventVariablesTableAdapter.Connection = oleDbConnection;
            eventVariablesTableAdapter.Fill(dataDictionary.EVENTVARIABLES);

            FILEINFOTableAdapter fileInfoTableAdapter = new FILEINFOTableAdapter();

            fileInfoTableAdapter.Connection = oleDbConnection;
            fileInfoTableAdapter.Fill(dataDictionary.FILEINFO);

            GROUPLISTTableAdapter groupListTableAdapter = new GROUPLISTTableAdapter();

            groupListTableAdapter.Connection = oleDbConnection;
            groupListTableAdapter.Fill(dataDictionary.GROUPLIST);

            GROUPLISTIDSTableAdapter groupListIdsTableAdapter = new GROUPLISTIDSTableAdapter();

            groupListIdsTableAdapter.Connection = oleDbConnection;
            groupListIdsTableAdapter.Fill(dataDictionary.GROUPLISTIDS);

            MACROCMDSTableAdapter macroCmdsTableAdapter = new MACROCMDSTableAdapter();

            macroCmdsTableAdapter.Connection = oleDbConnection;
            macroCmdsTableAdapter.Fill(dataDictionary.MACROCMDS);

            MACROSTableAdapter macrosTableAdapter = new MACROSTableAdapter();

            macrosTableAdapter.Connection = oleDbConnection;
            macrosTableAdapter.Fill(dataDictionary.MACROS);

            MAINTENANCETableAdapter maintenanceTableAdapter = new MAINTENANCETableAdapter();

            maintenanceTableAdapter.Connection = oleDbConnection;
            maintenanceTableAdapter.Fill(dataDictionary.MAINTENANCE);

            SELFTESTTableAdapter selfTestTableAdapter = new SELFTESTTableAdapter();

            selfTestTableAdapter.Connection = oleDbConnection;
            selfTestTableAdapter.Fill(dataDictionary.SELFTEST);

            SELFTESTENUMBITTableAdapter selfTestEnumBitTableAdapter = new SELFTESTENUMBITTableAdapter();

            selfTestEnumBitTableAdapter.Connection = oleDbConnection;
            selfTestEnumBitTableAdapter.Fill(dataDictionary.SELFTESTENUMBIT);

            SELFTESTERRMESSTableAdapter selfTestTerrMessTableAdapter = new SELFTESTERRMESSTableAdapter();

            selfTestTerrMessTableAdapter.Connection = oleDbConnection;
            selfTestTerrMessTableAdapter.Fill(dataDictionary.SELFTESTERRMESS);

            SELFTESTIDSTableAdapter selfTestIdsTableAdapter = new SELFTESTIDSTableAdapter();

            selfTestIdsTableAdapter.Connection = oleDbConnection;
            selfTestIdsTableAdapter.Fill(dataDictionary.SELFTESTIDS);

            SELFTESTVARIABLESTableAdapter selfTestVariablesTableAdapter = new SELFTESTVARIABLESTableAdapter();

            selfTestVariablesTableAdapter.Connection = oleDbConnection;
            selfTestVariablesTableAdapter.Fill(dataDictionary.SELFTESTVARIABLES);

            STRUCTTableAdapter structTableAdapter = new STRUCTTableAdapter();

            structTableAdapter.Connection = oleDbConnection;
            structTableAdapter.Fill(dataDictionary.STRUCT);

            TASKSTableAdapter tasksTableAdapter = new TASKSTableAdapter();

            tasksTableAdapter.Connection = oleDbConnection;
            tasksTableAdapter.Fill(dataDictionary.TASKS);

            TESTLISTTableAdapter testListTableAdapter = new TESTLISTTableAdapter();

            testListTableAdapter.Connection = oleDbConnection;
            testListTableAdapter.Fill(dataDictionary.TESTLIST);

            TESTLISTIDSTableAdapter testListIdsTableAdapter = new TESTLISTIDSTableAdapter();

            testListIdsTableAdapter.Connection = oleDbConnection;
            testListIdsTableAdapter.Fill(dataDictionary.TESTLISTIDS);

            TESTMESSAGESTableAdapter testMessagesTableAdapter = new TESTMESSAGESTableAdapter();

            testMessagesTableAdapter.Connection = oleDbConnection;
            testMessagesTableAdapter.Fill(dataDictionary.TESTMESSAGES);

            WATCHENUMBITTableAdapter watchEnumBitTableAdapter = new WATCHENUMBITTableAdapter();

            watchEnumBitTableAdapter.Connection = oleDbConnection;
            watchEnumBitTableAdapter.Fill(dataDictionary.WATCHENUMBIT);

            WATCHVARIABLESTableAdapter watchVariablesTableAdapter = new WATCHVARIABLESTableAdapter();

            watchVariablesTableAdapter.Connection = oleDbConnection;
            watchVariablesTableAdapter.Fill(dataDictionary.WATCHVARIABLES);

            // ----------------------------------------------------------------------------------------------------------------------
            // Include try/catch blocks on those tables that are not automatically created using the data dictionary builder utility.
            // If an OleDbException is thrown, the XML generation process will be terminated and the user will be informed which table
            // threw the exception. These tables are populated from the project PTU configuration database, <project-id>.PTU Configuration.mdb,
            // rather than the engineering data dictionary database generated from the Database Builder Utility.
            // ----------------------------------------------------------------------------------------------------------------------

            // --------------------------------------------------------------------------------------------------------
            // Instantiate and fill those tables that are derived from the project PTU configuration database.
            // --------------------------------------------------------------------------------------------------------
            try
            {
                CONFIGUREPTUTableAdapter configurePTUTableAdapter = new CONFIGUREPTUTableAdapter();
                configurePTUTableAdapter.Connection = oleDbPTUConfigurationConnection;
                configurePTUTableAdapter.Fill(dataDictionary.CONFIGUREPTU);
            }
            catch (OleDbException)
            {
                throw new Exception(string.Format(Resources.MBTTableColumnMissing, "CONFIGUREPTU"));
            }

            try
            {
                DataStreamTypesTableAdapter dataStreamTypesTableAdapter = new DataStreamTypesTableAdapter();
                dataStreamTypesTableAdapter.Connection = oleDbPTUConfigurationConnection;
                dataStreamTypesTableAdapter.Fill(dataDictionary.DataStreamTypes);
            }
            catch (OleDbException)
            {
                throw new Exception(string.Format(Resources.MBTTableColumnMissing, "DataStreamTypes"));
            }

            try
            {
                // TODO - DataDictionary.WriteDataSetToXml(). Include code to create and fill a standard LOGSTableAdapter if an exception is thrown.
                LOGSTableAdapter logsTableAdapter = new LOGSTableAdapter();
                logsTableAdapter.Connection = oleDbPTUConfigurationConnection;
                logsTableAdapter.Fill(dataDictionary.LOGS);
            }
            catch (OleDbException)
            {
                throw new Exception(string.Format(Resources.MBTTableColumnMissing, "LOGS"));
            }

            try
            {
                SecurityTableAdapter securityTableAdapter = new SecurityTableAdapter();
                securityTableAdapter.Connection = oleDbPTUConfigurationConnection;
                securityTableAdapter.Fill(dataDictionary.Security);
            }
            catch (OleDbException)
            {
                throw new Exception(string.Format(Resources.MBTTableColumnMissing, "Security"));
            }

            try
            {
                URITableAdapter uRITableAdapter = new URITableAdapter();
                uRITableAdapter.Connection = oleDbPTUConfigurationConnection;
                uRITableAdapter.Fill(dataDictionary.URI);
            }
            catch (OleDbException)
            {
                throw new Exception(string.Format(Resources.MBTTableColumnMissing, "URI"));
            }

            // Write the DataSet containing the data to the specified XML file.
            dataDictionary.WriteXml(fullFilename, XmlWriteMode.WriteSchema);
        }