forked from visualHFT/VisualHFT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvmPluginManager.cs
80 lines (70 loc) · 2.8 KB
/
vmPluginManager.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
using Prism.Commands;
using Prism.Mvvm;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
using VisualHFT.PluginManager;
namespace VisualHFT.ViewModel
{
public class vmPluginManager : BindableBase, IDisposable
{
private ObservableCollection<IPlugin> _plugins;
public ObservableCollection<IPlugin> Plugins
{
get { return _plugins; }
set { SetProperty(ref _plugins, value); }
}
public ICommand StartPluginCommand { get; private set; }
public ICommand StopPluginCommand { get; private set; }
public ICommand ConfigurePluginCommand { get; private set; }
public vmPluginManager()
{
_plugins = new ObservableCollection<IPlugin>(PluginManager.PluginManager.AllPlugins);
RaisePropertyChanged(nameof(Plugins));
StartPluginCommand = new DelegateCommand<IPlugin>(StartPlugin, CanStartPlugin);
StopPluginCommand = new DelegateCommand<IPlugin>(StopPlugin, CanStopPlugin);
ConfigurePluginCommand = new DelegateCommand<IPlugin>(ConfigurePlugin);
}
private bool CanStartPlugin(IPlugin plugin)
{
return plugin.Status != ePluginStatus.STARTED;
}
private bool CanStopPlugin(IPlugin plugin)
{
return plugin.Status != ePluginStatus.STOPPED;
}
private void StartPlugin(IPlugin plugin)
{
PluginManager.PluginManager.StartPlugin(plugin);
_plugins = new ObservableCollection<IPlugin>(PluginManager.PluginManager.AllPlugins);
// Notify of any property changes if needed
RaisePropertyChanged(nameof(Plugins));
// Refresh the CanExecute status
(StartPluginCommand as DelegateCommand<IPlugin>).RaiseCanExecuteChanged();
(StopPluginCommand as DelegateCommand<IPlugin>).RaiseCanExecuteChanged();
}
private void StopPlugin(IPlugin plugin)
{
PluginManager.PluginManager.StopPlugin(plugin);
_plugins = new ObservableCollection<IPlugin>(PluginManager.PluginManager.AllPlugins);
// Notify of any property changes if needed
RaisePropertyChanged(nameof(Plugins));
// Refresh the CanExecute status
(StartPluginCommand as DelegateCommand<IPlugin>).RaiseCanExecuteChanged();
(StopPluginCommand as DelegateCommand<IPlugin>).RaiseCanExecuteChanged();
}
private void ConfigurePlugin(IPlugin plugin)
{
PluginManager.PluginManager.SettingPlugin(plugin);
}
public void Dispose()
{
// Any cleanup logic if needed
}
}
}