Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
01/18/12 14:58:17 (12 years ago)
Author:
spimming
Message:

#1680:

  • Check if password is valid for pfx file
  • progress bar is now marquee style
  • control flow refactored
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Hive.Azure/HeuristicLab.Clients.Hive.CloudManager/3.3/Views/AddCertificate.cs

    r7339 r7362  
    11using System;
    22using System.ComponentModel;
    3 using System.Threading;
     3using System.Security.Cryptography.X509Certificates;
    44using System.Windows.Forms;
    55
     
    88    private BackgroundWorker worker = new BackgroundWorker();
    99    public bool ErrorOccured { get; set; }
     10    public string CertificateFile { get; set; }
     11    public string CertificatePassword { get; set; }
    1012
    1113    public AddCertificate() {
    1214      InitializeComponent();
     15      ErrorOccured = true;
     16
    1317      worker.DoWork += new DoWorkEventHandler(AddCertificateTask);
    1418      worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(WorkerCompleted);
     
    2832
    2933    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) {
    3138        MessageBox.Show("Certificate file is required", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
    32       } else if (tbCertificatePassword.Text.Length == 0) {
     39      } else if (CertificatePassword.Length == 0) {
    3340        MessageBox.Show("Password is required", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
    3441      } else {
    3542        SetControlsEnabled(false);
    3643        progressBar.Visible = true;
    37         worker.RunWorkerAsync();
     44        var parameters = Tuple.Create<string, string>(CertificateFile, CertificatePassword);
     45        worker.RunWorkerAsync(parameters);
    3846      }
    39 
    4047    }
    4148
     
    4855
    4956    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);
    5862    }
    5963
    6064    private void WorkerCompleted(object sender, RunWorkerCompletedEventArgs e) {
    6165      progressBar.Visible = false;
    62       if (!ErrorOccured) {
     66
     67      if (e.Error == null) {
     68        ErrorOccured = false;
    6369        this.Close();
    6470      } else {
     71        MessageBox.Show(e.Error.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     72        CertificateFile = string.Empty;
     73        CertificateFile = string.Empty;
     74        ErrorOccured = true;
    6575        this.Show();
    6676        SetControlsEnabled(true);
Note: See TracChangeset for help on using the changeset viewer.