Changeset 7362 for branches/HeuristicLab.Hive.Azure/HeuristicLab.Clients.Hive.CloudManager/3.3/Views/AddCertificate.cs
- Timestamp:
- 01/18/12 14:58:17 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Hive.Azure/HeuristicLab.Clients.Hive.CloudManager/3.3/Views/AddCertificate.cs
r7339 r7362 1 1 using System; 2 2 using System.ComponentModel; 3 using System. Threading;3 using System.Security.Cryptography.X509Certificates; 4 4 using System.Windows.Forms; 5 5 … … 8 8 private BackgroundWorker worker = new BackgroundWorker(); 9 9 public bool ErrorOccured { get; set; } 10 public string CertificateFile { get; set; } 11 public string CertificatePassword { get; set; } 10 12 11 13 public AddCertificate() { 12 14 InitializeComponent(); 15 ErrorOccured = true; 16 13 17 worker.DoWork += new DoWorkEventHandler(AddCertificateTask); 14 18 worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(WorkerCompleted); … … 28 32 29 33 private void btnOk_Click(object sender, EventArgs e) { 30 if (tbCertificateFile.Text.Length == 0) { 34 CertificateFile = tbCertificateFile.Text; 35 CertificatePassword = tbCertificatePassword.Text; 36 37 if (CertificateFile.Length == 0) { 31 38 MessageBox.Show("Certificate file is required", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); 32 } else if ( tbCertificatePassword.Text.Length == 0) {39 } else if (CertificatePassword.Length == 0) { 33 40 MessageBox.Show("Password is required", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); 34 41 } else { 35 42 SetControlsEnabled(false); 36 43 progressBar.Visible = true; 37 worker.RunWorkerAsync(); 44 var parameters = Tuple.Create<string, string>(CertificateFile, CertificatePassword); 45 worker.RunWorkerAsync(parameters); 38 46 } 39 40 47 } 41 48 … … 48 55 49 56 private void AddCertificateTask(object sender, DoWorkEventArgs e) { 50 try { 51 // simulate service call 52 Thread.Sleep(3000); 53 } 54 catch (Exception ex) { 55 ErrorOccured = true; 56 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); 57 } 57 Tuple<string, string> parameters = e.Argument as Tuple<string, string>; 58 string file = parameters.Item1; 59 string pw = parameters.Item2; 60 61 X509Certificate cert = new X509Certificate(file, pw); 58 62 } 59 63 60 64 private void WorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { 61 65 progressBar.Visible = false; 62 if (!ErrorOccured) { 66 67 if (e.Error == null) { 68 ErrorOccured = false; 63 69 this.Close(); 64 70 } else { 71 MessageBox.Show(e.Error.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); 72 CertificateFile = string.Empty; 73 CertificateFile = string.Empty; 74 ErrorOccured = true; 65 75 this.Show(); 66 76 SetControlsEnabled(true);
Note: See TracChangeset
for help on using the changeset viewer.