コード例 #1
0
        protected async Task Query(RestRequest query, Action <ICancellable, Stream> consumer,
                                   Action <Exception> onError, Action onComplete)
        {
            Arguments.CheckNotNull(query, "query");
            Arguments.CheckNotNull(consumer, "consumer");
            Arguments.CheckNotNull(onError, "onError");
            Arguments.CheckNotNull(onComplete, "onComplete");

            try
            {
                var cancellable = new DefaultCancellable();

                BeforeIntercept(query);

                query.AdvancedResponseWriter = (responseStream, response) =>
                {
                    responseStream = AfterIntercept((int)response.StatusCode, () => response.Headers, responseStream);

                    RaiseForInfluxError(response, responseStream);
                    consumer(cancellable, responseStream);
                };

                await Task.Run(() => { RestClient.DownloadData(query, true); }).ConfigureAwait(false);

                if (!cancellable.IsCancelled())
                {
                    onComplete();
                }
            }
            catch (Exception e)
            {
                onError(e);
            }
        }
コード例 #2
0
        private async Task Query(RestRequest query, Action <ICancellable, Stream> consumer,
                                 Action <Exception> onError, Action onComplete)
        {
            Arguments.CheckNotNull(query, "query");
            Arguments.CheckNotNull(consumer, "consumer");
            Arguments.CheckNotNull(onError, "onError");
            Arguments.CheckNotNull(onComplete, "onComplete");

            try
            {
                var cancellable = new DefaultCancellable();

                BeforeIntercept(query);

                query.AdvancedResponseWriter = (responseStream, response) =>
                {
                    responseStream = AfterIntercept((int)response.StatusCode, () => response.Headers, responseStream);

                    RaiseForInfluxError(response, responseStream);
                    consumer(cancellable, responseStream);
                };

                var restResponse = await RestClient.ExecuteAsync(query, Method.POST).ConfigureAwait(false);

                if (restResponse.ErrorException != null)
                {
                    throw restResponse.ErrorException;
                }

                if (!cancellable.IsCancelled())
                {
                    onComplete();
                }
            }
            catch (Exception e)
            {
                onError(e);
            }
        }