Example #1
0
        public async Task <Task> RegisterStreamAsync(StreamInfo <T> streamInfo, List <T> initData = null)
        {
            var data = StreamData <T> .Create(streamInfo, initData);

            _lock.EnterWriteLock();

            try
            {
                _streamList.Add(data);
            }
            finally
            {
                _lock.ExitWriteLock();
            }

            if (initData == null)
            {
                return(data.CompletionTask.Task);
            }

            var tasks = initData.Select(value => WriteStreamAsync(data, value)).ToList();

            await Task.WhenAll(tasks);

            return(data.CompletionTask.Task);
        }
Example #2
0
        private void RemoveStream(StreamData <T> streamData)
        {
            _lock.EnterWriteLock();
            try
            {
                streamData.CompletionTask.TrySetResult(1);
                _streamList.Remove(streamData);
            }
            finally
            {
                _lock.ExitWriteLock();
            }

            Console.WriteLine($"Remove stream connect (peer: {streamData.Peer})");
        }
Example #3
0
 private async Task WriteStreamAsync(StreamData <T> streamData, T data)
 {
     try
     {
         await streamData.Stream.WriteAsync(data);
     }
     catch (InvalidOperationException)
     {
         RemoveStream(streamData);
     }
     catch (Exception e)
     {
         _log.Error(e, "Can't write to stream", context: streamData.Peer);
         RemoveStream(streamData);
     }
 }
Example #4
0
        private Orderbook GetOrderbook(Orderbook data, StreamData <Orderbook> streamData, bool updateDate)
        {
            if (streamData.LastSentData == null)
            {
                return(data);
            }

            Orderbook update = _orderbooksService.GetOrderbookUpdates(streamData.LastSentData, data);

            if (updateDate)
            {
                update.Timestamp = Timestamp.FromDateTime(DateTime.UtcNow);
            }

            return(update);
        }
Example #5
0
 internal override PublicTradeUpdate ProcessPingDataBeforeSend(PublicTradeUpdate data, StreamData <PublicTradeUpdate> streamData)
 {
     return(new PublicTradeUpdate());
 }
Example #6
0
 internal override Task WriteStreamDataAsync(StreamData <PriceUpdate> streamData, PriceUpdate data)
 {
     _prices[data.AssetPairId] = data;
     return(Task.CompletedTask);
 }
Example #7
0
 protected Task WriteToStreamAsync(StreamData <T> streamData, T data)
 {
     return(WriteStreamAsync(streamData, data));
 }
Example #8
0
 internal virtual Task WriteStreamDataAsync(StreamData <T> streamData, T data)
 {
     return(WriteStreamAsync(streamData, data));
 }
Example #9
0
 internal virtual T ProcessPingDataBeforeSend(T data, StreamData <T> streamData)
 {
     return(data);
 }
Example #10
0
 internal override Orderbook ProcessPingDataBeforeSend(Orderbook data, StreamData <Orderbook> streamData)
 {
     return(GetOrderbook(data, streamData, true));
 }