-
Notifications
You must be signed in to change notification settings - Fork 187
/
Copy pathAppForm.cs
1975 lines (1623 loc) · 65.5 KB
/
AppForm.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using log4net;
using Newtonsoft.Json;
using CymaticLabs.InfluxDB.Data;
using CymaticLabs.InfluxDB.Studio.Controls;
using CymaticLabs.InfluxDB.Studio.Dialogs;
namespace CymaticLabs.InfluxDB.Studio
{
/// <summary>
/// The main application form.
/// </summary>
public partial class AppForm : Form
{
#region Enums
/// <summary>
/// Different InfluxDB types represented by tree view nodes.
/// </summary>
enum InfluxDbNodeTypes
{
/// <summary>
/// Loading place holder used for lazy loading node data.
/// </summary>
LoadingPlacholder = 0,
/// <summary>
/// An InfluxDB server/connection.
/// </summary>
Connection = 1,
/// <summary>
/// An InfluxDB database.
/// </summary>
Database = 2,
/// <summary>
/// An InfluxDB database measurement (table).
/// </summary>
Measurement = 3,
}
#endregion Enums
#region Fields
// Singleton instance
static AppForm instance;
// The connections dialog used to manage connections
ManageConnectionsDialog manageConnectionsDialog;
// Used to create new databases
CreateDatabaseDialog createDatabaseDialog;
// Used to perform back fill queries
private BackfillDialog backfillDialog;
// The application about dialog
AboutDialog aboutDialog;
#endregion Fields
#region Properties
/// <summary>
/// Gets the application settings.
/// </summary>
public static AppSettings Settings { get; private set; }
/// <summary>
/// Gets the application's logger.
/// </summary>
public static ILog Log { get; private set; }
/// <summary>
/// Gets the list of currently active InfluxDB client connections.
/// </summary>
public static List<InfluxDbClient> ActiveClients { get; private set; }
/// <summary>
/// The global tab context menu used for closing tabs with extended options.
/// </summary>
public static ContextMenuStrip TabContextMenu { get; private set; }
#endregion Properties
#region Constructors
public AppForm()
{
// Setup static properties
instance = this;
Settings = new AppSettings();
// Enable logging
Log = LogManager.GetLogger("AppLogger");
// Setup container for active database connection clients
ActiveClients = new List<InfluxDbClient>();
InitializeComponent();
// Create dialog windows
aboutDialog = new AboutDialog();
createDatabaseDialog = new CreateDatabaseDialog();
backfillDialog = new BackfillDialog();
manageConnectionsDialog = new ManageConnectionsDialog();
manageConnectionsDialog.ConnectionCreated += ManageConnectionsDialog_ConnectionCreated;
manageConnectionsDialog.ConnectionUpdated += ManageConnectionsDialog_ConnectionUpdated;
manageConnectionsDialog.ConnectionRemoved += ManageConnectionsDialog_ConnectionRemoved;
}
#endregion Constructors
#region Event Handlers
#region AppForm
// Handle app load
private async void AppForm_Load(object sender, EventArgs e)
{
// Assign the tab context menu
TabContextMenu = tabContextMenuStrip;
// Clear status
statusLabel.Text = null;
// Clear the current list of connections
connectionsTreeView.Nodes.Clear();
// Load current application settings
Settings.LoadAll();
// Apply the settings to the application
ApplySettings();
// Set initial tool strip state
UpdateUIState();
// Wait a little bit for the main form to load and then show the connections dialog
await Task.Delay(250);
await ShowConnectionsDialog();
}
#endregion AppForm
#region File Menu
#region File
// File -> Import -> Application Settings
private async void importAppSettingsMenuItem_Click(object sender, EventArgs e)
{
await ImportSettings(true);
}
// File -> Export -> Appliction Settings
private void exportAppSettingsMenuItem_Click(object sender, EventArgs e)
{
ExportSettings();
}
// File -> Exit
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{
Application.Exit();
}
#endregion File
#region Connections
// Handles Connections -> Manage
private async void manageToolStripMenuItem_Click(object sender, EventArgs e)
{
await ShowConnectionsDialog();
}
#endregion Connections
#region Query
// Query -> Run
private async void runQueryToolStripMenuItem_Click(object sender, EventArgs e)
{
await ExecuteCurrentRequest();
}
// Query -> New Query
private void newQueryToolStripMenuItem2_Click(object sender, EventArgs e)
{
var node = connectionsTreeView.SelectedNode;
if (node == null) return;
NewQuery(node);
}
// Query -> Show Queries
private async void showQueriesToolStripMenuItem_Click(object sender, EventArgs e)
{
var node = connectionsTreeView.SelectedNode;
if (node == null) return;
await ShowQueries(node);
}
#endregion Query
#region Settings
// Handles Settings -> Allow Untrusted SSL Certificates
private void allowUntrustedSSLToolStripMenuItem_CheckedChanged(object sender, EventArgs e)
{
var allowUntrustedSsl = allowUntrustedSSLToolStripMenuItem.Checked;
SslIgnoreValidator.AllowUntrusted = allowUntrustedSsl;
Settings.AllowUntrustedSsl = allowUntrustedSsl;
}
// Handles Settings -> Time Format -> change of time format
private void timeFormatComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
Settings.TimeFormat = timeFormatComboBox.SelectedIndex == 0 ? AppSettings.TimeFormat12Hour : AppSettings.TimeFormat24Hour;
}
// Handles Settings -> Date Format -> change of date format
private void dateFormatComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
Settings.DateFormat = dateFormatComboBox.SelectedIndex == 0 ? AppSettings.DateFormatMonth : AppSettings.DateFormatDay;
}
#endregion Settings
#region Help
// Help -> About
private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
{
aboutDialog.ShowDialog();
}
#endregion Help
#endregion File Menu
#region Tool Strip
// Manage Connections
private async void manageConnectionsButton_Click(object sender, EventArgs e)
{
await ShowConnectionsDialog();
}
// Disconnect
private void disconnectButton_Click(object sender, EventArgs e)
{
var node = connectionsTreeView.SelectedNode;
if (node == null) return;
var type = GetNodeType(node);
switch (type)
{
case InfluxDbNodeTypes.Connection:
Disconnect(node);
break;
case InfluxDbNodeTypes.Database:
Disconnect(node.Parent);
break;
case InfluxDbNodeTypes.Measurement:
Disconnect(node.Parent.Parent);
break;
}
}
// Show Retention Policies
private async void showPoliciesButton_Click(object sender, EventArgs e)
{
var node = connectionsTreeView.SelectedNode;
if (node == null) return;
await ShowRetentionPolicies(node);
}
// Show Users
private async void showUsersButton_Click(object sender, EventArgs e)
{
var node = connectionsTreeView.SelectedNode;
if (node == null) return;
await ShowUsers(node);
}
// Show Statistics
private async void showStatsButton_Click(object sender, EventArgs e)
{
var node = connectionsTreeView.SelectedNode;
if (node == null) return;
await ShowStatistics(node);
}
// Show Diagnostics
private async void showDiagnosticsButton_Click(object sender, EventArgs e)
{
var node = connectionsTreeView.SelectedNode;
if (node == null) return;
await ShowDiagnostics(node);
}
// Refresh
private async void refreshButton_Click(object sender, EventArgs e)
{
var node = connectionsTreeView.SelectedNode;
if (node == null) return;
var type = GetNodeType(node);
switch (type)
{
case InfluxDbNodeTypes.Connection:
await RefreshConnection(node);
break;
case InfluxDbNodeTypes.Database:
await RefreshDatabase(node);
break;
}
}
// Run Query
private async void runQueryButton_Click(object sender, EventArgs e)
{
if (CanRunQuery()) await ExecuteCurrentRequest();
}
// New Query
private void newQueryButton_Click(object sender, EventArgs e)
{
var node = connectionsTreeView.SelectedNode;
if (node == null) return;
NewQuery(node);
}
// Query -> Show Queries
private async void showQueriesButton_Click(object sender, EventArgs e)
{
var node = connectionsTreeView.SelectedNode;
if (node == null) return;
await ShowQueries(node);
}
// Create Database
private async void createDatabaseButton_Click(object sender, EventArgs e)
{
var node = connectionsTreeView.SelectedNode;
if (node == null) return;
await CreateDatabase(node);
}
// Show Continuous Queries
private async void continuousQueryButton_Click(object sender, EventArgs e)
{
var node = connectionsTreeView.SelectedNode;
if (node == null) return;
await ShowContinuousQueries(node);
}
// Run Back Fill
private async void backFillButton_Click(object sender, EventArgs e)
{
var node = connectionsTreeView.SelectedNode;
if (node == null) return;
await RunBackFill(node);
}
// Drop Database
private async void dropDatabaseButton_Click(object sender, EventArgs e)
{
var node = connectionsTreeView.SelectedNode;
if (node == null) return;
await DropDatabase(node);
}
// Show Tag Keys
private async void tagKeysButton_Click(object sender, EventArgs e)
{
var node = connectionsTreeView.SelectedNode;
if (node == null) return;
await ShowTagKeys(node);
}
// Show Tag Values
private async void tagValuesButton_Click(object sender, EventArgs e)
{
var node = connectionsTreeView.SelectedNode;
if (node == null) return;
await ShowTagValues(node);
}
// Show Field Keys
private async void fieldKeysButton_Click(object sender, EventArgs e)
{
var node = connectionsTreeView.SelectedNode;
if (node == null) return;
await ShowFieldKeys(node);
}
// Show Series
private async void showSeriesButton_Click(object sender, EventArgs e)
{
var node = connectionsTreeView.SelectedNode;
if (node == null) return;
await ShowSeries(node);
}
// Drop Series
private async void dropSeriesButton_Click(object sender, EventArgs e)
{
var node = connectionsTreeView.SelectedNode;
if (node == null) return;
await DropSeries(node);
}
// Drop Measurement
private async void dropMeasurementButton_Click(object sender, EventArgs e)
{
var node = connectionsTreeView.SelectedNode;
if (node == null) return;
await DropMeasurement(node);
}
#endregion Tool Strip
#region Connections Tree View
#region Tree Nodes
// Handle selection change
private void connectionsTreeView_AfterSelect(object sender, TreeViewEventArgs e)
{
// Update the UI accordingly
UpdateUIState();
}
// Handle connections clicks
private void connectionsTreeView_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
{
// If this is a right click, set the clicked node to the selected node for conext menus
if (e.Button == MouseButtons.Right) connectionsTreeView.SelectedNode = e.Node;
}
// Handle node double click
private void connectionsTreeView_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e)
{
// If this is a measurement, launch a new query
var node = e.Node;
if (GetNodeType(node) != InfluxDbNodeTypes.Measurement) return;
NewQuery(node);
}
// Handle tree node expansion
private async void connectionsTreeView_AfterExpand(object sender, TreeViewEventArgs e)
{
await ExpandNodeChildren(e.Node);
}
#endregion Tree Nodes
#region Connection Context Menu
// Connection -> Refresh
private async void connectionRefreshToolStripMenuItem_Click(object sender, EventArgs e)
{
var node = connectionsTreeView.SelectedNode;
if (node == null) return;
await RefreshConnection(node);
}
// Connection -> Create Database
private async void createDatabaseToolStripMenuItem_Click(object sender, EventArgs e)
{
var node = connectionsTreeView.SelectedNode;
if (node == null) return;
await CreateDatabase(node);
}
// Connection -> Show Queries
private async void showQueriesContextMenuItem_Click(object sender, EventArgs e)
{
var node = connectionsTreeView.SelectedNode;
if (node == null) return;
await ShowQueries(node);
}
// Connection -> Show Retention Policies
private async void showRetentionPoliciesToolStripMenuItem_Click(object sender, EventArgs e)
{
var node = connectionsTreeView.SelectedNode;
if (node == null) return;
await ShowRetentionPolicies(node);
}
// Connection -> Show Users
private async void showUsersToolStripMenuItem_Click(object sender, EventArgs e)
{
var node = connectionsTreeView.SelectedNode;
if (node == null) return;
await ShowUsers(node);
}
// Connection -> Show Statistics
private async void showStatisticsToolStripMenuItem_Click(object sender, EventArgs e)
{
var node = connectionsTreeView.SelectedNode;
if (node == null) return;
await ShowStatistics(node);
}
// Connection -> Show Diagnostics
private async void diagnosticsToolStripMenuItem_Click(object sender, EventArgs e)
{
var node = connectionsTreeView.SelectedNode;
if (node == null) return;
await ShowDiagnostics(node);
}
// Connection -> Disconnect
private void disconnectToolStripMenuItem_Click(object sender, EventArgs e)
{
var node = connectionsTreeView.SelectedNode;
if (node == null) return;
Disconnect(node);
}
#endregion Connection Context Menu
#region Database Context Menu
// Database -> Refresh
private async void databaseRefreshToolStripMenuItem_Click(object sender, EventArgs e)
{
var node = connectionsTreeView.SelectedNode;
if (node == null) return;
await RefreshDatabase(node);
}
// Database -> Continous Queries
private async void continousQueriesToolStripMenuItem_Click(object sender, EventArgs e)
{
var node = connectionsTreeView.SelectedNode;
if (node == null) return;
await ShowContinuousQueries(node);
}
// Database -> Run Back Fill
private async void backFillToolStripMenuItem_Click(object sender, EventArgs e)
{
var node = connectionsTreeView.SelectedNode;
if (node == null) return;
await RunBackFill(node);
}
// Database -> Drop Database
private async void dropDatabaseToolStripMenuItem_Click(object sender, EventArgs e)
{
var node = connectionsTreeView.SelectedNode;
if (node == null) return;
await DropDatabase(node);
}
#endregion Database Context Menu
#region Measurement Context Menu
// Measurement -> Show Series
private async void showSeriesToolStripMenuItem_Click(object sender, EventArgs e)
{
var node = connectionsTreeView.SelectedNode;
if (node == null) return;
await ShowSeries(node);
}
// Measurement -> Tag Keys
private async void tagKeysToolStripMenuItem_Click(object sender, EventArgs e)
{
var node = connectionsTreeView.SelectedNode;
if (node == null) return;
await ShowTagKeys(node);
}
// Measurement -> Tag Values
private async void tagValuesToolStripMenuItem_Click(object sender, EventArgs e)
{
var node = connectionsTreeView.SelectedNode;
if (node == null) return;
await ShowTagValues(node);
}
// Measurement -> Field Keys
private async void fieldKeysToolStripMenuItem_Click(object sender, EventArgs e)
{
var node = connectionsTreeView.SelectedNode;
if (node == null) return;
await ShowFieldKeys(node);
}
// Measurement -> Drop Measurement
private async void dropMeasurementToolStripMenuItem_Click(object sender, EventArgs e)
{
var node = connectionsTreeView.SelectedNode;
if (node == null) return;
await DropMeasurement(node);
}
// Measurement => Drop Series
private async void dropSeriesToolStripMenuItem_Click(object sender, EventArgs e)
{
var node = connectionsTreeView.SelectedNode;
if (node == null) return;
await DropSeries(node);
}
#endregion Measurement Context Menu
#region Context Menu Shared
// Handle database/measurement -> New Query
private void newQueryMenuItem_Click(object sender, EventArgs e)
{
var node = connectionsTreeView.SelectedNode;
if (node == null) return;
NewQuery(node);
}
#endregion Context Menu Shared
#endregion Connections Tree View
#region Tab Control
// Handle user closing of tabs
private void tabControl_TabClosed(object sender, TabPage e)
{
UpdateUIState();
}
#endregion Tab Control
#region Manage Connections Dialog
// Handles the creation of a connection
private void ManageConnectionsDialog_ConnectionCreated(InfluxDbConnection connection)
{
try
{
// Ensure this is not a duplicate by name
foreach (var c in Settings.Connections)
{
if (c.Name == connection.Name)
{
DisplayError("A connection already exists with name: " + c.Name, "Connection Exists");
return;
}
}
// Add to the global list
Settings.Connections.Add(connection);
// Save connection data
Settings.SaveConnections();
}
catch (Exception ex)
{
DisplayException(ex);
}
}
// Handles the update of a connection
private async void ManageConnectionsDialog_ConnectionUpdated(InfluxDbConnection connection)
{
try
{
// Save connection data
Settings.SaveConnections();
// Go through active connection and update the matching connection in the UI if found
foreach (TreeNode node in connectionsTreeView.Nodes)
{
var c = node.Tag as InfluxDbConnection;
if (c.Id == connection.Id || c == connection)
{
await RenderConnectionDetails(node, connection, true);
break;
}
}
}
catch (Exception ex)
{
DisplayException(ex);
}
}
// Handles the removal of a connection
private void ManageConnectionsDialog_ConnectionRemoved(InfluxDbConnection connection)
{
try
{
// Remove the connection from the global list
foreach (var c in Settings.Connections)
{
if (c.Id == connection.Id)
{
Settings.Connections.Remove(c);
break;
}
}
// Save connection data
Settings.SaveConnections();
// Remove from UI
foreach (TreeNode node in connectionsTreeView.Nodes)
{
if (node.Text == connection.Name)
{
Disconnect(node);
break;
}
}
}
catch (Exception ex)
{
DisplayException(ex);
}
}
#endregion Manage Connections Dialog
#endregion Event Handlers
#region Methods
#region Commands
#region Application
// Import application settings
async Task ImportSettings(bool showConnectionManage = false)
{
try
{
// Prompt to open
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
// Open the file
var json = File.ReadAllText(openFileDialog.FileName);
// Convert to app settings object
Settings = JsonConvert.DeserializeObject<AppSettings>(json);
// Save to disk
Settings.SaveAll();
// Apply Settings
ApplySettings();
// Show connections manager if requested
if (showConnectionManage) await ShowConnectionsDialog();
}
}
catch (Exception ex)
{
DisplayException(ex);
}
}
// Export application settings
void ExportSettings()
{
try
{
// Prompt to save
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
// Serialize to JSON
var json = JsonConvert.SerializeObject(Settings, Formatting.Indented);
// Write to file
File.WriteAllText(saveFileDialog.FileName, json);
}
}
catch (Exception ex)
{
DisplayException(ex);
}
}
#endregion Application
#region Connection
// Loads data under a tree node
async Task ExpandNodeChildren(TreeNode node)
{
try
{
// Check to see if this a loading place holder node
if (node.FirstNode == null || node.FirstNode.ImageIndex != (int)InfluxDbNodeTypes.LoadingPlacholder)
return;
// Get the connection and client for this node
var connection = GetConnection(node);
var client = GetClient(connection);
switch (GetNodeType(node))
{
case InfluxDbNodeTypes.Connection:
await RenderDatabases(node, client);
break;
case InfluxDbNodeTypes.Database:
await RenderMeasurements(node, client);
break;
}
}
catch (Exception ex)
{
DisplayException(ex);
}
}
// Connection -> Refresh
async Task RefreshConnection(TreeNode node)
{
try
{
// Remove all child nodes
node.Nodes.Clear();
// Get the connection and client for the node
var connection = GetConnection(node);
var client = GetClient(connection);
// Add a placeholder
var placeholderNode = CreateTreeNode("loading...", InfluxDbNodeTypes.LoadingPlacholder);
node.Nodes.Add(placeholderNode);
// Refresh and rerender
await RenderDatabases(node, client);
}
catch (Exception ex)
{
DisplayException(ex);
}
}
// Connection -> Create Database
async Task CreateDatabase(TreeNode node)
{
try
{
// Get the selected connection
var connection = node.Tag as InfluxDbConnection;
createDatabaseDialog.ConnectionName = connection.Name;
createDatabaseDialog.DatabaseName = connection.Database;
// Get the active client for this connection
var client = GetClient(connection);
// Show the create database dialog
if (createDatabaseDialog.ShowDialog() == DialogResult.OK)
{
// Get current list of database names
var currentDbNames = await client.GetDatabaseNamesAsync();
// Validate new database name
if (string.IsNullOrWhiteSpace(createDatabaseDialog.DatabaseName))
{
DisplayError("Database name cannot be blank.", "Error Creating Database");
}
// Ensure unique name
else if (currentDbNames.Contains(createDatabaseDialog.DatabaseName))
{
DisplayError("A database named '" + createDatabaseDialog.DatabaseName + "' already exists.", "Error Creating Database");
return;
}
// Attempt to create the database
else
{
// Create the database and receive the response
var response = await client.CreateDatabaseAsync(createDatabaseDialog.DatabaseName);
if (!response.Success)
{
DisplayError(response.Body, "Error Creating Database");
return;
}
// If the create was successful, show the new database
var newDatabaseNode = CreateTreeNode(createDatabaseDialog.DatabaseName, InfluxDbNodeTypes.Database);
node.Nodes.Add(newDatabaseNode);
newDatabaseNode.ContextMenuStrip = databaseContextMenu;
// Don't render measurement, instead include a loading place holder
var placeholderNode = CreateTreeNode("loading...", InfluxDbNodeTypes.LoadingPlacholder);
newDatabaseNode.Nodes.Add(placeholderNode);
connectionsTreeView.SelectedNode = newDatabaseNode;
}
}
}
catch (Exception ex)
{
DisplayException(ex);
}
}
// Connection -> Show Retention Policies
async Task ShowRetentionPolicies(TreeNode node)
{
try
{
// Get connection
var connection = GetConnection(node);
var client = GetClient(connection);
// Create a new control
var policyControl = new RetentionPolicyControl();
policyControl.InfluxDbClient = client;
// Add a tab with a query control in it
tabControl.AddTabWithControl(connection.Name + ".policies", policyControl, Properties.Resources.RetentionPolicy);
// Update UI
UpdateUIState();
// Render
await policyControl.ExecuteRequestAsync();
}
catch (Exception ex)
{
DisplayException(ex);
}
}
// Connection -> Show Users
async Task ShowUsers(TreeNode node)
{
try
{
// Get connection
var connection = GetConnection(node);
var client = GetClient(connection);
// Create a new users control
var usersControl = new InfluxDbUsersControl();
usersControl.InfluxDbClient = client;
// Add a tab with a query control in it
tabControl.AddTabWithControl(connection.Name + ".users", usersControl, Properties.Resources.Users);
// Update UI
UpdateUIState();
// Render
await usersControl.ExecuteRequestAsync();
}
catch (Exception ex)
{
DisplayException(ex);
}
}
// Connection -> Show Statistics
async Task ShowStatistics(TreeNode node)
{
try
{
// Get connection
var connection = GetConnection(node);
var client = GetClient(connection);
// Create a new diagnostics control
var statsControl = new StatsControl();
statsControl.InfluxDbClient = client;
// Add a tab with a query control in it
tabControl.AddTabWithControl(connection.Name + ".statistics", statsControl, Properties.Resources.Stats);
// Update UI
UpdateUIState();
// Render
await statsControl.ExecuteRequestAsync();
}
catch (Exception ex)