示例#1
0
 private void Relay <T>(WsNotificationType type)
 {
     messageBus.Listen <T>()
     .Select(x => Observable.FromAsync(() => BroadcastNotification(type, x)))
     .Concat()
     .Subscribe();
 }
示例#2
0
        private string ToJson <T>(WsNotificationType type, T msg)
        {
            var result = JObject.FromObject(msg, serializer);

            result["type"] = type.ToString().ToLower();

            return(result.ToString(Formatting.None));
        }
示例#3
0
        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);
            }
        }