Preliminary whitelist reload functionality present in agent gui, this is facilitated by the Prism 6 library.
parent
36e4f844d2
commit
789f5b1c7d
|
@ -53,6 +53,13 @@
|
|||
<ListBox x:Name="IgnoredNicsList"
|
||||
Grid.Row="4"
|
||||
ItemsSource="{Binding Whitelist, Mode=OneWay}" />
|
||||
<Button Grid.Row="4"
|
||||
Margin="4"
|
||||
Content="Reload"
|
||||
Command="{Binding ReloadWhitelist}"
|
||||
HorizontalAlignment="Right"
|
||||
VerticalAlignment="Top"/>
|
||||
|
||||
</Grid>
|
||||
</TabItem>
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@ using System.Diagnostics;
|
|||
using WifiSitterGui.ViewModel;
|
||||
using WifiSitter;
|
||||
using WifiSitter.Model;
|
||||
using Prism.Events;
|
||||
|
||||
namespace WifiSitterGui
|
||||
{
|
||||
|
@ -36,12 +37,13 @@ namespace WifiSitterGui
|
|||
public TrayIconControl() {
|
||||
InitializeComponent();
|
||||
|
||||
_agentVM = new WifiSitterAgentViewModel(new MainWindowViewModel());
|
||||
this.Closing += (o, e) => { this.TaskBarIcon.Visibility = Visibility.Hidden; };
|
||||
|
||||
_agentVM = new WifiSitterAgentViewModel(EventAggregator);
|
||||
DataContext = _agentVM;
|
||||
}
|
||||
|
||||
~TrayIconControl() {
|
||||
if (TaskBarIcon != null) TaskBarIcon.Visibility = Visibility.Hidden;
|
||||
TaskBarIcon?.Dispose();
|
||||
}
|
||||
|
||||
|
@ -50,6 +52,15 @@ namespace WifiSitterGui
|
|||
|
||||
#region properties
|
||||
|
||||
private IEventAggregator _eventAggregator;
|
||||
internal IEventAggregator EventAggregator {
|
||||
get {
|
||||
if (_eventAggregator == null)
|
||||
_eventAggregator = new EventAggregator();
|
||||
|
||||
return _eventAggregator;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion // properties
|
||||
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Prism.Events;
|
||||
|
||||
namespace WifiSitterGui.ViewModel.Events
|
||||
{
|
||||
public class ReloadWhitelistEvent : PubSubEvent { }
|
||||
}
|
|
@ -6,9 +6,16 @@ using System.Net.NetworkInformation;
|
|||
using System.ServiceProcess;
|
||||
using System.Text;
|
||||
using System.Timers;
|
||||
using System.Windows.Input;
|
||||
|
||||
// internal uings
|
||||
using WifiSitter;
|
||||
using WifiSitter.Model;
|
||||
using WifiSitterGui.ViewModel.Events;
|
||||
|
||||
// 3rd party usings
|
||||
using Prism.Events;
|
||||
using WifiSitterGui.Helpers;
|
||||
|
||||
namespace WifiSitterGui.ViewModel
|
||||
{
|
||||
|
@ -20,6 +27,8 @@ namespace WifiSitterGui.ViewModel
|
|||
private ServiceController _sc;
|
||||
private Timer _refreshProperties;
|
||||
private WifiSitterAgentViewModel _parent;
|
||||
private RelayCommand _reloadWhitelistCommand;
|
||||
private IEventAggregator _eventAggregator;
|
||||
|
||||
#endregion // fields
|
||||
|
||||
|
@ -28,9 +37,10 @@ namespace WifiSitterGui.ViewModel
|
|||
|
||||
public MainWindowViewModel() { }
|
||||
|
||||
public MainWindowViewModel (WifiSitterAgentViewModel Parent) {
|
||||
_parent = Parent;
|
||||
public MainWindowViewModel (IEventAggregator eventAggregator) {
|
||||
|
||||
_eventAggregator = eventAggregator;
|
||||
|
||||
_refreshProperties = new Timer();
|
||||
_refreshProperties.Interval = 1000 * 5;
|
||||
_refreshProperties.AutoReset = true;
|
||||
|
@ -114,6 +124,20 @@ namespace WifiSitterGui.ViewModel
|
|||
#endregion // methods
|
||||
|
||||
|
||||
#region commands
|
||||
|
||||
public ICommand ReloadWhitelist {
|
||||
get {
|
||||
return (_reloadWhitelistCommand != null)
|
||||
? _reloadWhitelistCommand
|
||||
: _reloadWhitelistCommand = new RelayCommand(
|
||||
() => { _eventAggregator?.GetEvent<ReloadWhitelistEvent>().Publish(); });
|
||||
}
|
||||
}
|
||||
|
||||
#endregion // commands
|
||||
|
||||
|
||||
#region eventhandlers
|
||||
#endregion // methods
|
||||
}
|
||||
|
|
|
@ -13,10 +13,12 @@ using System.Net.NetworkInformation;
|
|||
using WifiSitter;
|
||||
using WifiSitter.Model;
|
||||
using WifiSitterGui.Helpers;
|
||||
using WifiSitterGui.ViewModel.Events;
|
||||
|
||||
// 3rd party usings
|
||||
using NetMQ;
|
||||
using NetMQ.Sockets;
|
||||
using Prism.Events;
|
||||
|
||||
namespace WifiSitterGui.ViewModel
|
||||
{
|
||||
|
@ -27,12 +29,14 @@ namespace WifiSitterGui.ViewModel
|
|||
private static MainWindowViewModel _windowVM;
|
||||
private RelayCommand _launchWindowCommand;
|
||||
private RelayCommand _takeFiveCommand; // Asks service to pause for 5 minutes
|
||||
private RelayCommand _reloadWhitelistCommand; // Asks service to reload the nic whitelist
|
||||
private static MainWindow _statusGui;
|
||||
private static string _serviceChannel;
|
||||
private System.Timers.Timer _netstateCheckTimer;
|
||||
private static string _myChannel = String.Format("{0}-{1}", Process.GetCurrentProcess().Id, Process.GetCurrentProcess().ProcessName);
|
||||
private static DealerSocket _mqClient;
|
||||
private static NetMQPoller _poller;
|
||||
private IEventAggregator _eventAggregator;
|
||||
|
||||
#endregion // fields
|
||||
|
||||
|
@ -42,14 +46,16 @@ namespace WifiSitterGui.ViewModel
|
|||
}
|
||||
|
||||
|
||||
public WifiSitterAgentViewModel(MainWindowViewModel WindowVM) {
|
||||
public WifiSitterAgentViewModel(IEventAggregator eventtAggregator) {
|
||||
_eventAggregator = eventtAggregator;
|
||||
_eventAggregator?.GetEvent<ReloadWhitelistEvent>().Subscribe(() => { RequestReloadWhitelist(); });
|
||||
|
||||
_windowVM = WindowVM;
|
||||
Intitialize();
|
||||
}
|
||||
|
||||
|
||||
private void Intitialize() {
|
||||
|
||||
// Get NetState
|
||||
RequestNetworkState();
|
||||
|
||||
|
@ -78,7 +84,7 @@ namespace WifiSitterGui.ViewModel
|
|||
|
||||
public MainWindowViewModel WindowVM {
|
||||
get { if (_windowVM == null) {
|
||||
_windowVM = new MainWindowViewModel();
|
||||
_windowVM = new MainWindowViewModel(_eventAggregator);
|
||||
}
|
||||
return _windowVM;
|
||||
}
|
||||
|
@ -141,6 +147,21 @@ namespace WifiSitterGui.ViewModel
|
|||
}
|
||||
|
||||
|
||||
public void RequestReloadWhitelist() {
|
||||
if (!String.IsNullOrEmpty(ServiceChannelName)) {
|
||||
try {
|
||||
Trace.WriteLine("Checking for network state.");
|
||||
string request = new WifiSitterIpcMessage("reload_whitelist", _myChannel).ToJsonString();
|
||||
bool success = SendMessageToService(request);
|
||||
if (!success) Trace.WriteLine("Failed to send request reload_whitelist.");
|
||||
}
|
||||
catch (Exception e) {
|
||||
Trace.WriteLine(e.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private bool SendMessageToService(string msg) {
|
||||
|
||||
// Initialize messaging componenets if needed.
|
||||
|
@ -175,6 +196,11 @@ namespace WifiSitterGui.ViewModel
|
|||
return _mqClient.TrySendMultipartMessage(reqMessage);
|
||||
}
|
||||
|
||||
|
||||
private void ReceiveCommand(ICommand cmd) {
|
||||
|
||||
}
|
||||
|
||||
#endregion // methods
|
||||
|
||||
#region commands
|
||||
|
@ -200,6 +226,21 @@ namespace WifiSitterGui.ViewModel
|
|||
}
|
||||
|
||||
|
||||
public ICommand SendReloadWhitelistRequest {
|
||||
get {
|
||||
if (_reloadWhitelistCommand == null) {
|
||||
_reloadWhitelistCommand = new RelayCommand(() => {
|
||||
var request = new WifiSitterIpcMessage("reload_whitelist", _myChannel).ToJsonString();
|
||||
bool success = SendMessageToService(request);
|
||||
if (!success) Trace.WriteLine("Failed to send reload_whitelist");
|
||||
// TODO need response validation mechanism
|
||||
});
|
||||
}
|
||||
return _reloadWhitelistCommand;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public ICommand SendTakeFiveRequest {
|
||||
get {
|
||||
if (_takeFiveCommand == null) {
|
||||
|
@ -236,7 +277,9 @@ namespace WifiSitterGui.ViewModel
|
|||
if (_sr != null) {
|
||||
switch (_sr.Request) {
|
||||
case "give_netstate":
|
||||
try { WindowVM.NetState = Newtonsoft.Json.JsonConvert.DeserializeObject<SimpleNetworkState>(Encoding.UTF8.GetString(_sr.Payload)); }
|
||||
try {
|
||||
_netstateTimer.Stop(); _netstateTimer.Start();
|
||||
WindowVM.NetState = Newtonsoft.Json.JsonConvert.DeserializeObject<SimpleNetworkState>(Encoding.UTF8.GetString(_sr.Payload)); }
|
||||
catch { WifiSitter.WifiSitter.LogLine("Failed to deserialize netstate, payload."); }
|
||||
break;
|
||||
case "taking_five":
|
||||
|
|
|
@ -56,6 +56,10 @@
|
|||
<HintPath>..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="Prism, Version=6.2.0.0, Culture=neutral, PublicKeyToken=91a96d2a154366d8, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Prism.Core.6.2.0\lib\net45\Prism.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Drawing" />
|
||||
|
@ -96,6 +100,7 @@
|
|||
<Compile Include="TrayIconControl.xaml.cs">
|
||||
<DependentUpon>TrayIconControl.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="ViewModel\Events\Events.cs" />
|
||||
<Compile Include="ViewModel\WifiSitterAgentViewModel.cs" />
|
||||
<Compile Include="View\About.xaml.cs">
|
||||
<DependentUpon>About.xaml</DependentUpon>
|
||||
|
|
|
@ -4,4 +4,5 @@
|
|||
<package id="Hardcodet.NotifyIcon.Wpf" version="1.0.8" targetFramework="net452" />
|
||||
<package id="NetMQ" version="3.3.3.4" targetFramework="net452" />
|
||||
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="net452" />
|
||||
<package id="Prism.Core" version="6.2.0" targetFramework="net452" />
|
||||
</packages>
|
Loading…
Reference in New Issue