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; } } }
public HostsManager(Config config, EncryptedStorage storage, string filename, string password) { if (config == null) { throw new ArgumentNullException("config"); } if (storage == null) { throw new ArgumentNullException("storage"); } if (filename == null) { throw new ArgumentNullException("filename"); } if (password == null) { throw new ArgumentNullException("password"); } Filename = filename; Password = password; Config = config; Storage = storage; try { PuttyProfile = PuttyProfile.ReadOrCreate(PuttyProfileName); } catch (SSHTunnelManagerException e) { Logger.Log.Error(Helper.JoinExceptionMessages(e.Message, Resources.HostsManager_Error_LoadPuttyProfileError)); } var hosts = storage.Data.Hosts.Select(delegate(HostInfo h) { var viewModel = new THostViewModel(); viewModel.Model = new Host(h, Config, PuttyProfile) { ViewModel = viewModel }; return(viewModel); }).ToList(); Hosts = new BindingListView <THostViewModel>(hosts); Hosts.AddingNew += (o, e) => { e.NewObject = _addingNewHost; }; }
private void buttonOpen_Click(object sender, EventArgs e) { if (!_validatorOpen.ValidateControls()) return; var filename = textBoxExistingFile.Text; var password = textBoxOpenPassword.Text; var savePass = checkBoxSavePassOpen.Checked; try { Storage = new EncryptedStorage(filename, password); Filename = filename; Password = password; Settings.Default.EncryptedStorageFile = filename; Settings.Default.EncryptedStoragePassword = savePass ? password : null; Settings.Default.Save(); DialogResult = DialogResult.OK; Close(); } catch (Exception ex) { Error = ex.Message.TrimEnd('.'); } }
private void buttonCreate_Click(object sender, EventArgs e) { if (!_validatorCreate.ValidateControls()) return; var filename = textBoxNewFile.Text; var password = textBoxNewPassword.Text; var savePass = checkBoxSavePassNew.Checked; try { var storage = new EncryptedStorage(); /*storage.Data.Config.RestartEnabled = Settings.Default.Config_RestartEnabled; storage.Data.Config.RestartDelay = Settings.Default.Config_RestartDelay; storage.Data.Config.MaxAttemptsCount = Settings.Default.Config_MaxAttemptsCount;*/ storage.Save(filename, password); Storage = storage; Filename = filename; Password = password; Settings.Default.EncryptedStorageFile = filename; Settings.Default.EncryptedStoragePassword = savePass ? password : null; Settings.Default.Save(); DialogResult = DialogResult.OK; Close(); } catch (Exception ex) { Error = ex.Message; } }