Ejemplo n.º 1
0
        /// <summary>Deactivate License button click event handler</summary>
        /// <param name="sender">object</param>
        /// <param name="e">EventArgs</param>
        private void deactivateButton_Click(object sender, EventArgs e)
        {
            if (!m_IsEvaluation)
            {
                if (m_License.DeactivateOnline())
                {
                    m_EvaluationLicense = new SampleSelfSignedLicense();
                    File.Delete(LicenseConfiguration.LicenseFilePath);
                    if (m_EvaluationLicense.CreateExpiredEvaluation())
                    {
                        m_CurrentLicense = m_EvaluationLicense;
                        MessageBox.Show("The license has been deactivated successfully.", "License Deactivation", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else
                    {
                        MessageBox.Show("The license was not deactivated.  Error: (" + m_License.LastError.ErrorNumber + ")" + m_License.LastError.ErrorString, "License Deactivation", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                }
                else
                {
                    MessageBox.Show("The license was not deactivated.  Error: (" + m_License.LastError.ErrorNumber + ")" + m_License.LastError.ErrorString, "License Deactivation", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }

                ReloadLicense();
            }
        }
Ejemplo n.º 2
0
        /// <summary>Refreshes the license file.</summary>
        /// <returns>Returns true if the license file was refreshed successfully.  If false is returned, see the <see cref="License.LastError"/> property for details.</returns>
        internal bool RefreshLicense(XmlLicenseFileService webservice)
        {
            if (null == webservice)
            {
                LastError = new LicenseError(LicenseError.ERROR_WEBSERVICE_INVALID_CONFIGURATION);
                return(false);
            }

            string licenseContent = "";

            if (!base.RefreshLicense(webservice, ref licenseContent))
            {
                if (SampleLicense.ShouldLicenseBeRevoked(LastError.ExtendedErrorNumber))
                {
                    if (!RemoveLicense())
                    {
                        return(false);
                    }
                }
                return(false);
            }

            //try to save the license file to the file system
            if (!SaveLicenseFile(licenseContent))
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 3
0
        /// <summary>Shows the <see cref="LicensingGui"/> object's license management form.</summary>
        private void ManageLicense()
        {
            if (LicenseConfiguration.EncryptionKey.LastError.ErrorNumber != LicenseError.ERROR_NONE &&
                LicenseConfiguration.EncryptionKey.LastError.ErrorNumber != LicenseError.ERROR_PLUS_EVALUATION_WARNING)
            {
                m_License.LastError = LicenseConfiguration.EncryptionKey.LastError;
            }
            else if (SampleLicense.IsClockBackdatedAtRuntime(m_LastLicenseValidationTime))
            {
                m_LastLicenseValidationResult = false;
                m_License.LastError           = new LicenseError(LicenseError.ERROR_SYSTEM_TIME_INVALID);
            }
            else if (m_License.LastError.ErrorNumber != LicenseError.ERROR_COULD_NOT_LOAD_LICENSE)
            {
                m_LastLicenseValidationResult = m_License.Validate();
                m_LastLicenseValidationTime   = DateTime.UtcNow;
                statusLabel.Text = "Status: " + m_License.LastError.ErrorString;
            }

            this.criticalFeatureButton.Enabled = UpdateLicenseStatus();

            sampleLicensingGui.ShowDialog(LicensingGuiDialog.LicenseManagement, this, FormStartPosition.CenterParent);

            //Update the status
            this.criticalFeatureButton.Enabled = UpdateLicenseStatus();
        }
Ejemplo n.º 4
0
        /// <summary>Displays <see cref="NetworkLicenseBrowseForm"/> Initializes licensing objects.</summary>
        private void InitializeLicensingObjects()
        {
            using (NetworkLicenseBrowseForm dialog = new NetworkLicenseBrowseForm())
            {
                if (dialog.ShowDialog() == DialogResult.OK)
                {
                    LicenseConfiguration.LicenseFilePath = dialog.SelectedPath;
                }
                else
                {
                    Environment.Exit(0);
                }
            }

            //Initialize the license object.
            m_License = SampleLicense.CreateNewLicense(sampleLicensingGui);

            //Now pass the initialized license object to the LicenseingGui component.
            sampleLicensingGui.ApplicationLicense = m_License;

            //Configure the LicensingGui component with the trigger code seed data (only applicable with writable/self-signed licenses).
            sampleLicensingGui.TriggerCodeSeed = LicenseConfiguration.TriggerCodeSeed;
            sampleLicensingGui.RegKey2Seed     = LicenseConfiguration.RegKey2Seed;

            //Wire-up event handlers for the LicensingGui component.  Although this is typically done in the designer, this sample code intentionally
            //initializes to a) make it easier for you to copy-and-paste; and b) prevent the sample functions referenced here from being deleted when
            //the event handlers are changed in the designer.
            sampleLicensingGui.LicenseManagementActionComplete += new EventHandler <LicenseManagementActionCompleteEventArgs>(PostProcessingUpdates);
            sampleLicensingGui.ManualActionLoadRequested       += new EventHandler <ManualActionLoadRequestedEventArgs>(ManualActionLoadRequested);
            sampleLicensingGui.ManualActionSaveRequested       += new EventHandler <ManualActionSaveRequestedEventArgs>(ManualActionSaveRequested);
            sampleLicensingGui.SplashDoWork            += new EventHandler <EventArgs>(InitializeApplicationSettings);
            sampleLicensingGui.SplashWorkCompleteEvent += new EventHandler <EventArgs>(SplashWorkCompleted);
        }
Ejemplo n.º 5
0
        /// <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());
        }
Ejemplo n.º 6
0
        /// <summary>Refreshes the license file.</summary>
        /// <returns>Returns true if the license file was refreshed successfully.  If false is returned, see the <see cref="License.LastError"/> property for details.</returns>
        internal bool RefreshLicense()
        {
            string licenseContent = "";

            //initialize the object used for calling the web service method
            using (XmlLicenseFileService ws = m_Settings.CreateNewXmlLicenseFileServiceObject())
            {
                if (null == ws)
                {
                    LastError = new LicenseError(LicenseError.ERROR_WEBSERVICE_INVALID_CONFIGURATION);
                    return(false);
                }

                if (!base.RefreshLicense(ws, ref licenseContent))
                {
                    if (SampleLicense.ShouldLicenseBeRevoked(LastError.ExtendedErrorNumber))
                    {
                        RemoveLicense();
                    }
                    return(false);
                }
            }

            //try to save the license file to the file system
            if (!SaveLicenseFile(licenseContent, false))
            {
                return(false);
            }

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

            //Update the license status entries and the controls on this form.
            UpdateLicenseStatus();
        }
Ejemplo n.º 9
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();
        }
Ejemplo n.º 10
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;
        }
Ejemplo n.º 11
0
        /// <summary>Reloads the license file and refreshes the status on the main form.</summary>
        public void ReloadLicense()
        {
            m_License           = new SampleReadOnlyLicense();
            m_EvaluationLicense = new SampleSelfSignedLicense();
            m_CurrentLicense    = m_License;

            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;
                }

                m_CurrentLicense = m_EvaluationLicense;
                m_IsEvaluation   = true;

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

            RefreshLicenseStatus();
        }
Ejemplo n.º 12
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;
        }
Ejemplo n.º 13
0
        /// <summary>The method that performs the work, which is run asynchronously by the splash screen.</summary>
        /// <remarks><para>This method handles the <see cref="LicensingGui.SplashDoWork"/> event.</para></remarks>
        /// <param name="sender">The sender object.</param>
        /// <param name="e">Event arguments</param>
        private void InitializeApplicationSettings(object sender, EventArgs e)
        {
            //Load and initialize the license file.
            m_LastLicenseValidationResult = m_License.InitializeLicense();

            //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);
            }

            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...
                string licenseFilePath = (File.Exists(LicenseConfiguration.VolumeLicenseFilePath) ?
                                          LicenseConfiguration.VolumeLicenseFilePath :
                                          LicenseConfiguration.LicenseFilePath);
                try
                {
                    //Try to delete the downloadable file.
                    File.Delete(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)
                {
                    //We were unable to delete the downloadable license file.
                }
            }

            m_LastLicenseValidationTime = DateTime.UtcNow;

            //TODO: If your application has any of its own initialization logic, you can add it here so it runs while the
            //      splash screen is being displayed.
        }
Ejemplo n.º 14
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();
        }
Ejemplo n.º 15
0
        /// <summary>Main form Load event handler</summary>
        /// <param name="sender">object</param>
        /// <param name="e">EventArgs</param>
        private void MainForm_Load(object sender, EventArgs e)
        {
            using (NetworkLicenseBrowseForm browseDlg = new NetworkLicenseBrowseForm())
            {
                if (browseDlg.ShowDialog() == DialogResult.OK)
                {
                    LicenseConfiguration.LicenseFilePath = browseDlg.SelectedPath;
                }
                else
                {
                    Application.Exit();
                }
            }

            m_License = new SampleLicense();

            if (m_License.LastError.ErrorNumber == LicenseError.ERROR_PLUS_EVALUATION_WARNING)
            {
                MessageBox.Show("Warning: (" + m_License.LastError.ErrorNumber + ") " + m_License.LastError.ErrorString, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }

            ReloadLicense();
        }
Ejemplo n.º 16
0
 /// <summary>Occurs when a manual's action should be saved so it may be resumed later.</summary>
 /// <param name="sender">The sender object.</param>
 /// <param name="e">Event arguments</param>
 /// <remarks>
 /// <para>This method handles the <see cref="LicensingGui.ManualActionSaveRequested"/> event.</para>
 /// <note type="caution">
 /// <para>
 /// TODO: IMPORTANT: Either Implement your own handlers for loading and saving a manual request state/session, or update
 /// the ManualActionIV and ManualActionKey properties (in the LicenseConfiguration class) with randomized data which is
 /// unique for each of your applications. The implementations provided are simple and only designed to show you the
 /// functionality which you can achieve by saving and restoring manual action sessions.  However, it is VERY IMPORTANT
 /// that you take measures to hide and protect the saved request data/file so users may not easily restore and replay
 /// old responses (known as a replay attack).
 /// </para>
 /// </note>
 /// </remarks>
 private void ManualActionSaveRequested(object sender, ManualActionSaveRequestedEventArgs e)
 {
     SampleLicense.SaveManualActionSessionState(e.Contents);
 }
Ejemplo n.º 17
0
 /// <summary>Occurs when a manual action should be loaded and resumed.</summary>
 /// <param name="sender">The sender object.</param>
 /// <param name="e">Event arguments</param>
 /// <remarks>
 /// <para>This method handles the <see cref="LicensingGui.ManualActionLoadRequested"/> event.</para>
 /// <note type="caution">
 /// <para>
 /// TODO: IMPORTANT: Either Implement your own handlers for loading and saving a manual request state/session, or update
 /// the ManualActionIV and ManualActionKey properties (in the LicenseConfiguration class) with randomized data which is
 /// unique for each of your applications. The implementations provided are simple and only designed to show you the
 /// functionality which you can achieve by saving and restoring manual action sessions.  However, it is VERY IMPORTANT
 /// that you take measures to hide and protect the saved request data/file so users may not easily restore and replay
 /// old responses (known as a replay attack).
 /// </para>
 /// </note>
 /// </remarks>
 private void ManualActionLoadRequested(object sender, ManualActionLoadRequestedEventArgs e)
 {
     e.Contents = SampleLicense.LoadManualActionSessionState();
 }
Ejemplo n.º 18
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);
            }
        }
Ejemplo n.º 19
0
 /// <summary>Default main form constructor</summary>
 public MainForm()
 {
     InitializeComponent();
     m_License        = new SampleReadOnlyLicense();
     m_CurrentLicense = m_License;
 }