private void HandleConnection(NotificationData notifyObject) { var token = _table.GetOrAdd(notifyObject.Id, _ => { var args = new ConnectionArgs(notifyObject); OnConnected?.Invoke(this, args); return(new InternalTokenized { Data = notifyObject }); }); token.TimeStamp = DateTime.UtcNow.TimeOfDay; }
public RedistLocalConnectionTable(UdpConnectionOption options, RedistributableTableOption tableOption) { OnConnected += delegate { }; OnDisconnected += delegate { }; InitializeListener(options); _registrator = new RedistLocalConnectionTableRegistrator(options.Port, tableOption.NotifyTime); _timer = new AsyncLoopTimer(tableOption.LoopTime, () => { foreach (var value in _table) { if (DateTime.UtcNow.TimeOfDay.Subtract(value.Value.TimeStamp) <= tableOption.ExpirationTime) { continue; } _table.TryRemove(value.Key, out var info); var args = new ConnectionArgs(info.Data); OnDisconnected?.Invoke(this, args); } }); }