Free cookie consent management tool by TermsFeed Policy Generator

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

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

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

File size: 2.2 KB
Line 
1using System.ComponentModel;
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
20      worker.DoWork += new DoWorkEventHandler(LoadSubscription);
21      worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(WorkerCompleted);
22
23      ErrorOccured = true;
24    }
25
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
34    private void btnOk_Click(object sender, System.EventArgs e) {
35      this.progressBar.Visible = true;
36      SetAllControlsEnabled(this, false);
37      worker.RunWorkerAsync();
38    }
39
40    private void btnCancel_Click(object sender, System.EventArgs e) {
41      this.Close();
42    }
43
44    private void LoadSubscription(object sender, DoWorkEventArgs e) {
45      e.Result = CloudManagerClient.Instance.AzureProvider.GetSubscriptionInfo(txtSubscriptionId.Text, txtCertThumbprint.Text);
46    }
47
48    private void WorkerCompleted(object sender, RunWorkerCompletedEventArgs e) {
49      SetAllControlsEnabled(this, true);
50      progressBar.Visible = false;
51      if (e.Error == null) {
52        ErrorOccured = false;
53        Subscription = (Subscription)e.Result;
54        Subscription.SaveToConfig = cbSaveSubscription.Checked;
55        Subscription.DiscoverServices = cbDiscoverServices.Checked;
56        this.Close();
57      } else {
58        PluginInfrastructure.ErrorHandling.ShowErrorDialog(e.Error);
59        ErrorOccured = true;
60        Subscription = null;
61        this.Show();
62      }
63    }
64  }
65}
Note: See TracBrowser for help on using the repository browser.