/// <summary>Updates the LicenseStatus property.</summary> public void UpdateLicenseStatusProperty() { StringBuilder status = new StringBuilder(); switch (m_License.LastError.ErrorNumber) { case LicenseError.ERROR_COULD_NOT_LOAD_LICENSE: status.Append(m_License.LastError.ErrorNumber); status.Append(": "); status.Append("License not found - activation is required."); break; case LicenseError.ERROR_LICENSE_NOT_EFFECTIVE_YET: status.Append(m_License.LastError.ErrorNumber); status.Append(": "); status.Append("License not effective until "); DateTime local = m_License.EffectiveStartDate.ToLocalTime(); int daysUntilEffective = (int)local.Subtract(DateTime.Now.Date).TotalDays; if (1 < daysUntilEffective) { status.Append(local.ToLongDateString()); status.Append(" ("); status.Append(daysUntilEffective); status.Append(" days)."); } else if (1 == daysUntilEffective) { status.Append("tomorrow."); } else { status.Append(local.ToShortTimeString() + " today."); } break; case LicenseError.ERROR_LICENSE_EXPIRED: status.Append(m_License.LastError.ErrorNumber); status.Append(": "); status.Append("License invalid or expired."); break; case LicenseError.ERROR_WEBSERVICE_RETURNED_FAILURE: //Web service error message. status.Append(m_License.LastError.ExtendedErrorNumber); status.Append(": "); status.Append(LicenseError.GetWebServiceErrorMessage(m_License.LastError.ExtendedErrorNumber)); break; default: //Show a standard error message. status.Append(m_License.LastError.ErrorNumber); status.Append(": "); status.Append(m_License.LastError.ToString()); break; } LicenseStatus = status.ToString(); }
/// <summary>The Check-Out button click event handler</summary> /// <param name="sender">Sender object</param> /// <param name="e">Event arguments</param> private void checkoutButton_Click(object sender, EventArgs e) { if (m_NetworkSession.Certificate.CheckedOut) { MessageBox.Show(this, "Your network session has already been checked out.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } if (File.Exists(m_CertificatePath)) { MessageBox.Show(this, "Another process has checked out a network session. You may only check out from one instance of this application at a time.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } decimal requestedCheckoutDuration = 0; if (string.IsNullOrEmpty(checkoutDurationTextBox.Text) || !decimal.TryParse(checkoutDurationTextBox.Text, out requestedCheckoutDuration)) { MessageBox.Show(this, "Please enter a properly-formatted number of hours for which you would like to have this session checked out.", "Invalid Input", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); checkoutDurationTextBox.Focus(); return; } if (requestedCheckoutDuration < m_NetworkSession.Certificate.CheckoutDurationMinimum || requestedCheckoutDuration > m_NetworkSession.Certificate.CheckoutDurationMaximum) { if (m_NetworkSession.Certificate.CheckoutDurationMinimum == m_NetworkSession.Certificate.CheckoutDurationMaximum) { MessageBox.Show(this, "You may only request to check out the session for " + m_NetworkSession.Certificate.CheckoutDurationMinimum.ToString() + " hours.", "Invalid Input", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else { MessageBox.Show(this, "You may only request to check out the session for between " + m_NetworkSession.Certificate.CheckoutDurationMinimum.ToString() + " and " + m_NetworkSession.Certificate.CheckoutDurationMaximum.ToString() + " hours.", "Invalid Input", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } checkoutDurationTextBox.Focus(); return; } //call the web service using (XmlNetworkFloatingService webservice = new XmlNetworkFloatingService()) { webservice.Url = ConfigurationManager.AppSettings["NetworkFloatingServiceEndpointUrl"]; if (!m_NetworkSession.CheckoutSession(requestedCheckoutDuration, webservice)) { if (ShouldLastResponseRevokeSession()) { MessageBox.Show(this, "The session will be closed. Reason: " + LicenseError.GetWebServiceErrorMessage(m_NetworkSession.LastError.ExtendedErrorNumber), "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); closeSessionButton_Click(sender, e); return; } MessageBox.Show(this, "The session could not be checked out. " + m_NetworkSession.LastError.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } } this.RefreshSessionInformation(); }
/// <summary>The Check-In button click event handler</summary> /// <param name="sender">Sender object</param> /// <param name="e">Event arguments</param> private void checkInButton_Click(object sender, EventArgs e) { if (!m_NetworkSession.Certificate.CheckedOut) { MessageBox.Show(this, "Your network session must be checked out before you can check it back in.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } //call the web service using (XmlNetworkFloatingService webservice = new XmlNetworkFloatingService()) { webservice.Url = ConfigurationManager.AppSettings["NetworkFloatingServiceEndpointUrl"]; if (!m_NetworkSession.CheckinSession(webservice)) { if (ShouldLastResponseRevokeSession()) { MessageBox.Show(this, "The session will be closed. Reason: " + LicenseError.GetWebServiceErrorMessage(m_NetworkSession.LastError.ExtendedErrorNumber), "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); closeSessionButton_Click(sender, e); return; } MessageBox.Show(this, "The session could not be checked in. " + m_NetworkSession.LastError.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } } this.RefreshSessionInformation(); }
/// <summary>Generates a string containing a description of a license error.</summary> /// <remarks><para>This method is called from <see cref="GenerateLicenseStatusEntry"/>.</para></remarks> /// <returns>Returns a string containing the description of a license error.</returns> internal string GenerateLicenseErrorString() { StringBuilder status = new StringBuilder(); switch (LastError.ErrorNumber) { case LicenseError.ERROR_COULD_NOT_LOAD_LICENSE: status.Append(LastError.ErrorNumber); status.Append(": "); status.Append("License not found - activation is required."); break; case LicenseError.ERROR_COULD_NOT_LOAD_VOLUME_DOWNLOADABLE_LICENSE: status.Append(LastError.ErrorNumber); status.Append(": "); status.Append((ProductOption.OptionType == LicenseProductOption.ProductOptionType.VolumeLicense) ? "Volume" : "Downloadable"); status.Append(" license not found."); break; case LicenseError.ERROR_LICENSE_NOT_EFFECTIVE_YET: status.Append(LastError.ErrorNumber); status.Append(": "); if (ProductOption.OptionType == LicenseProductOption.ProductOptionType.DownloadableLicenseWithTriggerCodeValidation) { status.Append("Activation required."); break; } status.Append("License not effective until "); DateTime local = EffectiveStartDate.ToLocalTime(); int daysUntilEffective = (int)local.Subtract(DateTime.Now.Date).TotalDays; if (1 < daysUntilEffective) { status.Append(local.ToLongDateString()); status.Append(" ("); status.Append(daysUntilEffective); status.Append(" days)."); } else if (1 == daysUntilEffective) { status.Append("tomorrow."); } else { status.Append(local.ToShortTimeString() + " today."); } break; case LicenseError.ERROR_LICENSE_EXPIRED: status.Append(LastError.ErrorNumber); status.Append(": "); status.Append("License invalid or expired."); break; case LicenseError.ERROR_WEBSERVICE_RETURNED_FAILURE: //Web service error message. status.Append(LastError.ExtendedErrorNumber); status.Append(": "); status.Append(LicenseError.GetWebServiceErrorMessage(LastError.ExtendedErrorNumber)); break; default: //Show a standard error message. status.Append(LastError.ErrorNumber); status.Append(": "); status.Append(LastError.ToString()); break; } return(status.ToString()); }