public void OnAddPeer() { if(!CheckPeer()) { GlobalMessageCenter.Instance.Send("MainWindow.MsgBox", "地址信息格式不对"); return; } var peer = new PeerInfo() { Address = Address, Port = Port, Status = PeerStatus.Unknow, Range = PeerRange.Empty, }; if (!CheckRepeat(peer)) { GlobalMessageCenter.Instance.Send("MainWindow.MsgBox", "已存在该地址"); return; } PeerInfoList.Add(peer); }
private bool CheckRepeat(PeerInfo peer) { return !PeerInfoList.Contains(peer, PeerInfoComparer.Default); }
private static Peer PeerInfo2Peer(PeerInfo info) { IPAddress addr; if (IPAddress.TryParse(info.Address, out addr)) { return new Peer() { EndPoint = new IPEndPoint(addr, info.Port) }; } return null; }