Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Hive.Azure/HeuristicLab.Clients.Hive.CloudManager/3.3/Views/AddSubscriptionDialog.cs @ 15802

Last change on this file since 15802 was 7661, checked in by spimming, 13 years ago

#1680: Show error dialog (from PluginInfrastructure) instead of message box on exception

File size: 2.2 KB
RevLine 
[7362]1using System.ComponentModel;
[7281]2using System.Windows.Forms;
3using HeuristicLab.Clients.Hive.CloudManager.Model;
4
5namespace HeuristicLab.Clients.Hive.CloudManager.Views {
6  public partial class AddSubscriptionDialog : Form {
7    public bool ErrorOccured { get; set; }
8    public Subscription Subscription { get; set; }
9
10    private BackgroundWorker worker = new BackgroundWorker();
11
12    public AddSubscriptionDialog() {
13      InitializeComponent();
14
15      txtCertThumbprint.Text = "EFFD1808EF2F0658C52997CF00F7A86680F9FA62";
16      txtSubscriptionId.Text = "271e67e2-3132-4429-b0e7-ab94d3a95554";
17      cbSaveSubscription.Checked = false;
18      cbDiscoverServices.Checked = true;
19
[7362]20      worker.DoWork += new DoWorkEventHandler(LoadSubscription);
21      worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(WorkerCompleted);
22
[7281]23      ErrorOccured = true;
24    }
25
[7387]26    private void SetAllControlsEnabled(Form frm, bool isEnabled) {
27      foreach (Control ctrl in frm.Controls) {
28        if (!(ctrl is ProgressBar)) {
29          ctrl.Enabled = isEnabled;
30        }
31      }
32    }
33
[7281]34    private void btnOk_Click(object sender, System.EventArgs e) {
35      this.progressBar.Visible = true;
[7387]36      SetAllControlsEnabled(this, false);
[7281]37      worker.RunWorkerAsync();
38    }
39
40    private void btnCancel_Click(object sender, System.EventArgs e) {
41      this.Close();
42    }
43
[7362]44    private void LoadSubscription(object sender, DoWorkEventArgs e) {
45      e.Result = CloudManagerClient.Instance.AzureProvider.GetSubscriptionInfo(txtSubscriptionId.Text, txtCertThumbprint.Text);
[7281]46    }
47
48    private void WorkerCompleted(object sender, RunWorkerCompletedEventArgs e) {
[7387]49      SetAllControlsEnabled(this, true);
[7281]50      progressBar.Visible = false;
[7362]51      if (e.Error == null) {
52        ErrorOccured = false;
53        Subscription = (Subscription)e.Result;
54        Subscription.SaveToConfig = cbSaveSubscription.Checked;
55        Subscription.DiscoverServices = cbDiscoverServices.Checked;
[7281]56        this.Close();
57      } else {
[7661]58        PluginInfrastructure.ErrorHandling.ShowErrorDialog(e.Error);
[7362]59        ErrorOccured = true;
60        Subscription = null;
[7281]61        this.Show();
62      }
63    }
64  }
65}
Note: See TracBrowser for help on using the repository browser.