Skip to content

Instantly share code, notes, and snippets.

@kevingosse
Created September 5, 2017 15:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kevingosse/ec2be9a9695e0a8c06effbb21ff62080 to your computer and use it in GitHub Desktop.
Save kevingosse/ec2be9a9695e0a8c06effbb21ff62080 to your computer and use it in GitHub Desktop.
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