Пример #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>
        /// Show that the security level has been updated by modifying: (a) the Login/Logout text associated with the menu and button; (b) the status line text 
        /// and (c) the menu options to reflect the new clearance level.
        /// </summary>
        /// <param name="security">Reference to the security class for which the security clearance level is to be displayed.</param>
        public void ShowSecurityLevelChange(Security security)
        {
            // If the user logs in, change the 'Login' menu option text to 'Logout'.
            if (security.SecurityLevelCurrent <= m_Security.SecurityLevelBase)
            {
                m_MenuItemLogin.Text = Resources.SecurityLogIn;
            }
            else
            {
                m_MenuItemLogin.Text = Resources.SecurityLogOut;
            }

            // Update the status information.
            m_StatusLabelSecurityLevel.Text = security.Description;

            // Update the menu options to reflect the new security level.
            UpdateMenu(security);
        }
Пример #4
0
        /// <summary>
        /// Update the main menu options to reflect the mode and security level.
        /// </summary>
        public void UpdateMenu(Security security)
        {
            Debug.Assert(security != null);

            // Initially assert the Visible and Enabled properties for ALL menu options.
            General.SetMenuStripVisible(m_MenuStrip, true);
            General.SetMenuStripEnabled(m_MenuStrip, true);

            #region - [Mode] -
            // Disable those menu options that are not applicable to the current mode of operation.
            switch (m_Mode)
            {
                case Mode.Setup:
                    m_MenuItemConfigureWorksets.Enabled = false;

                    // Also add all menu items defined for off-line mode.
                    m_MenuItemFileOpen.Enabled = false;
                    m_MenuItemView.Enabled = false;
                    m_MenuItemDiagnostics.Enabled = false;
                    m_MenuItemConfigureRealTimeClock.Enabled = false;
                    m_MenuItemConfigureChartRecorder.Enabled = false;
                    m_MenuItemConfigureChartMode.Enabled = false;
                    break;
                case Mode.Configuration:
                    m_MenuItemView.Enabled = false;
                    m_MenuItemDiagnostics.Enabled = false;
                    m_MenuItemConfigureRealTimeClock.Enabled = false;
                    m_MenuItemConfigureChartRecorder.Enabled = false;
                    m_MenuItemConfigureChartMode.Enabled = false;
                    break;
                case Mode.Online:
                    m_MenuItemFileSelectDataDictionary.Enabled = false;
                    break;
                case Mode.Offline:
                    m_MenuItemFileSelectDataDictionary.Enabled = false;
                    break;
                case Mode.SelfTest:
                    m_MenuItemFileOpen.Enabled = false;
                    m_MenuItemFileSelectDataDictionary.Enabled = false;
                    m_MenuItemView.Enabled = false;
                    m_MenuItemDiagnostics.Enabled = false;
                    m_MenuItemConfigure.Enabled = false;
                    m_MenuItemTools.Enabled = false;
                    break;
                default:
                    throw new ArgumentOutOfRangeException("m_Mode", "MdiPTU.Support.UpdateMenu()");
            }
            #endregion - [Mode] -]

            #region - [Security] -
            if ((short)security.SecurityLevelCurrent > (short)security.SecurityLevelHighest)
            {
                // ----------------
                // System Developer
                // ----------------

                // Leave the Visible/Enabled properties of all menu options asserted.

                // Start the timer that checks whether the WibuBox is still attached.
                if (m_TimerWibuBox != null)
                {
                    m_TimerWibuBox.Start();
                }
            }
            else if ((short)security.SecurityLevelCurrent == (short)security.SecurityLevelHighest)
            {
                // ------------------------------------------------
                // Highest Security Level Appropriate to the Client
                // ------------------------------------------------

                // Clear the Visible/Enabled properties of those menu options, including separators, that are not applicable to client engineers.

                // - [File] -
                m_MenuItemFileSelectDataDictionary.Visible = false;

                // - [Configure] -
                m_MenuItemConfigureRealTimeClock.Visible = false;
                m_SeparatorConfigureRealTimeClock.Visible = false;

                // - [Tools] -
                m_MenuItemToolsConvertEngineeringFile.Visible = false;
                m_SeparatorToolsConvertEngineeringDatabase.Visible = false;

                m_MenuItemToolsDebugMode.Visible = false;
                m_SeparatorToolsDebug.Visible = false;

                // Start the timer that checks whether the WibuBox is still attached.
                if (m_TimerWibuBox != null)
                {
                    m_TimerWibuBox.Start();
                }
            }
            else if ((short)security.SecurityLevelCurrent >= (short)security.SecurityLevelBase)
            {
                // -----------
                // Maintenance
                // -----------

                // Clear the Visible/Enabled properties of those menu options, including separators, that are not applicable at the base security level.

                // - [File] -
                m_MenuItemFileSelectDataDictionary.Visible = false;

                // - [Diagnostics] -
                m_MenuItemDiagnosticsInitializeEventLogs.Enabled = false;

                // - [Configure] -
                m_MenuItemConfigureRealTimeClock.Visible = false;
                m_SeparatorConfigureRealTimeClock.Visible = false;

                m_MenuItemConfigurePasswordProtection.Enabled = false;

                // - [Tools] -
                m_MenuItemTools.Visible = false;

                // Stop the timer that checks whether the WibuBox is still attached as the WibuBox is not required to access
                // this security level.
                if (m_TimerWibuBox != null)
                {
                    m_TimerWibuBox.Stop();
                }
            }
            else
            {
                throw new ArgumentOutOfRangeException("security.SecurityLevelCurrent", "MdiPTU.Support.UpdateMenu()");
            }

            // Call the method to update the form specific changes to the main menu on any of the child forms that are open.
            int mdiChildren = MdiChildren.Length;
            if (MdiChildren.Length > 0)
            {
                for (int childIndex = 0; childIndex < mdiChildren; childIndex++)
                {
                    (MdiChildren[childIndex] as FormPTU).UpdateMenu(m_Security);
                }
            }
            #endregion - [Security] -

            OnMenuUpdated(this, new EventArgs());
        }
        /// <summary>
        /// Show the form which allows the user to log in, if currently logged out, and vice-versa.
        /// </summary>
        /// <param name="projectIdentifier">The project-identifier of the active project.</param>
        public void Login(string projectIdentifier)
        {
            MainWindow.Cursor = Cursors.WaitCursor;

            // If the user is currently logged out, display the login screen, else log the user out.
            Security security = new Security();
            if (security.SecurityLevelCurrent <= security.SecurityLevelBase)
            {
                try
                {
                    // ----------------------------------------------------
                    // Check whether a WibuBox security device is required.
                    // ----------------------------------------------------
                    if (WibuBoxCheckIfRequired(projectIdentifier) == true)
                    {
                        try
                        {
                            // Yes, check that a valid WibuBox is attached.
                            MenuInterfaceWibuKey menuInterfaceWibuKey = new MenuInterfaceWibuKey(MainWindow);
                            if (menuInterfaceWibuKey.WibuBoxCheckForValidEntry(false) == true)
                            {
                                FormLogin formLogin = new FormLogin();
                                MainWindow.ShowDialog(formLogin);
                            }
                        }
                        catch (Exception)
                        {
                            MessageBox.Show(Resources.MBTWibuKeyDeviceDriverNotInstalled + CommonConstants.NewPara + Resources.MBTWibuKeyInstall,
                                            Resources.MBCaptionError, MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                    else
                    {
                        FormLogin formLogin = new FormLogin();
                        MainWindow.ShowDialog(formLogin);
                    }
                }
                catch (Exception exception)
                {
                    MessageBox.Show(exception.Message, Resources.MBCaptionInformation, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                finally
                {
                    MainWindow.Cursor = Cursors.Default;
                }
            }
            else
            {
                DialogResult dialogResult = MessageBox.Show(Resources.MBTSecurityQueryLogOut, Resources.MBCaptionInformation, MessageBoxButtons.YesNo,
                                                            MessageBoxIcon.Question);
                if (dialogResult == DialogResult.Yes)
                {
                    // Update the security clearance.
                    security.SecurityLevelCurrent = security.SecurityLevelBase;
                    MainWindow.ShowSecurityLevelChange(security);
                }
                MainWindow.Cursor = Cursors.Default;
            }
        }
Пример #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;
            }
        }
        /// <summary>
        /// Calls the method which asks the user to specify an XML data dictionary and then loads this into the PTU application.
        /// </summary>
        public void OpenDataDictionary()
        {
            Security security = new Security();

            #region - [Mode and SecurityLevel Checks] -
            // -------------------------------------------------------------------------------------------
            // The user must be in either configuration or setup mode in order to set the data dictionary.
            // -------------------------------------------------------------------------------------------
            if ((MainWindow.Mode == Mode.Offline) || (MainWindow.Mode == Mode.Online))
            {
                MessageBox.Show(string.Format(Resources.MBTSetDataDictionaryNotAllowed, MainWindow.Mode.ToString().ToLower(),
                                              security.GetSecurityDescription(security.SecurityLevelHighest).ToLower()),
                                Resources.MBCaptionInformation, MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            else if (MainWindow.Mode == Mode.SelfTest)
            {
                MessageBox.Show(string.Format(Resources.MBTSetDataDictionaryNotAllowedSelfTest, MainWindow.Mode.ToString().ToLower(),
                                              security.GetSecurityDescription(security.SecurityLevelHighest).ToLower()),
                                Resources.MBCaptionInformation, MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            // --------------------------------------------------------------------------------------------
            // The user must be logged into the highest security level in order to set the data dictionary.
            // --------------------------------------------------------------------------------------------
            if (security.SecurityLevelCurrent < security.SecurityLevelHighest)
            {
                MessageBox.Show(string.Format(Resources.MBTUnauthorizedSetDataDictionary, security.GetSecurityDescription(security.SecurityLevelHighest).ToLower()),
                                Resources.MBCaptionInformation, MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            #endregion - [Mode and SecurityLevel Checks] -

            MainWindow.Cursor = Cursors.WaitCursor;

            try
            {
                General.LoadDataDictionary(MainWindow);
            }
            catch (Exception exception)
            {
                MessageBox.Show(Resources.MBTDataDictionaryLoadFailed + CommonConstants.NewLine + CommonConstants.NewLine + exception.Message,
                                Resources.MBCaptionInformation, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            finally
            {
                MainWindow.Cursor = Cursors.Default;
            }
        }
Пример #8
0
        /// <summary>
        /// <para>Check whether a WibuBox/U+ device is connected to either a USB or Parallel port and, if so, whether the appropriate slot has been programmed with
        /// the correct Firm and User Codes.</para>
        /// <para>This method is called during PTU start-up, in order to update the WibuBox status label, and whenever the 'Login' menu option is selected, provided
        /// the current project supports WibuBox/U+ hardware.</para>
        /// <para>The dialog box used to enter the Engineering password is only displayed if this method indicates that a valid WibuBox/U+ device was found.</para>
        /// </summary>
        /// <param name="suppressMessageBox">A flag that is used to control <c>MessageBox.Show()</c> reporting. True, if the method is to suppress<c>MessageBox.Show()</c>
        /// reporting; otherwise, false.</param>
        /// <returns>A flag to indicate whether a valid WibuBox device was found. True, if a valid WibuBox was found; otherwise, false.</returns>
        public bool WibuBoxCheckForValidEntry(bool suppressMessageBox)
        {
            m_WibuBoxFound = false;
            m_WibuBoxValid = false;

            try
            {
                // This method should only be called if the WibuBox security device has been initialized by calling the WibuBoxCheckIfRequired() method.
                if (m_WibuBoxIsInitialized == false)
                {
                    throw new InvalidOperationException(Resources.MBTWibuBoxNotInitialized);
                }

                // Ensure that the WibuKey data is refreshed.
                m_WibuKey.PurgeAll();

                // ------------------------------------
                // Scan each WibuBox in each subsystem.
                // ------------------------------------

                // Just access local subsystems i.e. LPT1 and USB.
                m_WibuKey.UsedSubsystems = (int)WkSubsystemType.wkSbLocal;
                m_WibuKey.UsedSubsystem.MoveType = (int)WkSubsystemMoveType.wkSbMvLocal;
                m_WibuKey.UsedSubsystem.MoveFirst();

                // Check for errors.
                if (m_WibuKey.LastErrorCode != 0)
                {
                    throw new InvalidOperationException(m_WibuKey.LastErrorText);
                }

                // The Boolean BOF property (“Begin Of File”) is True only if the navigation location is before the first element of the subsystem list
                // (and no information is available). Otherwise this property is always False.
                if (m_WibuKey.UsedSubsystem.BOF == true)
                {
                    // There were no local WibuBox subsystems found i.e. the computer had no USB or Parallel ports.
                    throw new InvalidOperationException(Resources.MBTWibuKeySubsystemNotFound);
                }

                // Subsystem scan.
                while (m_WibuKey.UsedSubsystem.EOF == false)
                {
                    m_WibuKey.UsedWibuBox.MoveType = (int)WkBoxMoveType.wkBxMvNonEmpty;
                    m_WibuKey.UsedWibuBox.MoveFirst();

                    // Check for errors.
                    if (m_WibuKey.LastErrorCode != 0)
                    {
                        throw new InvalidOperationException(m_WibuKey.LastErrorText);
                    }

                    // The Boolean BOF property (“Begin Of File”) is True only if the navigation location is before the first
                    // element of the WibuBox list (and no information is available). Otherwise this property is always
                    // False.
                    if (m_WibuKey.UsedWibuBox.BOF == true)
                    {
                        // No WibuBoxes were found in the current subsystem, move to the next subsystem.
                        m_WibuKey.UsedSubsystem.MoveNext();
                        continue;
                    }
                    else
                    {
                        // At least one WibuBox was found in the current subsystem.
                        m_WibuBoxFound = true;
                    }

                    // Scan each WibuBox in the current subsystem.
                    while (m_WibuKey.UsedWibuBox.EOF == false)
                    {
                        // Only check the appropriate slot of the WibuBox.
                        m_WibuKey.UsedBoxEntry.Index = m_SlotId;
                        m_WibuKey.UsedBoxEntry.MoveToIndex();

                        // Check for errors.
                        if (m_WibuKey.LastErrorCode != 0)
                        {
                            throw new InvalidOperationException(m_WibuKey.LastErrorText); ;
                        }

                        // -----------------------------------------------------------------------------------
                        // Check whether the Firm and User Codes associated with the specified slot are valid.
                        // -----------------------------------------------------------------------------------
                        /* Note: A valid WibuBox can be either: (a) a WibuBox that has been programmed, in the appropriate slot, with the client Firm and 
                         * User codes that are associated with the current project or (b) a development WibuBox. The slot, Firm code and User code associated 
                         * with the development WibuBox are not published and are only known to the author, for security reasons.
                         * 
                         * For the client WibuBox check, the retrieved WibuBox User code is checked against the value stored in the data dictionary, however, the 
                         * retrieved Firm code is checked against the variable m_FirmCode. This is initialized to the client value that is associated with the current 
                         * project by the WibuBoxCheckIfRequired() method. This method has been adopted for security reasons.
                         * 
                         * For the development WibuBox check, the Security class is used to get the hashcode associated with the retrieved WibuBox Firm and User 
                         * codes and these are checked aginst the hashcodes stored in the Settings file. This approach is adopted for security reasons as it means 
                         * the Firm and User codes associated with the development WibuBox need not be published in the source code.
                         */
                        Security security = new Security();

                        // Include the Firm and User codes associated with the development dongle.
                        if ((m_WibuKey.UsedBoxEntry.FirmCode == m_FirmCode && m_WibuKey.UsedBoxEntry.UserCode == m_UserCode) || 
                            (security.GetHashCode(m_WibuKey.UsedBoxEntry.FirmCode.ToString()) == Settings.Default.HashCodeWkDevFirm  &&
                             security.GetHashCode(m_WibuKey.UsedBoxEntry.UserCode.ToString()) == Settings.Default.HashCodeWkDevUser))
                        {
                            // Yes, the correct Firm and User Codes were found at the specified slot.
                            // Perform an encrytion and decryption to verify that the WibuBox is working correctly.
                            m_WibuKey.AlgorithmVersion = (int)WkAlgorithmVersion.wkAlgVersion2;
                            m_WibuKey.FirmCode = m_WibuKey.UsedBoxEntry.FirmCode;
                            m_WibuKey.UserCode = m_WibuKey.UsedBoxEntry.UserCode;
                            m_WibuKey.TextData = EncryptionData;
                            m_WibuKey.Encrypt();

                            // Check for errors.
                            if (m_WibuKey.LastErrorCode != 0)
                            {
                                // Invalid encryption.
                                throw new InvalidOperationException(m_WibuKey.LastErrorText); ;
                            }

                            m_WibuKey.Decrypt();
                            if (m_WibuKey.TextData != EncryptionData)
                            {
                                // Invalid encryption.
                                throw new InvalidOperationException(Resources.MBTWibuKeyEncryptionInvalid);
                            }
                            else
                            {
                                // Set the flag that identifies whether a valid WibuBox has been found and terminate the scan.
                                m_WibuBoxValid = true;

                                // Check whether the user logged in using a client WibuBox or development WibuBox.
                                if (security.GetHashCode(m_WibuKey.FirmCode.ToString()) == Settings.Default.HashCodeWkDevFirm)
                                {
                                    m_WibuBoxIsDevelopment = true;
                                }
                                break;
                            }
                        }

                        // Check the next WibuBox in the current sub-system.
                        m_WibuKey.UsedWibuBox.MoveNext();
                    }

                    // If a valid WibuBox was found, terminate the scan; otherwise, check the next subsystem.
                    if (m_WibuBoxValid == true)
                    {
                        // A valid WibuBox was found, terminate the scan of the sub-systems.
                        break;
                    }
                    else
                    {
                        // Check the next sub-system.
                        m_WibuKey.UsedSubsystem.MoveNext();
                    }
                }

                // Check whether MessageBox reporting is enabled.
                if (suppressMessageBox == false)
                {
                    if ((m_WibuBoxFound == true) && (m_WibuBoxValid == false))
                    {
                        // A WibuBox was found, however, the appropriate slot was not programmed with the correct Firm and User codes.
                        MessageBox.Show(Resources.MBTWibuBoxFoundButInvalid + CommonConstants.NewPara + Resources.MBTWibuBoxUserMessage, Resources.MBCaptionWarning,
                                        MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                    else if (m_WibuBoxFound == false)
                    {
                        // A WibuBox was not found.
                        MessageBox.Show(Resources.MBTWibuBoxNotFound + CommonConstants.NewPara + Resources.MBTWibuBoxUserMessage, Resources.MBCaptionWarning,
                                        MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                }
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message, Resources.MBCaptionWarning, MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }

            return m_WibuBoxValid;
        }
Пример #9
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)
        {
            // Skip, if the Dispose() method has been called.
            if (IsDisposed)
            {
                return;
            }

            try
            {
                if (disposing)
                {
                    // Cleanup managed objects by calling their Dispose() methods.
                    if (components != null)
                    {
                        components.Dispose();
                    }
                }

                // Whether called by consumer code or the garbage collector free all unmanaged resources and set the value of managed data members to null.
				if (MainWindow != null)
				{
					MainWindow.FontChanged -= new System.EventHandler(ChangeFont);
                    m_MainWindow = null;
				}

                if (m_OpenedDialogBoxList != null)
                {
                    m_OpenedDialogBoxList.Clear();
                    m_OpenedDialogBoxList = null;
                }

                if (m_ToolStripMenuItemEnabledList != null)
                {
                    m_ToolStripMenuItemEnabledList.Clear();
                    m_ToolStripMenuItemEnabledList = null;
                }

                if (m_ToolStripItemCollectionCalledFrom != null)
                {
                    m_ToolStripItemCollectionCalledFrom.Clear();
                    m_ToolStripItemCollectionCalledFrom = null;
                }

                if (m_ToolStripItemCollectionCurrent != null)
                {
                    m_ToolStripItemCollectionCurrent.Clear();
                    m_ToolStripItemCollectionCurrent = null;
                }

                m_KeyEventArgs = null;
                m_MainWindow = null;
                m_Security = null;
                m_CalledFrom = null;

				// This is to prevent a situation where the toolstrip maintains an automatically subscribed UserPreferenceChanged event.
				if (m_ToolStripFunctionKeysPTU != null)
				{
					m_ToolStripFunctionKeysPTU.Visible = false;
				}

                #region - [Detach the event handler methods.] -
                this.m_TSBEsc.Click -= new EventHandler(this.Escape_Click);
                this.m_TSBF1.Click -= new EventHandler(this.F1_Click);
                this.m_TSBF2.Click -= new EventHandler(this.F2_Click);
                this.m_TSBF3.Click -= new EventHandler(this.F3_Click);
                this.m_TSBF4.Click -= new EventHandler(this.F4_Click);
                this.m_TSBF5.Click -= new EventHandler(this.F5_Click);
                this.m_TSBF6.Click -= new EventHandler(this.F6_Click);
                this.m_TSBF7.Click -= new EventHandler(this.F7_Click);
                this.m_TSBF8.Click -= new EventHandler(this.F8_Click);
                this.m_TSBF9.Click -= new EventHandler(this.F9_Click);
                this.m_TSBF10.Click -= new EventHandler(this.F10_Click);
                this.m_TSBF11.Click -= new EventHandler(this.F11_Click);
                this.m_TSBF12.Click -= new EventHandler(this.F12_Click);
                this.m_ToolStripComboBox1.SelectedIndexChanged -= new EventHandler(this.m_ToolStripComboBox1_SelectedIndexChanged);
                this.Shown -= new EventHandler(this.FormPTU_Shown);
                this.KeyDown -= new KeyEventHandler(this.FormPTU_KeyDown);
                this.KeyUp -= new KeyEventHandler(this.FormPTU_KeyUp);
                this.Resize -= new EventHandler(this.FormPTU_Resize);
                #endregion - [Detach the event handler methods.] -

                #region - [Component Designer Variables] -
                this.m_ToolStripFunctionKeysPTU = null;
                this.m_TSBEsc = null;
                this.m_TSSeparatorEsc = null;
                this.m_TSBF1 = null;
                this.m_TSSeparatorF1 = null;
                this.m_TSBF2 = null;
                this.m_TSSeparatorF2 = null;
                this.m_TSBF3 = null;
                this.m_TSSeparatorF3 = null;
                this.m_TSBF4 = null;
                this.m_TSSeparatorF4 = null;
                this.m_TSBF5 = null;
                this.m_TSSeparatorF5 = null;
                this.m_TSBF6 = null;
                this.m_TSSeparatorF6 = null;
                this.m_TSBF7 = null;
                this.m_TSSeparatorF7 = null;
                this.m_TSBF8 = null;
                this.m_TSSeparatorF8 = null;
                this.m_TSBF9 = null;
                this.m_TSSeparatorF9 = null;
                this.m_TSBF10 = null;
                this.m_TSSeparatorF10 = null;
                this.m_TSBF11 = null;
                this.m_TSSeparatorF11 = null;
                this.m_TSBF12 = null;
                this.m_TSSeparatorF12 = null;
                this.m_ToolStripComboBox1 = null;
                this.m_ToolStripLegendComboBox1 = null;
                this.m_PanelInformation = null;
                this.m_TableLayoutPanelInformationLabels = null;
                this.m_Legend2 = null;
                this.m_Label1 = null;
                this.m_Legend1 = null;
                this.m_Legend4 = null;
                this.m_Label2 = null;
                this.m_Legend3 = null;
                this.m_Label3 = null;
                this.m_Label4 = null;
                this.m_Legend5 = null;
                this.m_Label5 = null;
                this.m_Label6 = null;
                this.m_Legend6 = null;
                this.m_TabControl = null;
                this.m_TabPage1 = null;
                #endregion - [Component Designer Variables] -
            }
            catch (Exception)
            {
                // Don't do anything, just ensure that an exception isn't thrown.
            }
        }
Пример #10
0
        /// <summary>
        /// Initializes a new instance of the form.
        /// </summary>
        public FormPTU()
        {
            InitializeComponent();

            m_Security = new Security();
        }
Пример #11
0
 /// <summary>
 /// Process any form specific changes to the main menu resulting from a change in the security level of the user.
 /// </summary>
 /// <param name="security">Reference to the security class.</param>
 public virtual void UpdateMenu(Security security)
 {
     // Apply the form specific menu changes that have been applied since the form was instantiated.
     for (int index = 0; index < m_ToolStripMenuItemEnabledList.Count; index++)
     {
         ToolStripMenuItem toolStripMenuItem = General.GetToolStripMenuItem(MainWindow.MenuStrip, m_ToolStripMenuItemEnabledList[index].Key);
         toolStripMenuItem.Enabled = m_ToolStripMenuItemEnabledList[index].EnabledNew;
     }
 }