mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-04-18 21:16:54 +02:00
update the peer list in place rather than replacing it
This commit is contained in:
parent
df74dd6e41
commit
f3e527e130
2 changed files with 36 additions and 6 deletions
|
@ -29,13 +29,25 @@ namespace WinUI
|
|||
dataGrid.ItemsSource = peersList;
|
||||
}
|
||||
|
||||
public void SetPeers(List<ZeroTierPeer> peerList)
|
||||
public void SetPeers(List<ZeroTierPeer> list)
|
||||
{
|
||||
if (peerList == null)
|
||||
if (list == null)
|
||||
return;
|
||||
|
||||
this.peersList = peerList;
|
||||
dataGrid.ItemsSource = this.peersList;
|
||||
|
||||
foreach(ZeroTierPeer p in list)
|
||||
{
|
||||
ZeroTierPeer curPeer = peersList.Find(peer => peer.Equals(p));
|
||||
if (curPeer == null)
|
||||
{
|
||||
peersList.Add(p);
|
||||
}
|
||||
else
|
||||
{
|
||||
curPeer.Update(p);
|
||||
}
|
||||
}
|
||||
|
||||
dataGrid.Items.Refresh();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ using Newtonsoft.Json;
|
|||
|
||||
namespace WinUI
|
||||
{
|
||||
public class ZeroTierPeer
|
||||
public class ZeroTierPeer : IEquatable<ZeroTierPeer>
|
||||
{
|
||||
[JsonProperty("address")]
|
||||
public string Address { get; set; }
|
||||
|
@ -57,7 +57,7 @@ namespace WinUI
|
|||
public int VersionMinor { get; set; }
|
||||
|
||||
[JsonProperty("versionRev")]
|
||||
public int Versionrev { get; set; }
|
||||
public int VersionRev { get; set; }
|
||||
|
||||
[JsonProperty("version")]
|
||||
public string Version { get; set; }
|
||||
|
@ -94,5 +94,23 @@ namespace WinUI
|
|||
return pathStr;
|
||||
}
|
||||
}
|
||||
|
||||
public bool Equals(ZeroTierPeer other)
|
||||
{
|
||||
return this.Address.Equals(other.Address, StringComparison.InvariantCultureIgnoreCase);
|
||||
}
|
||||
|
||||
public void Update(ZeroTierPeer other)
|
||||
{
|
||||
_lastUnicast = other._lastUnicast;
|
||||
_lastMulticast = other._lastMulticast;
|
||||
VersionMajor = other.VersionMajor;
|
||||
VersionMinor = other.VersionMinor;
|
||||
VersionRev = other.VersionRev;
|
||||
Version = other.Version;
|
||||
Latency = other.Latency;
|
||||
Role = other.Role;
|
||||
Paths = other.Paths;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue