Пример #1
0
        protected override async Task <LXResponse <T> > RequestCommandInternalAsync <T>(string command, CommandEncryption encryption, CancellationToken cancellationToken)
        {
            var handler = new LXResponseCommandHandler <T>();

            ApplyEncryption(handler, encryption);
            await EnqueueCommandAsync(command, handler, cancellationToken).ConfigureAwait(false);

            return(await handler.Task.ConfigureAwait(false));
        }
Пример #2
0
        private void ApplyEncryption <T>(LXResponseCommandHandler <T> handler, CommandEncryption encryption)
        {
            Encryptor encryptor = _encryptorProvider.GetEncryptor(encryption);

            if (encryption != CommandEncryption.Request)
            {
                handler.Encoder = encryptor;
                if (encryption == CommandEncryption.RequestAndResponse)
                {
                    handler.Decoder = encryptor;
                }
            }
        }
Пример #3
0
        public async Task <LXResponse <T> > RequestCommandAsync <T>(string command, RequestCommandValidation validation, CancellationToken cancellationToken)
        {
            var handler = new LXResponseCommandHandler <T>();

            await EnqueueCommandAsync(command, handler, cancellationToken).ConfigureAwait(false);

            var response = await handler.Task.ConfigureAwait(false);

            if ((validation & RequestCommandValidation.Command) != 0 && !AreCommandsEqual(command, response.Control))
            {
                throw new MiniserverTransportException();
            }

            if ((validation & RequestCommandValidation.Status) != 0 && !LXStatusCode.IsSuccess(response.Code))
            {
                throw new MiniserverCommandException(response.Code);
            }

            return(response);
        }