コード例 #1
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;
                }
            }
        }
コード例 #2
0
ファイル: LXClient.cs プロジェクト: kmate95/Loxone.NET
        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);
            }
        }
コード例 #3
0
ファイル: Encryptor.cs プロジェクト: kmate95/Loxone.NET
 public Encryptor(Session session, CommandEncryption mode)
 {
     Contract.Requires(session != null);
     this._session = session;
     this._mode    = mode;
 }
コード例 #4
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));
        }
コード例 #5
0
        protected override async Task <LXResponse <T> > RequestCommandInternalAsync <T>(string command, CommandEncryption encryption, CancellationToken cancellationToken)
        {
            EnsureHttpClient();
            using var response = await _httpClient.GetAsync(command, HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false);

            if (response.IsSuccessStatusCode && HttpUtils.IsJsonMediaType(response.Content.Headers.ContentType))
            {
                string contentStr = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

                var lxResponse = LXResponse <T> .Deserialize(contentStr);

                return(lxResponse);
            }
            else
            {
                throw new MiniserverTransportException();
            }
        }
コード例 #6
0
ファイル: LXClient.cs プロジェクト: kmate95/Loxone.NET
 protected abstract Task <LXResponse <T> > RequestCommandInternalAsync <T>(string command, CommandEncryption encryption, CancellationToken cancellationToken);
コード例 #7
0
ファイル: LXClient.cs プロジェクト: kmate95/Loxone.NET
 public Task <LXResponse <T> > RequestCommandAsync <T>(string command, CommandEncryption encryption, CancellationToken cancellationToken)
 => RequestCommandAsync <T>(command, encryption, RequestCommandValidation.All, cancellationToken);