コード例 #1
0
ファイル: MainForm.cs プロジェクト: pklompPCCA/Windows.Forms
        /// <summary>Reloads the license file and refreshes the status on the main form.</summary>
        /// <returns>bool</returns>
        public bool ReloadLicense()
        {
            m_License = new SampleLicense();

            //Get the Evaluation Encryption envelope warning message.
            if (m_License.LastError.ErrorNumber == LicenseError.ERROR_PLUS_EVALUATION_WARNING)
            {
                m_WarningMessage = "Warning: (" + m_License.LastError.ErrorNumber + ") " + m_License.LastError.ErrorString;
            }

            bool successful = m_License.LoadFile(LicenseConfiguration.LicenseFilePath);

            if (!successful)
            {
                successful = m_License.CreateFreshEvaluation();
                if (successful)
                {
                    successful = m_License.LoadFile(LicenseConfiguration.LicenseFilePath);
                }
            }

            if (!successful)
            {
                mnuRefreshLicense.Enabled = false;
                UpdateLicenseStatusProperty();
                SplashScreen.InitializeFeatures(m_Features, m_License, false);
                ToggleFeatures();
                return(false);
            }

            return(RefreshLicenseStatus());
        }
コード例 #2
0
        /// <summary>Reloads the license file and refreshes the status on the main form.</summary>
        internal void ReloadLicense()
        {
            if (!m_License.LoadFile(LicenseConfiguration.LicenseFilePath))
            {
                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;
                    refreshLicenseButton.Enabled   = false;
                    deactivateButton.Enabled       = false;
                    return;
                }

                if (!m_License.CreateFreshEvaluation())
                {
                    statusTextLabel.Text = "Invalid.  " + m_License.LastError.ErrorString;
                    return;
                }
                else
                {
                    if (!m_License.LoadFile(LicenseConfiguration.LicenseFilePath))
                    {
                        statusTextLabel.Text = "Invalid.  " + m_License.LastError.ErrorString;
                        return;
                    }
                }
            }

            RefreshLicenseStatus();
        }
コード例 #3
0
ファイル: MainForm.cs プロジェクト: pklompPCCA/Windows.Forms
        /// <summary>Reloads the license file and refreshes the status on the main form.</summary>
        public bool ReloadLicense()
        {
            m_License = new SampleLicense();

            //Get the Evaluation Encryption envelope warning message.
            if (m_License.LastError.ErrorNumber == LicenseError.ERROR_PLUS_EVALUATION_WARNING)
            {
                m_WarningMessage = "Warning: (" + m_License.LastError.ErrorNumber + ") " + m_License.LastError.ErrorString;
            }

            bool successful = m_License.LoadFile(LicenseConfiguration.LicenseFilePath);

            SplashScreen.InitializeFeatures(m_Features, m_License, successful);
            this.mnuNew.Enabled       = newToolStripButton.Enabled = m_Features.CheckStatus(LicenseFeatures.New.ToString());
            this.mnuOpen.Enabled      = openToolStripButton.Enabled = m_Features.CheckStatus(LicenseFeatures.Open.ToString());
            this.mnuPrint.Enabled     = printToolStripButton.Enabled = m_Features.CheckStatus(LicenseFeatures.Print.ToString());
            this.mnuFind.Enabled      = findToolStripButton.Enabled = m_Features.CheckStatus(LicenseFeatures.Find.ToString());
            this.mnuSave.Enabled      = saveToolStripButton.Enabled = m_Features.CheckStatus(LicenseFeatures.Save.ToString());
            this.mnuSelectAll.Enabled = m_Features.CheckStatus(LicenseFeatures.SelectAll.ToString());
            this.mnuCut.Enabled       = cutToolStripButton.Enabled = m_Features.CheckStatus(LicenseFeatures.Cut.ToString());
            this.mnuCopy.Enabled      = copyToolStripButton.Enabled = m_Features.CheckStatus(LicenseFeatures.Copy.ToString());
            this.mnuPaste.Enabled     = pasteToolStripButton.Enabled = m_Features.CheckStatus(LicenseFeatures.Paste.ToString());
            this.mnuSaveAs.Enabled    = m_Features.CheckStatus(LicenseFeatures.SaveAs.ToString());
            this.mnuReplace.Enabled   = m_Features.CheckStatus(LicenseFeatures.Replace.ToString());

            if (!successful)
            {
                m_IsLicenseValid          = false;
                mnuRefreshLicense.Enabled = false;
                UpdateLicenseStatusProperty();
                return(false);
            }

            return(RefreshLicenseStatus());
        }
コード例 #4
0
ファイル: MainForm.cs プロジェクト: pklompPCCA/Windows.Forms
        /// <summary>Reloads the license file and refreshes the status on the main form.</summary>
        internal 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;
                    }
                }

                return;
            }

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

            RefreshLicenseStatus();
        }
コード例 #5
0
        /// <summary>Performs post-processing updates for actions performed through the <see cref="LicensingGui"/>.</summary>
        /// <remarks><para>This method is called by the <see cref="LicensingGui.LicenseManagementActionComplete"/> event handler method.  In the
        /// sample application form source code (i.e. MainForm.cs), this method is similarly named PostProcessingUpdates.  This might be named
        /// something like licensingGui1_LicenseManagementActionComplete in your application.</para></remarks>
        /// <param name="lic">The <see cref="License"/> being processed.</param>
        /// <param name="licGui">The <see cref="LicensingGui"/> used to process updates for the license.</param>
        /// <param name="e">The post-processing event arguments returned from the <see cref="LicensingGui"/> object.</param>
        /// <param name="newValidationSuccessful">Whether or not validation after processing updates has passed successfully.</param>
        internal static void PostProcessingUpdates(ref SampleLicense lic, ref LicensingGui licGui, ref LicenseManagementActionCompleteEventArgs e, out bool newValidationSuccessful)
        {
            //If an action was processed, run some post-processing actions.
            if (LicenseManagementActionTypes.ManualTriggerCode == e.ActionType)
            {
                //A trigger code needs to be processed...
                if (!lic.ProcessTriggerCode(e.LicenseID, e.Password, e.TriggerCodeNumber, e.TriggerCodeEventData))
                {
                    //If trigger code processing failed, show the error in the license management dialog.
                    e.PostProcessingSuccessful = false;
                    e.LastError = lic.LastError;
                }

                //Reload and revalidate the license file.
                if (lic.LoadFile(LicenseConfiguration.LicenseFilePath))
                {
                    newValidationSuccessful = lic.Validate();
                }
                else
                {
                    newValidationSuccessful = false;
                }
            }
            else if (LicenseError.ERROR_WEBSERVICE_RETURNED_FAILURE == e.LastError.ErrorNumber)
            {
                //The last action failed because the license is no longer valid in SOLO Server, so remove the license from the system.
                if (ShouldLicenseBeRevoked(lic.LastError.ExtendedErrorNumber))
                {
                    RevokeLicense(ref lic, ref licGui);
                    newValidationSuccessful = false;
                }
                else
                {
                    //The web service returned an error, which should be disabled to the user.
                    e.PostProcessingSuccessful = false;
                    e.LastError = lic.LastError;
                }
            }
            else if (LicenseManagementActionTypes.OnlineDeactivation == e.ActionType ||
                     LicenseManagementActionTypes.ManualDeactivation == e.ActionType)
            {
                RevokeLicense(ref lic, ref licGui);
                newValidationSuccessful = false;
                return;
            }
            else if (e.ProcessedSuccessfully &&
                     (LicenseManagementActionTypes.OnlineActivation == e.ActionType ||
                      LicenseManagementActionTypes.OnlineRefresh == e.ActionType ||
                      LicenseManagementActionTypes.ManualActivation == e.ActionType ||
                      LicenseManagementActionTypes.ManualRefresh == e.ActionType))
            {
                //This was a successful activation or license refresh attempt, which means we have a new license to process.
                lic.ProcessNewLicense(ref e, out newValidationSuccessful);
            }

            newValidationSuccessful = lic.Validate();
        }
コード例 #6
0
        /// <summary>Revokes the license.</summary>
        /// <remarks><para>This method is called from <see cref="PostProcessingUpdates"/>.</para></remarks>
        /// <param name="lic">The <see cref="License"/> object being revoked.</param>
        /// <param name="licGui">The <see cref="LicensingGui"/> which references the <see cref="License"/> object.</param>
        internal static void RevokeLicense(ref SampleLicense lic, ref LicensingGui licGui)
        {
            //The license has been revoked, so remove it from the system.
            lic.RemoveLicense();

            //Create a new License to clear out any data (like the License ID and Installation ID) from memory.
            lic = SampleLicense.CreateNewLicense(licGui);

            //Now try to load the license file even though it doesn't exist.  This helps ensure the correct error
            //message is displayed in the license status entry if the license management form is opened again.
            lic.LoadFile(LicenseConfiguration.LicenseFilePath);

            //Update the reference to the License object in case the license management form is opened again.
            licGui.ApplicationLicense = lic;
        }
コード例 #7
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);
            }
        }