Exemplo n.º 1
0
        /// <summary>Invalid semaphore handler</summary>
        /// <param name="sender">object</param>
        /// <param name="e">EventArgs</param>
        private void InvalidSemaphoreHandler(object sender, EventArgs e) // fires when the network session is no longer valid
        {
            if (this.InvokeRequired)
            {
                this.Invoke(new InvalidSemaphoreThreadDelegate(InvalidSemaphoreHandler), new Object[] { sender, e }); // invoke this method using our UI thread delegate
            }
            else
            {
                if (!m_Semaphore.Open()) // see if we can re-open our network session
                {
                    while (true)
                    {
                        DialogResult mbResult = MessageBox.Show("Your network session is no longer valid. " + m_Semaphore.LastError + "\n\nPress 'Retry' to attempt to re-establish your network session. Pressing 'Cancel' will give you 60 seconds to save your work and exit the application.", "Warning", MessageBoxButtons.RetryCancel, MessageBoxIcon.Warning);

                        if (mbResult == DialogResult.Cancel)
                        {
                            m_CountdownDialog = new LicenseInvalidCountdownForm(60); // exit the application in 60 seconds
                            m_CountdownDialog.Show();

                            break;
                        }

                        if (!m_Semaphore.Open())                                                                   // see if we can re-open our network session
                        {
                            using (NetworkLicenseSearchForm searchDlg = new NetworkLicenseSearchForm(m_Semaphore)) // try to search for an open network seat
                            {
                                if (searchDlg.ShowDialog() == DialogResult.OK)
                                {
                                    break;
                                }
                            }
                        }
                        else
                        {
                            break;
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>Refreshes the license status on the main form</summary>
        public void RefreshLicenseStatus()
        {
            refreshLicenseButton.Enabled = (m_License.InstallationID.Length > 0);

            if (!m_License.Validate())
            {
                if (m_Semaphore != null)
                {
                    m_Semaphore.Close(); // close our network session if it is open
                    m_Semaphore = null;
                }

                statusTextLabel.Text = "The license is invalid or expired.";
                userCountLabel.Text  = "N/A";
            }
            else
            {
                if (m_Semaphore == null)
                {
                    m_Semaphore          = new NetworkSemaphore(Path.GetDirectoryName(LicenseConfiguration.LicenseFilePath), LicenseConfiguration.NetworkSemaphorePrefix, m_License.LicenseCounter, true, 15, true);
                    m_Semaphore.Invalid += new NetworkSemaphore.InvalidEventHandler(InvalidSemaphoreHandler);

                    if (!m_Semaphore.Open() && m_Semaphore.LastError.ErrorNumber == LicenseError.ERROR_NETWORK_LICENSE_FULL) // try to open a network session
                    {
                        NetworkLicenseSearchForm searchDlg = new NetworkLicenseSearchForm(m_Semaphore);                      // try to search for an open network seat

                        if (searchDlg.ShowDialog() != DialogResult.OK)
                        {
                            statusTextLabel.Text = "Unable to establish a network session. " + m_Semaphore.LastError;
                            userCountLabel.Text  = "N/A";
                            m_Semaphore          = null;
                        }
                    }
                    else if (m_Semaphore.LastError.ErrorNumber != LicenseError.ERROR_NONE)
                    {
                        statusTextLabel.Text = "Unable to establish a network session. " + m_Semaphore.LastError;
                        userCountLabel.Text  = "N/A";
                        m_Semaphore          = null;
                    }
                }

                if (m_Semaphore != null && m_Semaphore.IsValid)
                {
                    StringBuilder registerInfo = new StringBuilder();

                    //Check if first name is not empty and not unregistered
                    if (m_License.Customer.FirstName != "" && m_License.Customer.FirstName != "UNREGISTERED")
                    {
                        registerInfo.Append("Registered To: ");

                        //Append first name
                        registerInfo.Append(m_License.Customer.FirstName);
                    }

                    //Check if last name is not empty and not unregistered
                    if (m_License.Customer.LastName != "" && m_License.Customer.LastName != "UNREGISTERED")
                    {
                        if (registerInfo.ToString() == "")
                        {
                            registerInfo.Append("Registered To:");
                        }
                        registerInfo.Append(" ");

                        //Append last name
                        registerInfo.Append(m_License.Customer.LastName);
                    }

                    //Check if company name is not empty and not unregistered
                    if (m_License.Customer.CompanyName != "" && m_License.Customer.CompanyName != "UNREGISTERED")
                    {
                        if (registerInfo.ToString() == "")
                        {
                            registerInfo.Append("Registered To:");
                        }
                        registerInfo.Append(" ");

                        //Append company name
                        registerInfo.Append("[" + m_License.Customer.CompanyName + "]");
                    }

                    if (registerInfo.ToString() != "")
                    {
                        registerInfo.Append(Environment.NewLine);
                    }

                    //Append license ID
                    registerInfo.Append("License ID: " + m_License.LicenseID);

                    statusTextLabel.Text = "Fully Licensed." + Environment.NewLine +
                                           registerInfo.ToString();

                    userCountLabel.Text = m_Semaphore.SeatsActive.ToString() + " out of " + m_License.LicenseCounter.ToString(); // display how many network users are running the application
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>Updates the License's status in the <see cref="LicensingGui"/> and checks if network seats are available.</summary>
        /// <returns>Returns true if the network seats are not depleted, false otherwise</returns>
        private bool UpdateLicenseStatus()
        {
            SampleLicense license = SampleLicense.CreateNewLicense(sampleLicensingGui);

            license.LoadFile(LicenseConfiguration.LicenseFilePath);
            if (license.LicenseID != m_License.LicenseID || license.InstallationID != m_License.InstallationID)
            {
                sampleLicensingGui.ApplicationLicense = license;
                m_License = license;
                if (m_Semaphore != null)
                {
                    m_Semaphore.Close();
                    m_Semaphore = null;
                }
            }

            if (!m_LastLicenseValidationResult || m_License.LastError.ErrorNumber != LicenseError.ERROR_NONE)
            {
                statusLabel.Text = m_License.GenerateNetworkLicenseStatusString(m_LastLicenseValidationResult, m_Semaphore);
                m_License.InitializeNetworkLicenseStatusEntries(m_LastLicenseValidationResult, sampleLicensingGui, m_Semaphore);

                //Check seats count and set the status, when No seats available and license re-activation completed with errors(No activation left or Invalid License ID and/or Password).
                if (m_License.LastError.ErrorNumber == LicenseError.ERROR_WEBSERVICE_RETURNED_FAILURE && m_Semaphore == null)
                {
                    m_Semaphore = new NetworkSemaphore(Path.GetDirectoryName(LicenseConfiguration.LicenseFilePath), LicenseConfiguration.NetworkSemaphorePrefix, m_License.LicenseCounter, true, 15, true);
                    if (!m_Semaphore.Open() && m_Semaphore.LastError.ErrorNumber == LicenseError.ERROR_NETWORK_LICENSE_FULL) // try to open a network session
                    {
                        statusLabel.Text = m_License.GenerateLicenseStatusString(m_LastLicenseValidationResult) + "No Seats Available.";
                        m_License.InitializeLicenseStatusEntries(m_LastLicenseValidationResult, sampleLicensingGui);
                        sampleLicensingGui.LicenseStatusEntries.Add(new LicenseStatusEntry(LicenseStatusIcon.Information, "Network Seats", "No Seats Available"));
                    }
                    m_Semaphore = null;
                }

                return(false);
            }

            if (!m_License.Validate())
            {
                if (m_Semaphore != null)
                {
                    m_Semaphore.Close(); // close our network session if it is open
                    m_Semaphore = null;
                }
                statusLabel.Text = "The license is invalid or expired";
                m_License.InitializeNetworkLicenseStatusEntries(m_LastLicenseValidationResult, sampleLicensingGui, m_Semaphore);
                return(false);
            }
            else
            {
                if (m_Semaphore == null)
                {
                    m_Semaphore          = new NetworkSemaphore(Path.GetDirectoryName(LicenseConfiguration.LicenseFilePath), LicenseConfiguration.NetworkSemaphorePrefix, m_License.LicenseCounter, true, 15, true);
                    m_Semaphore.Invalid += new NetworkSemaphore.InvalidEventHandler(InvalidSemaphoreHandler);

                    if (!m_Semaphore.Open() && m_Semaphore.LastError.ErrorNumber == LicenseError.ERROR_NETWORK_LICENSE_FULL) // try to open a network session
                    {
                        using (NetworkLicenseSearchForm searchDialog = new NetworkLicenseSearchForm(m_Semaphore))
                        {
                            if (searchDialog.ShowDialog() != DialogResult.OK)
                            {
                                statusLabel.Text = m_License.GenerateLicenseStatusString(m_LastLicenseValidationResult) + "No Seats Available.";
                                m_License.InitializeLicenseStatusEntries(m_LastLicenseValidationResult, sampleLicensingGui);
                                sampleLicensingGui.LicenseStatusEntries.Add(new LicenseStatusEntry(LicenseStatusIcon.Information, "Network Seats", "No Seats Available"));
                                m_Semaphore = null;
                            }
                        }
                    }
                    else if (m_Semaphore.LastError.ErrorNumber != LicenseError.ERROR_NONE)
                    {
                        statusLabel.Text  = "Status: Unable to establish a network session. " + m_Semaphore.LastError;
                        statusLabel.Text += "\nUsers: N/A";
                        m_Semaphore       = null;
                    }
                    else
                    {
                        statusLabel.Text = m_License.GenerateNetworkLicenseStatusString(m_LastLicenseValidationResult, m_Semaphore);
                        m_License.InitializeNetworkLicenseStatusEntries(m_LastLicenseValidationResult, sampleLicensingGui, m_Semaphore);
                    }
                    return(false);
                }
                if (m_Semaphore != null && m_Semaphore.IsValid)
                {
                    statusLabel.Text = m_License.GenerateNetworkLicenseStatusString(m_LastLicenseValidationResult, m_Semaphore);
                    m_License.InitializeNetworkLicenseStatusEntries(m_LastLicenseValidationResult, sampleLicensingGui, m_Semaphore);
                }
                return(true);
            }
        }