Ejemplo n.º 1
0
        /// <summary>
        /// Executes the Flux query against the InfluxDB and asynchronously map whole response to list of object with
        /// given type.
        /// <para>
        /// NOTE: This method is not intended for large query results.
        /// Use <see cref="QueryAsync{T}(string,System.Action{InfluxDB.Client.Core.ICancellable,T},System.Action{System.Exception},System.Action)"/> for large data streaming.
        /// </para>
        /// </summary>
        /// <param name="query">the flux query to execute</param>
        /// <typeparam name="T">the type of measurement</typeparam>
        /// <returns><see cref="List{T}"/> which are matched the query</returns>
        public async Task <List <T> > QueryAsync <T>(string query)
        {
            var measurements = new List <T>();

            var consumer = new FluxResponseConsumerPoco <T>((cancellable, poco) => { measurements.Add(poco); }, Mapper);

            await QueryAsync(query, GetDefaultDialect(), consumer, ErrorConsumer, EmptyAction).ConfigureAwait(false);

            return(measurements);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Executes the Flux query against the InfluxDB and asynchronously stream result as POCO.
        /// </summary>
        /// <param name="query">the flux query to execute</param>
        /// <param name="onNext">the callback to consume the FluxRecord result with capability to discontinue a streaming query</param>
        /// <param name="onError">the callback to consume any error notification</param>
        /// <param name="onComplete">the callback to consume a notification about successfully end of stream</param>
        /// <typeparam name="T">the type of measurement</typeparam>
        /// <returns>async task</returns>
        public Task QueryAsync <T>(string query, Action <ICancellable, T> onNext, Action <Exception> onError,
                                   Action onComplete)
        {
            Arguments.CheckNonEmptyString(query, "query");
            Arguments.CheckNotNull(onNext, "onNext");
            Arguments.CheckNotNull(onError, "onError");
            Arguments.CheckNotNull(onComplete, "onComplete");

            var consumer = new FluxResponseConsumerPoco <T>(onNext, Mapper);

            return(QueryAsync(query, GetDefaultDialect(), consumer, onError, onComplete));
        }
        /// <summary>
        /// Executes the Flux query against the InfluxDB 2.0 and synchronously map whole response
        /// to list of object with given type.
        ///
        /// <para>
        /// NOTE: This method is not intended for large query results.
        /// </para>
        /// </summary>
        /// <param name="query">the flux query to execute</param>
        /// <param name="org">specifies the source organization</param>
        /// <typeparam name="T">the type of measurement</typeparam>
        /// <returns>Measurements which are matched the query</returns>
        public List <T> QuerySync <T>(Query query, string org)
        {
            Arguments.CheckNotNull(query, nameof(query));
            Arguments.CheckNonEmptyString(org, nameof(org));

            var measurements = new List <T>();

            var consumer = new FluxResponseConsumerPoco <T>((cancellable, poco) => { measurements.Add(poco); }, Mapper);

            var requestMessage = _service.PostQueryWithRestRequest(null, "application/json", null, org, null, query);

            QuerySync(requestMessage, consumer, ErrorConsumer, EmptyAction);

            return(measurements);
        }