aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Azure/Tango.AzureUtils.UI/ViewModels/EnvironmentLogStreamViewVM.cs
diff options
context:
space:
mode:
authorShlomo Hecht <shlomo@twine-s.com>2020-02-20 11:39:04 +0200
committerShlomo Hecht <shlomo@twine-s.com>2020-02-20 11:39:04 +0200
commit57a828b4d11ab8274053ee035c8de8014ddd4ca1 (patch)
treec88e63b5e9019fe67cc3be451e46fbe57efc4a35 /Software/Visual_Studio/Azure/Tango.AzureUtils.UI/ViewModels/EnvironmentLogStreamViewVM.cs
parent2d55102532afaccc447c8a28ded8ccb93437683b (diff)
parentd6e2772dd98e6880de14ea12be0ef53bae24f763 (diff)
downloadTango-57a828b4d11ab8274053ee035c8de8014ddd4ca1.tar.gz
Tango-57a828b4d11ab8274053ee035c8de8014ddd4ca1.zip
merge
Diffstat (limited to 'Software/Visual_Studio/Azure/Tango.AzureUtils.UI/ViewModels/EnvironmentLogStreamViewVM.cs')
-rw-r--r--Software/Visual_Studio/Azure/Tango.AzureUtils.UI/ViewModels/EnvironmentLogStreamViewVM.cs107
1 files changed, 107 insertions, 0 deletions
diff --git a/Software/Visual_Studio/Azure/Tango.AzureUtils.UI/ViewModels/EnvironmentLogStreamViewVM.cs b/Software/Visual_Studio/Azure/Tango.AzureUtils.UI/ViewModels/EnvironmentLogStreamViewVM.cs
new file mode 100644
index 000000000..04fca66e1
--- /dev/null
+++ b/Software/Visual_Studio/Azure/Tango.AzureUtils.UI/ViewModels/EnvironmentLogStreamViewVM.cs
@@ -0,0 +1,107 @@
+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 System.Windows;
+using Tango.AzureUtils.Environment;
+using Tango.AzureUtils.Logging;
+using Tango.Core.Commands;
+using Tango.SharedUI.Components;
+
+namespace Tango.AzureUtils.UI.ViewModels
+{
+ public class EnvironmentLogStreamViewVM : AzureDashboardViewModel
+ {
+ private LogStreamManager _logStreamManager;
+
+ private List<IWebAppBase> _deploymentSlots;
+ public List<IWebAppBase> DeploymentSlots
+ {
+ get { return _deploymentSlots; }
+ set { _deploymentSlots = value; RaisePropertyChangedAuto(); }
+ }
+
+ private IWebAppBase _selectedDeploymentSlot;
+ public IWebAppBase SelectedDeploymentSlot
+ {
+ get { return _selectedDeploymentSlot; }
+ set { _selectedDeploymentSlot = value; RaisePropertyChangedAuto(); }
+ }
+
+ private TextController _log;
+ public TextController Log
+ {
+ get { return _log; }
+ set { _log = value; RaisePropertyChangedAuto(); }
+ }
+
+ private bool _isStarted;
+ public bool IsStarted
+ {
+ get { return _isStarted; }
+ set { _isStarted = value; RaisePropertyChangedAuto(); InvalidateRelayCommands(); }
+ }
+
+ public RelayCommand StartCommand { get; set; }
+
+ public RelayCommand StopCommand { get; set; }
+
+ public RelayCommand ClearCommand { get; set; }
+
+ public EnvironmentLogStreamViewVM()
+ {
+ Log = new TextController();
+
+ StartCommand = new RelayCommand(Start,() => !IsStarted);
+ StopCommand = new RelayCommand(Stop, () => IsStarted);
+ ClearCommand = new RelayCommand(Clear);
+ }
+
+ public override void OnAuthenticated(IAzure azure, List<IWebAppBase> apps)
+ {
+ DeploymentSlots = apps.ToList();
+ SelectedDeploymentSlot = DeploymentSlots.SingleOrDefault(x => x.Name.EndsWith("DEV"));
+
+ _logStreamManager = new LogStreamManager(azure);
+ _logStreamManager.ConfirmationRequired += ConfirmationHandler;
+ _logStreamManager.Progress += ProgressHandler;
+ _logStreamManager.LogAvailable += _logStreamManager_LogAvailable;
+ }
+
+ private void _logStreamManager_LogAvailable(object sender, string msg)
+ {
+ Log.WriteLine(msg);
+ }
+
+ private void Clear()
+ {
+ Log.Clear();
+ }
+
+ private void Stop()
+ {
+ IsStarted = false;
+ _logStreamManager.StopLogStreaming();
+ }
+
+ private async void Start()
+ {
+ if (SelectedDeploymentSlot != null && _logStreamManager != null)
+ {
+ try
+ {
+ IsStarted = true;
+ Log.Clear();
+ await _logStreamManager.StartLogStreamingAsync(SelectedDeploymentSlot);
+ }
+ catch
+ {
+ IsStarted = false;
+ }
+ }
+ }
+ }
+}