fix serialization issue.

Apparently the JSON parser uses this same serialization method under the hood to create objects from JSON.
This commit is contained in:
Grant Limberg 2016-11-10 15:21:54 -08:00
parent fd71ceeab5
commit 71aadcbecb
2 changed files with 52 additions and 42 deletions

View File

@ -13,18 +13,18 @@ namespace WinUI
{
protected NetworkRoute(SerializationInfo info, StreamingContext ctx)
{
Target = info.GetString("Target");
Via = info.GetString("Via");
Flags = info.GetInt32("Flags");
Metric = info.GetInt32("Metric");
Target = info.GetString("target");
Via = info.GetString("via");
Flags = info.GetInt32("flags");
Metric = info.GetInt32("metric");
}
public virtual void GetObjectData(SerializationInfo info, StreamingContext ctx)
{
info.AddValue("Target", Target);
info.AddValue("Via", Via);
info.AddValue("Flags", Flags);
info.AddValue("Metric", Metric);
info.AddValue("target", Target);
info.AddValue("via", Via);
info.AddValue("flags", Flags);
info.AddValue("metric", Metric);
}
[JsonProperty("target")]

View File

@ -13,45 +13,49 @@ namespace WinUI
{
protected ZeroTierNetwork(SerializationInfo info, StreamingContext ctx)
{
NetworkId = info.GetString("NetworkId");
MacAddress = info.GetString("MacAddress");
NetworkName = info.GetString("NetworkName");
NetworkStatus = info.GetString("NetworkStatus");
NetworkType = info.GetString("NetworkType");
MTU = info.GetInt32("MTU");
DHCP = info.GetBoolean("DHCP");
Bridge = info.GetBoolean("Bridge");
BroadcastEnabled = info.GetBoolean("BroadcastEnabled");
PortError = info.GetInt32("PortError");
NetconfRevision = info.GetInt32("NetconfRevision");
AssignedAddresses = (string[])info.GetValue("AssignedAddresses", typeof(string[]));
Routes = (NetworkRoute[])info.GetValue("Routes", typeof(NetworkRoute[]));
DeviceName = info.GetString("DeviceName");
AllowManaged = info.GetBoolean("AllowManaged");
AllowGlobal = info.GetBoolean("AllowGlobal");
AllowDefault = info.GetBoolean("AllowDefault");
try
{
NetworkId = info.GetString("nwid");
MacAddress = info.GetString("mac");
NetworkName = info.GetString("name");
NetworkStatus = info.GetString("status");
NetworkType = info.GetString("type");
MTU = info.GetInt32("mtu");
DHCP = info.GetBoolean("dhcp");
Bridge = info.GetBoolean("bridge");
BroadcastEnabled = info.GetBoolean("broadcastEnabled");
PortError = info.GetInt32("portError");
NetconfRevision = info.GetInt32("netconfRevision");
AssignedAddresses = (string[])info.GetValue("assignedAddresses", typeof(string[]));
Routes = (NetworkRoute[])info.GetValue("routes", typeof(NetworkRoute[]));
DeviceName = info.GetString("portDeviceName");
AllowManaged = info.GetBoolean("allowManaged");
AllowGlobal = info.GetBoolean("allowGlobal");
AllowDefault = info.GetBoolean("allowDefault");
}
catch { }
IsConnected = false;
}
public virtual void GetObjectData(SerializationInfo info, StreamingContext ctx)
{
info.AddValue("NetworkId", NetworkId);
info.AddValue("MacAddress", MacAddress);
info.AddValue("NetworkName", NetworkName);
info.AddValue("NetworkStatus", NetworkStatus);
info.AddValue("NetworkType", NetworkType);
info.AddValue("MTU", MTU);
info.AddValue("DHCP", DHCP);
info.AddValue("Bridge", Bridge);
info.AddValue("BroadcastEnabled", BroadcastEnabled);
info.AddValue("PortError", PortError);
info.AddValue("NetconfRevision", NetconfRevision);
info.AddValue("AssignedAddresses", AssignedAddresses);
info.AddValue("Routes", Routes);
info.AddValue("DeviceName", DeviceName);
info.AddValue("AllowManaged", AllowManaged);
info.AddValue("AllowGlobal", AllowGlobal);
info.AddValue("AllowDefault", AllowDefault);
info.AddValue("nwid", NetworkId);
info.AddValue("mac", MacAddress);
info.AddValue("name", NetworkName);
info.AddValue("status", NetworkStatus);
info.AddValue("type", NetworkType);
info.AddValue("mtu", MTU);
info.AddValue("dhcp", DHCP);
info.AddValue("bridge", Bridge);
info.AddValue("broadcastEnabled", BroadcastEnabled);
info.AddValue("portError", PortError);
info.AddValue("netconfRevision", NetconfRevision);
info.AddValue("assignedAddresses", AssignedAddresses);
info.AddValue("routes", Routes);
info.AddValue("portDeviceName", DeviceName);
info.AddValue("allowManaged", AllowManaged);
info.AddValue("allowGlobal", AllowGlobal);
info.AddValue("allowDefault", AllowDefault);
}
@ -126,11 +130,17 @@ namespace WinUI
public bool Equals(ZeroTierNetwork network)
{
if (NetworkId == null || network == null)
return false;
return NetworkId.Equals(network.NetworkId);
}
public int CompareTo(ZeroTierNetwork network)
{
if (NetworkId == null || network == null)
return -1;
UInt64 thisNwid = UInt64.Parse(NetworkId, System.Globalization.NumberStyles.HexNumber);
UInt64 otherNwid = UInt64.Parse(network.NetworkId, System.Globalization.NumberStyles.HexNumber);