Ejemplo n.º 1
0
        /// <summary>Hit when we got the list of projects.</summary>
        /// <param name="sender">SoapServiceClient</param>
        /// <param name="e">Project_RetrieveCompletedEventArgs</param>
        private void client1_Project_RetrieveCompleted(object sender, Project_RetrieveCompletedEventArgs e)
        {
            const string METHOD = CLASS_NAME + "client1_Project_RetrieveCompleted()";

            if (e.Error == null)
            {
                Logger.LogTrace(METHOD, "Screen #1: Got project list.");

                //Set the data source..
                if (e.Result != null)
                {
                    this._page2.setAvailableProjects(e.Result);
                }

                //Advance the page.
                this.grdContent.Children.Clear();
                this.grdContent.Children.Add(this._page2);
                this._pageNo = 2;

                this.grdForm.IsEnabled = true;
                this.Cursor            = Cursors.Arrow;
                this.btnBack.IsEnabled = true;

                //Log it..
                Logger.LogTrace(METHOD, "Screen #1: Moved to screen #2.");
            }
            else
            {
                string msg = ((e.Error.InnerException != null) ? e.Error.InnerException.Message : e.Error.Message);
                MessageBox.Show("There was an error retrieving projects from the system:" + Environment.NewLine + msg, "Server Error", MessageBoxButton.OK, MessageBoxImage.Error);
                Logger.LogError(METHOD, e.Error);
            }
        }
        /// <summary>Hit after we logged in. We have to select a project before creating a user. D'oh.</summary>
        /// <param name="sender">SoapServiceClient</param>
        /// <param name="e">Project_RetrieveCompletedEventArgs</param>
        void client_Project_RetrieveCompleted(object sender, Project_RetrieveCompletedEventArgs e)
        {
            this.txtTesting.Text += ".";

            if (e.Error == null)
            {
                //We got out projects.  Get the first one and connect to it.
                RemoteProject tmpProj = e.Result.Where(prj => prj.Active).FirstOrDefault();
                if (tmpProj != null)
                {
                    ((SoapServiceClient)e.UserState).Connection_ConnectToProjectAsync(tmpProj.ProjectId.Value, e.UserState);
                }
                else
                {
                    Exception ex = new Exception("No active projects to select to!");
                    Logger.LogError("", ex, "Testing new user password. Trying to retrieve projects.");
                    MessageBox.Show("Could not connect to an existing project. To test the password, there must be an existing active project to connect you. You can continue without testing the password, but if the import fails you will need to re-run it.", "Error Testing", MessageBoxButton.OK, MessageBoxImage.Warning);
                    this.divTesting.Visibility = System.Windows.Visibility.Collapsed;
                }
            }
        }
        /// <summary>Hit when communication is finished with the server.</summary>
        /// <param name="sender">SoapServiceClient</param>
        /// <param name="e">EventArgs</param>
        private void _client_CommunicationFinished(object sender, AsyncCompletedEventArgs e)
        {
            try
            {
                if (e.Error == null)
                {
                    try
                    {
                        if (e.GetType() == typeof(Connection_Authenticate2CompletedEventArgs))
                        {
                            Connection_Authenticate2CompletedEventArgs evt = e as Connection_Authenticate2CompletedEventArgs;
                            if (evt.Result)
                            {
                                this.txtStatus.Text = "Getting user information...";
                                this._client.User_RetrieveByUserNameAsync(this.txbUserID.Text, false);
                            }
                            else
                            {
                                //Failed login.
                                this.btnConnect_Click(null, null);
                                //Just act like they canceled the service, then set error flag.
                                this.barProg.Foreground = (Brush) new System.Windows.Media.BrushConverter().ConvertFrom(StaticFuncs.getCultureResource.GetString("app_Colors_StyledBarError"));
                                this.barProg.Value      = 1;
                                this.txtStatus.Text     = "Invalid username or password.";
                            }
                        }
                        else if (e.GetType() == typeof(User_RetrieveByUserNameCompletedEventArgs))
                        {
                            User_RetrieveByUserNameCompletedEventArgs evt = e as User_RetrieveByUserNameCompletedEventArgs;
                            if (evt != null)
                            {
                                this.txtStatus.Text  = "Getting Projects...";
                                this.txbUserNum.Text = evt.Result.UserId.ToString();
                                this._client.Project_RetrieveAsync();
                            }
                            else
                            {
                                throw new Exception("Results are null.");
                            }
                        }
                        else if (e.GetType() == typeof(Project_RetrieveCompletedEventArgs))
                        {
                            this.cmbProjectList.Items.Clear();

                            Project_RetrieveCompletedEventArgs evt = e as Project_RetrieveCompletedEventArgs;

                            //Load projects here.
                            if (evt != null && evt.Result.Count > 0)
                            {
                                SpiraProject matchingProject = null;
                                foreach (RemoteProject RemoteProj in evt.Result)
                                {
                                    Business.SpiraProject Project = new Business.SpiraProject();
                                    Project.ProjectId = RemoteProj.ProjectId.Value;
                                    Project.ServerURL = new Uri(this.txbServer.Text);
                                    Project.UserName  = this.txbUserID.Text;
                                    Project.UserPass  = this.txbUserPass.Password;
                                    Project.UserID    = int.Parse(this.txbUserNum.Text);

                                    this.cmbProjectList.Items.Add(Project);

                                    if (SpiraContext.ProjectId == Project.ProjectId)
                                    {
                                        matchingProject = Project;
                                    }
                                }

                                //Select one if necessary
                                if (matchingProject != null)
                                {
                                    this.cmbProjectList.SelectedItem = matchingProject;
                                }
                                else
                                {
                                    this.cmbProjectList.SelectedIndex = 0;
                                }
                                this.grdAvailProjs.IsEnabled = true;
                            }
                            else
                            {
                                int num = this.cmbProjectList.Items.Add("-- No Projects Available --");
                                this.cmbProjectList.SelectedIndex = num;
                            }

                            //Reset form.
                            this.btnConnect_Click(null, null);
                        }
                    }
                    catch (Exception ex)
                    {
                        Logger.LogMessage(ex);
                        //Reset form.
                        this.btnConnect_Click(null, null);
                        //Just act like they canceled the service, then set error flag.
                        this.barProg.Foreground = (Brush) new System.Windows.Media.BrushConverter().ConvertFrom(StaticFuncs.getCultureResource.GetString("app_Colors_StyledBarError"));
                        this.barProg.Value      = 1;
                        this.txtStatus.Text     = "Error connecting.";
                        this.txtStatus.ToolTip  = ex.Message;
                    }
                }
                else
                {
                    Logger.LogMessage(e.Error);
                    //Reset form.
                    this.btnConnect_Click(null, null);
                    //Just act like they canceled the service, then set error flag.
                    this.barProg.Foreground = (Brush) new System.Windows.Media.BrushConverter().ConvertFrom(StaticFuncs.getCultureResource.GetString("app_Colors_StyledBarError"));
                    this.barProg.Value      = 1;
                    this.txtStatus.Text     = "Could not connect!";
                    this.txtStatus.ToolTip  = e.Error.Message;
                }
            }
            catch (Exception ex)
            {
                Logger.LogMessage(ex, "_client_CommunicationFinished()");
                MessageBox.Show(StaticFuncs.getCultureResource.GetString("app_General_UnexpectedError"), StaticFuncs.getCultureResource.GetString("app_General_ApplicationShortName"), MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
        /// <summary>Called when the client finished a piece of work.</summary>
        /// <param name="sender">The client.</param>
        /// <param name="e">EventArgs</param>
        void client_ActionCompleted(object sender, EventArgs e)
        {
            try
            {
                if (e.GetType() == typeof(Connection_Authenticate2CompletedEventArgs))
                {
                    Connection_Authenticate2CompletedEventArgs evt = (Connection_Authenticate2CompletedEventArgs)e;
                    if (evt.Error == null)
                    {
                        this.txtStatus.Text = "Getting user information...";
                        this._client.User_RetrieveByUserNameAsync(this.txbUserID.Text);
                    }
                    else
                    {
                        this.btnConnect_Click(null, null);
                        //Just act like they canceled the service, then set error flag.
                        this.barProg.Foreground = System.Windows.Media.Brushes.Red;
                        this.barProg.Value      = 1;
                        this.txtStatus.Text     = "Could not connect!";
                        this.txtStatus.ToolTip  = evt.Error.Message;
                    }
                }
                else if (e.GetType() == typeof(User_RetrieveByUserNameCompletedEventArgs))
                {
                    User_RetrieveByUserNameCompletedEventArgs evt = (User_RetrieveByUserNameCompletedEventArgs)e;
                    if (evt.Error == null)
                    {
                        this.txtStatus.Text  = "Getting Projects...";
                        this.txbUserNum.Text = evt.Result.UserId.ToString();
                        this._client.Project_RetrieveAsync();
                    }
                    else
                    {
                        this.btnConnect_Click(null, null);
                        //Just act like they canceled the service, then set error flag.
                        this.barProg.Foreground = System.Windows.Media.Brushes.Red;
                        this.barProg.Value      = 1;
                        this.txtStatus.Text     = "Could not get user info.";
                        this.txtStatus.ToolTip  = evt.Error.Message;
                    }
                }
                else if (e.GetType() == typeof(Spira_ImportExport.Project_RetrieveCompletedEventArgs))
                {
                    Project_RetrieveCompletedEventArgs evt = (Project_RetrieveCompletedEventArgs)e;
                    if (evt.Error == null)
                    {
                        this.cmbProjectList.Items.Clear();
                        //Load projects here.
                        if (evt.Result.Length > 0)
                        {
                            foreach (RemoteProject RemoteProj in evt.Result)
                            {
                                Connect.SpiraProject Project = new Connect.SpiraProject();
                                Project.ProjectID = RemoteProj.ProjectId.Value;
                                Project.ServerURL = new Uri(this.txbServer.Text);
                                Project.UserName  = this.txbUserID.Text;
                                Project.UserPass  = this.txbUserPass.Password;
                                Project.UserID    = int.Parse(this.txbUserNum.Text);

                                this.cmbProjectList.Items.Add(Project);
                            }
                            this.cmbProjectList.SelectedIndex = 0;
                            this.grdAvailProjs.IsEnabled      = true;
                            this.grdEntry.IsEnabled           = true;
                            this.barProg.IsIndeterminate      = false;
                            this.barProg.Value      = 0;
                            this.btnConnect.Content = "_Get Projects";
                            this.btnConnect.Tag     = false;
                            this.txtStatus.Text     = "";
                            this.txtStatus.ToolTip  = null;
                        }
                        else
                        {
                            int num = this.cmbProjectList.Items.Add("-- No Projects Available --");
                            this.cmbProjectList.SelectedIndex = num;
                            //Reset form.
                            this.grdEntry.IsEnabled      = true;
                            this.barProg.IsIndeterminate = false;
                            this.btnConnect.Content      = "_Get Projects";
                            this.btnConnect.Tag          = false;
                        }
                    }
                    else
                    {
                        this.btnConnect_Click(null, null);
                        //Just act like they canceled the service, then set error flag.
                        this.barProg.Foreground = System.Windows.Media.Brushes.Red;
                        this.barProg.Value      = 1;
                        this.txtStatus.Text     = "Could not get projects.";
                        this.txtStatus.ToolTip  = evt.Error.Message;
                    }
                }
            }
            catch (Exception ex)
            {
                Connect.logEventMessage("wpfNewSpiraProject::client_ActionCompleted", ex, System.Diagnostics.EventLogEntryType.Error);
            }
        }
        private void _client_CommunicationFinished(object sender, AsyncCompletedEventArgs e)
        {
            try
            {
                if (e.Error == null)
                {
                    try
                    {
                        if (e.GetType() == typeof(Connection_Authenticate2CompletedEventArgs))
                        {
                            Connection_Authenticate2CompletedEventArgs evt = e as Connection_Authenticate2CompletedEventArgs;
                            if (evt.Result)
                            {
                                this._client.User_RetrieveByUserNameAsync(this.id, false);
                            }
                        }
                        else if (e.GetType() == typeof(User_RetrieveByUserNameCompletedEventArgs))
                        {
                            User_RetrieveByUserNameCompletedEventArgs evt = e as User_RetrieveByUserNameCompletedEventArgs;
                            if (evt != null)
                            {
                                this._client.Project_RetrieveAsync();
                            }
                            else
                            {
                                throw new Exception("Results are null.");
                            }
                        }
                        else if (e.GetType() == typeof(Project_RetrieveCompletedEventArgs))
                        {
                            _Projects.Clear();

                            Project_RetrieveCompletedEventArgs evt = e as Project_RetrieveCompletedEventArgs;

                            //Load projects here.
                            if (evt != null && evt.Result.Count > 0)
                            {
                                SpiraProject matchingProject = null;
                                foreach (RemoteProject RemoteProj in evt.Result)
                                {
                                    Business.SpiraProject Project = new Business.SpiraProject();
                                    Project.ProjectId = RemoteProj.ProjectId.Value;
                                    Project.ServerURL = new Uri(this.address);
                                    Project.UserName  = this.id;
                                    Project.UserPass  = this.password;
                                    Project.UserID    = int.Parse(this.id);

                                    TreeViewArtifact nProject = new TreeViewArtifact(spiraExplorer.refresh);
                                    nProject.ArtifactTag      = Project;
                                    nProject.ArtifactId       = ((Business.SpiraProject)nProject.ArtifactTag).ProjectId;
                                    nProject.ArtifactName     = ((Business.SpiraProject)nProject.ArtifactTag).ProjectName;
                                    nProject.ArtifactType     = TreeViewArtifact.ArtifactTypeEnum.Project;
                                    nProject.ArtifactIsFolder = true;
                                    nProject.Parent           = null;

                                    _Projects.Add(nProject);

                                    if (SpiraContext.ProjectId == Project.ProjectId)
                                    {
                                        matchingProject = Project;
                                    }
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Logger.LogMessage(ex);
                    }
                }
                else
                {
                    Logger.LogMessage(e.Error);
                }
            }
            catch (Exception ex)
            {
                Logger.LogMessage(ex, "_client_CommunicationFinished()");
                MessageBox.Show(StaticFuncs.getCultureResource.GetString("app_General_UnexpectedError"), StaticFuncs.getCultureResource.GetString("app_General_ApplicationShortName"), MessageBoxButton.OK, MessageBoxImage.Error);
            }
            //Access the SLN/SUO file to get the associated Spira URL, credentials and project
            if (SpiraContext.HasSolutionProps)
            {
                spiraExplorer.loadProject(SpiraContext.ProjectId);
            }
        }