Пример #1
0
        internal async Task ProcessCommandsAsync(CancellationToken ct)
        {
            while (!ct.IsCancellationRequested)
            {
                try
                {
                    var command = await _transport.ReadCommandAsync(ct);

                    if (command != null)
                    {
                        if (!AuthorizedForReceive && !(command.Payload is InitiateHandshakeMessage))
                        {
                            await Send(new NotAuthorizedMessage("You are not authorized to send messages"));

                            continue;
                        }

                        await SendReceiveConfirmation(command);

                        await _dispatcher.Execute(command.Payload, this);
                        await SendHandledConfirmation(command);
                    }

                    Thread.Sleep(5);
                }
                catch (IOException)
                {
                    break;
                }
            }
            Dispose();
        }