Example #1
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);
        }
Example #2
0
        public async Task <LXResponse <T> > RequestCommandAsync <T>(string command, CommandEncryption encryption, RequestCommandValidation validation, CancellationToken cancellationToken)
        {
            try
            {
                var response = await RequestCommandInternalAsync <T>(command, encryption, cancellationToken).ConfigureAwait(false);

                string control = Uri.EscapeUriString(response.Control);
                if ((validation & RequestCommandValidation.Command) != 0 && !AreCommandsEqual(command, control))
                {
                    throw new MiniserverTransportException();
                }
                if ((validation & RequestCommandValidation.Status) != 0 && !LXStatusCode.IsSuccess(response.Code))
                {
                    throw new MiniserverCommandException(response.Code);
                }
                return(response);
            }
            catch (ObjectDisposedException)
            {
                throw new MiniserverTransportException("No connection " + this.ClosedException?.Message, this.ClosedException);
            }
        }