From c9597d3b4a053b7a1246419cb31517dd9f530543 Mon Sep 17 00:00:00 2001 From: Roy Ben Shabat Date: Sun, 9 Feb 2020 00:15:09 +0200 Subject: Working on azure utils... Fixed issue with TangoWebApplication logging. --- .../ViewModels/EnvironmentLogStreamViewVM.cs | 68 ++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 Software/Visual_Studio/Azure/Tango.AzureUtils.UI/ViewModels/EnvironmentLogStreamViewVM.cs (limited to 'Software/Visual_Studio/Azure/Tango.AzureUtils.UI/ViewModels/EnvironmentLogStreamViewVM.cs') 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..40548bd31 --- /dev/null +++ b/Software/Visual_Studio/Azure/Tango.AzureUtils.UI/ViewModels/EnvironmentLogStreamViewVM.cs @@ -0,0 +1,68 @@ +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.SharedUI.Components; + +namespace Tango.AzureUtils.UI.ViewModels +{ + public class EnvironmentLogStreamViewVM : AzureDashboardViewModel + { + private LogStreamManager _logStreamManager; + + private List _deploymentSlots; + public List DeploymentSlots + { + get { return _deploymentSlots; } + set { _deploymentSlots = value; RaisePropertyChangedAuto(); } + } + + private IWebAppBase _selectedDeploymentSlot; + public IWebAppBase SelectedDeploymentSlot + { + get { return _selectedDeploymentSlot; } + set { _selectedDeploymentSlot = value; RaisePropertyChangedAuto(); OnSelectedDeploymentSlotChanged(); } + } + + private TextController _log; + public TextController Log + { + get { return _log; } + set { _log = value; RaisePropertyChangedAuto(); } + } + + public EnvironmentLogStreamViewVM() + { + Log = new TextController(); + } + + public override void OnAuthenticated(IAzure azure, List apps) + { + DeploymentSlots = apps.ToList(); + + _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 async void OnSelectedDeploymentSlotChanged() + { + if (SelectedDeploymentSlot != null && _logStreamManager != null) + { + await _logStreamManager.StartLogStreamingAsync(SelectedDeploymentSlot); + } + } + } +} -- cgit v1.3.1 From 771fd149d07b15174d7811f5b3630859d8fb4f0b Mon Sep 17 00:00:00 2001 From: Roy Ben Shabat Date: Sun, 9 Feb 2020 00:42:01 +0200 Subject: Working on azure utils... --- .../ViewModels/EnvironmentLogStreamViewVM.cs | 45 ++++++++++++++++++++-- .../Views/EnvironmentLogStreamView.xaml | 13 +++++-- .../Views/EnvironmentUpgradeView.xaml | 6 +-- .../Tango.AzureUtils/Logging/LogStreamManager.cs | 15 ++++++-- 4 files changed, 66 insertions(+), 13 deletions(-) (limited to 'Software/Visual_Studio/Azure/Tango.AzureUtils.UI/ViewModels/EnvironmentLogStreamViewVM.cs') diff --git a/Software/Visual_Studio/Azure/Tango.AzureUtils.UI/ViewModels/EnvironmentLogStreamViewVM.cs b/Software/Visual_Studio/Azure/Tango.AzureUtils.UI/ViewModels/EnvironmentLogStreamViewVM.cs index 40548bd31..04fca66e1 100644 --- a/Software/Visual_Studio/Azure/Tango.AzureUtils.UI/ViewModels/EnvironmentLogStreamViewVM.cs +++ b/Software/Visual_Studio/Azure/Tango.AzureUtils.UI/ViewModels/EnvironmentLogStreamViewVM.cs @@ -8,6 +8,7 @@ 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 @@ -27,7 +28,7 @@ namespace Tango.AzureUtils.UI.ViewModels public IWebAppBase SelectedDeploymentSlot { get { return _selectedDeploymentSlot; } - set { _selectedDeploymentSlot = value; RaisePropertyChangedAuto(); OnSelectedDeploymentSlotChanged(); } + set { _selectedDeploymentSlot = value; RaisePropertyChangedAuto(); } } private TextController _log; @@ -37,14 +38,32 @@ namespace Tango.AzureUtils.UI.ViewModels 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 apps) { DeploymentSlots = apps.ToList(); + SelectedDeploymentSlot = DeploymentSlots.SingleOrDefault(x => x.Name.EndsWith("DEV")); _logStreamManager = new LogStreamManager(azure); _logStreamManager.ConfirmationRequired += ConfirmationHandler; @@ -57,11 +76,31 @@ namespace Tango.AzureUtils.UI.ViewModels Log.WriteLine(msg); } - private async void OnSelectedDeploymentSlotChanged() + private void Clear() + { + Log.Clear(); + } + + private void Stop() + { + IsStarted = false; + _logStreamManager.StopLogStreaming(); + } + + private async void Start() { if (SelectedDeploymentSlot != null && _logStreamManager != null) { - await _logStreamManager.StartLogStreamingAsync(SelectedDeploymentSlot); + try + { + IsStarted = true; + Log.Clear(); + await _logStreamManager.StartLogStreamingAsync(SelectedDeploymentSlot); + } + catch + { + IsStarted = false; + } } } } diff --git a/Software/Visual_Studio/Azure/Tango.AzureUtils.UI/Views/EnvironmentLogStreamView.xaml b/Software/Visual_Studio/Azure/Tango.AzureUtils.UI/Views/EnvironmentLogStreamView.xaml index 168e0b546..fbfbf8d6c 100644 --- a/Software/Visual_Studio/Azure/Tango.AzureUtils.UI/Views/EnvironmentLogStreamView.xaml +++ b/Software/Visual_Studio/Azure/Tango.AzureUtils.UI/Views/EnvironmentLogStreamView.xaml @@ -18,13 +18,13 @@ Foreground="{StaticResource PrimaryForegroundBrush}"> - + - + @@ -32,7 +32,14 @@ - + + + + + + + + diff --git a/Software/Visual_Studio/Azure/Tango.AzureUtils.UI/Views/EnvironmentUpgradeView.xaml b/Software/Visual_Studio/Azure/Tango.AzureUtils.UI/Views/EnvironmentUpgradeView.xaml index 113fd7b34..b82be1e67 100644 --- a/Software/Visual_Studio/Azure/Tango.AzureUtils.UI/Views/EnvironmentUpgradeView.xaml +++ b/Software/Visual_Studio/Azure/Tango.AzureUtils.UI/Views/EnvironmentUpgradeView.xaml @@ -22,7 +22,7 @@ - + @@ -39,7 +39,7 @@ - + Upgrade Database Schema Upgrade Database Static Collections @@ -61,7 +61,7 @@ - + diff --git a/Software/Visual_Studio/Azure/Tango.AzureUtils/Logging/LogStreamManager.cs b/Software/Visual_Studio/Azure/Tango.AzureUtils/Logging/LogStreamManager.cs index 4c37adb61..19752a6b8 100644 --- a/Software/Visual_Studio/Azure/Tango.AzureUtils/Logging/LogStreamManager.cs +++ b/Software/Visual_Studio/Azure/Tango.AzureUtils/Logging/LogStreamManager.cs @@ -50,14 +50,21 @@ namespace Tango.AzureUtils.Logging { while (_currentStream != null) { - String line = String.Empty; + String line = null; do { - line = _reader.ReadLine(); - if (line != null) + try { - LogAvailable?.Invoke(this, line); + line = _reader.ReadLine(); + if (line != null) + { + LogAvailable?.Invoke(this, line); + } + } + catch + { + line = null; } } while (line != null); -- cgit v1.3.1