/// <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); } }
/// <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); } }
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); } }