/// <summary>
        /// Runs the gateway service.
        /// </summary>
        /// <param name="cancellationToken">Token used to cancel the operation.</param>
        /// <returns>The resulting task.</returns>
        public async Task Run(CancellationToken cancellationToken = default)
        {
            cancellationToken.ThrowIfCancellationRequested();
            ThrowIfNotRunning();
            if (webSocket !.State != WebSocketState.Open)
            {
                await webSocket !.Connect(options.Uri, cancellationToken);
            }

            var result = await webSocket !.Receive(memoryBuffer, cancellationToken);
            var chunk  = new GatewayMessageChunk(memoryBuffer, result.Count, result.EndOfMessage);
            await rxWorker.Emit(chunk, cancellationToken);
        }
Exemplo n.º 2
0
            public async Task SendShouldThrowIfTheOperationWasCanceled(
                string chunk,
                [Frozen, Substitute] IGatewayService gateway,
                [Target] DefaultGatewayRxWorker worker
                )
            {
                var message = new GatewayMessageChunk {
                    Bytes = Encoding.UTF8.GetBytes(chunk)
                };
                var cancellationToken = new CancellationToken(false);

                await worker.Start(gateway);

                var         operationCancellationToken = new CancellationToken(true);
                Func <Task> func = () => worker.Emit(message, operationCancellationToken);

                await func.Should().ThrowAsync <OperationCanceledException>();
            }
Exemplo n.º 3
0
            public async Task EmitShouldEmitTheMessageToTheChannel(
                int sequenceNumber,
                string chunk,
                IGatewayService gateway,
                [Frozen, Substitute] IChannel <GatewayMessageChunk> channel,
                [Target] DefaultGatewayRxWorker worker
                )
            {
                var message = new GatewayMessageChunk {
                    Bytes = Encoding.UTF8.GetBytes(chunk)
                };
                var cancellationToken = new CancellationToken(false);

                await worker.Start(gateway);

                await worker.Emit(message, cancellationToken);

                await channel.Received().Write(Is(message), Is(cancellationToken));
            }
Exemplo n.º 4
0
 /// <inheritdoc />
 public async Task Emit(GatewayMessageChunk chunk, CancellationToken cancellationToken)
 {
     cancellationToken.ThrowIfCancellationRequested();
     ThrowIfNotRunning();
     await channel.Write(chunk, cancellationToken);
 }