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