diff options
Diffstat (limited to 'Software/Visual_Studio/Azure/Tango.AzureUtils.UI/ViewModels/EnvironmentRollbackViewVM.cs')
| -rw-r--r-- | Software/Visual_Studio/Azure/Tango.AzureUtils.UI/ViewModels/EnvironmentRollbackViewVM.cs | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/Software/Visual_Studio/Azure/Tango.AzureUtils.UI/ViewModels/EnvironmentRollbackViewVM.cs b/Software/Visual_Studio/Azure/Tango.AzureUtils.UI/ViewModels/EnvironmentRollbackViewVM.cs new file mode 100644 index 000000000..69e18b51d --- /dev/null +++ b/Software/Visual_Studio/Azure/Tango.AzureUtils.UI/ViewModels/EnvironmentRollbackViewVM.cs @@ -0,0 +1,86 @@ +using Microsoft.Azure.Management.AppService.Fluent; +using Microsoft.Azure.Management.Fluent; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.AzureUtils.Environment; +using Tango.Core.Commands; + +namespace Tango.AzureUtils.UI.ViewModels +{ + public class EnvironmentRollbackViewVM : 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 RollbackEnvironmentConfiguration _config; + public RollbackEnvironmentConfiguration Config + { + get { return _config; } + set { _config = value; RaisePropertyChangedAuto(); } + } + + public RelayCommand RollbackEnvironmentCommand { get; set; } + + public EnvironmentRollbackViewVM() + { + RollbackEnvironmentCommand = new RelayCommand(RollbackEnvironment); + Config = new RollbackEnvironmentConfiguration(); + } + + 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 RollbackEnvironment() + { + try + { + IsFree = false; + + await _environmentManager.RollbackEnvironment(SelectedDeploymentSlot, Config); + } + catch (Exception ex) + { + StatusManager.UpdateStatus(ex); + } + finally + { + RequireRefresh(); + IsFree = true; + } + } + + protected override void OnRefreshRequired() + { + base.OnRefreshRequired(); + + var old = SelectedDeploymentSlot; + SelectedDeploymentSlot = null; + SelectedDeploymentSlot = old; + } + } +} |
