using System.ComponentModel; using System.Threading.Tasks; using System.Windows.Forms; using HeuristicLab.Clients.Hive.CloudManager.Azure; using HeuristicLab.Clients.Hive.CloudManager.Model; namespace HeuristicLab.Clients.Hive.CloudManager.Views { public partial class DeleteHostedServiceView : Form { private const string formatDeleteHostedService = "Are you sure you want to delete \"{0}\""; private HostedService hostedService; private BackgroundWorker worker; public bool ErrorOccured { get; set; } public DeleteHostedServiceView(HostedService hs) { InitializeComponent(); worker = new BackgroundWorker(); worker.DoWork += new DoWorkEventHandler(DeleteHostedServiceTask); worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(WorkerCompleted); hostedService = hs; lblDialogText.Text = string.Format(formatDeleteHostedService, hostedService.HostedServiceProperties.Label); } private void btnNo_Click(object sender, System.EventArgs e) { this.Close(); } private void btnYes_Click(object sender, System.EventArgs e) { SetControlsEnabled(false); progressBar.Visible = true; worker.RunWorkerAsync(hostedService); } private void SetControlsEnabled(bool isEnabled) { btnNo.Enabled = isEnabled; btnYes.Enabled = isEnabled; } private void DeleteHostedServiceTask(object sender, DoWorkEventArgs e) { HostedService hs = e.Argument as HostedService; //foreach (Deployment d in hs.Deployments) { // string requestId = CloudManagerClient.Instance.AzureProvider.DeleteDeployment(hs.Subscription, hs.ServiceName, d.Name); // Constants.OperationResult result = CloudManagerClient.Instance.AzureProvider.PollGetOperationStatus(hs.Subscription, requestId, 5, 30); //} Parallel.ForEach(hs.Deployments, dep => { string requestId = CloudManagerClient.Instance.AzureProvider.DeleteDeployment(hs.Subscription, hs.ServiceName, dep.Name); Constants.OperationResult result = CloudManagerClient.Instance.AzureProvider.PollGetOperationStatus(hs.Subscription, requestId, 4, 30); }); CloudManagerClient.Instance.AzureProvider.DeleteHostedService(hs.Subscription, hs.ServiceName); } private void WorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { progressBar.Visible = false; if (e.Error == null) { ErrorOccured = false; this.Close(); } else { PluginInfrastructure.ErrorHandling.ShowErrorDialog(e.Error); ErrorOccured = true; this.Show(); SetControlsEnabled(true); } } } }