/// <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);
            }
        }
Example #2
0
        public bool Handle(AsyncCompletedEventArgs result, bool isJustCheck)
        {
            if (result != null)
            {
                if (result.Error != null && result.Error.ToString().Contains("System.TimeoutException"))
                {
                    if (m_page != null && !isJustCheck)
                    {
                        m_page.Context.Window.MessageBox.Show(MessageResource.PageException_Timeout_Message, MessageBoxType.Error);
                    }
                    return(true);
                }

                if (result.Error != null && result.Error.ToString().Contains("Newegg.Oversea.Framework.ExceptionBase.BusinessException"))
                {
                    if (m_page != null && !isJustCheck)
                    {
                        m_page.Context.Window.MessageBox.Show(result.Error.Message, MessageBoxType.Warning);
                    }
                    return(true);
                }

                if (result.Error != null || m_page == null)
                {
                    if (m_page != null && !isJustCheck)
                    {
                        m_page.Context.Window.MessageBox.Show(result.Error.Message, MessageBoxType.Error);
                    }
                    return(true);
                }

                PropertyInfo property = result.GetType().GetProperty("Result");
                object       target   = property.GetValue(result, null);
                IEnumerable  list;
                string       message = null;

                if (target != null)
                {
                    property = target.GetType().GetProperty("Faults");
                    target   = property.GetValue(target, null);
                    if (target != null && (list = target as IEnumerable) != null)
                    {
                        StringBuilder bulider = new StringBuilder();
                        foreach (object item in list)
                        {
                            bulider.Append(item.ToString());

                            bulider.Append("\r\n");
                        }

                        if (bulider.Length > 0)
                        {
                            message = bulider.ToString();
                            message = message.Substring(0, message.Length - 2);
                        }
                    }

                    if (!string.IsNullOrEmpty(message) || m_page == null)
                    {
                        if (m_page != null && !isJustCheck)
                        {
                            m_page.Context.Window.MessageBox.Show(message, MessageBoxType.Error);
                        }

                        return(true);
                    }
                }
            }

            return(false);
        }
        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);
            }
        }