Пример #1
0
        /// <summary>
        /// Clean up the resources used by the form.
        /// </summary>
        /// <param name="disposing">True to release both managed and unmanaged resources; false to release only unmanaged resources.</param>
        protected virtual void Cleanup(bool disposing)
        {
            this.Cursor = Cursors.WaitCursor;
            try
            {
                // Provided that the form isn't minimized, update the WindowState setting.
                if (this.WindowState != FormWindowState.Minimized)
                {
                    Settings.Default.WindowState = this.WindowState;
                    Settings.Default.Save();
                }

                // If the WindowState property is normal, update the: Location and Size settings.
                if (this.WindowState == FormWindowState.Normal)
                {
                    Settings.Default.FormLocation = this.Location;
                    Settings.Default.FormSize = this.Size;
                    Settings.Default.Save();
                }

                CloseChildForms();
                DebugMode.Close();
                WinHlp32.Close(this.Handle.ToInt32());

                // Ensure that the communication port is closed.
                if (m_CommunicationInterface != null)
                {
                    CommunicationInterface.CloseCommunication(CommunicationInterface.CommunicationSetting.Protocol);
                }

                if (disposing)
                {
                    // Method called by consumer code. Call the Dispose method of any managed data members that implement the dispose method.
                    // Cleanup managed objects by calling their Dispose() methods.
                    if (components != null)
                    {
                        components.Dispose();
                    }

                    if (m_DataDictionary != null)
                    {
                        m_DataDictionary.Dispose();
                    }

                    if (m_ControlPanel != null)
                    {
                        m_ControlPanel.Dispose();
                    }

                    if (m_TimerWibuBox != null)
                    {
                        m_TimerWibuBox.Stop();
                        m_TimerWibuBox.Enabled = false;
                        m_TimerWibuBox.Tick -= new EventHandler(WibuBoxCheck);
                        m_TimerWibuBox.Dispose();
                    }
                }

                // Whether called by consumer code or the garbage collector free all unmanaged resources and set the value of managed data 
                // members to null.
                m_DataDictionary = null;
                m_TimerWibuBox = null;
                m_ControlPanel = null;
                m_CommunicationInterface = null;
                m_MenuInterfaceApplication = null;
                m_MenuInterfaceEvent = null;
                m_MenuInterfaceSelfTest = null;
                m_MenuInterfaceWatch = null;
                m_MenuInterfaceWibuKey = null;
                m_Security = null;
            }
            catch (Exception)
            {
                // Don't do anything, just ensure that an exception is not thrown.
            }
            this.Cursor = Cursors.Default;
        }
Пример #2
0
        /// <summary>
        /// Event handler for the form 'Shown' event. Loads the PTU configuration file and initializes the communication interface.
        /// </summary>
        /// <param name="sender">Reference to the object that raised the event.</param>
        /// <param name="e">Parameter passed from the object that raised the event.</param>
        private void MdiPTU_Shown(object sender, EventArgs e)
        {
            // Skip, if the Dispose() method has been called.
            if (IsDisposed)
            {
                return;
            }

            this.Update();
            Cursor = Cursors.WaitCursor;

            // ----------------------------------
            // Load the XML data dictionary file.
            // ----------------------------------
            m_DataDictionary = new DataDictionary();

            // Check whether the default XML configuration file is to be used.
            if (m_FilenameDataDictionary == Resources.FilenameDefaultDataDictionary)
            {
                // Yes - Check whether the default configuration file exists.
                string fullFilename = DirectoryManager.PathPTUConfigurationFiles + @"\" + m_FilenameDataDictionary;
                FileInfo fileInfo = new FileInfo(fullFilename);
                if (fileInfo.Exists == false)
                {
                    MessageBox.Show(string.Format(Resources.MBTConfigDefaultNotFound, Resources.FilenameDefaultDataDictionary), Resources.MBCaptionWarning,
                                    MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    Security.Initialize();
                    m_Security = new Security();
                    ShowSecurityLevelChange(m_Security);
                    Cursor = Cursors.Default;
                    SetMode(Mode.Setup);
                    return;
                }
            }
            
            // Read the XML configuration file.
            try
            {
                // If the XML file hasn't been updated to include the YearCodeSize field of the CONFIGUREPTU table, the other fields of the table are still
                // read in correctly. If an attempt is made to access 'm_DataDictionary.CONFIGUREPTU[0].YearCodeSize' an exception is thrown.
                m_DataDictionary.ReadXml(DirectoryManager.PathPTUConfigurationFiles + CommonConstants.BindingFilename + m_FilenameDataDictionary);
            }
            catch (Exception)
            {
                MessageBox.Show(string.Format(Resources.MBTConfigInvalid, m_FilenameDataDictionary) + CommonConstants.Space + Resources.MBTConfigReselect,
                                              Resources.MBCaptionError, MessageBoxButtons.OK, MessageBoxIcon.Error);
                Security.Initialize();
                m_Security = new Security();
                ShowSecurityLevelChange(m_Security);
                Cursor = Cursors.Default;
                SetMode(Mode.Setup);
                return;
            }
            finally
            {
                this.Cursor = Cursors.Default;
            }

            Cursor = Cursors.WaitCursor;
            LoadDictionary(m_DataDictionary);
            Cursor = Cursors.Default;
        }
Пример #3
0
        /// <summary>
        /// Initializes the class properties to the parameter values contained within the specified configuration file. If any configuration file
        /// parameters are invalid all properties associated with the table to which the parameter belongs will be left at their default values.
        /// </summary>
        /// <param name="dataDictionary">The <c>DataSet</c> corresponding to the current data dictionary.</param>
        public static void Initialize(DataDictionary dataDictionary)
        {
            // Set the data dictionary defined properties to their default values.
            SetToDefault();

            // Now overlay the values defined in the data dictionary. If an exception is thrown the properties will be left in their default state.

            // --------------------
            // Function Flags
            // --------------------
            try
            {
                m_FunctionFlags = dataDictionary.CONFIGUREPTU[0].FunctionFlags;
                m_Use4DigitYearCode = ((m_FunctionFlags & CommonConstants.MaskBit0) == CommonConstants.MaskBit0) ? true : false;
                m_ShowLogName = ((m_FunctionFlags & CommonConstants.MaskBit1) == CommonConstants.MaskBit1) ? true : false;
            }
            catch (Exception)
            {
                // Use the default values set up by the static constructor instead.
            }

            // --------------------
            // Recorded Watch Data
            // --------------------
            try
            {
                m_WatchSize = dataDictionary.CONFIGUREPTU[0].WatchSize;
                short watchReturn = (short)CommunicationError.UnknownError;

                // Inform the VcuCommunication32/VcuCommunication64 dynamic link library of the number of watch variables that are associated with the
                // project.
                CommunicationParent communicationInterface = new CommunicationParent();
                watchReturn = communicationInterface.SetWatchSize(m_WatchSize);
                communicationInterface = null;

                if (watchReturn != m_WatchSize)
                {
                    // Use the returned value.
                    m_WatchSize = watchReturn;

                    MessageBox.Show(Resources.MBTWatchSizeInvalid, Resources.MBCaptionWarning, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
            catch (System.EntryPointNotFoundException)
            {
                MessageBox.Show(Resources.MBTSetWatchSizeNotSupported, Resources.MBCaptionWarning, MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            catch (Exception)
            {
                // Use the default values set up by the static constructor instead.
            }

            // --------------------
            // Fault Log WatchSize
            // --------------------
            try
            {
                // Scan the number of watch variables that are recorded by each event log and determine the maximum.
                short watchVariablesMax = 0;
                short watchVariablesPrev = 0;
                short watchVariableCurrent;
                bool firstPass = true;
                m_SupportsMultipleDataStreamTypes = false;
                for (short recordIndex = 0; recordIndex < dataDictionary.LOGS.Count; recordIndex++)
                {
                    watchVariableCurrent = dataDictionary.DataStreamTypes[dataDictionary.LOGS[recordIndex].DataStreamTypeIdentifier].WatchVariablesMax;

                    if (firstPass == true)
                    {
                        watchVariablesMax = watchVariableCurrent;
                        watchVariablesPrev = watchVariableCurrent;
                        firstPass = false;
                    }
                    else
                    {
                        if (watchVariableCurrent > watchVariablesMax)
                        {
                            watchVariablesMax = watchVariableCurrent;
                        }

                        if (watchVariableCurrent != watchVariablesPrev)
                        {
                            m_SupportsMultipleDataStreamTypes = true;
                        }
                    }
                }

                m_WatchSizeFaultLog = watchVariablesMax;
            }
            catch (Exception)
            {
                // Use the default values set up by the static constructor instead.
            }

            // --------------------
            // Project Information
            // --------------------
            try
            {
                m_ProjectInformation.DataDictionaryName = dataDictionary.FILEINFO[0].DDNAME;
                m_ProjectInformation.ProjectIdentifier = dataDictionary.FILEINFO[0].PROJECTSTRING;
                m_ProjectInformation.Version = dataDictionary.FILEINFO[0].VERSION;
                m_ProjectInformation.DataDictionaryBuilderVersion = dataDictionary.FILEINFO[0].DDBVersion;
                m_ProjectInformation.WatchIdentifierCount = dataDictionary.FILEINFO[0].NUMOFVARS;
            }
            catch (Exception)
            {
                // Use the default values set up by the static constructor instead.
            }

            // ----------------------
            // WibuBox Parameters
            // ----------------------
            try
            {
                m_WibuBox.FirmCode = dataDictionary.CONFIGUREPTU[0].FIRMCODE;
                m_WibuBox.UserCode = dataDictionary.CONFIGUREPTU[0].USERCODE;
                m_WibuBox.SlotId = dataDictionary.CONFIGUREPTU[0].SLOTID;
                m_WibuBox.PortId = dataDictionary.CONFIGUREPTU[0].PORTID;
            }
            catch(Exception)
            {
                // Use the default values set up by the static constructor instead.
            }

            // ----------------------
            // Application Data Path
            // ----------------------
            try
            {
                m_PathPTUApplicationData = dataDictionary.CONFIGUREPTU[0].ApplicationDataPath;
            }
            catch (Exception)
            {
                // Use the default values set up by the static constructor instead.
            }

            // --------
            // Security
            // --------
            try
            {
                m_SecurityConfiguration.DescriptionLevel0 = dataDictionary.Security[0].DescriptionLevel0;
                m_SecurityConfiguration.DescriptionLevel1 = dataDictionary.Security[0].DescriptionLevel1;
                m_SecurityConfiguration.DescriptionLevel2 = dataDictionary.Security[0].DescriptionLevel2;
                m_SecurityConfiguration.DescriptionLevel3 = dataDictionary.Security[0].DescriptionLevel3;
                m_SecurityConfiguration.SecurityLevelBase = (SecurityLevel)dataDictionary.Security[0].SecurityLevelBase;
                m_SecurityConfiguration.SecurityLevelHighest = (SecurityLevel)dataDictionary.Security[0].SecurityLevelHighest;
            }
            catch (Exception)
            {
                // Use the default values set up by the static constructor instead.
            }

            // ----------------------
            // Communication Variables
            // ----------------------
            try
            {
                //DAS m_CommunicationType = (CommunicationTypeEnum)dataDictionary.CONFIGUREPTU[0].CommunicationType;
            }
            catch (Exception)
            {
                // Use the default values set up by the static constructor instead.
            }

            try
            {
                m_URIList = new List<string>(dataDictionary.URI.Count);
                foreach (System.Data.DataRow dataRow in dataDictionary.URI.Rows)
                {
                    string URI = (string)dataRow.ItemArray[1];
                    if (URI.Length > 0)
                    {
                        m_URIList.Add(URI);
                    }
                }
            }
            catch (Exception)
            {
                // Use the default values set up by the static constructor instead.
            }
        }
Пример #4
0
        /// <summary>
        /// Check whether the PTU configuration and the propulsion system software match. This method checks whether the PTU configuration matches that of the
        /// propulsion system software and attempts to load the correct configuration file if they do not match.
        /// </summary>
        /// <param name="targetProjectIdentifier">The project identifier of the propulsion system software.</param>
        /// <param name="targetVersion">The version reference of the propulsion system software.</param>
        /// <returns>A flag that indicates whether the PTU configuration matches that of the propulsion system software. True, if they are matched; otherwise, false.
        /// </returns>
        private bool CheckConfiguration(string targetProjectIdentifier, string targetVersion)
        {
            // A flag that indicates whether the PTU configuration matches that of the propulsion system software. True, if they are matched; otherwise, false.
            bool configurationMatch = false;

            // The DialogResult returned from the call to the MessageBox() method.
            DialogResult dialogResult;

#if ByPassVersionCheck
            while (Parameter.ProjectInformation.ProjectIdentifier != targetProjectIdentifier)
#else
            // Repeat until the PTU configuration matches that of the propulsion system software.
            while ((Parameter.ProjectInformation.ProjectIdentifier != targetProjectIdentifier) ||
                   (Parameter.ProjectInformation.Version != targetVersion))
#endif
            {
                #region - [Configuration Mismatch] -
                this.Cursor = Cursors.WaitCursor;
                // ---------------------------------------------------------------------------------------------------------------------------------------------
                // There is a mismatch between the PTU configuration and the propulsion system software. Determine whether the mismatch is a result of a version
                // number mismatch or because of a project mismatch.
                // ---------------------------------------------------------------------------------------------------------------------------------------------

                // Check whether the project identifiers match.
                if (Parameter.ProjectInformation.ProjectIdentifier == targetProjectIdentifier)
                {
                    // The project identifiers match, therefore the mismatch is between the version numbers. Ask whether an attempt is to be made to load the
                    // data dictionary associated with the target version number.
                    dialogResult = MessageBox.Show(Resources.MBTConfigVCUMismatchVersion, Resources.MBCaptionWarning, MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                }
                else
                {
                    // The PTU project identifier does not match that of the propulsion system software. Ask whether an attempt is to be made to load the data dictionary
                    // associated with the project-identifier and version reference of the embedded software loaded into the VCU.
                    dialogResult = MessageBox.Show(Resources.MBTConfigVCUMismatchProjectId, Resources.MBCaptionWarning, MessageBoxButtons.YesNo,
                                                    MessageBoxIcon.Warning);
                }

                // Skip, if the user does not wish to load the appropriate data dictionary.
                if (dialogResult == DialogResult.No)
                {
                    this.Cursor = Cursors.Default;
                    configurationMatch = false;
                    return (configurationMatch);
                }

                // ------------------------------------------------------------------------------------------------------
                // The user has selected to update the PTU configuration to match that of the propulsion system software.
                // ------------------------------------------------------------------------------------------------------

                // Check whether the correct PTU configuration file associated with the propulsion system software exists in the default 'PTU Configuration Files'
                // sub-directory.
                string fullyQualifiedSourceFilename = DirectoryManager.PathPTUConfigurationFiles + CommonConstants.BindingFilename +
                                                      targetVersion + CommonConstants.ExtensionDataDictionary;
                FileInfo fileInfoSource = new FileInfo(fullyQualifiedSourceFilename);
                m_DataDictionary = new DataDictionary();

                if (fileInfoSource.Exists == false)
                {
                    #region - [Locate PTU Configuration File] -
                    switch (Parameter.ProjectInformation.ProjectIdentifier)
                    {
                        case CommonConstants.ProjectIdCTA:
                            #region - [Download From VCU] -
                            // Modified for the CTA contract. Ref.: P.O. 4800011369-CU2 07.07.2015. Attempt to download the PTU configuration files
                            // from the propulsion system software.

                            // Check that the Windows command file exists.
                            string fullyQualifiedCommandFilename = DirectoryManager.PathPTUApplicationData + CommonConstants.BindingFilename +
                                                                   Resources.FilenameWindowsCommandFile;
                            FileInfo fileInfoCommandFile = new FileInfo(fullyQualifiedCommandFilename);
                            if (fileInfoCommandFile.Exists != true)
                            {
                                MessageBox.Show(string.Format(Resources.MBTConfigVCUDownloadCommandFileNotFound, Resources.FilenameWindowsCommandFile),
                                                              Resources.MBCaptionError, MessageBoxButtons.OK, MessageBoxIcon.Error);
                                this.Cursor = Cursors.Default;
                                configurationMatch = false;
                                return (configurationMatch);
                            }

                            // The error code that is returned from the batch file.
                            FTPErrorCode ftpErrorCode = FTPErrorCode.Undefined;
                            int exitCode = 0;
                            System.Text.StringBuilder stringBuilder = new System.Text.StringBuilder();
                            string newInstruction = CommonConstants.NewLine + CommonConstants.NewLine;
                            stringBuilder.AppendFormat(Resources.MBTConfigVCUDownloadStart, newInstruction, newInstruction, newInstruction, newInstruction);
                            dialogResult = MessageBox.Show(stringBuilder.ToString(), Resources.MBCaptionInformation, MessageBoxButtons.OK, MessageBoxIcon.Information);
                            

                            try
                            {
                                Process commandProcess = new Process();
                                commandProcess.StartInfo.WorkingDirectory = DirectoryManager.PathPTUApplicationData;
                                commandProcess.StartInfo.FileName = Resources.FilenameWindowsCommandFile;
                                commandProcess.StartInfo.Arguments = (Parameter.ProjectInformation.ProjectIdentifier.Equals(CommonConstants.ProjectIdCTA)) ?
                                                                      Resources.CommandLineArgumentCTA : Resources.CommandLineArgumentBART;
                                commandProcess.Start();
                                WriteStatusMessage(Resources.MBTConfigVCUDownloadInProgress, System.Drawing.Color.White, System.Drawing.Color.Red);
                                commandProcess.WaitForExit();
                                exitCode = commandProcess.ExitCode;
                                ftpErrorCode = (FTPErrorCode)exitCode;
                            }
                            catch (Exception)
                            {
                                ftpErrorCode = FTPErrorCode.SystemException;
                            }

                            // Check the error code that was returned from the batch file.
                            if (ftpErrorCode == FTPErrorCode.Success)
                            {
                                // Check that the correct PTU configuration and help files now exists.
                                string fullyQualifiedRequiredFilenameXML = DirectoryManager.PathPTUConfigurationFiles + CommonConstants.BindingFilename +
                                                      targetVersion + CommonConstants.ExtensionDataDictionary;
                                FileInfo fileInfoRequiredFilenameXML = new FileInfo(fullyQualifiedRequiredFilenameXML);

                                string fullyQualifiedRequiredFilenameHLP = DirectoryManager.PathDiagnosticHelpFiles + CommonConstants.BindingFilename +
                                                      targetVersion + CommonConstants.ExtensionHelpFile;
                                FileInfo fileInfoRequiredFilenameHLP = new FileInfo(fullyQualifiedRequiredFilenameHLP);
                                if ((fileInfoRequiredFilenameXML.Exists == true) &&
                                    (fileInfoRequiredFilenameHLP.Exists == true))
                                {
                                    WriteStatusMessage(string.Empty);
                                    MessageBox.Show(Resources.MBTConfigVCUDownloadComplete, Resources.MBCaptionInformation, MessageBoxButtons.OK,
                                               MessageBoxIcon.Information);
                                }
                                else
                                {
                                    WriteStatusMessage(string.Empty);
                                    MessageBox.Show(Resources.MBTConfigVCUDownloadUnsuccessful, Resources.MBCaptionError, MessageBoxButtons.OK, MessageBoxIcon.Error);
                                    this.Cursor = Cursors.Default;
                                    configurationMatch = false;
                                    return (configurationMatch);
                                }
                            }
                            else
                            {
                                WriteStatusMessage(string.Empty);
                                MessageBox.Show(string.Format(Resources.MBTConfigVCUDownloadUnsuccessfulWithErrorCode,
                                                exitCode, FtpErrorProcessing.GetErrorMessage(ftpErrorCode)),
                                                Resources.MBCaptionError, MessageBoxButtons.OK, MessageBoxIcon.Error);
                                this.Cursor = Cursors.Default;
                                configurationMatch = false;
                                return (configurationMatch);
                            }
                            #endregion - [Download From VCU] -
                            break;
                        default:
                            #region - [Manual File Selection] -
                            // The PTU configuration file associated with the propulsion system software cannot be found in the default 'PTU Configuration Files'
                            // sub-directory. Ask the user whether the file is to be located manually.
                            dialogResult = MessageBox.Show(Resources.MBTConfigVCUMatchNotFoundManualSelection, Resources.MBCaptionWarning, MessageBoxButtons.YesNo,
                                                           MessageBoxIcon.Warning);

                            if (dialogResult == DialogResult.Yes)
                            {
                                // -----------------------------------------------------------------
                                // Allow the user to select an alternative data dictionary XML file.
                                // -----------------------------------------------------------------
                                fullyQualifiedSourceFilename = General.FileDialogOpenFile(Resources.FileDialogOpenTitleDataDictionary,
                                                                                          CommonConstants.ExtensionDataDictionary,
                                                                                          Resources.FileDialogOpenFilterDataDictionary,
                                                                                          DirectoryManager.PathPTUConfigurationFiles);

                                // Skip, if no alternative data dictionary XML file is selected.
                                if (fullyQualifiedSourceFilename == string.Empty)
                                {
                                    this.Cursor = Cursors.Default;
                                    configurationMatch = false;
                                    return (configurationMatch);
                                }
                            }
                            else
                            {
                                this.Cursor = Cursors.Default;
                                configurationMatch = false;
                                return (configurationMatch);
                            }
                            #endregion - [Manual File Selection] -
                            break;
                    }
                    #endregion - [Locate PTU Configuration File]] -
                }

                #region - [Load the PTU Configuration File] -
                // ------------------------------------------------------------------------------------------
                // The PTU configuration file corresponding to the propulsion system software exists, load it.
                // ------------------------------------------------------------------------------------------
                try
                {
                    FileHandling.LoadDataSet<DataDictionary>(fullyQualifiedSourceFilename, ref m_DataDictionary);

                    // Copy the selected PTU configuration file to the default directory and rename it to the default filename.
                    string fullyQualifiedDestinationFilename = DirectoryManager.PathPTUConfigurationFiles + CommonConstants.BindingFilename + FilenameDataDictionary;
                    FileInfo fileInfoDestination = new FileInfo(fullyQualifiedDestinationFilename);
                    fileInfoSource = new FileInfo(fullyQualifiedSourceFilename);
                    fileInfoSource.CopyTo(fullyQualifiedDestinationFilename, true);
                    LoadDictionary(m_DataDictionary);

                }
                catch (ArgumentNullException)
                {
                    MessageBox.Show(Resources.MBTConfigReadFailed, Resources.MBCaptionError, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    configurationMatch = false;
                    return (configurationMatch);
                }
                catch (FileNotFoundException)
                {
                    MessageBox.Show(Resources.MBTConfigVCUMatchNotFoundTryAgain, Resources.MBCaptionError, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    configurationMatch = false;
                    return (configurationMatch);
                }
                finally
                {
                    Cursor = Cursors.Default;
                }
                #endregion - [Load the PTU Configuration File] -
                #endregion - [Configuration Mismatch] -
            }

            configurationMatch = true;
            return (configurationMatch);
        }
Пример #5
0
        /// <summary>
        /// Initializes the static properties that allow the class user to access the primary key data tables defined within the data dictionary.
        /// </summary>
        /// <param name="dataDictionary">The data dictionary containing the data tables.</param>
        public static void Initialize(DataDictionary dataDictionary)
        {
            m_DataDictionary = dataDictionary;

            m_WatchVariableTable = new WatchVariableTable(dataDictionary.WATCHVARIABLES, dataDictionary.WATCHENUMBIT);
            m_WatchVariableTableByOldIdentifier = new WatchVariableTableByOldIdentifier(dataDictionary.WATCHVARIABLES, dataDictionary.WATCHENUMBIT);
            m_EventVariableTable = new EventVariableTable(dataDictionary.EVENTVARIABLES, dataDictionary.EVENTENUMBIT);
            m_SelfTestVariableTable = new SelfTestVariableTable(dataDictionary.SELFTESTVARIABLES, dataDictionary.SELFTESTENUMBIT);

            m_EventTable = new EventTable(dataDictionary.EVENTS, dataDictionary.STRUCT);
            m_LogTable = new LogTable(dataDictionary.LOGS, dataDictionary.DataStreamTypes);

            m_SelfTestTable = new SelfTestTable(dataDictionary.SELFTEST, dataDictionary.SELFTESTIDS, dataDictionary.TESTMESSAGES);
            m_SelfTestTableBySelfTestNumber = new SelfTestTableBySelfTestNumber(dataDictionary.SELFTEST, dataDictionary.SELFTESTIDS, dataDictionary.TESTMESSAGES);
            m_GroupListTable = new GroupListTable(dataDictionary.GROUPLIST, dataDictionary.GROUPLISTIDS);
            m_TestListTable = new TestListTable(dataDictionary.TESTLIST, dataDictionary.TESTLISTIDS);
        }
Пример #6
0
        /// <summary>
        /// <para>Configures the PTU application using the specified data dictionary. The configuration procedure is as follows:</para>
        /// <para>(1) updates the <c>Parameter</c> class;</para>
        /// <para>(2) updates the Lookup static class to allow the records contained within the primary key data tables of the data dictionary to be accessed;</para> 
        /// <para>(3) creates the application data sub-directories if they do not exist;</para>
        /// <para>(4) updates the main menu options to reflect the current project and security level;</para>
        /// <para>(5) updates the file header information;</para>
        /// <para>(6) loads the default worksets associated with the specified data dictionary, if they exist;</para>
        /// <para>(7) loads the help file associated with the current project and software version;</para>
        /// <para>(8) shows the 'Help/About' screen.</para>
        /// </summary>
        /// <param name="dataDictionary">The data dictionary that is to be used to configure the PTU.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="dataDictionary"/> is null.</exception>
        public void LoadDictionary(DataDictionary dataDictionary)
        {
            Debug.Assert(dataDictionary != null, "MdiPTU.Support.LoadDictionary - [dataDictionary != null]");

            // The configuration file was OK, initialize the Parameter class.
            Parameter.Initialize(dataDictionary);

            // Check whether the project identifier was passed as a shortcut parameter.
            if (m_ProjectIdentifierPassedAsParameter.Equals(string.Empty))
            {
                // No, initialize the project specific features of the PTU application.
                InitializePTUProjectSpecific(Parameter.ProjectInformation.ProjectIdentifier);

                // Update the member variable that records the project-identifier that was passed as a parameter with the project-identifier associated with the
                // selected configuration file.
                m_ProjectIdentifierPassedAsParameter = Parameter.ProjectInformation.ProjectIdentifier;
            }
            else
            {
                // Check whether the data dictionary matches the project identifier that was passed as a shortcut parameter.
                if (Parameter.ProjectInformation.ProjectIdentifier != m_ProjectIdentifierPassedAsParameter)
                {
                    MessageBox.Show(Resources.MBTConfigProjectAsParameterMismatch, Resources.MBCaptionError, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    this.Close();
                    return;
                }
            }

            Lookup.Initialize(dataDictionary);

            InitializeDataSubDirectories();

            // Initialize the system security and set the security clearance to the base level.
            Security.Initialize();
            m_Security = new Security();
            ShowSecurityLevelChange(m_Security);

            // Update the FileHeader.HeaderCurrent property with the parameter values that are currently known.
            Header_t header = new Header_t();
            FileHeader.Initialize(ref header);
            header.ProjectInformation = Parameter.ProjectInformation;
            FileHeader.HeaderCurrent = header;

            SetMode(Mode.Configuration);
            LoadAllWorksetCollections(Parameter.ProjectInformation.ProjectIdentifier);
            LoadHelpFile(Parameter.ProjectInformation.Version, Parameter.ProjectInformation.ProjectIdentifier);

            // If applicable to the current project, show the splash screen.
            switch (m_ProjectIdentifierPassedAsParameter)
            {
                case CommonConstants.ProjectIdNYCT:
                    // Do not show the splash screen for the R188 project.
                    break;
                default:
                    // Show the splash screen.
                    using (FormHelpAbout formHelpAbout = new FormHelpAbout(Resources.ProductNamePTU))
                    {
                        formHelpAbout.ShowDialog();
                    }
                    break;
            }
        }
Пример #7
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);
        }
Пример #8
0
        /// <summary>
        /// Ask the user to select an XML data dictionary and then load this data dictionary into the PTU application.
        /// </summary>
        /// <param name="mainWindow">Reference to the main application window interface.</param>
        public static void LoadDataDictionary(IMainWindow mainWindow)
        {
            string fullyQualifiedSourceFilename = General.FileDialogOpenFile(Resources.FileDialogOpenTitleDataDictionary,
                                                                             CommonConstants.ExtensionDataDictionary, 
                                                                             Resources.FileDialogOpenFilterDataDictionary,
                                                                             DirectoryManager.PathPTUConfigurationFiles);
            // Skip, if the user didn't select a data dictionary XML file.
            if (fullyQualifiedSourceFilename == string.Empty)
            {
                return;
            }

            #region - [Exclude 'PTU Configuration.xml' or '*.PTU Configuration.xml'] -
            // if the user has selected either the default configuration file, 'PTU Configuration.xml',  or one of the project default configuration files,
            // '<project-identifier>.PTU Configuration.xml', terminate the operation.
            if (Path.GetFileName(fullyQualifiedSourceFilename).ToLower().Contains(Resources.FilenameDefaultDataDictionary.ToLower()))
			{
                MessageBox.Show(string.Format(Resources.MBTConfigSelectionInvalid, Resources.FilenameDefaultDataDictionary), Resources.MBCaptionError,
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
				return;
            }
            #endregion - [Exclude 'PTU Configuration.xml' or '*.PTU Configuration.xml'] -

            FileInfo fileInfoSource = new FileInfo(fullyQualifiedSourceFilename);
            DataDictionary dataDictionary = new DataDictionary();
            try
            {
                // Load the specified XML configuration file.
                FileHandling.LoadDataSet<DataDictionary>(fullyQualifiedSourceFilename, ref dataDictionary);

                #region - [Check whether the selected data dictionary is valid for the current project] -
                // If the project identifier was passed to the application as a desktop shortcut parameter, ensure that the project identifier associated with
                // the selected data dictionary matches this, and if not, terminate the operation.
                if (mainWindow.ProjectIdentifierPassedAsParameter.Equals(string.Empty))
                {
                    // Do nothing. It is perfectly acceptable to select the configuration file associated with ANY project if no project identifier was passed to the
                    // application as the desktop shortcut parameter. Indeed, this is the recommended way of quickly changing between different projects
                    // for Bombardier field engineers. Simply set up a desktop shortcut that points to the PTU application but do not supply any shortcuts.
                    ;
                }
                else
                {
                    // The project identifier was passed to the application as a desktop shortcut parameter. Check that the project identifier associated with the
                    // selected configuration file matches this and, if not, terminate the operation.
                    if (dataDictionary.FILEINFO[0].PROJECTSTRING != mainWindow.ProjectIdentifierPassedAsParameter)
                    {
                        // The data dictionary is not associated with the current project, terminate the operation.
                        MessageBox.Show(string.Format(Resources.MBTConfigProjectAsParameterMismatch, mainWindow.ProjectIdentifierPassedAsParameter),
                                        Resources.MBCaptionError, MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                }
                #endregion - [Check whether the selected data dictionary is valid for the current project] -

                // Update the appropriate default configuration file.\
                string fullyQualifiedDestinationFilename;
                if (mainWindow.ProjectIdentifierPassedAsParameter.Equals(string.Empty))
                {
                    // Copy to the default configuration file.
                    fullyQualifiedDestinationFilename = DirectoryManager.PathPTUConfigurationFiles + CommonConstants.BindingFilename +
                                                        Resources.FilenameDefaultDataDictionary;
                }
                else
                {
                    // Copy to the default project configuration file.
                    fullyQualifiedDestinationFilename = DirectoryManager.PathPTUConfigurationFiles + CommonConstants.BindingFilename +
                                                        dataDictionary.FILEINFO[0].PROJECTSTRING + CommonConstants.Period + Resources.FilenameDefaultDataDictionary;
                }
                
                FileInfo fileInfoDestination = new FileInfo(fullyQualifiedDestinationFilename);
                fileInfoSource.CopyTo(fullyQualifiedDestinationFilename, true);

                if (mainWindow != null)
                {
                    mainWindow.SetRestart(true);
                    mainWindow.Close();
                }
            }
            catch (ArgumentNullException)
            {
                MessageBox.Show(Resources.MBTConfigurationFileLoadFailed, Resources.MBCaptionError, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        /// <summary>
        /// Build an array of the records contained within the <c>SELFTEST</c> table of the data dictionary. This array is used to access the 
        /// parameters associated with the self tests defined in the table. The array element is mapped to the self test number field of the table. 
        /// </summary>
        /// <param name="dataTable">Reference to the <c>SELFTEST</c> table of the data dictionary.</param>
        /// <returns>An array of the records contained within the <c>SELFTEST</c> table of the data dictionary, if the parameters are valid; otherwise, null.</returns>
        protected override SelfTestRecord[] BuildDataTable(DataDictionary.SELFTESTDataTable dataTable)
        {
            // Local copy of the data table.
            SelfTestRecord[] records;

            if (dataTable == null)
            {
                return null;
            }

            try
            {
                // Determine the maximum value of the identifier field in the data table, it cannot be assumed that the table is sorted by identifier.
                int iDMax = 0;
                int iDCurrent = 0;
                for (int recordIndex = 0; recordIndex < dataTable.Count; recordIndex++)
                {
                    iDCurrent = dataTable[recordIndex].SELFTESTNUMBER;
                    if (iDCurrent > iDMax)
                    {
                        iDMax = iDCurrent;
                    }
                }

                m_IdentifierMax = iDMax;

                // Instantiate the lookup array.
                records = new SelfTestRecord[iDMax + 1];

                // Populate the lookup table;
                int identifier;
                DataDictionary.SELFTESTRow row;
                for (int recordIndex = 0; recordIndex < dataTable.Count; recordIndex++)
                {
                    row = dataTable[recordIndex];
                    identifier = row.SELFTESTNUMBER;

                    // Instantiate a new structure to contain the data and copy the data across.
                    SelfTestRecord record = new SelfTestRecord();
                    record.Identifier = (short)row.SELFTESTID;
                    record.SelfTestNumber = row.SELFTESTNUMBER;
                    record.Description = row.DESCRIPTION;
                    record.HelpIndex = row.HELPINDEX;

                    // Add the record to the correct element of the array.
                    records[identifier] = record;
                }
            }
            catch (Exception)
            {
                return null;
            }

            return records;
        }
 /// <summary>
 /// Initialize a new instance of the class.
 /// </summary>
 /// <param name="dataTable">>Reference to the <c>SELFTEST</c> table of the data dictionary. This table contains the self test definitions.</param>
 /// <param name="selfTestIdentifiersDataTable">Reference to the <c>SELFTESTIDS</c> table of the data dictionary. This table defines which self test 
 /// variables are associated with each self test.</param>
 /// <param name="testMessagesDataTable">Reference to the <c>TESTMESSAGES</c> table of the data dictionary. This table defines the help index of the 
 /// test messages associated with the test case value for each test number.</param>
 public SelfTestTableBySelfTestNumber(DataDictionary.SELFTESTDataTable dataTable, DataDictionary.SELFTESTIDSDataTable selfTestIdentifiersDataTable, 
                                      DataDictionary.TESTMESSAGESDataTable testMessagesDataTable)
     : base(dataTable, selfTestIdentifiersDataTable, testMessagesDataTable)
 {
 }
        /// <summary>
        /// Build the array that is used to access the list of <c>SelfTestIdentifier</c> records associated with a specified self test identifier.
        /// Build an array of lists of <c>SelfTestIdentifier_t</c> records associated with each unique <c>SELFTESTID</c> value defined in the <c>SELFTESTIDS</c> 
        /// table of the data dictionary. The array element is mapped to the <c>SELFTESTNUMBER</c> field of the table.
        /// </summary>
        /// <param name="selfTestIdentifiersDataTable">Reference to the <c>SELFTESTIDS</c> data table of the data dictionary.</param>
        /// <returns>An array of lists of <c>SelfTestIdentifier_t</c> records associated with each unique <c>SELFTESTID</c> value in the <c>SELFTESTIDS</c> table of the 
        /// data dictionary, if the parameters are valid; otherwise, null.</returns>
        protected override List<SelfTestIdentifier_t>[] BuildSelfTestIdentifierLists(DataDictionary.SELFTESTIDSDataTable selfTestIdentifiersDataTable)
        {
            // Local copy of the data table.
            List<SelfTestIdentifier_t>[] records;

            if (selfTestIdentifiersDataTable == null)
            {
                return null;
            }

            try
            {
                // Determine the maximum value of the identifier field in the data table, it cannot be assumed that the table is sorted by identifier.
                int iDMax = 0;
                int iDCurrent = 0;
                for (int recordIndex = 0; recordIndex < selfTestIdentifiersDataTable.Count; recordIndex++)
                {
                    iDCurrent = selfTestIdentifiersDataTable[recordIndex].SELFTESTNUMBER;
                    if (iDCurrent > iDMax)
                    {
                        iDMax = iDCurrent;
                    }
                }

                // Instantiate the lookup array.
                records = new List<SelfTestIdentifier_t>[iDMax + 1];

                // Instantiate a generic list for each element of the array. 
                for (int recordIndex = 0; recordIndex < iDMax + 1; recordIndex++)
                {
                    records[recordIndex] = new List<SelfTestIdentifier_t>();
                }

                // Populate the lookup table;
                int identifier;
                DataDictionary.SELFTESTIDSRow row;
                for (int recordIndex = 0; recordIndex < selfTestIdentifiersDataTable.Count; recordIndex++)
                {
                    row = selfTestIdentifiersDataTable[recordIndex];
                    identifier = row.SELFTESTNUMBER;

                    // Instantiate a new structure to contain the data and copy the data across.
                    SelfTestIdentifier_t record = new SelfTestIdentifier_t();
                    record.SelfTestIdentifier = row.SELFTESTID;
                    record.SelfTestNumber = row.SELFTESTNUMBER;
                    record.SelfTestVariableIdentifier = row.SELFTESTVARID;

                    // Add the record to the correct element of the array.
                    records[identifier].Add(record);
                }
            }
            catch (Exception)
            {
                return null;
            }

            return records;
        }
        /// <summary>
        /// Build an array of the watch variable records contained within the <c>WATCHVARIABLES</c> table of the data dictionary. This array is used to access the 
        /// parameters associated with the watch variables defined in the table. The array element is mapped to the old identifier field of the table.
        /// </summary>
        /// <param name="variableDataTable">Reference to the <c>WATCHVARIABLES</c> table of the data dictionary.</param>
        /// <returns>>An array of the records contained within the <c>WATCHVARIABLES</c> table of the data dictionary, if the specified table is valid; otherwise, null.</returns>
        protected override WatchVariable[] BuildDataTable(DataDictionary.WATCHVARIABLESDataTable variableDataTable)
        {
            // Local copy of the table.
            WatchVariable[] variables;

            if (variableDataTable == null)
            {
                return null;
            }

            try
            {
                // Determine the maximum value of the identifier field in the WatchVariables table, it cannot be assumed that the table is sorted by WatchID value.
                int iDMax = 0;
                int iDCurrent = 0;
                for (int record = 0; record < variableDataTable.Count; record++)
                {
                    iDCurrent = variableDataTable[record].OLDID;
                    if (iDCurrent > iDMax)
                    {
                        iDMax = iDCurrent;
                    }
                }

                m_IdentifierMax = iDMax;

                // Instantiate the lookup array.
                variables = new WatchVariable[iDMax + 1];

                // Populate the lookup table;
                int identifier;
                DataDictionary.WATCHVARIABLESRow row;
                for (int record = 0; record < variableDataTable.Count; record++)
                {
                    row = variableDataTable[record];
                    identifier = row.OLDID;

                    // Instantiate a new structure to contain the variable data and copy the data across.
                    WatchVariable watchVariable = new WatchVariable() as WatchVariable;
                    watchVariable.Identifier = row.WATCHID;
                    watchVariable.OldIdentifier = row.OLDID;
                    watchVariable.Name = row.VARIABLENAME;
                    watchVariable.FormatString = row.FORMATSTRING;
                    watchVariable.EmbeddedName = row.EMBEDDEDVARNAME;
                    watchVariable.DataType = (DataType_e)row.TYPEID;
                    watchVariable.ScaleFactor = row.SCALEFACTOR;
                    watchVariable.EnumBitIdentifier = row.ENUMBITID;
                    watchVariable.IsBitMask = (row.BITMASK == 0) ? true : false;
                    watchVariable.Units = row.UNITS;
                    watchVariable.MinChartScale = row.MINCHARTSCALE;
                    watchVariable.MaxChartScale = row.MAXCHARTSCALE;
                    watchVariable.AttributeFlags = row.FLAGS;
                    watchVariable.HelpIndex = row.HELPINDEX;
                    watchVariable.MinModifyValue = row.MINMODIFYVALUE;
                    watchVariable.MaxModifyValue = row.MAXMODIFYVALUE;

                    // Determine the variable type.
                    if (watchVariable.IsBitMask)
                    {
                        watchVariable.VariableType = VariableType.Bitmask;
                    }
                    else
                    {
                        if (watchVariable.EnumBitIdentifier == 0)
                        {
                            watchVariable.VariableType = VariableType.Scalar;
                        }
                        else
                        {
                            watchVariable.VariableType = VariableType.Enumerator;
                        }
                    }

                    // Add the structure to the correct element of the array.
                    variables[identifier] = watchVariable;
                }
            }
            catch (Exception)
            {
                return null;
            }

            return variables;
        }
 /// <summary>
 /// Initialize a new instance of the class.
 /// </summary>
 /// <param name="watchVariableDataTable">Reference to the <c>WATCHVARIABLES</c> table of the data dictionary.</param>
 /// <param name="enumBitDataTable">Reference to the <c>WATCHENUMBIT</c> table of the data dictionary i.e. the enumerator/bitmask data table associated with 
 /// watch variables.</param>
 public WatchVariableTableByOldIdentifier(DataDictionary.WATCHVARIABLESDataTable watchVariableDataTable, DataDictionary.WATCHENUMBITDataTable enumBitDataTable) 
     : base(watchVariableDataTable, enumBitDataTable)
 {
 }