public void batchPasswordChangerWorkerCompleted(object sender, EventArgs e) { Debug.WriteLine("batchPasswordChangerWorkerCompleted"); this.pwChangerWorker = null; this.Invoke((MethodInvoker) delegate { this.toogleControls(true); this.checkControls(); this.buttonStartChangePasswords.Text = "Start Change Passwords"; }); }
private void changePasswordClick(object sender, EventArgs e) { if (this.pwChangerWorker == null || !this.pwChangerWorker.IsRunning) { this.toogleControls(false); var entries = new Collection <IHostPwEntry>() { this.hostPwEntry }; this.pwChangerWorker = new BatchPasswordChangerWorker(this.pwChangerService, entries, maskedTextBoxNewPassword.Text); var thread = new Thread(new ThreadStart(() => runBatchPasswordChangerWorker(this.pwChangerService))); thread.Name = "FormPasswordChangeThread"; thread.IsBackground = true; thread.Start(); } }
public void ChangePasswordOnMultipleHostsAndSaveDatabaseAfterEachUpdate() { var passwordChangerService = new MockPasswordChangerService(); var pwHostEntries = new Collection <IHostPwEntry>() { new InMemoryHostPwEntry() { IPAddress = "localhost1", Username = "******", Password = "******" }, new InMemoryHostPwEntry() { IPAddress = "localhost2", Username = "******", Password = "******" }, }; var batchPasswordChangerWorker = new BatchPasswordChangerWorker(passwordChangerService, pwHostEntries, "newPassword"); batchPasswordChangerWorker.SaveDatabaseAfterEachUpdate = true; int changedEventCount = 0; int errorEventCount = 0; int completedEventCount = 0; batchPasswordChangerWorker.Changed += (o, e) => { changedEventCount++; }; batchPasswordChangerWorker.Error += (o, e) => { errorEventCount++; }; batchPasswordChangerWorker.Completed += (o, e) => { completedEventCount++; }; batchPasswordChangerWorker.Run(); Assert.AreEqual(pwHostEntries.Count, changedEventCount); Assert.AreEqual(0, errorEventCount); Assert.AreEqual(1, completedEventCount); Assert.AreEqual(pwHostEntries.Count, passwordChangerService.ChangePasswordCount); Assert.AreEqual(pwHostEntries.Count, passwordChangerService.SaveDatabaseCount); }
private void startChangePasswordsClick(object sender, EventArgs e) { if (this.buttonStartChangePasswords.Text.Equals("Stop")) { if (this.pwChangerWorker != null && this.pwChangerWorker.IsRunning) { this.buttonStartChangePasswords.Text = "Stopping..."; this.buttonStartChangePasswords.Enabled = false; this.pwChangerWorker.Cancel(); } } else { Debug.WriteLine("buttonStartChangePasswordsClick"); if (this.pwChangerWorker == null || !this.pwChangerWorker.IsRunning) { this.toogleControls(false); var selectedEntries = getSelectedEntries(); // Reset progress bar in case batchPasswordChangerWorker was run before. this.progressBar.Value = 0; this.progressBar.Maximum = selectedEntries.Count; Debug.WriteLine(String.Format("selectedEntries.Count: {0}", selectedEntries.Count)); var hostTypeMapper = this.checkBoxOverrideHostType.Checked && this.comboBoxHostType.SelectedIndex > -1 ? (IHostTypeMapper) new FixedHostTypeMapper((HostType)this.comboBoxHostType.SelectedItem) : new HostTypeMapper(new HostTypeSafeConverter()); var passwordChangerService = this.pwChangerServiceFactory.Create(hostTypeMapper); this.pwChangerWorker = new BatchPasswordChangerWorker(passwordChangerService, selectedEntries, maskedTextBoxNewPassword.Text); var thread = new Thread(new ThreadStart(() => runBatchPasswordChangerWorker(passwordChangerService))); thread.Name = "FormBatchPasswordChangerThread"; thread.IsBackground = true; thread.Start(); this.buttonStartChangePasswords.Text = "Stop"; this.buttonStartChangePasswords.Enabled = true; } } }