Ejemplo n.º 1
0
        private string CreateQueryUrl(string commandOrQuery, string db, bool isTimeSeriesQuery, bool requireChunking, object parameters, InfluxQueryOptions options)
        {
            var  query     = "query";
            char seperator = '?';

            if (!string.IsNullOrEmpty(db))
            {
                query    += $"{seperator}db={UriHelper.SafeEscapeDataString(db)}";
                seperator = '&';
            }

            if (!string.IsNullOrEmpty(commandOrQuery))
            {
                query    += $"{seperator}q={UriHelper.SafeEscapeDataString(commandOrQuery)}";
                seperator = '&';
            }
            if (parameters != null)
            {
                query    += $"{seperator}params={UriHelper.SafeEscapeDataString(ParamsConverter.GetParams(parameters))}";
                seperator = '&';
            }

            if (options != null)
            {
                if (options.Precision.HasValue && isTimeSeriesQuery)
                {
                    query    += $"{seperator}epoch={options.Precision.Value.GetQueryParameter()}";
                    seperator = '&';
                }

                if (options.ChunkSize.HasValue)
                {
                    query    += $"{seperator}chunked=true&chunk_size={options.ChunkSize.Value}";
                    seperator = '&';
                }
            }

            // add chunking if it is not already set
            if (requireChunking && options?.ChunkSize.HasValue != true)
            {
                query += $"{seperator}chunked=true";
            }

            return(new Uri(_endpoint, query).ToString());
        }
Ejemplo n.º 2
0
        private LongFormUrlEncodedContent CreateQueryPostContent(string commandOrQuery, string db, bool isTimeSeriesQuery, bool requireChunking, object parameters, InfluxQueryOptions options)
        {
            List <KeyValuePair <string, string> > param = new List <KeyValuePair <string, string> >(5);

            if (!string.IsNullOrEmpty(db))
            {
                param.Add(new KeyValuePair <string, string>("db", db));
            }
            if (!string.IsNullOrEmpty(commandOrQuery))
            {
                param.Add(new KeyValuePair <string, string>("q", commandOrQuery));
            }
            if (parameters != null)
            {
                param.Add(new KeyValuePair <string, string>("params", ParamsConverter.GetParams(parameters)));
            }

            if (options != null)
            {
                if (options.Precision.HasValue && isTimeSeriesQuery)
                {
                    param.Add(new KeyValuePair <string, string>("epoch", options.Precision.Value.GetQueryParameter()));
                }
                if (options.ChunkSize.HasValue)
                {
                    param.Add(new KeyValuePair <string, string>("chunked", "true"));
                    param.Add(new KeyValuePair <string, string>("chunk_size", options.ChunkSize.Value.ToString(CultureInfo.InvariantCulture)));
                }
            }

            // add chunking if it is not already set
            if (requireChunking && options?.ChunkSize.HasValue != true)
            {
                param.Add(new KeyValuePair <string, string>("chunked", "true"));
            }

            return(new LongFormUrlEncodedContent(param));
        }