Example #1
0
        private void OnUnsubscribe(BitfinexWebSocketWrapper webSocket, Messages.ChannelUnsubscribing data)
        {
            try
            {
                lock (_locker)
                {
                    List <BitfinexChannel> channels;
                    if (!_channelsByWebSocket.TryGetValue(webSocket, out channels))
                    {
                        return;
                    }

                    channels.Remove(channels.First(x => x.ChannelId == data.ChannelId));

                    if (channels.Count != 0)
                    {
                        return;
                    }

                    _channelsByWebSocket.TryRemove(webSocket, out channels);
                }

                webSocket.Close();
                webSocket.ConnectionHandler.DisposeSafely();
            }
            catch (Exception e)
            {
                Log.Error(e);
                throw;
            }
        }
Example #2
0
        private void OnUnsubscribe(BitfinexWebSocketWrapper webSocket, Messages.ChannelUnsubscribing data)
        {
            try
            {
                lock (_locker)
                {
                    Channel channel;
                    if (!_channels.TryRemove(data.ChannelId, out channel))
                    {
                        return;
                    }

                    _onUnsubscribeEvent.Set();

                    List <Channel> channels;
                    if (!_channelsByWebSocket.TryGetValue(webSocket, out channels))
                    {
                        return;
                    }

                    channels.Remove(channel);

                    if (channels.Count(c => c.Symbol.Equals(channel.Symbol)) == 0)
                    {
                        List <BitfinexWebSocketWrapper> subscriptions;
                        if (_subscriptionsBySymbol.TryGetValue(channel.Symbol, out subscriptions))
                        {
                            subscriptions.Remove(webSocket);

                            if (subscriptions.Count == 0)
                            {
                                _subscriptionsBySymbol.TryRemove(channel.Symbol, out subscriptions);
                            }
                        }
                    }

                    if (channels.Count != 0)
                    {
                        return;
                    }

                    _channelsByWebSocket.TryRemove(webSocket, out channels);
                }

                webSocket.Close();
                webSocket.ConnectionHandler.DisposeSafely();
            }
            catch (Exception e)
            {
                Log.Error(e);
                throw;
            }
        }
 private void OnUnsubscribe(Messages.ChannelUnsubscribing data)
 {
     try
     {
         lock (channelLocker)
         {
             ChannelList.Remove(data.ChannelId);
         }
     }
     catch (Exception e)
     {
         Log.Error(e);
         throw;
     }
 }