2016-11-15 17:04:48 -05:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2016-11-21 19:16:14 -05:00
|
|
|
|
using System.Collections.ObjectModel;
|
2016-11-15 17:04:48 -05:00
|
|
|
|
using System.Linq;
|
2016-12-17 21:49:05 -05:00
|
|
|
|
using System.Net.NetworkInformation;
|
2016-11-18 23:28:53 -05:00
|
|
|
|
using System.ServiceProcess;
|
2016-11-15 17:04:48 -05:00
|
|
|
|
using System.Text;
|
2016-11-19 01:32:59 -05:00
|
|
|
|
using System.Timers;
|
2016-11-15 17:04:48 -05:00
|
|
|
|
|
2016-11-16 13:10:30 -05:00
|
|
|
|
using WifiSitter;
|
2016-11-17 03:10:44 -05:00
|
|
|
|
using WifiSitter.Model;
|
2016-11-16 13:10:30 -05:00
|
|
|
|
|
|
|
|
|
namespace WifiSitterGui.ViewModel
|
2016-11-15 17:04:48 -05:00
|
|
|
|
{
|
2016-11-17 13:06:17 -05:00
|
|
|
|
public class MainWindowViewModel : MvvmObservable
|
2016-11-15 17:04:48 -05:00
|
|
|
|
{
|
|
|
|
|
#region fields
|
2016-11-16 13:10:30 -05:00
|
|
|
|
|
2016-11-17 03:10:44 -05:00
|
|
|
|
SimpleNetworkState _netState;
|
2016-11-18 23:28:53 -05:00
|
|
|
|
private ServiceController _sc;
|
2016-11-19 01:32:59 -05:00
|
|
|
|
private Timer _refreshProperties;
|
|
|
|
|
private WifiSitterAgentViewModel _parent;
|
2016-11-16 13:10:30 -05:00
|
|
|
|
|
2016-11-15 17:04:48 -05:00
|
|
|
|
#endregion // fields
|
|
|
|
|
|
2016-11-15 20:33:07 -05:00
|
|
|
|
|
2016-11-15 17:04:48 -05:00
|
|
|
|
#region constructor
|
|
|
|
|
|
2016-11-19 01:32:59 -05:00
|
|
|
|
public MainWindowViewModel() { }
|
|
|
|
|
|
|
|
|
|
public MainWindowViewModel (WifiSitterAgentViewModel Parent) {
|
|
|
|
|
_parent = Parent;
|
2016-11-15 17:04:48 -05:00
|
|
|
|
|
2016-11-19 01:32:59 -05:00
|
|
|
|
_refreshProperties = new Timer();
|
|
|
|
|
_refreshProperties.Interval = 1000 * 5;
|
|
|
|
|
_refreshProperties.AutoReset = true;
|
|
|
|
|
_refreshProperties.Elapsed += (o, e) => {
|
|
|
|
|
this.OnPropertyChanged("ServiceState");
|
|
|
|
|
};
|
|
|
|
|
_refreshProperties.Start();
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-15 17:04:48 -05:00
|
|
|
|
#endregion // constructor
|
|
|
|
|
|
2016-11-15 20:33:07 -05:00
|
|
|
|
|
2016-11-15 17:04:48 -05:00
|
|
|
|
#region properties
|
2016-11-16 13:10:30 -05:00
|
|
|
|
|
2016-11-17 03:10:44 -05:00
|
|
|
|
public SimpleNetworkState NetState {
|
2016-11-16 13:10:30 -05:00
|
|
|
|
get { return _netState; }
|
2016-11-17 13:37:57 -05:00
|
|
|
|
set { _netState = value; OnPropertyChanged(null); }
|
2016-11-16 13:10:30 -05:00
|
|
|
|
}
|
2016-11-18 23:28:53 -05:00
|
|
|
|
|
2016-11-16 13:10:30 -05:00
|
|
|
|
|
2016-12-17 21:49:05 -05:00
|
|
|
|
public List<SimpleNic> WiredNics {
|
2016-11-21 19:16:14 -05:00
|
|
|
|
get {
|
2016-12-17 21:49:05 -05:00
|
|
|
|
return NetState.Nics.Where(x => x.InterfaceType == "Ethernet").Where(x => !NetState.IgnoreAdapters.Any(y => x.Description.StartsWith(y))).ToList();
|
2016-11-21 19:16:14 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-17 21:49:05 -05:00
|
|
|
|
|
|
|
|
|
public List<SimpleNic> WirelessNics {
|
|
|
|
|
get {
|
|
|
|
|
return NetState.Nics.Where(x => x.InterfaceType != "Ethernet").Where(x => !NetState.IgnoreAdapters.Any(y => x.Description.StartsWith(y))).ToList();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public List<NetworkInterface> IgnoredNics {
|
|
|
|
|
get {
|
|
|
|
|
if (NetState == null) return null;
|
|
|
|
|
var n = NetworkInterface.GetAllNetworkInterfaces();
|
|
|
|
|
|
|
|
|
|
return n.Where(x => NetState.IgnoreAdapters.Any(y => x.Description.StartsWith(y))).ToList();
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-11-21 19:16:59 -05:00
|
|
|
|
|
2016-12-17 21:49:05 -05:00
|
|
|
|
|
|
|
|
|
public List<string> Whitelist {
|
2016-11-21 19:16:14 -05:00
|
|
|
|
get {
|
|
|
|
|
if (NetState == null) return null;
|
2016-12-17 21:49:05 -05:00
|
|
|
|
return NetState.IgnoreAdapters;
|
2016-11-21 19:16:14 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
2016-11-17 13:37:57 -05:00
|
|
|
|
|
2016-11-18 23:28:53 -05:00
|
|
|
|
|
|
|
|
|
public string ServiceState {
|
|
|
|
|
get {
|
2016-11-21 17:27:34 -05:00
|
|
|
|
ServiceControllerStatus status;
|
|
|
|
|
try { if (_sc == null) _sc = new ServiceController("WifiSitter"); status = _sc.Status; }
|
2016-11-18 23:28:53 -05:00
|
|
|
|
catch { return "No Service"; }
|
|
|
|
|
|
|
|
|
|
_sc.Refresh();
|
2016-11-21 17:27:34 -05:00
|
|
|
|
switch (status) {
|
2016-11-18 23:28:53 -05:00
|
|
|
|
case ServiceControllerStatus.Running:
|
|
|
|
|
return "Running";
|
|
|
|
|
case ServiceControllerStatus.Stopped:
|
|
|
|
|
return "Stopped";
|
|
|
|
|
case ServiceControllerStatus.Paused:
|
|
|
|
|
return "Paused";
|
|
|
|
|
case ServiceControllerStatus.StopPending:
|
|
|
|
|
return "Stopping";
|
|
|
|
|
case ServiceControllerStatus.StartPending:
|
|
|
|
|
return "Starting";
|
|
|
|
|
default:
|
|
|
|
|
return "Status Changing";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-15 17:04:48 -05:00
|
|
|
|
#endregion // properties
|
|
|
|
|
|
2016-11-15 20:33:07 -05:00
|
|
|
|
|
2016-11-15 17:04:48 -05:00
|
|
|
|
#region methods
|
|
|
|
|
#endregion // methods
|
|
|
|
|
|
2016-11-15 20:33:07 -05:00
|
|
|
|
|
2016-11-15 17:04:48 -05:00
|
|
|
|
#region eventhandlers
|
|
|
|
|
#endregion // methods
|
|
|
|
|
}
|
|
|
|
|
}
|