void _referencedObjectDisposed(object o, EventArgs a) { IDto dto = o as IDto; if (dto == null) { return; } var delegatesToRemove = _delegates.Keys.Where(k => k.Item1 == dto.DtoGuid); foreach (var dk in delegatesToRemove) { Delegate delegateToRemove; if (_delegates.TryRemove(dk, out delegateToRemove)) { EventInfo ei = dto.GetType().GetEvent(dk.Item2); ei.RemoveEventHandler(dto, delegateToRemove); Debug.WriteLine($"Server: Delegate {dk.Item2} on {dto} removed;"); } } WebSocketMessage message = new WebSocketMessage() { DtoGuid = dto.DtoGuid, MessageType = WebSocketMessage.WebSocketMessageType.ObjectDisposed, #if DEBUG DtoName = dto.ToString(), #endif }; Send(_serialize(message)); Debug.WriteLine($"Server: ObjectDisposed notification on {dto} sent"); }
void _notifyClient(object o, EventArgs e, string eventName) { IDto dto = o as IDto; if (dto == null) { return; } EventArgs eventArgs; PropertyChangedEventArgs ea = e as PropertyChangedEventArgs; if (ea != null && eventName == nameof(INotifyPropertyChanged.PropertyChanged)) { PropertyInfo p = o.GetType().GetProperty(ea.PropertyName); if (p?.CanRead == true) { eventArgs = new PropertyChangedWithValueEventArgs(ea.PropertyName, p.GetValue(o, null)); } else { eventArgs = new PropertyChangedWithValueEventArgs(ea.PropertyName, null); Debug.WriteLine(o, $"{GetType()}: Couldn't get value of {ea.PropertyName}"); } } else { eventArgs = e; } WebSocketMessage message = new WebSocketMessage() { DtoGuid = dto.DtoGuid, Response = eventArgs, MessageType = WebSocketMessage.WebSocketMessageType.EventNotification, MemberName = eventName, #if DEBUG DtoName = dto.ToString(), #endif }; string s = _serialize(message); Send(s); //Debug.WriteLine($"Server: Notification {eventName} on {dto} sent:\n{s}"); }