Now passing simplified network state to client.
parent
d9ceeedeff
commit
0b444d04c2
|
@ -22,6 +22,9 @@ namespace WifiSitter
|
||||||
|
|
||||||
|
|
||||||
#region constructor
|
#region constructor
|
||||||
|
public NetworkState() {
|
||||||
|
Initialize();
|
||||||
|
}
|
||||||
|
|
||||||
public NetworkState(string[] NicWhitelist) {
|
public NetworkState(string[] NicWhitelist) {
|
||||||
if (NicWhitelist == null)
|
if (NicWhitelist == null)
|
|
@ -0,0 +1,50 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using WifiSitter;
|
||||||
|
|
||||||
|
namespace WifiSitter.Model
|
||||||
|
{
|
||||||
|
[Serializable]
|
||||||
|
public class SimpleNetworkState
|
||||||
|
{
|
||||||
|
public bool EthernetUp { get; set; }
|
||||||
|
public bool CheckNet { get; set; }
|
||||||
|
public List<SimpleNic> Nics { get; set; }
|
||||||
|
public bool NetworkAvailable { get; set; }
|
||||||
|
public bool ProcessingState { get; set; }
|
||||||
|
|
||||||
|
public SimpleNetworkState() { }
|
||||||
|
|
||||||
|
public SimpleNetworkState(NetworkState netstate) {
|
||||||
|
NetworkAvailable = netstate.NetworkAvailable;
|
||||||
|
ProcessingState = netstate.ProcessingState;
|
||||||
|
EthernetUp = netstate.EthernetUp;
|
||||||
|
CheckNet = netstate.CheckNet;
|
||||||
|
Nics = netstate.Nics.Select(x => new SimpleNic(x)).ToList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[Serializable]
|
||||||
|
public class SimpleNic {
|
||||||
|
public bool IsEnabled { get; set; }
|
||||||
|
public bool IsConnected { get; set; }
|
||||||
|
public string Name { get; set; }
|
||||||
|
public string Description { get; set; }
|
||||||
|
public string Id { get; set; }
|
||||||
|
public string InterfaceType { get; set; }
|
||||||
|
|
||||||
|
public SimpleNic() { }
|
||||||
|
|
||||||
|
public SimpleNic(TrackedNic nic) {
|
||||||
|
IsEnabled = nic.IsEnabled;
|
||||||
|
IsConnected = nic.IsConnected;
|
||||||
|
Name = nic.Name;
|
||||||
|
Description = nic.Description;
|
||||||
|
Id = nic.Id;
|
||||||
|
InterfaceType = nic.Nic.NetworkInterfaceType.ToString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -17,6 +17,10 @@ namespace WifiSitter
|
||||||
private bool _isEnabled;
|
private bool _isEnabled;
|
||||||
private bool _isConnected;
|
private bool _isConnected;
|
||||||
|
|
||||||
|
public TrackedNic() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
#region constructor
|
#region constructor
|
||||||
public TrackedNic(NetworkInterface Nic) {
|
public TrackedNic(NetworkInterface Nic) {
|
||||||
this._nic = Nic;
|
this._nic = Nic;
|
||||||
|
@ -34,6 +38,7 @@ namespace WifiSitter
|
||||||
|
|
||||||
public NetworkInterface Nic {
|
public NetworkInterface Nic {
|
||||||
get { return _nic; }
|
get { return _nic; }
|
||||||
|
set { _nic = value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool IsEnabled {
|
public bool IsEnabled {
|
||||||
|
@ -42,6 +47,12 @@ namespace WifiSitter
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public bool IsConnected {
|
||||||
|
get { return _isConnected; }
|
||||||
|
set { _isConnected = value; }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public string Name {
|
public string Name {
|
||||||
get { return Nic.Name; }
|
get { return Nic.Name; }
|
||||||
}
|
}
|
||||||
|
@ -56,12 +67,6 @@ namespace WifiSitter
|
||||||
get { return Nic.Id; }
|
get { return Nic.Id; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public bool IsConnected {
|
|
||||||
get { return _isConnected; }
|
|
||||||
set { _isConnected = value; }
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion // properties
|
#endregion // properties
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,64 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.IO;
|
||||||
|
using System.Runtime.Serialization.Formatters.Binary;
|
||||||
|
|
||||||
|
namespace WifiSitter
|
||||||
|
{
|
||||||
|
[Serializable]
|
||||||
|
public class WifiSitterIpcMessage
|
||||||
|
{
|
||||||
|
public string Request { get; set; }
|
||||||
|
public string Requestor { get; set; }
|
||||||
|
public string Target { get; set; }
|
||||||
|
public byte[] Payload { get; set; }
|
||||||
|
public Type PayloadType { get; set; }
|
||||||
|
|
||||||
|
public WifiSitterIpcMessage() { }
|
||||||
|
|
||||||
|
public WifiSitterIpcMessage(string Verb, string WhosAsking, string WhereTo, string SendingWhat = "") {
|
||||||
|
Request = Verb;
|
||||||
|
Requestor = WhosAsking;
|
||||||
|
Target = WhereTo;
|
||||||
|
Payload = System.Text.Encoding.UTF8.GetBytes(SendingWhat);
|
||||||
|
PayloadType = typeof(string);
|
||||||
|
}
|
||||||
|
|
||||||
|
public WifiSitterIpcMessage(string Verb, string WhosAsking, string WhereTo, object SendingWhat, Type type) {
|
||||||
|
Request = Verb;
|
||||||
|
Requestor = WhosAsking;
|
||||||
|
Target = WhereTo;
|
||||||
|
Payload = SendingWhat.ObjectToByteArray();
|
||||||
|
PayloadType = SendingWhat.GetType();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class WifiSitterExtensions
|
||||||
|
{
|
||||||
|
public static string IpcMessageJsonString(this WifiSitterIpcMessage message) {
|
||||||
|
string result;
|
||||||
|
result = Newtonsoft.Json.JsonConvert.SerializeObject(message);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static byte[] ObjectToByteArray(this object obj) {
|
||||||
|
BinaryFormatter bf = new BinaryFormatter();
|
||||||
|
using (var ms = new MemoryStream()) {
|
||||||
|
bf.Serialize(ms, obj);
|
||||||
|
return ms.ToArray();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Object ByteArrayToObject(this byte[] arrBytes) {
|
||||||
|
using (var memStream = new MemoryStream()) {
|
||||||
|
var binForm = new BinaryFormatter();
|
||||||
|
memStream.Write(arrBytes, 0, arrBytes.Length);
|
||||||
|
memStream.Seek(0, SeekOrigin.Begin);
|
||||||
|
var obj = binForm.Deserialize(memStream);
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -369,13 +369,13 @@ namespace WifiSitter
|
||||||
|
|
||||||
WifiSitterIpcMessage _msg = null;
|
WifiSitterIpcMessage _msg = null;
|
||||||
try { _msg = Newtonsoft.Json.JsonConvert.DeserializeObject<WifiSitterIpcMessage>(e.DataGram.Message); }
|
try { _msg = Newtonsoft.Json.JsonConvert.DeserializeObject<WifiSitterIpcMessage>(e.DataGram.Message); }
|
||||||
catch { Trace.WriteLine("Deserialize to ServiceRequest failed."); }
|
catch { LogLine("Deserialize to WifiSitterIpcMessage failed."); }
|
||||||
|
|
||||||
if (_msg != null) {
|
if (_msg != null) {
|
||||||
if (_msg.Request == "get_netstate") {
|
if (_msg.Request == "get_netstate") {
|
||||||
LogLine("Sending netstate to: {0}", _msg.Requestor);
|
LogLine("Sending netstate to: {0}", _msg.Requestor);
|
||||||
var response = new WifiSitterIpcMessage("give_netstate", _wsIpc.MyChannelName, "", Newtonsoft.Json.JsonConvert.SerializeObject(netstate));
|
var response = new WifiSitterIpcMessage("give_netstate", _wsIpc.MyChannelName, "", Newtonsoft.Json.JsonConvert.SerializeObject(new Model.SimpleNetworkState(netstate)));
|
||||||
_wsIpc.MsgBroadcaster.SendToChannel(_msg.Target, response);
|
_wsIpc.MsgBroadcaster.SendToChannel(_msg.Target, response.IpcMessageJsonString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -109,15 +109,16 @@
|
||||||
<Compile Include="Helpers\Interop.cs" />
|
<Compile Include="Helpers\Interop.cs" />
|
||||||
<Compile Include="Helpers\NativeWifi.cs" />
|
<Compile Include="Helpers\NativeWifi.cs" />
|
||||||
<Compile Include="Helpers\NetshHelper.cs" />
|
<Compile Include="Helpers\NetshHelper.cs" />
|
||||||
<Compile Include="NetworkState.cs" />
|
<Compile Include="Model\NetworkState.cs" />
|
||||||
|
<Compile Include="Model\SimpleNetworkState.cs" />
|
||||||
<Compile Include="Program.cs" />
|
<Compile Include="Program.cs" />
|
||||||
<Compile Include="WifiSitter.cs">
|
<Compile Include="WifiSitter.cs">
|
||||||
<SubType>Component</SubType>
|
<SubType>Component</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="SitterNic.cs" />
|
<Compile Include="Model\SitterNic.cs" />
|
||||||
<Compile Include="WifiSitterIpc.cs" />
|
<Compile Include="WifiSitterIpc.cs" />
|
||||||
<Compile Include="WifiSitterIpcMessage.cs" />
|
<Compile Include="Model\WifiSitterIpcMessage.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="App.config" />
|
<None Include="App.config" />
|
||||||
|
@ -148,7 +149,7 @@
|
||||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
<ProjectExtensions>
|
<ProjectExtensions>
|
||||||
<VisualStudio>
|
<VisualStudio>
|
||||||
<UserProperties BuildVersion_UpdateFileVersion="False" BuildVersion_BuildVersioningStyle="None.None.None.Increment" BuildVersion_StartDate="2000/1/1" />
|
<UserProperties BuildVersion_StartDate="2000/1/1" BuildVersion_BuildVersioningStyle="None.None.None.Increment" BuildVersion_UpdateFileVersion="False" />
|
||||||
</VisualStudio>
|
</VisualStudio>
|
||||||
</ProjectExtensions>
|
</ProjectExtensions>
|
||||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||||
|
|
|
@ -1,32 +0,0 @@
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace WifiSitter
|
|
||||||
{
|
|
||||||
[Serializable]
|
|
||||||
public class WifiSitterIpcMessage
|
|
||||||
{
|
|
||||||
public string Request { get; set; }
|
|
||||||
public string Requestor { get; set; }
|
|
||||||
public string Target { get; set; }
|
|
||||||
public string Payload { get; set; }
|
|
||||||
|
|
||||||
public WifiSitterIpcMessage(string Verb, string WhosAsking, string WhereTo, string SendingWhat = "") {
|
|
||||||
Request = Verb;
|
|
||||||
Requestor = WhosAsking;
|
|
||||||
Target = WhereTo;
|
|
||||||
Payload = SendingWhat;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class WifiSitterExtensions
|
|
||||||
{
|
|
||||||
public static string IpcMessageJsonString(this WifiSitterIpcMessage message) {
|
|
||||||
string result;
|
|
||||||
result = Newtonsoft.Json.JsonConvert.SerializeObject(message);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -17,7 +17,7 @@
|
||||||
<tb:TaskbarIcon
|
<tb:TaskbarIcon
|
||||||
x:Name="TaskBarIcon"
|
x:Name="TaskBarIcon"
|
||||||
IconSource="pack://application:,,,/Resources/wifisitter-icon.ico"
|
IconSource="pack://application:,,,/Resources/wifisitter-icon.ico"
|
||||||
ToolTipText="hello world"
|
ToolTipText="WifiSitter Agent"
|
||||||
MenuActivation="LeftOrRightClick"
|
MenuActivation="LeftOrRightClick"
|
||||||
NoLeftClickDelay="True">
|
NoLeftClickDelay="True">
|
||||||
<tb:TaskbarIcon.ContextMenu>
|
<tb:TaskbarIcon.ContextMenu>
|
||||||
|
@ -30,7 +30,7 @@
|
||||||
<MenuItem Header="Quit"
|
<MenuItem Header="Quit"
|
||||||
Click="ContextMenu_Quit"
|
Click="ContextMenu_Quit"
|
||||||
Icon="{StaticResource CloseIcon}"
|
Icon="{StaticResource CloseIcon}"
|
||||||
/>
|
ToolTip="Does not stop WifiSitter service." />
|
||||||
</ContextMenu>
|
</ContextMenu>
|
||||||
</tb:TaskbarIcon.ContextMenu>
|
</tb:TaskbarIcon.ContextMenu>
|
||||||
</tb:TaskbarIcon>
|
</tb:TaskbarIcon>
|
||||||
|
|
|
@ -15,6 +15,7 @@ using System.Diagnostics;
|
||||||
|
|
||||||
using WifiSitterGui.ViewModel;
|
using WifiSitterGui.ViewModel;
|
||||||
using WifiSitter;
|
using WifiSitter;
|
||||||
|
using WifiSitter.Model;
|
||||||
|
|
||||||
using XDMessaging;
|
using XDMessaging;
|
||||||
|
|
||||||
|
@ -78,7 +79,8 @@ namespace WifiSitterGui
|
||||||
}
|
}
|
||||||
|
|
||||||
private void GetServiceChannelName() {
|
private void GetServiceChannelName() {
|
||||||
var serviceProc = Process.GetProcesses().Where(x => x.ProcessName.ToLower() == "wifisitter").ToArray();
|
var serviceProc = Process.GetProcesses().Where(x => x.ProcessName.ToLower().StartsWith("wifisitter"))
|
||||||
|
.Where(x => !x.ProcessName.ToLower().Contains("gui")).ToArray();
|
||||||
if (serviceProc != null &&
|
if (serviceProc != null &&
|
||||||
serviceProc.Length > 0) {
|
serviceProc.Length > 0) {
|
||||||
_serviceChannel = String.Format("{0}-{1}", serviceProc[0].Id, serviceProc[0].ProcessName);
|
_serviceChannel = String.Format("{0}-{1}", serviceProc[0].Id, serviceProc[0].ProcessName);
|
||||||
|
@ -134,9 +136,9 @@ namespace WifiSitterGui
|
||||||
if (_sr != null) {
|
if (_sr != null) {
|
||||||
if (_sr.Request == "give_netstate") {
|
if (_sr.Request == "give_netstate") {
|
||||||
try {
|
try {
|
||||||
WifiSitter.NetworkState ns = Newtonsoft.Json.JsonConvert.DeserializeObject<WifiSitter.NetworkState>(_sr.Payload);
|
_windowVm.NetState = Newtonsoft.Json.JsonConvert.DeserializeObject<SimpleNetworkState>(System.Text.Encoding.UTF8.GetString(_sr.Payload));
|
||||||
}
|
}
|
||||||
catch { WifiSitter.WifiSitter.LogLine("Failed to deserialize netstate, payload: {0}", _sr.Payload); }
|
catch { WifiSitter.WifiSitter.LogLine("Failed to deserialize netstate, payload."); }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -4,6 +4,7 @@ using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
using WifiSitter;
|
using WifiSitter;
|
||||||
|
using WifiSitter.Model;
|
||||||
|
|
||||||
namespace WifiSitterGui.ViewModel
|
namespace WifiSitterGui.ViewModel
|
||||||
{
|
{
|
||||||
|
@ -11,7 +12,7 @@ namespace WifiSitterGui.ViewModel
|
||||||
{
|
{
|
||||||
#region fields
|
#region fields
|
||||||
|
|
||||||
WifiSitter.NetworkState _netState;
|
SimpleNetworkState _netState;
|
||||||
|
|
||||||
#endregion // fields
|
#endregion // fields
|
||||||
|
|
||||||
|
@ -19,7 +20,7 @@ namespace WifiSitterGui.ViewModel
|
||||||
#region constructor
|
#region constructor
|
||||||
|
|
||||||
public MainWindowViewModel () {
|
public MainWindowViewModel () {
|
||||||
_netState = new NetworkState(new string[] { });
|
_netState = new SimpleNetworkState();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion // constructor
|
#endregion // constructor
|
||||||
|
@ -27,9 +28,9 @@ namespace WifiSitterGui.ViewModel
|
||||||
|
|
||||||
#region properties
|
#region properties
|
||||||
|
|
||||||
public NetworkState NetState {
|
public SimpleNetworkState NetState {
|
||||||
get { return _netState; }
|
get { return _netState; }
|
||||||
set { _netState = value; }
|
set { _netState = value; OnPropertyChanged("NetState"); }
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion // properties
|
#endregion // properties
|
||||||
|
|
|
@ -73,18 +73,19 @@
|
||||||
<Compile Include="..\WifiSitter\Helpers\NetshHelper.cs">
|
<Compile Include="..\WifiSitter\Helpers\NetshHelper.cs">
|
||||||
<Link>Model\NetshHelper.cs</Link>
|
<Link>Model\NetshHelper.cs</Link>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="..\WifiSitter\NetworkState.cs">
|
<Compile Include="..\WifiSitter\Model\NetworkState.cs">
|
||||||
<Link>Model\NetworkState.cs</Link>
|
<Link>Model\NetworkState.cs</Link>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="..\WifiSitter\SitterNic.cs">
|
<Compile Include="..\WifiSitter\Model\SimpleNetworkState.cs">
|
||||||
|
<Link>Model\SimpleNetworkState.cs</Link>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="..\WifiSitter\Model\SitterNic.cs">
|
||||||
<Link>Model\SitterNic.cs</Link>
|
<Link>Model\SitterNic.cs</Link>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="..\WifiSitter\WifiSitterIpc.cs">
|
<Compile Include="..\WifiSitter\WifiSitterIpc.cs">
|
||||||
<Link>WifiSitterIpc.cs</Link>
|
<Link>WifiSitterIpc.cs</Link>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="..\WifiSitter\WifiSitterIpcMessage.cs">
|
<Compile Include="Model\WifiSitterIpcMessage.cs" />
|
||||||
<Link>WifiSitterIpcMessage.cs</Link>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="Model\WifiSitterStub.cs" />
|
<Compile Include="Model\WifiSitterStub.cs" />
|
||||||
<Compile Include="TrayIconControl.xaml.cs">
|
<Compile Include="TrayIconControl.xaml.cs">
|
||||||
<DependentUpon>TrayIconControl.xaml</DependentUpon>
|
<DependentUpon>TrayIconControl.xaml</DependentUpon>
|
||||||
|
|
Loading…
Reference in New Issue