-
-
Save kevingosse/ec2be9a9695e0a8c06effbb21ff62080 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections.Generic; | |
using System.ComponentModel; | |
using System.ComponentModel.Composition; | |
using System.Runtime.CompilerServices; | |
using System.Threading.Tasks; | |
using System.Windows; | |
using DbgX.Interfaces; | |
using DbgX.Interfaces.Enums; | |
using DbgX.Interfaces.Listeners; | |
using DbgX.Interfaces.Services; | |
using DbgX.Util; | |
namespace SosLoader | |
{ | |
[RibbonTabGroupExtensionMetadata("HomeRibbonTab", "Help", 0)] | |
[Export(typeof(IDbgRibbonTabGroupExtension))] | |
[Export(typeof(IDbgCommandExecutionListener))] | |
[Export(typeof(IDbgEngineConnectionListener))] | |
public class SosLoaderViewModel : IDbgRibbonTabGroupExtension, IDbgCommandExecutionListener, IDbgEngineConnectionListener, INotifyPropertyChanged | |
{ | |
private bool _isLoaded; | |
[Import] | |
public IDbgConsole _console; | |
[Import] | |
private IDbgEngineControl _engineControl; | |
public SosLoaderViewModel() | |
{ | |
LoadSosCommand = new AsyncDelegateCommand(LoadSos, CanLoadSos); | |
} | |
public event PropertyChangedEventHandler PropertyChanged; | |
public AsyncDelegateCommand LoadSosCommand { get; } | |
public IEnumerable<FrameworkElement> Controls => new[] { new SosLoaderButton(this) }; | |
public bool IsLoaded | |
{ | |
get => _isLoaded; | |
set | |
{ | |
_isLoaded = value; | |
OnPropertyChanged(); | |
} | |
} | |
public void OnCommandExecuted(string command) | |
{ | |
if (command.StartsWith(".loadby sos clr")) | |
{ | |
IsLoaded = true; | |
} | |
} | |
public void OnEngineConnectionChanged(EngineConnectionState state) | |
{ | |
LoadSosCommand.RaiseCanExecuteChanged(); | |
} | |
protected void OnPropertyChanged([CallerMemberName] string propertyName = null) | |
{ | |
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); | |
} | |
private Task LoadSos() | |
{ | |
return _console.ExecuteCommandAsync(".loadby sos clr"); | |
} | |
private bool CanLoadSos() | |
{ | |
return _engineControl.ConnectionState != EngineConnectionState.NoSession && !IsLoaded; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment