private void AddDevice(DeviceRow device) { if (deviceGrid.InvokeRequired) { BeginInvoke(new addDevice(AddDevice), device); } else { _devices.Add(device); } }
private void UpdateCache(string client, string uid) { DeviceRow device = _devices.Where(q => q.ClientCode.Equals(client)).FirstOrDefault(); //_online.TryGetValue(client, out _uid); if (device != null && !string.IsNullOrEmpty(device.UID) && device.UID.Equals(uid)) { return; } if (device == null) { //_online.TryAdd(client, uid); //新增设备列表记录 AsyncUserTokenInfo info = _listener.OnlineUserToken.Where(q => q.UID.Equals(uid)).FirstOrDefault(); if (info != null) { AddDevice(new DeviceRow() { ClientCode = client, UID = uid, ClientIP = info.Remote.Address.ToString(), InTime = info.ConnectTime.ToString(), ModifyTime = info.FreshTime.ToString() }); } //数据库更新上线时间 ConnectionHelper.OnLine(client); } else { string _uid = device.UID; //_online.TryUpdate(client, uid, _uid); device.UID = uid; //如果IP地址变化,则关闭之前的连接 _listener.CloseClientSocket(_uid); } }