aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Azure/Tango.AzureUtils.UI/ViewModels/EnvironmentCreationViewVM.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Software/Visual_Studio/Azure/Tango.AzureUtils.UI/ViewModels/EnvironmentCreationViewVM.cs')
-rw-r--r--Software/Visual_Studio/Azure/Tango.AzureUtils.UI/ViewModels/EnvironmentCreationViewVM.cs93
1 files changed, 93 insertions, 0 deletions
diff --git a/Software/Visual_Studio/Azure/Tango.AzureUtils.UI/ViewModels/EnvironmentCreationViewVM.cs b/Software/Visual_Studio/Azure/Tango.AzureUtils.UI/ViewModels/EnvironmentCreationViewVM.cs
new file mode 100644
index 000000000..a4c65fcdd
--- /dev/null
+++ b/Software/Visual_Studio/Azure/Tango.AzureUtils.UI/ViewModels/EnvironmentCreationViewVM.cs
@@ -0,0 +1,93 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+using Microsoft.Azure.Management.AppService.Fluent;
+using Microsoft.Azure.Management.Fluent;
+using Tango.AzureUtils.ActiveDirectory;
+using Tango.AzureUtils.Deployment;
+using Tango.AzureUtils.Environment;
+using Tango.Core.Commands;
+
+namespace Tango.AzureUtils.UI.ViewModels
+{
+ public class EnvironmentCreationViewVM : 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 is required.")]
+ public String SlotName
+ {
+ get { return _slotName; }
+ set { _slotName = value; RaisePropertyChangedAuto(); }
+ }
+
+ private CreateEnvironmentConfiguration _config;
+ public CreateEnvironmentConfiguration Config
+ {
+ get { return _config; }
+ set { _config = value; RaisePropertyChangedAuto(); }
+ }
+
+ public RelayCommand CreateEnvironmentCommand { get; set; }
+
+ public EnvironmentCreationViewVM()
+ {
+ CreateEnvironmentCommand = new RelayCommand(CreateEnvironment);
+ Config = new CreateEnvironmentConfiguration();
+ }
+
+ 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 CreateEnvironment()
+ {
+ try
+ {
+ if (!Validate()) return;
+
+ IsFree = false;
+
+ Config.Email = Settings.Email;
+ Config.Password = Settings.Password;
+
+ await _environmentManager.CreateEnvironment(_machineServiceApp as IWebApp, SelectedDeploymentSlot, SlotName, Config);
+ }
+ catch (Exception ex)
+ {
+ StatusManager.UpdateStatus(ex);
+ }
+ finally
+ {
+ IsFree = true;
+ }
+ }
+ }
+}