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

            // Clear list items
            statsComboBox.Items.Clear();

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

            // Execute the query
            CurrentStatistics = await InfluxDbClient.GetStatsAsync();

            // Use reflection to dynamically create results
            foreach (var pi in CurrentStatistics.GetType().GetProperties())
            {
                var value      = pi.GetValue(CurrentStatistics);
                var statResult = value as IEnumerable <InfluxDbSeries>;
                if (value == null || statResult == null || statResult.Count() == 0)
                {
                    continue;                                                                 // no results/not supported
                }
                statsComboBox.Items.Add(pi.Name);
            }

            // Restore selection if one existed
            if (!string.IsNullOrWhiteSpace(SelectedStatistic))
            {
                for (var i = 0; i < statsComboBox.Items.Count; i++)
                {
                    var item = statsComboBox.Items[i];

                    if (item.ToString() == SelectedStatistic)
                    {
                        statsComboBox.SelectedIndex = i;
                        BindSelectedStats();
                        break;
                    }
                }
            }
            // Otherwise just select the first result
            else
            {
                statsComboBox.SelectedIndex = 0;
            }
        }