Example #1
0
        /// <summary>
        /// Runs the current query against the configured connection and database.
        /// </summary>
        public override async Task ExecuteRequestAsync()
        {
            if (InfluxDbClient == null)
            {
                throw new Exception("No InfluxDB client available.");
            }

            // Reset the results count
            resultsCount = 0;

            // Get the database and the query
            var  query       = EditorText.Trim();
            bool isAggregate = query.ToLower().Contains("group by");

            // Clear the current results
            tabControl.Controls.Clear();

            // Start timing...
            stopWatch.Restart();

            // Execute the query
            var results = await InfluxDbClient.QueryAsync(Database, query);

            // Stop timing...
            stopWatch.Stop();

            // If there are results
            if (results != null && results.Count() > 0)
            {
                var tabCount = 0;
                var tabLabel = isAggregate ? "Group" : "Results";

                foreach (var result in results)
                {
                    // Create a new tab page to hold the query results control
                    var tab = new TabPage(string.Format("{0} {1}", tabLabel, ++tabCount));

                    // Create a new query results control
                    var queryResultsControl = new QueryResultsControl();
                    queryResultsControl.InfluxDbClient = InfluxDbClient;
                    queryResultsControl.Database       = Database;
                    queryResultsControl.Dock           = DockStyle.Fill;
                    tab.Controls.Add(queryResultsControl);

                    // Add the tab to the control
                    tabControl.TabPages.Add(tab);

                    // Render the results and increment the global total
                    resultsCount += queryResultsControl.UpdateResults(result);
                }
            }

            // Show stat results of query
            resultsLabel.Text = string.Format("results: {0}, response time: {1:0} ms", resultsCount, stopWatch.Elapsed.TotalMilliseconds);
        }
        // Displays the statistic data for the selected statistic
        void BindSelectedStats()
        {
            // Clear current tab list
            tabControl.TabPages.Clear();

            if (string.IsNullOrWhiteSpace(SelectedStatistic) || statsComboBox.SelectedItem == null)
            {
                return;
            }
            IEnumerable <InfluxDbSeries> statResults = null;

            // Use reflection to get the selected statistic
            statResults = (from pi in CurrentStatistics.GetType().GetProperties()
                           where pi.Name == SelectedStatistic
                           select pi.GetValue(CurrentStatistics) as IEnumerable <InfluxDbSeries>).FirstOrDefault();

            if (statResults == null)
            {
                return;
            }

            var tabCount = 0;

            // Go through each result data set for the current stat and create tab'd result set.
            foreach (var series in statResults)
            {
                // Create a new tab page to hold the query results control
                var tab = new TabPage(string.Format("{0} {1}", series.Name, ++tabCount));
                //var tab = new TabPage(string.Format("{0}", series.Name));

                // Create a new query results control
                var queryResultsControl = new QueryResultsControl();
                queryResultsControl.InfluxDbClient = InfluxDbClient;
                //queryResultsControl.Database = Database;
                queryResultsControl.Dock = DockStyle.Fill;
                tab.Controls.Add(queryResultsControl);

                // Add the tab to the control
                tabControl.TabPages.Add(tab);

                // Display result data
                queryResultsControl.UpdateResults(series);
            }
        }