Exemple #1
0
        /// <summary>Method for refreshing the Network Session status and all of the form elements for every/any action performed</summary>
        private void RefreshSessionInformation()
        {
            NetworkSessionCertificate certificate = m_NetworkSession.Certificate;

            if (certificate == null || string.IsNullOrEmpty(certificate.SessionID))
            {
                openSessionButton.Enabled    = true;
                usePollTimerCheckBox.Enabled = true;
                licenseIDTextBox.Enabled     = true;
                passwordTextBox.Enabled      = true;
                pollSessionButton.Enabled    = false;
                closeSessionButton.Enabled   = false;
                checkoutButton.Enabled       = false;
                checkInButton.Enabled        = false;

                sessionIDTextBox.Text          = "";
                allocatedUntilDateTextBox.Text = "";
                seatsAvailableTextBox.Text     = "";
                totalSeatsTextBox.Text         = "";

                checkoutMinMaxLabel.Visible     = false;
                checkoutStatusLabel.Text        = "Not applicable";
                checkoutDurationTextBox.Enabled = false;

                if (pollTimer.Enabled)
                {
                    pollTimer.Stop();
                }

                return;
            }

            openSessionButton.Enabled    = false;
            usePollTimerCheckBox.Enabled = false;
            licenseIDTextBox.Enabled     = false;
            passwordTextBox.Enabled      = false;
            pollSessionButton.Enabled    = true;
            closeSessionButton.Enabled   = true;

            sessionIDTextBox.Text          = certificate.SessionID;
            allocatedUntilDateTextBox.Text = certificate.AllocatedUntilDate.ToLocalTime().ToString();
            seatsAvailableTextBox.Text     = certificate.SeatsAvailable.ToString();
            totalSeatsTextBox.Text         = certificate.TotalSeats.ToString();

            //make sure we pass basic validation
            NetworkSessionValidation validation = new NetworkSessionValidation(m_NetworkSession);

            if (!validation.Validate())
            {
                MessageBox.Show(this, "Your session is no longer valid!  Reason: " + validation.LastError.ErrorString);
                //close the session
                this.closeSessionButton_Click(this, new EventArgs());
                return;
            }

            //setup check-out/check-in form elements
            if (certificate.CheckoutDurationMinimum > 0 && certificate.CheckoutDurationMaximum > 0)
            {
                checkoutDurationTextBox.Enabled = true;
                checkoutButton.Enabled          = !certificate.CheckedOut;
                checkInButton.Enabled           = certificate.CheckedOut;

                if (certificate.CheckedOut && certificate.AllocatedUntilDate.Subtract(DateTime.UtcNow).TotalMilliseconds > 0)
                {
                    checkoutExpiredTimer.Interval = (int)certificate.AllocatedUntilDate.Subtract(DateTime.UtcNow).TotalMilliseconds;
                    checkoutExpiredTimer.Start();
                    m_NetworkSession.LockCertificate();
                    checkoutStatusLabel.Text = "Checked out";
                }
                else
                {
                    m_NetworkSession.UnlockCertificate();
                    if (certificate.AllocatedUntilDate.Subtract(DateTime.UtcNow).TotalMilliseconds < 0)
                    {
                        //the checked out session has expired -- notify the user and start with a fresh, unopened session
                        MessageBox.Show(this, "Your session has expired!", "Expired", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        m_NetworkSession.ClearSession();
                        RefreshSessionInformation();
                    }
                    checkoutStatusLabel.Text = "Not checked out";
                }

                if (certificate.CheckoutDurationMinimum == certificate.CheckoutDurationMaximum)
                {
                    checkoutMinMaxLabel.Visible      = false;
                    checkoutDurationTextBox.ReadOnly = true;
                    checkoutDurationTextBox.Text     = certificate.CheckoutDurationMaximum.ToString();
                }
                else
                {
                    checkoutDurationTextBox.ReadOnly = false;
                    checkoutMinMaxLabel.Visible      = true;
                    checkoutMinMaxLabel.Text         = "Must be between " + certificate.CheckoutDurationMinimum.ToString() + " and " + certificate.CheckoutDurationMaximum.ToString() + " hours.";
                }
            }
            else
            {
                checkoutStatusLabel.Text        = "Not applicable";
                checkoutDurationTextBox.Enabled = false;
                checkoutButton.Enabled          = false;
                checkInButton.Enabled           = false;
            }

            //setup the poll timer
            if (usePollTimerCheckBox.Checked && !certificate.CheckedOut)
            {
                if (m_LastPollSuccessful)
                {
                    pollTimer.Stop();
                    pollTimer.Interval = certificate.PollFrequency * 1000;
                    pollTimer.Start();
                }
                else
                {
                    if (m_RetryCount >= certificate.PollRetryCount)
                    {
                        pollTimer.Stop();
                        return;
                    }
                    else
                    {
                        pollTimer.Stop();
                        pollTimer.Interval = certificate.PollRetryFrequency * 1000;
                        pollTimer.Start();
                    }
                }
            }
            else
            {
                if (pollTimer.Enabled)
                {
                    pollTimer.Stop();
                }
            }
        }