Beispiel #1
0
        /// <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();
        }
Beispiel #2
0
        /// <summary>The Open Session button click event handler</summary>
        /// <param name="sender">Sender object</param>
        /// <param name="e">Event arguments</param>
        private void openSessionButton_Click(object sender, EventArgs e)
        {
            int licenseId = 0;

            //validate the License ID
            if (string.IsNullOrEmpty(licenseIDTextBox.Text) || !int.TryParse(licenseIDTextBox.Text, out licenseId))
            {
                MessageBox.Show(this, "Please enter a properly formatted License ID.", "Invalid Input", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                licenseIDTextBox.Focus();
                return;
            }

            //validate the password
            if (string.IsNullOrEmpty(passwordTextBox.Text))
            {
                MessageBox.Show(this, "Please enter a password.", "Invalid Input", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                passwordTextBox.Focus();
                return;
            }

            using (XmlNetworkFloatingService client = new XmlNetworkFloatingService())
            {
                client.Url = ConfigurationManager.AppSettings["NetworkFloatingServiceEndpointUrl"];
                if (!this.m_NetworkSession.OpenSession(licenseId, passwordTextBox.Text, client))
                {
                    MessageBox.Show(this, "An error occurred while trying to open the session. " + m_NetworkSession.LastError.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    this.m_NetworkSession.ClearSession();
                }
            }

            this.RefreshSessionInformation();
        }
Beispiel #3
0
        /// <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();
        }
Beispiel #4
0
        /// <summary>Form Load event handler</summary>
        /// <param name="sender">Sender object</param>
        /// <param name="e">Event arguments</param>
        private void MainForm_Load(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(ConfigurationManager.AppSettings["NetworkFloatingServiceEndpointUrl"]))
            {
                MessageBox.Show(this, "The application configuration appears to be missing or is missing information required for this program to run.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                this.Close();
                return;
            }

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

            if (File.Exists(m_CertificatePath))
            {
                try
                {
                    m_NetworkSession = new NetworkSession(m_EncryptionKey, true, true, m_IdentifierAlgorithms, m_CertificatePath, true);
                    m_NetworkSession.LockCertificate();
                    this.RefreshSessionInformation();

                    /* Validate the checked-out session against the server during application startup.
                     *
                     * This will help prevent a user from checking-out a session, backing-up the session
                     * XML certificate file, checking the session in, closing the application,
                     * restoring the session XML certificate file, and then running the application
                     * again to continue to use the checked-out session, even though it was already
                     * checked back in. */
                    if (this.m_NetworkSession.Certificate != null)
                    {
                        //call the web service to try and poll the session
                        using (XmlNetworkFloatingService webservice = new XmlNetworkFloatingService())
                        {
                            webservice.Url = ConfigurationManager.AppSettings["NetworkFloatingServiceEndpointUrl"];

                            if (!m_NetworkSession.PollSession(webservice) && ShouldLastResponseRevokeSession())
                            {
                                MessageBox.Show(this, "The session poll failed. " + m_NetworkSession.LastError.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                                closeSessionButton_Click(sender, e);
                            }
                        }
                        this.RefreshSessionInformation();
                    }
                    return;
                }
                catch (IOException)
                {
                    this.m_NetworkSession.ClearSession();
                    MessageBox.Show(this, "A session has been checked out, but appears to be in use by another process.  The application will now terminate.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    this.Close();
                    return;
                }
            }
        }
        /// <summary>Gets a new <see cref="XmlNetworkFloatingService"/> object, which may be used for processing web service methods centered around network floating licensing via SOLO Server.</summary>
        /// <returns>Returns a new <see cref="XmlNetworkFloatingService"/> object.</returns>
        public XmlNetworkFloatingService CreateXmlNetworkFloatingServiceObject()
        {
            //create the new web service object with our URL
            SoapHttpClientProtocol ws = new XmlNetworkFloatingService();

            ws.Url = m_XmlNetworkFloatingServiceUrl;

            if (!this.InitializeWebServiceObject(ref ws))
            {
                return(null);
            }

            //return the web service object
            return((XmlNetworkFloatingService)ws);
        }
Beispiel #6
0
 /// <summary>The Close Session button click event handler</summary>
 /// <param name="sender">Sender object</param>
 /// <param name="e">Event arguments</param>
 private void closeSessionButton_Click(object sender, EventArgs e)
 {
     //call the web service
     using (XmlNetworkFloatingService webservice = new XmlNetworkFloatingService())
     {
         webservice.Url = ConfigurationManager.AppSettings["NetworkFloatingServiceEndpointUrl"];
         if (!m_NetworkSession.CloseSession(webservice))
         {
             MessageBox.Show(this, "The session could not be closed. " + m_NetworkSession.LastError.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
             return;
         }
     }
     this.m_NetworkSession.ClearSession();
     this.RefreshSessionInformation();
 }