public async void Broadcast(string eventType, IEvent evt) { using (var wsc = new ClientWebSocket()) { var uri = new Uri(_appSettingsRetriever.GetValue("WebSocket:Url")); await wsc.ConnectAsync(uri, CancellationToken.None); var evtToSend = new { PayloadType = eventType, Payload = Serialize(evt) }; var buffer = System.Text.Encoding.UTF8.GetBytes( JsonConvert.SerializeObject(new { action = "sendMessage", data = Serialize(evtToSend) })); var message = new ArraySegment <byte>(buffer); await wsc.SendAsync(message, WebSocketMessageType.Text, true, CancellationToken.None); await wsc.CloseAsync(WebSocketCloseStatus.NormalClosure, string.Empty, CancellationToken.None); } }
/// <summary> /// Returns a string representation of this application setting /// </summary> /// <param name="key"></param> /// <returns></returns> private string GetString(string key) { return(Config.GetValue(key) ?? ""); }