Free cookie consent management tool by TermsFeed Policy Generator

source: branches/1680_HeuristicLab.Hive.Azure/HeuristicLab.Clients.Hive.CloudManager/3.3/Views/DeleteHostedServiceView.cs @ 17712

Last change on this file since 17712 was 7661, checked in by spimming, 13 years ago

#1680: Show error dialog (from PluginInfrastructure) instead of message box on exception

File size: 2.7 KB
Line 
1using System.ComponentModel;
2using System.Threading.Tasks;
3using System.Windows.Forms;
4using HeuristicLab.Clients.Hive.CloudManager.Azure;
5using HeuristicLab.Clients.Hive.CloudManager.Model;
6
7namespace HeuristicLab.Clients.Hive.CloudManager.Views {
8  public partial class DeleteHostedServiceView : Form {
9    private const string formatDeleteHostedService = "Are you sure you want to delete \"{0}\"";
10    private HostedService hostedService;
11    private BackgroundWorker worker;
12
13    public bool ErrorOccured { get; set; }
14
15    public DeleteHostedServiceView(HostedService hs) {
16      InitializeComponent();
17      worker = new BackgroundWorker();
18      worker.DoWork += new DoWorkEventHandler(DeleteHostedServiceTask);
19      worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(WorkerCompleted);
20
21      hostedService = hs;
22
23      lblDialogText.Text = string.Format(formatDeleteHostedService, hostedService.HostedServiceProperties.Label);
24    }
25
26    private void btnNo_Click(object sender, System.EventArgs e) {
27      this.Close();
28    }
29
30    private void btnYes_Click(object sender, System.EventArgs e) {
31      SetControlsEnabled(false);
32      progressBar.Visible = true;
33
34      worker.RunWorkerAsync(hostedService);
35    }
36
37    private void SetControlsEnabled(bool isEnabled) {
38      btnNo.Enabled = isEnabled;
39      btnYes.Enabled = isEnabled;
40    }
41
42    private void DeleteHostedServiceTask(object sender, DoWorkEventArgs e) {
43      HostedService hs = e.Argument as HostedService;
44
45      //foreach (Deployment d in hs.Deployments) {
46      //  string requestId = CloudManagerClient.Instance.AzureProvider.DeleteDeployment(hs.Subscription, hs.ServiceName, d.Name);
47      //  Constants.OperationResult result = CloudManagerClient.Instance.AzureProvider.PollGetOperationStatus(hs.Subscription, requestId, 5, 30);
48      //}
49
50      Parallel.ForEach(hs.Deployments, dep => {
51        string requestId = CloudManagerClient.Instance.AzureProvider.DeleteDeployment(hs.Subscription, hs.ServiceName, dep.Name);
52        Constants.OperationResult result = CloudManagerClient.Instance.AzureProvider.PollGetOperationStatus(hs.Subscription, requestId, 4, 30);
53      });
54      CloudManagerClient.Instance.AzureProvider.DeleteHostedService(hs.Subscription, hs.ServiceName);
55    }
56
57    private void WorkerCompleted(object sender, RunWorkerCompletedEventArgs e) {
58      progressBar.Visible = false;
59
60      if (e.Error == null) {
61        ErrorOccured = false;
62        this.Close();
63      } else {
64        PluginInfrastructure.ErrorHandling.ShowErrorDialog(e.Error);
65        ErrorOccured = true;
66        this.Show();
67        SetControlsEnabled(true);
68      }
69    }
70  }
71}
Note: See TracBrowser for help on using the repository browser.