Ejemplo n.º 1
0
        private void ParallelNotify(ApiFeedResponse response)
        {
            var msg  = response.JContent;
            var type = msg.Value <string>("type");

            if ("error" == type)
            {
                var message = msg.Value <string>("message");
                var reason  = msg.Value <string>("reason");
                this.observableManager.ParallelFaultAsync(new GdaxFeedApiException($"{message}. {reason}."));
            }

            this.observableManager.ParallelNotifyAsync(msg);
        }
Ejemplo n.º 2
0
        private async Task ReceiveLoop(CancellationToken ct)
        {
            var buffer     = new byte[1024 * 8];
            var offset     = 0;
            var count      = buffer.Length;
            var maxSegment = new ArraySegment <byte>(buffer, offset, count);

            try
            {
                while (!ct.IsCancellationRequested)
                {
                    try
                    {
                        var result = await this.client.ReceiveAsync(maxSegment, ct).ConfigureAwait(false);

                        offset += result.Count;
                        while (!result.EndOfMessage)
                        {
                            count -= offset;
                            result = await this.client.ReceiveAsync(new ArraySegment <byte>(buffer, offset, count), ct).ConfigureAwait(false);

                            offset += result.Count;
                        }

                        var response = new ApiFeedResponse(buffer, 0, offset);
                        Array.Clear(buffer, 0, offset);
                        offset = 0;
                        count  = buffer.Length;

                        this.responses.Add(response);
                    }
                    catch (OperationCanceledException)
                    {
                        throw;
                    }
                    catch (Exception ex)
                    {
                        this.logger.ErrorAsync(DateTimeOffset.UtcNow, "ReceiveLoop FAIL", ex);
                        await EnsureConnectionAsync(ct).ConfigureAwait(false);
                    }
                }
            }
            catch (OperationCanceledException)
            {
            }
        }