Esempio n. 1
0
 /// <summary>Close form button click event handler</summary>
 /// <param name="sender">object</param>
 /// <param name="e">EventArgs</param>
 private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
 {
     if (m_Semaphore != null)
     {
         m_Semaphore.Close(); // close our network session if it is open
         m_Semaphore = null;
     }
 }
Esempio n. 2
0
        /// <summary>Generates a string containing the license status and network seats status for display on the main form.</summary>
        /// <param name="validationResult">whether or not last license validation was successful</param>
        /// <param name="semaphore">The NetworkSemaphore object that contains total seats count and active/used seats count</param>
        /// <returns>Returns a string that contains description of the license</returns>
        internal string GenerateNetworkLicenseStatusString(bool validationResult, NetworkSemaphore semaphore)
        {
            StringBuilder status = new StringBuilder();

            status.AppendLine(GenerateLicenseStatusString(validationResult));

            if (validationResult && semaphore != null)
            {
                status.AppendLine("Seats Used: " + semaphore.SeatsActive.ToString() + " out of " + semaphore.SeatsTotal.ToString());
            }
            return(status.ToString());
        }
Esempio n. 3
0
        /// <summary>The method that performs the work, which is run asynchronously by the splash screen.</summary>
        /// <param name="sender">The sender object.</param>
        /// <param name="e">Event arguments</param>
        /// <remarks><para>This method handles the <see cref="LicensingGui.SplashDoWork"/> event.</para></remarks>
        private void InitializeApplicationSettings(object sender, EventArgs e)
        {
            //Load and initialize the license file.
            m_LastLicenseValidationResult = m_License.InitializeLicense();

            //If License is initialized properly, display status. If we created a fresh evaluation, clear the prior error generated from being unable to load an existing license file.
            if (m_LastLicenseValidationResult && m_License.LastError.ErrorNumber == LicenseError.ERROR_COULD_NOT_LOAD_LICENSE)
            {
                m_License.LastError = new LicenseError(LicenseError.ERROR_NONE);
            }

            //this.criticalFeatureButton.Enabled = UpdateLicenseStatus();

            if (m_Semaphore != null)
            {
                m_Semaphore.Close();
                m_Semaphore = null;
            }

            if (!m_LastLicenseValidationResult && !(m_License.IsWritable) &&
                m_License.ProductOption.OptionType == LicenseProductOption.ProductOptionType.DownloadableLicenseWithTriggerCodeValidation)
            {
                //The license is a downloadable license file, and is not supported since the application license is not a WritableLicense...
                try
                {
                    //Try to delete the downloadable file.
                    File.Delete(LicenseConfiguration.LicenseFilePath);

                    //Re-initialize the settings and the license objects so none of the information from the downloadable license carries over.
                    m_License = SampleLicense.CreateNewLicense(sampleLicensingGui);
                    sampleLicensingGui.ApplicationLicense = m_License;

                    //Try to load and initialize the license file again.
                    m_LastLicenseValidationResult = m_License.InitializeLicense();
                }
                catch (Exception ex)
                {
                    statusLabel.Text = "Error: " + ex.Message;
                }
            }

            m_LastLicenseValidationTime = DateTime.UtcNow;
        }
Esempio n. 4
0
        /// <summary>Performs post-processing updates.</summary>
        /// <param name="sender">The sender object.</param>
        /// <param name="e">Event arguments</param>
        /// <remarks><para>This method handles the <see cref="LicensingGui.LicenseManagementActionComplete"/> event.</para></remarks>
        private void PostProcessingUpdates(object sender, LicenseManagementActionCompleteEventArgs e)
        {
            SampleLicense.PostProcessingUpdates(ref m_License, ref sampleLicensingGui, ref e, out m_LastLicenseValidationResult);
            m_LastLicenseValidationTime = DateTime.UtcNow;

            //Update SeatsTotal when Semaphore is not null
            if (m_Semaphore != null)
            {
                m_Semaphore.SeatsTotal = m_License.LicenseCounter;
                if (m_Semaphore.SeatsAvailable < 0)
                {
                    m_Semaphore.Close();
                    m_Semaphore = null;
                }
            }

            //Update license LastError if license activation has been completed successfully in post-Processing updates
            if (m_LastLicenseValidationResult && e.LastError.ErrorNumber == LicenseError.ERROR_NONE)
            {
                m_License.LastError = new LicenseError(LicenseError.ERROR_NONE);
            }
            UpdateLicenseStatus();
        }
Esempio n. 5
0
 /// <summary>Generates the LicenseStatusEntry objects containing network seats status, which displayed in the license management form</summary>
 /// <param name="validationResult">whether or not last license validation was successful</param>
 /// <param name="licensingGui">The LicensingGui object which will display the status</param>
 /// <param name="semaphore">The NetworkSemaphore object that contains total seats count and active/used seats count</param>
 internal void InitializeNetworkLicenseStatusEntries(bool validationResult, LicensingGui licensingGui, NetworkSemaphore semaphore)
 {
     InitializeLicenseStatusEntries(validationResult, licensingGui);
     if (validationResult && semaphore != null)
     {
         licensingGui.LicenseStatusEntries.Add(new LicenseStatusEntry(LicenseStatusIcon.Information, "Network Seats", "Seats Used: " + semaphore.SeatsActive.ToString() + " out of " + semaphore.SeatsTotal.ToString()));
     }
 }
Esempio n. 6
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
                }
            }
        }
Esempio n. 7
0
        /// <summary>Reloads the license file and refreshes the status on the main form.</summary>
        public void ReloadLicense()
        {
            if (!m_License.LoadFile(LicenseConfiguration.LicenseFilePath))
            {
                refreshLicenseButton.Enabled = false;
                deactivateButton.Enabled     = false;

                if (m_License.LastError.ErrorNumber == LicenseError.ERROR_PLUS_EVALUATION_INVALID)
                {
                    //Invalid Protection PLUS 5 SDK evaluation envelope.
                    statusTextLabel.Text           = m_License.LastError.ErrorString;
                    activateButton.Enabled         = false;
                    activateManuallyButton.Enabled = false;
                }
                else
                {
                    switch (m_License.LastError.ErrorNumber)
                    {
                    case LicenseError.ERROR_COULD_NOT_LOAD_LICENSE:
                        statusTextLabel.Text = string.Format("No license found - activation is required.", m_License.LastError.ErrorNumber);
                        break;

                    case LicenseError.ERROR_LICENSE_NOT_EFFECTIVE_YET:
                        string effectiveAsOf;

                        DateTime local = m_License.EffectiveStartDate.ToLocalTime();
                        int      daysUntilEffective = (int)local.Subtract(DateTime.Now.Date).TotalDays;

                        if (1 < daysUntilEffective)
                        {
                            effectiveAsOf = string.Format("{0} ({1} days).", local.ToLongDateString(), daysUntilEffective);
                        }
                        else if (1 == daysUntilEffective)
                        {
                            effectiveAsOf = "tomorrow.";
                        }
                        else
                        {
                            effectiveAsOf = string.Format("{0} today.", local.ToShortTimeString());
                        }

                        statusTextLabel.Text = string.Format("The license is not effective until {1}", m_License.LastError.ErrorNumber);
                        break;

                    default:
                        statusTextLabel.Text = "Invalid.  " + m_License.LastError.ErrorString;
                        break;
                    }
                }

                userCountLabel.Text = "N/A";

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

                return;
            }

            refreshLicenseButton.Enabled = true;
            deactivateButton.Enabled     = true;

            RefreshLicenseStatus();
        }
        /// <summary>Network license search dialog event handler</summary>
        /// <param name="semaphore">semaphore</param>
        public NetworkLicenseSearchForm(NetworkSemaphore semaphore)
        {
            m_semaphore = semaphore;

            InitializeComponent();
        }
Esempio n. 9
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);
            }
        }