[7281] | 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 | worker.RunWorkerAsync();
|
---|
| 29 | }
|
---|
| 30 |
|
---|
| 31 | private void btnCancel_Click(object sender, System.EventArgs e) {
|
---|
| 32 | this.Close();
|
---|
| 33 | }
|
---|
| 34 |
|
---|
| 35 | private void SetWorkerEvents() {
|
---|
| 36 | worker.WorkerReportsProgress = true;
|
---|
| 37 | worker.DoWork += new DoWorkEventHandler(LoadSubscription);
|
---|
| 38 | worker.ProgressChanged += new ProgressChangedEventHandler(ProgressChanged);
|
---|
| 39 | worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(WorkerCompleted);
|
---|
| 40 | }
|
---|
| 41 |
|
---|
| 42 | private void ProgressChanged(object sender, ProgressChangedEventArgs e) {
|
---|
| 43 | progressBar.Value = e.ProgressPercentage;
|
---|
| 44 | }
|
---|
| 45 |
|
---|
| 46 | private void WorkerCompleted(object sender, RunWorkerCompletedEventArgs e) {
|
---|
| 47 | progressBar.Visible = false;
|
---|
| 48 | if (!ErrorOccured) {
|
---|
| 49 | this.Close();
|
---|
| 50 | } else {
|
---|
| 51 | this.Show();
|
---|
| 52 | }
|
---|
| 53 | }
|
---|
| 54 |
|
---|
| 55 | private void LoadSubscription(object sender, DoWorkEventArgs e) {
|
---|
| 56 | try {
|
---|
| 57 | worker.ReportProgress(25, "Add Subscription");
|
---|
| 58 | //Subscription = service.GetSubscriptionInfo(txtSubscriptionId.Text, txtCertThumbprint.Text);
|
---|
| 59 | Subscription.SaveToConfig = cbSaveSubscription.Checked;
|
---|
| 60 | Subscription.DiscoverServices = cbDiscoverServices.Checked;
|
---|
| 61 | ErrorOccured = false;
|
---|
| 62 | }
|
---|
| 63 | catch (SystemException ex) {
|
---|
| 64 | ErrorOccured = true;
|
---|
| 65 | MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
---|
| 66 | }
|
---|
| 67 | try {
|
---|
| 68 |
|
---|
| 69 | if (!ErrorOccured) {
|
---|
| 70 | worker.ReportProgress(50, "Get Subscription Info");
|
---|
| 71 | //TODO: operation
|
---|
| 72 | ErrorOccured = false;
|
---|
| 73 | }
|
---|
| 74 | }
|
---|
| 75 | catch (SystemException ex) {
|
---|
| 76 | ErrorOccured = true;
|
---|
| 77 | MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
---|
| 78 | worker.ReportProgress(25, "Rollback: Remove hosted service");
|
---|
| 79 | // Rollback operation
|
---|
| 80 | }
|
---|
| 81 |
|
---|
| 82 | if (!ErrorOccured) {
|
---|
| 83 | worker.ReportProgress(100, "");
|
---|
| 84 | Thread.Sleep(1000);
|
---|
| 85 | }
|
---|
| 86 | }
|
---|
| 87 | }
|
---|
| 88 | }
|
---|