Exemplo n.º 1
0
        private bool CheckCreds()
        {
            bool result;

            txtUserID.Text = txtUserID.Text.Trim();

            if (txtUserID.Text == "")
            {
                // No user ID means no password, even if the user entered one.

                _newPW = null;
                result = true;
            }
            else if (string.IsNullOrWhiteSpace(txtPassword.Text))
            {
                MainForm.ShowMessageBox("A password is required when a non-blank User ID is specified.");
                result = false;
            }
            else
            {
                if (_pwChanged)
                {
                    _newPW = CredentialsDialog.Encrypt64(txtPassword.Text);
                }
                else
                {
                    // The textbox still holds the placeholder text and
                    // _newPW still holds the original password (so leave it there).
                }

                result = true;
            }

            return(result);
        }
Exemplo n.º 2
0
        // Sets the credentials used for multiple servers.
        private void setCredentialsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SavedServer firstSelectedServer = (listView1.SelectedItems[0] as ServerListItem).Server;
            var         credDlg             = new CredentialsDialog();

            credDlg.UserID = firstSelectedServer.UserId;
            credDlg.PW     = firstSelectedServer.PW;

            if (credDlg.ShowDialog() == DialogResult.OK)
            {
                foreach (ServerListItem item in listView1.SelectedItems)
                {
                    item.Server.UserId = credDlg.UserID;

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

                    item.SubItems[colUserID.Index].Text = item.Server.UserId;
                }

                btnOK.Enabled = true;
            }
        }
Exemplo n.º 3
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();
                }
            }
        }