Exemple #1
0
        private async Task <InfluxResultSet <TInfluxRow> > ExecuteQueryInternalAsync <TInfluxRow>(string query)
            where TInfluxRow : new()
        {
            var queryResult = await GetInternalAsync(CreateQueryUrl( query ), false).ConfigureAwait(false);

            return(await ResultSetFactory.CreateAsync <TInfluxRow>(this, queryResult, null, false).ConfigureAwait(false));
        }
        private async Task <InfluxResultSet <TInfluxRow> > ExecuteQueryInternalAsync <TInfluxRow>(string query, string db, bool isTimeSeriesQuery, bool forcePost, object parameters, InfluxQueryOptions options)
            where TInfluxRow : new()
        {
            List <QueryResult> queryResults = await PerformQueryInternal(query, db, forcePost, isTimeSeriesQuery, false, parameters, options).ConfigureAwait(false);

            return(await ResultSetFactory.CreateAsync <TInfluxRow>(this, queryResults, db, isTimeSeriesQuery, options).ConfigureAwait(false));
        }
Exemple #3
0
        private async Task <InfluxResultSet <TInfluxRow> > ExecuteQueryInternalAsync <TInfluxRow>(string query, string db, bool isMeasurementQuery = false)
            where TInfluxRow : new()
        {
            var queryResult = await GetInternalAsync(CreateQueryUrl( query, db ), isMeasurementQuery).ConfigureAwait(false);

            return(await ResultSetFactory.CreateAsync <TInfluxRow>(this, queryResult, db, !isMeasurementQuery).ConfigureAwait(false));
        }
Exemple #4
0
        private async Task <InfluxResultSet <TInfluxRow> > ExecuteQueryInternalAsync <TInfluxRow>(string query, string db, InfluxQueryOptions options)
            where TInfluxRow : new()
        {
            var queryResult = await GetInternalAsync(CreateQueryUrl( query, db, options ), true).ConfigureAwait(false);

            return(await ResultSetFactory.CreateAsync <TInfluxRow>(this, queryResult, db, false).ConfigureAwait(false));
        }
Exemple #5
0
        private async Task <bool> ConsumeNextQueryResultAsync()
        {
            // read the next object from the object iterator (stream)
            var queryResult = _objectIterator.ReadNext <QueryResult>();

            if (queryResult == null)
            {
                _currentResultSet = null;
                return(false);
            }

            // if we found something, construct a normal result object, and initialize our indices
            _currentResultSet = await ResultSetFactory.CreateAsync <TInfluxRow>(_client, new[] { queryResult }, _db, true, _options).ConfigureAwait(false);

            _currentResultIndex = -1;
            _currentSerieIndex  = -1;

            // indicate we found something
            return(true);
        }
        private async Task <InfluxResultSet> ExecuteQueryInternalAsync(string query, string db, bool forcePost, object parameters, InfluxQueryOptions options)
        {
            List <QueryResult> queryResults = await PerformQueryInternal(query, db, forcePost, false, false, parameters, options).ConfigureAwait(false);

            return(ResultSetFactory.Create(queryResults));
        }
Exemple #7
0
        private async Task <InfluxResultSet> ExecuteQueryInternalAsync(string query)
        {
            var queryResult = await GetInternalAsync(CreateQueryUrl( query ), false).ConfigureAwait(false);

            return(ResultSetFactory.Create(queryResult));
        }
Exemple #8
0
        protected override Task SerializeToStreamAsync(Stream stream, TransportContext context)
        {
            var writer = new StreamWriter(stream, UTF8);

            var precision          = _precision;
            var getMeasurementName = _getMeasurementName;

            if (ResultSetFactory.IsIInfluxRow <TInfluxRow>())
            {
                foreach (IInfluxRow dp in _dataPoints)
                {
                    // write measurement name
                    writer.Write(getMeasurementName((TInfluxRow)dp));

                    // write all tags
                    foreach (var kvp in dp.GetAllTags()) // Ensure tags are in correct order?
                    {
                        var value = kvp.Value;
                        if (value != null)
                        {
                            writer.Write(',');
                            writer.Write(LineProtocolEscape.EscapeKey(kvp.Key));
                            writer.Write('=');
                            writer.Write(LineProtocolEscape.EscapeTagValue(value));
                        }
                    }

                    // write tag to field seperator
                    writer.Write(' ');

                    // write all fields
                    using (var enumerator = dp.GetAllFields().GetEnumerator())
                    {
                        bool   hasMore  = enumerator.MoveNext();
                        bool   hasValue = false;
                        object value    = null;
                        KeyValuePair <string, object> current = default(KeyValuePair <string, object>);
                        while (hasMore && !hasValue)
                        {
                            current  = enumerator.Current;
                            value    = enumerator.Current.Value;
                            hasValue = value != null;

                            hasMore = enumerator.MoveNext();
                        }

                        while (hasValue)
                        {
                            writer.Write(LineProtocolEscape.EscapeKey(current.Key));
                            writer.Write('=');
                            writer.Write(LineProtocolEscape.EscapeFieldValue(value));

                            // get a hold of the next non-null value
                            hasValue = false;
                            while (hasMore && !hasValue)
                            {
                                current  = enumerator.Current;
                                value    = enumerator.Current.Value;
                                hasValue = value != null;

                                hasMore = enumerator.MoveNext();
                            }

                            // we have just written a value, and now we have the next non-null value
                            if (hasValue)
                            {
                                writer.Write(',');
                            }
                        }
                    }

                    // write timestamp, if exists
                    var ts = dp.GetTimestamp();
                    if (ts != null)
                    {
                        writer.Write(' ');
                        long ticks = ts.Value.ToPrecision(precision);
                        writer.Write(ticks);
                    }

                    writer.Write('\n');
                }
            }
            else
            {
                var cache     = MetadataCache.GetOrCreate <TInfluxRow>();
                var tags      = cache.Tags;
                var fields    = cache.Fields;
                var timestamp = cache.Timestamp;

                foreach (var dp in _dataPoints)
                {
                    // write measurement name
                    writer.Write(getMeasurementName(dp));

                    // write all tags
                    if (tags.Count > 0)
                    {
                        foreach (var tagProperty in tags)
                        {
                            var value = tagProperty.GetValue(dp);
                            if (value != null)
                            {
                                writer.Write(',');
                                writer.Write(tagProperty.LineProtocolEscapedKey);
                                writer.Write('=');
                                writer.Write(LineProtocolEscape.EscapeTagValue(tagProperty.GetStringValue(value)));
                            }
                        }
                    }

                    // write tag to fields seperator
                    writer.Write(' ');

                    // write all fields
                    using (var enumerator = fields.GetEnumerator())
                    {
                        bool   hasMore  = enumerator.MoveNext();
                        bool   hasValue = false;
                        object value    = null;
                        PropertyExpressionInfo <TInfluxRow> property = null;
                        while (hasMore && !hasValue)
                        {
                            property = enumerator.Current;
                            value    = property.GetValue(dp);
                            hasValue = value != null;

                            hasMore = enumerator.MoveNext();
                        }

                        while (hasValue)
                        {
                            writer.Write(property.LineProtocolEscapedKey);
                            writer.Write('=');
                            if (property.IsEnum)
                            {
                                writer.Write(LineProtocolEscape.EscapeFieldValue(property.GetStringValue(value)));
                            }
                            else
                            {
                                writer.Write(LineProtocolEscape.EscapeFieldValue(value));
                            }

                            // get a hold of the next non-null value
                            hasValue = false;
                            while (hasMore && !hasValue)
                            {
                                property = enumerator.Current;
                                value    = property.GetValue(dp);
                                hasValue = value != null;

                                hasMore = enumerator.MoveNext();
                            }

                            // we have just written a value, and now we have the next non-null value
                            if (hasValue)
                            {
                                writer.Write(',');
                            }
                        }
                    }

                    // write timestamp, if exists
                    if (timestamp != null)
                    {
                        var ts = timestamp.GetValue(dp);
                        if (ts != null)
                        {
                            writer.Write(' ');
                            long ticks = ((DateTime)ts).ToPrecision(precision);
                            writer.Write(ticks);
                        }
                    }

                    writer.Write('\n');
                }
            }

            writer.Flush();

            return(Task.FromResult(0));
        }