1 | using System.ComponentModel;
|
---|
2 | using System.Threading.Tasks;
|
---|
3 | using System.Windows.Forms;
|
---|
4 | using HeuristicLab.Clients.Hive.CloudManager.Azure;
|
---|
5 | using HeuristicLab.Clients.Hive.CloudManager.Model;
|
---|
6 |
|
---|
7 | namespace 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 | MessageBox.Show(e.Error.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
---|
65 | ErrorOccured = true;
|
---|
66 | this.Show();
|
---|
67 | SetControlsEnabled(true);
|
---|
68 | }
|
---|
69 | }
|
---|
70 | }
|
---|
71 | }
|
---|