diff options
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.cs | 107 |
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; + } + } + } + } +} |
