Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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