1 | using System;
|
---|
2 | using System.ComponentModel;
|
---|
3 | using System.Threading;
|
---|
4 | using System.Windows.Forms;
|
---|
5 | using HeuristicLab.Clients.Hive.CloudManager.Model;
|
---|
6 |
|
---|
7 | namespace HeuristicLab.Clients.Hive.CloudManager.Views {
|
---|
8 | public partial class AddSubscriptionDialog : Form {
|
---|
9 | public bool ErrorOccured { get; set; }
|
---|
10 | public Subscription Subscription { get; set; }
|
---|
11 |
|
---|
12 | private BackgroundWorker worker = new BackgroundWorker();
|
---|
13 |
|
---|
14 | public AddSubscriptionDialog() {
|
---|
15 | InitializeComponent();
|
---|
16 |
|
---|
17 | txtCertThumbprint.Text = "EFFD1808EF2F0658C52997CF00F7A86680F9FA62";
|
---|
18 | txtSubscriptionId.Text = "271e67e2-3132-4429-b0e7-ab94d3a95554";
|
---|
19 | cbSaveSubscription.Checked = false;
|
---|
20 | cbDiscoverServices.Checked = true;
|
---|
21 |
|
---|
22 | SetWorkerEvents();
|
---|
23 | ErrorOccured = true;
|
---|
24 | }
|
---|
25 |
|
---|
26 | private void btnOk_Click(object sender, System.EventArgs e) {
|
---|
27 | this.progressBar.Visible = true;
|
---|
28 | //this.progressBar.Style = ProgressBarStyle.Continuous;
|
---|
29 | worker.RunWorkerAsync();
|
---|
30 | }
|
---|
31 |
|
---|
32 | private void btnCancel_Click(object sender, System.EventArgs e) {
|
---|
33 | this.Close();
|
---|
34 | }
|
---|
35 |
|
---|
36 | private void SetWorkerEvents() {
|
---|
37 | worker.WorkerReportsProgress = true;
|
---|
38 | worker.DoWork += new DoWorkEventHandler(LoadSubscription);
|
---|
39 | worker.ProgressChanged += new ProgressChangedEventHandler(ProgressChanged);
|
---|
40 | worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(WorkerCompleted);
|
---|
41 | }
|
---|
42 |
|
---|
43 | private void ProgressChanged(object sender, ProgressChangedEventArgs e) {
|
---|
44 | progressBar.Value = e.ProgressPercentage;
|
---|
45 | }
|
---|
46 |
|
---|
47 | private void WorkerCompleted(object sender, RunWorkerCompletedEventArgs e) {
|
---|
48 | progressBar.Visible = false;
|
---|
49 | if (!ErrorOccured) {
|
---|
50 | this.Close();
|
---|
51 | } else {
|
---|
52 | this.Show();
|
---|
53 | }
|
---|
54 | }
|
---|
55 |
|
---|
56 | private void LoadSubscription(object sender, DoWorkEventArgs e) {
|
---|
57 | try {
|
---|
58 | worker.ReportProgress(25, "Add Subscription");
|
---|
59 | Subscription = CloudManagerClient.Instance.AzureProvider.GetSubscriptionInfo(txtSubscriptionId.Text, txtCertThumbprint.Text);
|
---|
60 | Subscription.SaveToConfig = cbSaveSubscription.Checked;
|
---|
61 | Subscription.DiscoverServices = cbDiscoverServices.Checked;
|
---|
62 | ErrorOccured = false;
|
---|
63 | }
|
---|
64 | catch (SystemException ex) {
|
---|
65 | ErrorOccured = true;
|
---|
66 | MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
---|
67 | }
|
---|
68 | try {
|
---|
69 |
|
---|
70 | if (!ErrorOccured) {
|
---|
71 | worker.ReportProgress(50, "Get Subscription Info");
|
---|
72 | //TODO: operation
|
---|
73 | ErrorOccured = false;
|
---|
74 | }
|
---|
75 | }
|
---|
76 | catch (SystemException ex) {
|
---|
77 | ErrorOccured = true;
|
---|
78 | MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
---|
79 | worker.ReportProgress(25, "Rollback: Remove hosted service");
|
---|
80 | // Rollback operation
|
---|
81 | }
|
---|
82 |
|
---|
83 | if (!ErrorOccured) {
|
---|
84 | worker.ReportProgress(100, "");
|
---|
85 | Thread.Sleep(1000);
|
---|
86 | }
|
---|
87 | }
|
---|
88 | }
|
---|
89 | }
|
---|