/// <summary>Hit when the users wants to get projects from the server or cancel an existing connection.</summary>
        /// <param name="sender">btnConnect</param>
        /// <param name="e">EventArgs</param>
        private void btnConnect_Click(object sender, RoutedEventArgs e)
        {
            e.Handled = true;
            //They asked for it!
            if ((bool)btnConnect.Tag)
            {
                //Cancel the operation
                this._Client.Abort();
            }
            else
            {
                //Error check, first.
                if (this.CheckEntryFields())
                {
                    //Set display.
                    this.setDisplayforProgress(true);

                    //Save in settings
                    Properties.Settings.Default.SpiraUrl      = this.txbServer.Text.Trim();
                    Properties.Settings.Default.SpiraLogin    = this.txbUserID.Text.Trim();
                    Properties.Settings.Default.SpiraPassword = (chkRememberPassword.IsChecked.Value) ? this.txbUserPass.Password : "";

                    //Fire off a new client.
                    this._numRunning              = 0;
                    this.msgStatus.Text           = "Connecting to server...";
                    this._Client                  = new SpiraSoapService.SoapServiceClient();
                    this._Client.Endpoint.Address = new EndpointAddress(this.txbServer.Text + URI_APPEND);
                    BasicHttpBinding httpBinding = (BasicHttpBinding)this._Client.Endpoint.Binding;
                    WcfUtils.ConfigureBinding(httpBinding, this._Client.Endpoint.Address.Uri);
                    this._Client.Connection_Authenticate2Completed += new EventHandler <SpiraSoapService.Connection_Authenticate2CompletedEventArgs>(Client_Connection_Authenticate2Completed);
                    this._Client.Connection_Authenticate2Async(this.txbUserID.Text, this.txbUserPass.Password, Properties.Resources.Global_ApplicationName, this._numRunning++);
                }
            }
        }
        private bool ConnectToSpira(StreamWriter streamWriter, out FinalStatusEnum Status)
        {
            Status = FinalStatusEnum.OK;
            this.ProgressUpdate(this, new ProgressArgs()
            {
                ErrorText = "", Progress = -1, Status = ItemProgress.ProcessStatusEnum.Processing, TaskNum = 1
            });
            streamWriter.WriteLine("Connecting to Spira.");

            this._spiraClient = new SpiraSoapService.SoapServiceClient();
            this._spiraClient.Endpoint.Address = new EndpointAddress(this._SpiraProject.ServerURL + SpiraProject.URL_APIADD);
            BasicHttpBinding httpBinding = (BasicHttpBinding)this._spiraClient.Endpoint.Binding;

            WcfUtils.ConfigureBinding(httpBinding, this._spiraClient.Endpoint.Address.Uri);

            //Try connecting.
            try
            {
                bool CanConnect = this._spiraClient.Connection_Authenticate2(this._SpiraProject.UserName, this._SpiraProject.UserPass, Properties.Resources.Global_ApplicationName);
                if (CanConnect && !ProcessThread.WantCancel)
                {
                    //Try connecting to the project, now.
                    if (this._spiraClient.Connection_ConnectToProject(this._SpiraProject.ProjectNum) && !ProcessThread.WantCancel)
                    {
                        //Do they have a root requirement set? Verify it exists.
                        if (this._SpiraProject.RootReq > 0 && !ProcessThread.WantCancel)
                        {
                            this._RootReq = this._spiraClient.Requirement_RetrieveById(this._SpiraProject.RootReq);
                            if (this._RootReq == null)
                            {
                                string ErrorMsg = "Could not access root requirement RQ" + this._SpiraProject.RootReq.ToString();
                                this.ProgressUpdate(this, new ProgressArgs()
                                {
                                    ErrorText = ErrorMsg, Progress = -1, Status = ItemProgress.ProcessStatusEnum.Error, TaskNum = 1
                                });
                                return(false);
                            }
                        }
                        else
                        {
                            if (ProcessThread.WantCancel)
                            {
                                this.ProgressUpdate(this, new ProgressArgs()
                                {
                                    ErrorText = App.CANCELSTRING, Progress = -1, Status = ItemProgress.ProcessStatusEnum.Error, TaskNum = 1
                                });
                                return(false);
                            }
                        }
                    }
                    else
                    {
                        string ErrorMsg = "";
                        if (ProcessThread.WantCancel)
                        {
                            ErrorMsg = App.CANCELSTRING;
                        }

                        else
                        {
                            ErrorMsg = "Could not access specified SpiraTeam project.";
                        }
                        this.ProgressUpdate(this, new ProgressArgs()
                        {
                            ErrorText = ErrorMsg, Progress = -1, Status = ItemProgress.ProcessStatusEnum.Error, TaskNum = 1
                        });
                        return(false);
                    }
                }
                else
                {
                    string ErrorMsg = "";
                    if (ProcessThread.WantCancel)
                    {
                        ErrorMsg = App.CANCELSTRING;
                    }
                    else
                    {
                        ErrorMsg = "Unable to log into the system.";
                    }
                    this.ProgressUpdate(this, new ProgressArgs()
                    {
                        ErrorText = ErrorMsg, Progress = -1, Status = ItemProgress.ProcessStatusEnum.Error, TaskNum = 1
                    });
                    return(false);
                }

                this.ProgressUpdate(this, new ProgressArgs()
                {
                    ErrorText = "", Progress = -1, Status = ItemProgress.ProcessStatusEnum.Success, TaskNum = 1
                });
                return(true);
            }
            catch (Exception ex)
            {
                //Log error.
                streamWriter.WriteLine("Unable to log into SpiraTeam Server: " + ex.Message);

                string ErrorMsg = "Unable to log into the system:" + Environment.NewLine + ex.Message;
                this.ProgressUpdate(this, new ProgressArgs()
                {
                    ErrorText = ErrorMsg, Progress = -1, Status = ItemProgress.ProcessStatusEnum.Error, TaskNum = 1
                });
                return(false);
            }
        }