示例#1
0
        async Task UnsubscribeAndClose(InfoWebSocketConnection connection)
        {
            Unsubscribe(connection);
            await connection.CloseConnection();

            connection.Dispose();
        }
示例#2
0
 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));
 }
示例#3
0
        /// <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
            });
        }
示例#6
0
 async Task SendSubscriptionUpdate(BaseSubscription subscription, SubscriptionUpdateBase update, InfoWebSocketConnection connection)
 {
     await connection.SendSubscriptionUpdate(subscription, update);
 }
示例#7
0
 void Unsubscribe(InfoWebSocketConnection connection)
 {
     connection.OnClosed -= OnClosed;
 }
示例#8
0
 void Subscribe(InfoWebSocketConnection connection)
 {
     connection.OnClosed += OnClosed;
 }
示例#9
0
 void RemoveConnection(InfoWebSocketConnection connection)
 {
     _ = UnsubscribeAndClose(connection);
     connections.TryRemove(connection.ConnectionId, out _);
 }