private void Relay <T>(WsNotificationType type) { messageBus.Listen <T>() .Select(x => Observable.FromAsync(() => BroadcastNotification(type, x))) .Concat() .Subscribe(); }
private string ToJson <T>(WsNotificationType type, T msg) { var result = JObject.FromObject(msg, serializer); result["type"] = type.ToString().ToLower(); return(result.ToString(Formatting.None)); }
private async Task BroadcastNotification <T>(WsNotificationType type, T notification) { try { var json = ToJson(type, notification); var msg = new Message { MessageType = MessageType.TextRaw, Data = json }; await SendMessageToAllAsync(msg); } catch (Exception ex) { logger.Error(ex); } }