async Task UnsubscribeAndClose(InfoWebSocketConnection connection) { Unsubscribe(connection); await connection.CloseConnection(); connection.Dispose(); }
public async Task <BaseResponse> HandleCommand(InfoWebSocketConnection infoWebSocket, BaseCommand command) { if (!handlers.ContainsKey(command.Command)) { throw new NotSupportedException($"Command {command.Command} is not supported."); } return(await handlers[command.Command].Handle(infoWebSocket, command)); }
/// <summary> /// Registers new client websocket connection /// </summary> /// <param name="webSocket">New websocket connection</param> public async Task OnNewConnection(WebSocket webSocket, string connectionId, string ip) { var connection = new InfoWebSocketConnection(Context, webSocket, connectionId, ip); Subscribe(connection); if (!connections.TryAdd(connectionId, connection)) { throw new Exception($"Connection with id {connectionId} already exists."); } await connection.Listen(); }
public override Task <BaseResponse> Handle(InfoWebSocketConnection infoWebSocket, UnsubscribeCommand command) { if (command.Subscriptions.Count < 0) { throw new BadRequestException("At least one subscription must be specified."); } foreach (var subs in command.Subscriptions) { var subscription = Context.SubscriptionsManager.GetOrAddSubscription(BaseSubscription.GetBySubscriptionName(subs)); infoWebSocket.RemoveSubsctioption(subscription); } return(Task.FromResult((BaseResponse) new SuccesResponse { RequestId = command.RequestId })); }
public override async Task <BaseResponse> Handle(InfoWebSocketConnection infoWebSocket, GetPriceHistoryCommand command) { var asset = Context.Constellation.Assets.FirstOrDefault(a => a.Id == command.Market); if (asset == null && asset.IsXlm) { throw new BadRequestException("Invalid market."); } var res = await Context.AnalyticsManager.PriceHistoryManager.GetPriceHistory(command.Cursor, command.Market, command.Period); return(new PriceHistoryResponse { RequestId = command.RequestId, PriceHistory = res.frames, NextCursor = res.nextCursor }); }
async Task SendSubscriptionUpdate(BaseSubscription subscription, SubscriptionUpdateBase update, InfoWebSocketConnection connection) { await connection.SendSubscriptionUpdate(subscription, update); }
void Unsubscribe(InfoWebSocketConnection connection) { connection.OnClosed -= OnClosed; }
void Subscribe(InfoWebSocketConnection connection) { connection.OnClosed += OnClosed; }
void RemoveConnection(InfoWebSocketConnection connection) { _ = UnsubscribeAndClose(connection); connections.TryRemove(connection.ConnectionId, out _); }