コード例 #1
0
        /// <summary>
        /// Logs into the specified project/domain combination
        /// </summary>
        /// <param name="sender">The sending object</param>
        /// <param name="e">The event arguments</param>
        private void btnLogin_Click(object sender, System.EventArgs e)
        {
            //Make sure that a login was entered
            if (this.txtLogin.Text.Trim() == "")
            {
                MessageBox.Show("You need to enter a SpiraTest login", "Authentication Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            //Make sure that a server was entered
            if (this.txtServer.Text.Trim() == "")
            {
                MessageBox.Show("You need to enter a SpiraTest web-server URL", "Authentication Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            //Store the info in settings for later
            Properties.Settings.Default.SpiraUrl      = this.txtServer.Text.Trim();
            Properties.Settings.Default.SpiraUserName = this.txtLogin.Text.Trim();
            if (chkPassword.Checked)
            {
                Properties.Settings.Default.SpiraPassword = this.txtPassword.Text;
            }
            else
            {
                Properties.Settings.Default.SpiraPassword = "";
            }
            Properties.Settings.Default.Save();

            //Put the password into settings after save so that we can use for the current import run regardless
            Properties.Settings.Default.SpiraPassword = this.txtPassword.Text;

            //Default the Start Import and login button to disabled
            this.btnImport.Enabled  = false;
            this.btnLogin.Enabled   = false;
            this.progressBar1.Style = ProgressBarStyle.Marquee;

            try
            {
                //Instantiate the web-service proxy class and set the URL from the text box
                SpiraImportProxy = new SpiraSoapService.SoapServiceClient();

                //Set the end-point and allow cookies
                string url = Properties.Settings.Default.SpiraUrl + IMPORT_WEB_SERVICES_URL;
                SpiraImportProxy.Endpoint.Address = new EndpointAddress(url);
                BasicHttpBinding httpBinding = (BasicHttpBinding)SpiraImportProxy.Endpoint.Binding;
                ConfigureBinding(httpBinding, SpiraImportProxy.Endpoint.Address.Uri);

                //Authenticate asynchronously
                SpiraImportProxy.Connection_AuthenticateCompleted += new EventHandler <SpiraSoapService.Connection_AuthenticateCompletedEventArgs>(spiraImportExport_Connection_AuthenticateCompleted);
                SpiraImportProxy.Connection_AuthenticateAsync(Properties.Settings.Default.SpiraUserName, this.txtPassword.Text);
            }
            catch (UriFormatException)
            {
                MessageBox.Show("You need to enter a valid URL!", "Connection Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                this.progressBar1.Style = ProgressBarStyle.Blocks;
                this.btnLogin.Enabled   = true;
            }
            catch (TimeoutException exception)
            {
                // Handle the timeout exception.
                this.progressBar1.Style = ProgressBarStyle.Blocks;
                this.btnLogin.Enabled   = true;
                SpiraImportProxy.Abort();
                MessageBox.Show("A timeout error occurred! (" + exception.Message + ")", "Timeout Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (CommunicationException exception)
            {
                // Handle the communication exception.
                this.progressBar1.Style = ProgressBarStyle.Blocks;
                this.btnLogin.Enabled   = true;

                SpiraImportProxy.Abort();
                MessageBox.Show("A communication error occurred! (" + exception.Message + ")", "Connection Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }