public WebSocketMiddleware(RequestDelegate next, DeliveryStore store) { _next = next; store.newDelivery += (_, delivery) => { _sockets.Values .Where(socket => socket.State == WebSocketState.Open) .ToList() .ForEach(async socket => { var message = new { Sms = delivery.ReceiverInfo.Sms, Address = delivery.ReceiverInfo.Address, OrderId = delivery.ReferenceId }; var text = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(message, _camelCaseSettings)); var buffer = new ArraySegment <byte>(text); await socket.SendAsync(buffer, WebSocketMessageType.Text, true, _token); }); }; }
public DeliveryController(DeliveryStore store) => _store = store;
public NotifyBackgroundService(IHttpClientFactory httpClient, DeliveryStore store) { _httpClient = httpClient; _store = store; }