Esempio n. 1
0
        public void RefreshFilesAndFolders()
        {
            Cursor originalCursor = this.Cursor;

            this.Cursor = Cursors.WaitCursor;

            try
            {
                if (_curServer == _localHost)
                {
                    StopLocalFileWatch();
                    ClearAllPaths();
                    StartLocalFileWatch(forceSetPaths: true);
                }
                else
                {
                    _curServer.Refresh();
                    ClearAllPaths();
                    RefreshGrids(_curServer);
                }
            }
            catch (Exception ex)
            {
                Log.Warn("Exception getting files from server ", _curServer, ": ", ex);
                string msg = "Error getting file list from server '" + _curServer + "'.";

                while (ex != null)
                {
                    msg += "\n\n" + ex.Message;
                    ex   = ex.InnerException;
                }

                MainForm.ShowMessageBox(msg);
            }
            finally
            {
                this.Cursor = originalCursor;
            }
        }
Esempio n. 2
0
        private void SetCurServer(RemoteServer newServer)
        {
            using (Log.InfoCall())
            {
                Log.Info("newServer = ", newServer, "_curServer = ", _curServer);

                if (newServer != _curServer)
                {
                    Log.Info("Setting _curServer to ", newServer);

                    if (newServer == _localHost)
                    {
                        ClearAllPaths();
                        SetPathsAreLocal(true);
                        StartLocalFileWatch(forceSetPaths: true);
                    }
                    else
                    {
                        Cursor originalCursor = this.Cursor;
                        this.Cursor = Cursors.WaitCursor;

                        StopLocalFileWatch();
                        ClearAllPaths();
                        SetPathsAreLocal(false);

                        DialogResult dr = DialogResult.Yes;

                        // Retry connecting to the server while dr == Yes.

                        while (dr == DialogResult.Yes)
                        {
                            Application.DoEvents();

                            try
                            {
                                // newServer.Refresh() is likely to throw an exception because it performs
                                // WCF calls to the TracerX-Service on the remote host.

                                Log.Info("Connecting to server ", newServer);
                                newServer.Refresh();
                                RefreshGrids(newServer);
                                break;
                            }
                            catch (Exception ex)
                            {
                                // Display an error message including the exception and inner
                                // exception messages.  If the exception is about bad credentials
                                // and failed logon, ask the user if he wants to specify new
                                // credentials for the server.

                                Log.Warn("Exception getting files from server ", newServer, ": ", ex);
                                string            msg     = "Error getting file list from server '" + newServer + "'.";
                                MessageBoxButtons buttons = MessageBoxButtons.OK;

                                if (ex is SecurityNegotiationException && ex.InnerException is InvalidCredentialException)
                                {
                                    msg    += "\nWould you like to specify credentials for the connection?";
                                    buttons = MessageBoxButtons.YesNo;
                                }

                                while (ex != null)
                                {
                                    msg += "\n\n" + ex.Message;
                                    ex   = ex.InnerException;
                                }

                                dr = MainForm.ShowMessageBoxBtns(msg, buttons);

                                if (dr == DialogResult.Yes)
                                {
                                    var credDlg = new CredentialsDialog();

                                    credDlg.UserID = newServer.UserId;
                                    credDlg.PW     = newServer.PW;

                                    if (credDlg.ShowDialog() == DialogResult.OK)
                                    {
                                        newServer.UserId = credDlg.UserID;

                                        if (credDlg.UserID == "")
                                        {
                                            newServer.PW = null;
                                        }
                                        else
                                        {
                                            newServer.PW = credDlg.PW;
                                        }

                                        serverTree1.SaveRemoteServers();
                                    }
                                    else
                                    {
                                        break;
                                    }
                                }
                            }
                        }

                        this.Cursor = originalCursor;
                    }

                    filesGrid.RemoteServer   = newServer;
                    foldersGrid.RemoteServer = newServer;
                    _curServer = newServer;
                    OnServerChanged();
                }
            }
        }