using System.ComponentModel; using System.Windows.Forms; using HeuristicLab.Clients.Hive.CloudManager.Model; namespace HeuristicLab.Clients.Hive.CloudManager.Views { public partial class AddSubscriptionDialog : Form { public bool ErrorOccured { get; set; } public Subscription Subscription { get; set; } private BackgroundWorker worker = new BackgroundWorker(); public AddSubscriptionDialog() { InitializeComponent(); txtCertThumbprint.Text = "EFFD1808EF2F0658C52997CF00F7A86680F9FA62"; txtSubscriptionId.Text = "271e67e2-3132-4429-b0e7-ab94d3a95554"; cbSaveSubscription.Checked = false; cbDiscoverServices.Checked = true; worker.DoWork += new DoWorkEventHandler(LoadSubscription); worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(WorkerCompleted); ErrorOccured = true; } private void SetAllControlsEnabled(Form frm, bool isEnabled) { foreach (Control ctrl in frm.Controls) { if (!(ctrl is ProgressBar)) { ctrl.Enabled = isEnabled; } } } private void btnOk_Click(object sender, System.EventArgs e) { this.progressBar.Visible = true; SetAllControlsEnabled(this, false); worker.RunWorkerAsync(); } private void btnCancel_Click(object sender, System.EventArgs e) { this.Close(); } private void LoadSubscription(object sender, DoWorkEventArgs e) { e.Result = CloudManagerClient.Instance.AzureProvider.GetSubscriptionInfo(txtSubscriptionId.Text, txtCertThumbprint.Text); } private void WorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { SetAllControlsEnabled(this, true); progressBar.Visible = false; if (e.Error == null) { ErrorOccured = false; Subscription = (Subscription)e.Result; Subscription.SaveToConfig = cbSaveSubscription.Checked; Subscription.DiscoverServices = cbDiscoverServices.Checked; this.Close(); } else { PluginInfrastructure.ErrorHandling.ShowErrorDialog(e.Error); ErrorOccured = true; Subscription = null; this.Show(); } } } }