aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Azure/Tango.AzureUtils.UI/ViewModels/EnvironmentUpgradeViewVM.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Software/Visual_Studio/Azure/Tango.AzureUtils.UI/ViewModels/EnvironmentUpgradeViewVM.cs')
-rw-r--r--Software/Visual_Studio/Azure/Tango.AzureUtils.UI/ViewModels/EnvironmentUpgradeViewVM.cs139
1 files changed, 139 insertions, 0 deletions
diff --git a/Software/Visual_Studio/Azure/Tango.AzureUtils.UI/ViewModels/EnvironmentUpgradeViewVM.cs b/Software/Visual_Studio/Azure/Tango.AzureUtils.UI/ViewModels/EnvironmentUpgradeViewVM.cs
new file mode 100644
index 000000000..3f353d54d
--- /dev/null
+++ b/Software/Visual_Studio/Azure/Tango.AzureUtils.UI/ViewModels/EnvironmentUpgradeViewVM.cs
@@ -0,0 +1,139 @@
+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.Deployment;
+using Tango.AzureUtils.Environment;
+using Tango.Core.Commands;
+using Tango.SharedUI;
+
+namespace Tango.AzureUtils.UI.ViewModels
+{
+ public class EnvironmentUpgradeViewVM : AzureDashboardViewModel
+ {
+ private List<IWebAppBase> _apps;
+ public List<IWebAppBase> Apps
+ {
+ get { return _apps; }
+ set { _apps = value; RaisePropertyChangedAuto(); }
+ }
+
+ private IWebAppBase _selectedSourceApp;
+ public IWebAppBase SelectedSourceApp
+ {
+ get { return _selectedSourceApp; }
+ set { _selectedSourceApp = value; RaisePropertyChangedAuto(); }
+ }
+
+ private IWebAppBase _selectedTargetAPp;
+ public IWebAppBase SelectedTargetApp
+ {
+ get { return _selectedTargetAPp; }
+ set { _selectedTargetAPp = value; RaisePropertyChangedAuto(); }
+ }
+
+ private EnvironmentManager _environmentManager;
+ public EnvironmentManager EnvironmentManager
+ {
+ get { return _environmentManager; }
+ set { _environmentManager = value; RaisePropertyChangedAuto(); }
+ }
+
+ private bool _canUpgrade;
+ public bool CanUpgrade
+ {
+ get { return _canUpgrade; }
+ set { _canUpgrade = value; RaisePropertyChangedAuto(); }
+ }
+
+ private UpgradeEnvironmentConfiguration _config;
+ public UpgradeEnvironmentConfiguration Config
+ {
+ get { return _config; }
+ set { _config = value; RaisePropertyChangedAuto(); }
+ }
+
+
+ public RelayCommand ValidateUpgradeCommand { get; set; }
+
+ public RelayCommand UpgradeEnvironmentCommand { get; set; }
+
+ public EnvironmentUpgradeViewVM()
+ {
+ Config = new UpgradeEnvironmentConfiguration();
+ ValidateUpgradeCommand = new RelayCommand(() => ValidateUpgrade());
+ UpgradeEnvironmentCommand = new RelayCommand(() => UpgradeEnvironment());
+ }
+
+ public override void OnAuthenticated(IAzure azure, List<IWebAppBase> apps)
+ {
+ Apps = apps;
+
+ SelectedSourceApp = Apps.FirstOrDefault();
+ SelectedTargetApp = Apps.FirstOrDefault();
+
+ EnvironmentManager = new EnvironmentManager(azure);
+ _environmentManager.ConfirmationRequired += ConfirmationHandler;
+ _environmentManager.Progress += ProgressHandler;
+ }
+
+ private async void ValidateUpgrade()
+ {
+ if (SelectedSourceApp == null || SelectedTargetApp == null)
+ {
+ return;
+ }
+
+ try
+ {
+ IsFree = false;
+ StatusManager.UpdateStatus(AzureUtilsStage.Validating, "Validating configuration...", true);
+ await EnvironmentManager.ValidateEnvironmentUpgrade(SelectedSourceApp, SelectedTargetApp, Config);
+ CanUpgrade = true;
+ StatusManager.UpdateStatus(AzureUtilsStage.Ready, "Configuration validated successfully.");
+ }
+ catch (Exception ex)
+ {
+ CanUpgrade = false;
+ StatusManager.UpdateStatus(ex);
+ }
+ finally
+ {
+ IsFree = true;
+ }
+ }
+
+ private async void UpgradeEnvironment()
+ {
+ try
+ {
+ IsFree = false;
+ await EnvironmentManager.UpgradeEnvironment(SelectedSourceApp, SelectedTargetApp, Config);
+ }
+ catch (Exception ex)
+ {
+ StatusManager.UpdateStatus(ex);
+ }
+ finally
+ {
+ RequireRefresh();
+ IsFree = true;
+ }
+ }
+
+ protected override void OnRefreshRequired()
+ {
+ base.OnRefreshRequired();
+
+ var oldSource = SelectedSourceApp;
+ var oldTarget = SelectedTargetApp;
+ SelectedSourceApp = null;
+ SelectedTargetApp = null;
+ SelectedSourceApp = oldSource;
+ SelectedTargetApp = oldTarget;
+ }
+ }
+}