Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Hive.Azure/HeuristicLab.Clients.Hive.CloudManager/3.3/Views/DeleteDeploymentView.cs @ 11679

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

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

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