1 | using System.ComponentModel;
|
---|
2 | using System.Windows.Forms;
|
---|
3 | using HeuristicLab.Clients.Hive.CloudManager.Model;
|
---|
4 |
|
---|
5 | namespace 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 | }
|
---|