blob: e296ac16e4e128e8c237a9c0d5ec186710285eb7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
using Microsoft.Azure.Management.AppService.Fluent;
using Microsoft.Azure.Management.Fluent;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using Tango.AzureUtils.Environment;
using Tango.Core.Commands;
namespace Tango.AzureUtils.UI.ViewModels
{
public class EnvironmentRemovalViewVM : AzureDashboardViewModel
{
private IWebAppBase _machineServiceApp;
private EnvironmentManager _environmentManager;
private List<IDeploymentSlot> _deploymentSlots;
public List<IDeploymentSlot> DeploymentSlots
{
get { return _deploymentSlots; }
set { _deploymentSlots = value; RaisePropertyChangedAuto(); }
}
private IDeploymentSlot _selectedDeploymentSlot;
public IDeploymentSlot SelectedDeploymentSlot
{
get { return _selectedDeploymentSlot; }
set { _selectedDeploymentSlot = value; RaisePropertyChangedAuto(); }
}
private String _slotName;
[Required(ErrorMessage = "Deployment slot name confirmation is required.")]
public String SlotName
{
get { return _slotName; }
set { _slotName = value; RaisePropertyChangedAuto(); }
}
private RemoveEnvironmentConfiguration _config;
public RemoveEnvironmentConfiguration Config
{
get { return _config; }
set { _config = value; RaisePropertyChangedAuto(); }
}
public RelayCommand RemoveEnvironmentCommand { get; set; }
public EnvironmentRemovalViewVM()
{
RemoveEnvironmentCommand = new RelayCommand(RemoveEnvironment);
Config = new RemoveEnvironmentConfiguration();
}
public override void OnAuthenticated(IAzure azure, List<IWebAppBase> apps)
{
_machineServiceApp = apps.SingleOrDefault(x => x.Name == "MachineService");
DeploymentSlots = apps.OfType<IDeploymentSlot>().Where(x => x.Parent == _machineServiceApp).ToList();
SelectedDeploymentSlot = DeploymentSlots.FirstOrDefault();
_environmentManager = new EnvironmentManager(azure);
_environmentManager.ConfirmationRequired += ConfirmationHandler;
_environmentManager.Progress += ProgressHandler;
}
private async void RemoveEnvironment()
{
try
{
if (!Validate()) return;
IsFree = false;
Config.Email = Settings.Email;
Config.Password = Settings.Password;
await _environmentManager.RemoveEnvironment(SelectedDeploymentSlot, SlotName, Config);
}
catch (Exception ex)
{
StatusManager.UpdateStatus(ex);
}
finally
{
RequireRefresh();
IsFree = true;
}
}
protected override void OnRefreshRequired()
{
base.OnRefreshRequired();
SelectedDeploymentSlot = null;
}
}
}
|