コード例 #1
0
ファイル: MainForm.cs プロジェクト: pklompPCCA/Windows.Forms
        /// <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();
        }