public static void Register(Validator validator, TextBox control1, TextBox control2)
 {
     if (validator == null) throw new ArgumentNullException("validator");
     if (control1 == null) throw new ArgumentNullException("control1");
     if (control2 == null) throw new ArgumentNullException("control2");
     validator.AddControl(control1, new NewPasswordValidatorFunctor(validator, control1, control2).Validate);
     validator.AddControl(control2, new NewPasswordValidatorFunctor(validator, control1, control2).Validate);
 }
 public NewPasswordValidatorFunctor(Validator validator, Control control1, Control control2)
 {
     if (validator == null) throw new ArgumentNullException("validator");
     if (control1 == null) throw new ArgumentNullException("control1");
     if (control2 == null) throw new ArgumentNullException("control2");
     Validator = validator;
     _control1 = control1;
     _control2 = control2;
 }
        public ChangePasswordDialog(bool savePasswordChecked = false)
        {
            InitializeComponent();

            checkBoxSavePass.Checked = savePasswordChecked;
            SavePassword = savePasswordChecked;

            _validator = new Validator(theErrorProvider, theGoodProvider);
            NewPasswordValidatorFunctor.Register(_validator, textBoxNewPassword, textBoxNewPasswordConfirm);
        }
Esempio n. 4
0
        public HostDialog(EMode mode, List<HostInfo> committedHosts)
        {
            if (committedHosts == null) throw new ArgumentNullException("committedHosts");

            InitializeComponent();
            _committedHosts = committedHosts;
            Mode = mode;

            // validators
            _hostValidator = new Validator(theErrorProvider, theGoodProvider);
            _hostValidator.AddControl(textBoxName, validateAlias);
            _hostValidator.AddControl(textBoxHostname, _hostValidator.ValidateHostname);
            _hostValidator.AddControl(textBoxPort, _hostValidator.ValidatePort);
            _hostValidator.AddControl(textBoxLogin, _hostValidator.ValidateUsername);
            _hostValidator.AddControl(tbxPassword, validatePassword);
            _hostValidator.AddControl(lblPrivateKeyFilename, control => control.Text, validatePrivateKeyData);

            _tunnelValidator = new Validator(theErrorProvider, theGoodProvider);
            _tunnelValidator.AddControl(textBoxSourcePort, validateTunnelSourcePort);
            _tunnelValidator.AddControl(textBoxDestHost, validateTunnelDestinationHost);
            _tunnelValidator.AddControl(textBoxDestPort, validateTunnelDestinationPort);
            _tunnelValidator.AddControl(textBoxTunnelName, validateTunnelAlias);
            // style for selected mode
            if (mode == EMode.AddHost)
            {
                flowLayoutPanelAddHost.Visible = true;
                flowLayoutPanelEditHost.Visible = false;
                AcceptButton = buttonAddHost;
                CancelButton = buttonClose;
            }
            else
            {
                flowLayoutPanelAddHost.Visible = false;
                flowLayoutPanelEditHost.Visible = true;
                AcceptButton = buttonOk;
                CancelButton = buttonCancel;
            }
            // modified check
            textBoxName.TextChanged += delegate { Modified = true; };
            textBoxHostname.TextChanged += delegate { Modified = true; };
            textBoxPort.TextChanged += delegate { Modified = true; };
            textBoxLogin.TextChanged += delegate { Modified = true; };
            tbxPassword.TextChanged += delegate { Modified = true; };
            tbxPassphrase.TextChanged += delegate { Modified = true; };
            tbxRemoteCommand.TextChanged += delegate { Modified = true; };
            rbxPassword.CheckedChanged += delegate { Modified = true; };
            btnLoadPrivateKey.Click += delegate { Modified = true; };
            comboBoxDependsOn.SelectedIndexChanged += delegate { Modified = true; };
        }
Esempio n. 5
0
        public StartUpDialog()
        {
            InitializeComponent();

            applySource(StorageSource.NewStorage);

            _validatorCreate = new Validator(theErrorProvider, theGoodProvider);
            _validatorCreate.AddControl(textBoxNewFile, validateNewFile);
            _validatorCreate.AddControl(textBoxNewPassword, validateNewPassword);
            _validatorCreate.AddControl(textBoxNewPasswordConfirm, validateNewPassword);

            _validatorOpen = new Validator(theErrorProvider, theGoodProvider);
            _validatorOpen.AddControl(textBoxExistingFile, validateOpenFile);
            _validatorOpen.AddControl(textBoxOpenPassword, validateOpenPassword);

            Error = null;

            // Stored settings loading
            var lastFile = Settings.Default.EncryptedStorageFile;
            var lastFileEmpty = string.IsNullOrEmpty(lastFile);
            var lastPass = Settings.Default.EncryptedStoragePassword;
            var lastPassEmpty = string.IsNullOrEmpty(lastPass);
            if (!lastFileEmpty)
            {
                radioButtonOpenStorage.Checked = true;
                textBoxExistingFile.Text = lastFile;
            }
            if (!lastPassEmpty)
            {
                textBoxOpenPassword.Text = lastPass;
                checkBoxSavePassOpen.Checked = true;
            }
            if (!lastFileEmpty && !lastPassEmpty)
            {
                // Both file and pass was saved last time
                try
                {
                    Storage = new EncryptedStorage(lastFile, lastPass);
                    Filename = lastFile;
                    Password = lastPass;
                }
                catch (Exception e)
                {
                    Error = e.Message;
                }
            }
        }
Esempio n. 6
0
        public OptionsDialog(PuttyProfile puttyProfile)
        {
            InitializeComponent();

            PuttyProfile = puttyProfile;

            buttonApply.Enabled = false;

            checkGroupBoxAutoRestart.Checked = Settings.Default.Config_RestartEnabled;
            numericUpDownRestartDelay.Value = Settings.Default.Config_RestartDelay;
            numericUpDownMaxAttemptsCount.Value = Settings.Default.Config_MaxAttemptsCount;
            radioButtonMakeDelay.Checked = Settings.Default.Config_AfterMaxAttemptsMakeDelay;
            checkBoxTraceDebug.Checked = Settings.Default.Config_TraceDebug;
            checkGroupBoxRestartHostsWithWarns.Checked = Settings.Default.Config_RestartHostsWithWarnings;
            numericUpDownRestartHWWInterval.Value = Settings.Default.Config_RestartHostsWithWarningsInterval;
            chbxRunAtWindowsStartup.Checked = Settings.Default.Config_RunAtWindowsStartup;
            chbxStartHostsBeingActiveLastTime.Checked = Settings.Default.Config_StartHostsBeingActiveLastTime;
            if (PuttyProfile != null)
            {
                checkBoxLocalPortAcceptAll.Checked = PuttyProfile.LocalPortAcceptAll;
                checkBoxRemotePortAcceptAll.Checked = PuttyProfile.RemotePortAcceptAll;
                checkGroupBoxProxy.Checked = PuttyProfile.ProxyMethod != PuttyProfile.ProxyType.None;
                comboBoxProxyType.SelectedIndex = PuttyProfile.ProxyMethod == PuttyProfile.ProxyType.Http ? 0 
                    : PuttyProfile.ProxyMethod == PuttyProfile.ProxyType.Socks4 ? 1
                    : PuttyProfile.ProxyMethod == PuttyProfile.ProxyType.Socks5 ? 2
                    : 0;
                textBoxHostname.Text = PuttyProfile.ProxyHost;
                textBoxPort.Text = PuttyProfile.ProxyPort.ToString();
                textBoxUsername.Text = PuttyProfile.ProxyUsername;
                textBoxPassword.Text = PuttyProfile.ProxyPassword;
                checkBoxAuthReq.Checked = !string.IsNullOrEmpty(PuttyProfile.ProxyUsername);
                checkBoxProxyLocalhost.Checked = PuttyProfile.ProxyLocalhost;
                textBoxProxyExcludes.Text = PuttyProfile.ProxyExcludeList;
            } else
            {
                checkBoxLocalPortAcceptAll.Enabled = false;
                checkBoxRemotePortAcceptAll.Enabled = false;
                checkGroupBoxProxy.Enabled = false;
            }

            _validator = new Validator(theErrorProvider);
            _validator.AddControl(textBoxHostname, validateHostname);
            _validator.AddControl(textBoxPort, validatePort);
            _validator.AddControl(textBoxUsername, validateUsername);
            _validator.AddControl(textBoxPassword, validatePassword);

            var controls = new List<Control>();
            collectControls(Controls, ref controls);
            foreach (var textBox in controls.OfType<TextBox>())
            {
                textBox.TextChanged += controlChanged;
            }
            foreach (var textBox in controls.OfType<CheckBox>())
            {
                textBox.CheckedChanged += controlChanged;
            }
            foreach (var textBox in controls.OfType<RadioButton>())
            {
                textBox.CheckedChanged += controlChanged;
            }
            foreach (var textBox in controls.OfType<ComboBox>())
            {
                textBox.SelectedIndexChanged += controlChanged;
            }
            foreach (var textBox in controls.OfType<CheckGroupBox>())
            {
                textBox.CheckedChanged += controlChanged;
            }
            foreach (var textBox in controls.OfType<NumericUpDown>())
            {
                textBox.ValueChanged += controlChanged;
            }
        }