-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathfrmAntMonitor.vb
5982 lines (4390 loc) · 257 KB
/
frmAntMonitor.vb
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
Imports MMinerMonitor.Extensions
Public Class frmMain
'handles the attempt to run this program when it's already running
Public Event StartupNextInstance As Microsoft.VisualBasic.ApplicationServices.StartupNextInstanceEventHandler
'what it sounds like
Private ToldUserRunningInNotificationTray As Boolean
'web browser control and busy indicators
Private wb(0 To 2) As WebBrowser
Private wbData(0 To 2) As clsWBData
Private Class clsWBData
Public IsBusy As Boolean
Public StartTime As Date
End Class
'tracks last time emails and reboots occurred
Private RebootInfo, EMailAlertInfo As System.Collections.Generic.Dictionary(Of String, Date)
'the dataset that holds the grid data
Private ds, dsMinerConfig As DataSet
'location of the configuration settings in the registry
Private Const csRegKey As String = "Software\MAntMonitor"
'version
Private Const csVersion As String = "M's Miner Monitor v4.3"
'alert string
Private sAlerts As String
'how many seconds until next refresh
Private iCountDown As Integer
'how often we refresh
Private iRefreshRate As Integer
'class to make managing configuration settings easy
Private ctlsByKey As ControlsByRegistry
'used to prevent controls from firing before the app is fully started
Private bStarted As Boolean
Private Class clsSupportedMinerInfo
'supported miner types
Public Enum enSupportedMinerTypes
AntMinerS1 = 1
AntMinerS2 = 2
AntMinerS3 = 3
AntMinerS4 = 4
AntMinerC1 = 5
SpondooliesSP10 = 6
SpondooliesSP20 = 7
SpondooliesSP30 = 8
SpondooliesSP31 = 9
SpondooliesSP35 = 10
AntminerS5 = 11
End Enum
Public Structure stAlertTypes
Public Fans As Boolean
Public Hash As Boolean
Public Temps As Boolean
Public XCount As Boolean
End Structure
Public Structure stAlertInfoStringRegistry
Public Key As String
Public Value As String
End Structure
Public Structure stAlertInfoBooleanRegistry
Public Key As String
Public Value As Boolean
End Structure
Public Class clsAlertInfo
Public Item As stAlertInfoStringRegistry
Public Enabled As stAlertInfoBooleanRegistry
Public Sub Initialize(ByVal sEnabledKey As String, ByVal sValueKey As String, ByVal sDefault As String, ByVal bDefaultEnabled As Boolean)
Dim sReturn As String
Me.Item.Key = sValueKey
Me.Enabled.Key = sEnabledKey
Using key As Microsoft.Win32.RegistryKey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(csRegKey)
If key Is Nothing Then
My.Computer.Registry.CurrentUser.CreateSubKey(csRegKey)
End If
End Using
Using key As Microsoft.Win32.RegistryKey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(csRegKey)
'is enabled
sReturn = key.GetValue(sEnabledKey)
If String.IsNullOrEmpty(sReturn) = True Then
Me.Enabled.Value = bDefaultEnabled
Else
If sReturn = "Y" Then
Me.Enabled.Value = True
Else
Me.Enabled.Value = False
End If
End If
'value
sReturn = key.GetValue(sValueKey)
If String.IsNullOrEmpty(sReturn) = False Then
Me.Item.Value = sReturn
Else
Me.Item.Value = sDefault
End If
End Using
End Sub
Public Sub SaveSettings(ByVal bEnabled As Boolean, ByVal sValue As String)
If Me.Enabled.Key Is Nothing Then
'unsupported value
Exit Sub
End If
Me.Enabled.Value = bEnabled
Me.Item.Value = sValue
If bEnabled = True Then
My.Computer.Registry.SetValue("HKEY_CURRENT_USER\" & csRegKey, Me.Enabled.Key, "Y")
Else
My.Computer.Registry.SetValue("HKEY_CURRENT_USER\" & csRegKey, Me.Enabled.Key, "N")
End If
My.Computer.Registry.SetValue("HKEY_CURRENT_USER\" & csRegKey, Me.Item.Key, sValue)
End Sub
End Class
Public Class clsAlerts
Public FanHigh As clsAlertInfo
Public FanLow As clsAlertInfo
Public HashLow As clsAlertInfo
Public TempHigh As clsAlertInfo
Public XCount As clsAlertInfo
Public Sub New()
FanHigh = New clsAlertInfo
FanLow = New clsAlertInfo
HashLow = New clsAlertInfo
TempHigh = New clsAlertInfo
XCount = New clsAlertInfo
End Sub
End Class
Public Class clsMinerInfo
Private sShortName As String
Private sLongName As String
Private xMinerType As clsSupportedMinerInfo.enSupportedMinerTypes
Private xAlertTypes As stAlertTypes
Private xAlerts As clsAlerts
Private ctlsByKey As ControlsByRegistry
Public ReadOnly Property ShortName As String
Get
Return Me.sShortName
End Get
End Property
Public ReadOnly Property LongName As String
Get
Return Me.sLongName
End Get
End Property
Public ReadOnly Property MinerType As clsSupportedMinerInfo.enSupportedMinerTypes
Get
Return Me.xMinerType
End Get
End Property
Public ReadOnly Property AlertTypes As stAlertTypes
Get
Return xAlertTypes
End Get
End Property
Public ReadOnly Property AlertValues As clsAlerts
Get
Return xAlerts
End Get
End Property
Public Sub New(ByVal MinerType As clsSupportedMinerInfo.enSupportedMinerTypes)
Me.xMinerType = MinerType
Me.xAlerts = New clsAlerts
Select Case MinerType
Case clsSupportedMinerInfo.enSupportedMinerTypes.AntMinerC1
Me.sShortName = "C1"
Me.sLongName = "Antminer C1"
Me.xAlertTypes.Fans = True
Me.xAlertTypes.Hash = True
Me.xAlertTypes.Temps = True
Me.xAlertTypes.XCount = True
With Me.xAlerts
.FanHigh.Initialize("AlertIfC1Fan", "AlertValueC1Fan", "", False)
.FanLow.Initialize("AlertIfC1FanLow", "AlertValueC1FanLow", "", False)
.TempHigh.Initialize("AlertIfC1Temp", "AlertValueC1Temp", "", False)
.HashLow.Initialize("AlertIfC1Hash", "AlertValueC1Hash", "", False)
.XCount.Initialize("AlertIfC1XCount", "AlertValueC1XCount", "", False)
End With
Case clsSupportedMinerInfo.enSupportedMinerTypes.AntMinerS1
Me.sShortName = "S1"
Me.sLongName = "Antminer S1"
Me.xAlertTypes.Fans = True
Me.xAlertTypes.Hash = True
Me.xAlertTypes.Temps = True
Me.xAlertTypes.XCount = True
With Me.xAlerts
.FanHigh.Initialize("AlertIfS1Fan", "AlertValueS1Fan", "", False)
.FanLow.Initialize("AlertIfS1FanLow", "AlertValueS1FanLow", "", False)
.TempHigh.Initialize("AlertIfS1Temp", "AlertValueS1Temp", "", False)
.HashLow.Initialize("AlertIfS1Hash", "AlertValueS1Hash", "", False)
.XCount.Initialize("AlertIfS1XCount", "AlertValueS1XCount", "", False)
End With
Case clsSupportedMinerInfo.enSupportedMinerTypes.AntMinerS2
Me.sShortName = "S2"
Me.sLongName = "Antminer S2"
Me.xAlertTypes.Fans = True
Me.xAlertTypes.Hash = True
Me.xAlertTypes.Temps = True
Me.xAlertTypes.XCount = True
With Me.xAlerts
.FanHigh.Initialize("AlertIfS2Fan", "AlertValueS2Fan", "", False)
.FanLow.Initialize("AlertIfS2FanLow", "AlertValueS2FanLow", "", False)
.TempHigh.Initialize("AlertIfS2Temp", "AlertValueS2Temp", "", False)
.HashLow.Initialize("AlertIfS2Hash", "AlertValueS2Hash", "", False)
.XCount.Initialize("AlertIfS2XCount", "AlertValueS2XCount", "", False)
End With
Case clsSupportedMinerInfo.enSupportedMinerTypes.AntMinerS3
Me.sShortName = "S3"
Me.sLongName = "Antminer S3"
Me.xAlertTypes.Fans = True
Me.xAlertTypes.Hash = True
Me.xAlertTypes.Temps = True
Me.xAlertTypes.XCount = True
With Me.xAlerts
.FanHigh.Initialize("AlertIfS3Fan", "AlertValueS3Fan", "", False)
.FanLow.Initialize("AlertIfS3FanLow", "AlertValueS3FanLow", "", False)
.TempHigh.Initialize("AlertIfS3Temp", "AlertValueS3Temp", "", False)
.HashLow.Initialize("AlertIfS3Hash", "AlertValueS3Hash", "", False)
.XCount.Initialize("AlertIfS3XCount", "AlertValueS3XCount", "", False)
End With
Case clsSupportedMinerInfo.enSupportedMinerTypes.AntMinerS4
Me.sShortName = "S4"
Me.sLongName = "Antminer S4"
Me.xAlertTypes.Fans = True
Me.xAlertTypes.Hash = True
Me.xAlertTypes.Temps = True
Me.xAlertTypes.XCount = True
With Me.xAlerts
.FanHigh.Initialize("AlertIfS4Fan", "AlertValueS4Fan", "", False)
.FanLow.Initialize("AlertIfS4FanLow", "AlertValueS4FanLow", "", False)
.TempHigh.Initialize("AlertIfS4Temp", "AlertValueS4Temp", "", False)
.HashLow.Initialize("AlertIfS4Hash", "AlertValueS4Hash", "", False)
.XCount.Initialize("AlertIfS4XCount", "AlertValueS4XCount", "", False)
End With
Case clsSupportedMinerInfo.enSupportedMinerTypes.AntminerS5
Me.sShortName = "S5"
Me.sLongName = "Antminer S5"
Me.xAlertTypes.Fans = True
Me.xAlertTypes.Hash = True
Me.xAlertTypes.Temps = True
Me.xAlertTypes.XCount = True
With Me.xAlerts
.FanHigh.Initialize("AlertIfS5Fan", "AlertValueS5Fan", "", False)
.FanLow.Initialize("AlertIfS5FanLow", "AlertValueS5FanLow", "", False)
.TempHigh.Initialize("AlertIfS5Temp", "AlertValueS5Temp", "", False)
.HashLow.Initialize("AlertIfS5Hash", "AlertValueS5Hash", "", False)
.XCount.Initialize("AlertIfS5XCount", "AlertValueS5XCount", "", False)
End With
Case clsSupportedMinerInfo.enSupportedMinerTypes.SpondooliesSP10
Me.sShortName = "SP10"
Me.sLongName = "Spondoolies SP10"
Me.xAlertTypes.Fans = False
Me.xAlertTypes.Hash = True
Me.xAlertTypes.Temps = True
Me.xAlertTypes.XCount = False
With Me.xAlerts
.TempHigh.Initialize("AlertIfSP10Temp", "AlertValueSP10Temp", "", False)
.HashLow.Initialize("AlertIfSP10Hash", "AlertValueSP10Hash", "", False)
End With
Case clsSupportedMinerInfo.enSupportedMinerTypes.SpondooliesSP20
Me.sShortName = "SP20"
Me.sLongName = "Spondoolies SP20"
Me.xAlertTypes.Fans = False
Me.xAlertTypes.Hash = True
Me.xAlertTypes.Temps = True
Me.xAlertTypes.XCount = False
With Me.xAlerts
.TempHigh.Initialize("AlertIfSP20Temp", "AlertValueSP20Temp", "", False)
.HashLow.Initialize("AlertIfSP20Hash", "AlertValueSP20Hash", "", False)
End With
Case clsSupportedMinerInfo.enSupportedMinerTypes.SpondooliesSP30
Me.sShortName = "SP30"
Me.sLongName = "Spondoolies SP30"
Me.xAlertTypes.Fans = False
Me.xAlertTypes.Hash = True
Me.xAlertTypes.Temps = True
Me.xAlertTypes.XCount = False
With Me.xAlerts
.TempHigh.Initialize("AlertIfSP30Temp", "AlertValueSP30Temp", "", False)
.HashLow.Initialize("AlertIfSP30Hash", "AlertValueSP30Hash", "", False)
End With
Case clsSupportedMinerInfo.enSupportedMinerTypes.SpondooliesSP31
Me.sShortName = "SP31"
Me.sLongName = "Spondoolies SP31"
Me.xAlertTypes.Fans = False
Me.xAlertTypes.Hash = True
Me.xAlertTypes.Temps = True
Me.xAlertTypes.XCount = False
With Me.xAlerts
.TempHigh.Initialize("AlertIfSP31Temp", "AlertValueSP31Temp", "", False)
.HashLow.Initialize("AlertIfSP31Hash", "AlertValueSP31Hash", "", False)
End With
Case clsSupportedMinerInfo.enSupportedMinerTypes.SpondooliesSP35
Me.sShortName = "SP35"
Me.sLongName = "Spondoolies SP35"
Me.xAlertTypes.Fans = False
Me.xAlertTypes.Hash = True
Me.xAlertTypes.Temps = True
Me.xAlertTypes.XCount = False
With Me.xAlerts
.TempHigh.Initialize("AlertIfSP35Temp", "AlertValueSP35Temp", "", False)
.HashLow.Initialize("AlertIfSP35Hash", "AlertValueSP35Hash", "", False)
End With
Case Else
Throw New Exception("Internal error: miner type not found")
End Select
End Sub
End Class
Public AntMinerS1 As clsMinerInfo
Public AntMinerS2 As clsMinerInfo
Public AntMinerS3 As clsMinerInfo
Public AntMinerS4 As clsMinerInfo
Public AntMinerS5 As clsMinerInfo
Public AntMinerC1 As clsMinerInfo
Public SpondoolieSP10 As clsMinerInfo
Public SpondoolieSP20 As clsMinerInfo
Public SpondoolieSP30 As clsMinerInfo
Public SpondoolieSP31 As clsMinerInfo
Public SpondoolieSP35 As clsMinerInfo
Public SupportedMinerCollection As System.Collections.Generic.List(Of clsMinerInfo)
Public Sub New()
AntMinerC1 = New clsMinerInfo(enSupportedMinerTypes.AntMinerC1)
AntMinerS1 = New clsMinerInfo(enSupportedMinerTypes.AntMinerS1)
AntMinerS2 = New clsMinerInfo(enSupportedMinerTypes.AntMinerS2)
AntMinerS3 = New clsMinerInfo(enSupportedMinerTypes.AntMinerS3)
AntMinerS4 = New clsMinerInfo(enSupportedMinerTypes.AntMinerS4)
AntMinerS5 = New clsMinerInfo(enSupportedMinerTypes.AntminerS5)
SpondoolieSP10 = New clsMinerInfo(enSupportedMinerTypes.SpondooliesSP10)
SpondoolieSP20 = New clsMinerInfo(enSupportedMinerTypes.SpondooliesSP20)
SpondoolieSP30 = New clsMinerInfo(enSupportedMinerTypes.SpondooliesSP30)
SpondoolieSP31 = New clsMinerInfo(enSupportedMinerTypes.SpondooliesSP31)
SpondoolieSP35 = New clsMinerInfo(enSupportedMinerTypes.SpondooliesSP35)
SupportedMinerCollection = New System.Collections.Generic.List(Of clsMinerInfo)
SupportedMinerCollection.Add(Me.AntMinerS1)
SupportedMinerCollection.Add(Me.AntMinerS2)
SupportedMinerCollection.Add(Me.AntMinerS3)
SupportedMinerCollection.Add(Me.AntMinerS4)
SupportedMinerCollection.Add(Me.AntMinerS5)
SupportedMinerCollection.Add(Me.AntMinerC1)
SupportedMinerCollection.Add(Me.SpondoolieSP10)
SupportedMinerCollection.Add(Me.SpondoolieSP20)
SupportedMinerCollection.Add(Me.SpondoolieSP30)
SupportedMinerCollection.Add(Me.SpondoolieSP31)
SupportedMinerCollection.Add(Me.SpondoolieSP35)
End Sub
Public Function GetMinerObjectByShortName(ByVal sShortName As String) As clsMinerInfo
Dim mi As clsMinerInfo
For Each mi In Me.SupportedMinerCollection
If mi.ShortName.ToLower = sShortName.ToLower Then
Return mi
End If
Next
Throw New Exception("Internal error: No match on ShortName in GetMinerObjectByShortName: " & sShortName)
End Function
Public Function GetMinerObjectByLongName(ByVal sLongName As String) As clsMinerInfo
Dim mi As clsMinerInfo
For Each mi In Me.SupportedMinerCollection
If mi.LongName.ToLower = sLongName.ToLower Then
Return mi
End If
Next
Throw New Exception("Internal error: No match on LongName in GetMinerObjectByLongName: " & sLongName)
End Function
Public Function GetMinerObjectByType(ByVal minerType As clsSupportedMinerInfo.enSupportedMinerTypes) As clsMinerInfo
Dim mi As clsMinerInfo
For Each mi In Me.SupportedMinerCollection
If mi.MinerType = minerType Then
Return mi
End If
Next
Throw New Exception("Internal error: No match on MinerType in GetMinerObjectByType: " & minerType)
End Function
End Class
Private SupportedMinerInfo As clsSupportedMinerInfo
'log queue from other threads
Private Shared logQueue As System.Collections.Generic.Queue(Of String)
Private Shared logQueueLock As Object
'queue of ants to check
Private Shared minersToCheckQueue As System.Collections.Generic.Queue(Of stMinerConfig)
Private Shared minersToCheckLock As Object
'data coming back from the worker threads with Miner refresh data
Private Shared MinerRefreshDataQueue As System.Collections.Generic.Queue(Of clsMinerRefreshData)
Private Shared MinerRefreshLock As Object
'display refresh period after miner refresh is initiated
Private iDisplayRefreshPeriod As Integer
'object populated by the worker threads that is passed back to the UI thread for grid population
Private Class clsMinerRefreshData
Public MinerType As clsSupportedMinerInfo.enSupportedMinerTypes
Public ID As Integer
Public sStats As String
Public sSummary As String
Public sPools As String
Public sAntIP As String
Public bError As Boolean
Public ex As Exception
End Class
'ant data from the config
Private Structure stMinerConfig
Dim sName As String
Dim sIP As String
Dim MinerType As clsSupportedMinerInfo.enSupportedMinerTypes
Dim sAPIPort As String
Dim sHTTPPort As String
Dim sSSHPort As String
Dim ID As Integer
Dim sSSHPassword As String
Dim sSSHUsername As String
Dim sWebUsername As String
Dim sWebPassword As String
End Structure
'# of ants enabled in the config
Private iAntsEnabled As Integer
'worker threads and data
Private workerThread() As System.Threading.Thread
Private ThreadHandlers() As clsThreadHandler
Private Class clsThreadHandler
Public bBusy As Boolean
Public MinerToCheck As stMinerConfig
Public bGotWork As Boolean
End Class
'set to true when shutting down
Private bShutDown As Boolean
'pool data for pushing pool data to ants
Private Class clsPoolData
Public URL As String
Public UID As String
Public PW As String
Public Sub New()
PW = ""
End Sub
End Class
'for miner scanning on another thread
Private sIPDataResponse As String
Private sIPToCheck As String
'for get miner info on another thread
Private sIPToGetInfo As String
Private Shared listOfGetInfoResponse As System.Collections.Generic.List(Of String)
'for tracking scheduled reboots
Private dictScheduledReboots As System.Collections.Generic.Dictionary(Of Integer, Date)
'for tracking reboot at
Private dictRebootAt As System.Collections.Generic.Dictionary(Of Integer, Date)
'for tracking reboot at also
Private dictRebootAtAlso As System.Collections.Generic.Dictionary(Of Integer, Date)
#If DEBUG Then
Private bErrorHandle As Boolean = False
#Else
Private bErrorHandle As Boolean = True
#End If
Private Sub Form1_Load(sender As Object, e As System.EventArgs) Handles Me.Load
Dim host As System.Net.IPHostEntry
Dim x As Integer
Dim s() As String
Dim dr As DataRow
Dim MinerInfo As clsSupportedMinerInfo.clsMinerInfo
Dim bTemp As Boolean
bStarted = True
Me.Text = csVersion
'initialize objects
logQueue = New System.Collections.Generic.Queue(Of String)
logQueueLock = New Object
SupportedMinerInfo = New clsSupportedMinerInfo
minersToCheckQueue = New System.Collections.Generic.Queue(Of stMinerConfig)
minersToCheckLock = New Object
MinerRefreshDataQueue = New System.Collections.Generic.Queue(Of clsMinerRefreshData)
MinerRefreshLock = New Object
wbData(0) = New clsWBData
wbData(1) = New clsWBData
wbData(2) = New clsWBData
dictScheduledReboots = New System.Collections.Generic.Dictionary(Of Integer, Date)
dictRebootAt = New System.Collections.Generic.Dictionary(Of Integer, Date)
dictRebootAtAlso = New System.Collections.Generic.Dictionary(Of Integer, Date)
AddToLogQueue(csVersion & " starting")
host = System.Net.Dns.GetHostEntry(System.Net.Dns.GetHostName)
For Each IP As System.Net.IPAddress In host.AddressList
If IP.AddressFamily = Net.Sockets.AddressFamily.InterNetwork Then
s = IP.ToString.Split(".")
Me.txtIPRangeToScan.Text = s(0) & "." & s(1) & "." & s(2)
End If
Next
For x = 1 To 254
Me.cmbAntScanStart.Items.Add(x)
Me.cmbAntScanStop.Items.Add(x)
Next
For Each SupportMiner As clsSupportedMinerInfo.clsMinerInfo In SupportedMinerInfo.SupportedMinerCollection
Me.cmbMinerType.Items.Add(SupportMiner.LongName)
Me.cmbAlertMinerType.Items.Add(SupportMiner.LongName)
Next
RebootInfo = New System.Collections.Generic.Dictionary(Of String, Date)
EMailAlertInfo = New System.Collections.Generic.Dictionary(Of String, Date)
'ant output
ds = New DataSet
With ds
.Tables.Add()
Me.dataMiners.DataSource = .Tables(0)
With .Tables(0).Columns
.Add("Name")
.Add("Uptime")
.Add("GH/s(5s)", GetType(Double))
.Add("GH/s(avg)", GetType(Double))
.Add("Blocks")
.Add("HWE%")
.Add("BestShare")
.Add("Diff")
.Add("Pools")
.Add("PoolData")
.Add("PoolData2", GetType(Object))
.Add("Rej%")
.Add("Stale%")
.Add("HFan", GetType(Integer))
.Add("Fans")
.Add("HTemp", GetType(Integer))
.Add("Temps")
.Add("Freq", GetType(Double))
.Add("XCount")
.Add("Status")
.Add("ACount", GetType(Integer))
'.Add("IPAddress")
.Add("ID")
.Add("Type")
End With
End With
Me.dataMiners.Columns("PoolData").Visible = False
Me.dataMiners.Columns("PoolData2").Visible = False
'Me.dataMiners.Columns("IPAddress").Visible = False
Me.dataMiners.Columns("Type").Visible = False
Me.dataMiners.Columns("HWE%").ToolTipText = "Hardware Error Percentage"
Me.dataMiners.Columns("Diff").ToolTipText = "Difficulty Miner is using. For web scraping, it's the value from all 3 pools."
Me.dataMiners.Columns("HFan").ToolTipText = "Highest Fan Speed"
Me.dataMiners.Columns("Rej%").ToolTipText = "Reject Percentage"
Me.dataMiners.Columns("HTemp").ToolTipText = "Highest Temperature across all blades"
Me.dataMiners.Columns("Freq").ToolTipText = "Frequency Miner is running at"
Me.dataMiners.Columns("XCount").ToolTipText = "Number of Xs this Miner has"
Me.dataMiners.Columns("ACount").ToolTipText = "Alert count for this Miner"
With Me.dataMiners
.Columns("ACount").Width = 74
.Columns("Blocks").Width = 65
.Columns("Diff").Width = 48
.Columns("Freq").Width = 62
.Columns("GH/s(5s)").Width = 87
.Columns("GH/s(avg)").Width = 92
.Columns("HFan").Width = 63
.Columns("HTemp").Width = 73
.Columns("HWE%").Width = 76
.Columns("Name").Width = 69
.Columns("Pools").Width = 60
.Columns("Rej%").Width = 65
.Columns("Stale%").Width = 71
.Columns("Status").Width = 266
.Columns("Temps").Width = 220
.Columns("XCount").Width = 71
.Columns("ID").Width = 49
End With
ctlsByKey = New ControlsByRegistry(csRegKey)
Call SetGridSizes("\Columns\dataMiners", Me.dataMiners)
Call SetGridColumnPositions("\Columns\" & Me.dataMiners.Name & "_DisplayIndex", Me.dataMiners)
'handles saving of column widths and column locations
AddHandler Me.dataMiners.ColumnWidthChanged, AddressOf Me.dataGrid_ColumnWidthChanged
AddHandler Me.dataMiners.ColumnDisplayIndexChanged, AddressOf Me.dataMiners_ColumnDisplayIndexChanged
Using key As Microsoft.Win32.RegistryKey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(csRegKey)
If key Is Nothing Then
My.Computer.Registry.CurrentUser.CreateSubKey(csRegKey)
End If
End Using
'load configuration
Using key As Microsoft.Win32.RegistryKey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(csRegKey)
If key.GetValue("Width") > 100 Then
Me.Width = key.GetValue("Width")
End If
If key.GetValue("Height") > 100 Then
Me.Height = key.GetValue("Height")
End If
If key.GetValue("ToldUserAboutNotification") = "Y" Then
ToldUserRunningInNotificationTray = True
End If
End Using
With ctlsByKey
'options
'.AddControl(Me.chklstAnts, "AntList")
.AddControl(Me.txtRefreshRate, "RefreshRateValue")
.AddControl(Me.cmbRefreshRate, "RefreshRateVolume")
.AddControl(Me.chkShowBestShare, "ShowBestShare")
.AddControl(Me.chkShowBlocks, "ShowBlocks")
.AddControl(Me.chkShowFans, "ShowFans")
.AddControl(Me.chkShowGHs5s, "ShowGHs5s")
.AddControl(Me.chkShowGHsAvg, "ShowGHsAvg")
.AddControl(Me.chkShowHWE, "ShowHWE")
.AddControl(Me.chkShowPools, "ShowPools")
.AddControl(Me.chkShowStatus, "ShowStatus")
.AddControl(Me.chkShowTemps, "ShowTemps")
.AddControl(Me.chkShowUptime, "ShowUptime")
.AddControl(Me.chkShowFreqs, "ShowFreqs")
.AddControl(Me.chkShowHighFan, "ShowHighFan")
.AddControl(Me.chkShowHighTemp, "ShowHighTemp")
.AddControl(Me.chkShowXCount, "ShowXCount")
.AddControl(Me.chkShowRej, "ShowReject")
.AddControl(Me.chkShowStale, "ShowStale")
.AddControl(Me.chkShowDifficulty, "ShowDifficulty")
.AddControl(Me.chkShowACount, "ShowACount")
.AddControl(Me.chkShowSelectionColumn, "ShowSelectionColumn")
'.AddControl(Me.chkUseAPI, "UseAPI")
.AddControl(Me.trackThreadCount, "WorkerThreadCount")
.AddControl(Me.txtDisplayRefreshInSecs, "DisplayRefreshPeriod")
''alerts
''S1
'.AddControl(Me.chkAlertIfS1Temp, "AlertIfS1Temp")
'.AddControl(Me.txtAlertS1Temp, "AlertValueS1Temp")
'.AddControl(Me.chkAlertIfS1FanHigh, "AlertIfS1Fan")
'.AddControl(Me.txtAlertS1FanHigh, "AlertValueS1Fan")
'.AddControl(Me.chkAlertIfS1FanLow, "AlertIfS1FanLow")
'.AddControl(Me.txtAlertS1FanLow, "AlertValueS1FanLow")
'.AddControl(Me.chkAlertIfS1Hash, "AlertIfS1Hash")
'.AddControl(Me.txtAlertS1Hash, "AlertValueS1Hash")
'.AddControl(Me.chkAlertIfS1XCount, "AlertIfS1XCount")
'.AddControl(Me.txtAlertS1XCount, "AlertValueS1XCount")
''S2
'.AddControl(Me.chkAlertIfS2Temp, "AlertIfS2Temp")
'.AddControl(Me.txtAlertS2Temp, "AlertValueS2Temp")
'.AddControl(Me.chkAlertIfS2FanHigh, "AlertIfS2Fan")
'.AddControl(Me.txtAlertS2FanHigh, "AlertValueS2Fan")
'.AddControl(Me.chkAlertIfS2FanLow, "AlertIfS2FanLow")
'.AddControl(Me.txtAlertS2FanLow, "AlertValueS2FanLow")
'.AddControl(Me.chkAlertIfS2Hash, "AlertIFS2Hash")
'.AddControl(Me.txtAlertS2Hash, "AlertValueS2Hash")
'.AddControl(Me.chkAlertIfS2XCount, "AlertIFS2XCount")
'.AddControl(Me.txtAlertS2XCount, "AlertValueS2XCount")
''S3
'.AddControl(Me.chkAlertIfS3Temp, "AlertIfS3Temp")
'.AddControl(Me.txtAlertS3Temp, "AlertValueS3Temp")
'.AddControl(Me.chkAlertIfS3FanHigh, "AlertIfS3Fan")
'.AddControl(Me.txtAlertS3FanHigh, "AlertValueS3Fan")
'.AddControl(Me.chkAlertIfS3FanLow, "AlertIfS3FanLow")
'.AddControl(Me.txtAlertS3FanLow, "AlertValueS3FanLow")
'.AddControl(Me.chkAlertIfS3Hash, "AlertIFS3Hash")
'.AddControl(Me.txtAlertS3Hash, "AlertValueS3Hash")
'.AddControl(Me.chkAlertIfS3XCount, "AlertIFS3XCount")
'.AddControl(Me.txtAlertS3XCount, "AlertValueS3XCount")
''S4
'.AddControl(Me.chkAlertIfS4Temp, "AlertIfS4Temp")
'.AddControl(Me.txtAlertS4Temp, "AlertValueS4Temp")
'.AddControl(Me.chkAlertIfS4FanHigh, "AlertIfS4Fan")
'.AddControl(Me.txtAlertS4FanHigh, "AlertValueS4Fan")
'.AddControl(Me.chkAlertIfS4FanLow, "AlertIfS4FanLow")
'.AddControl(Me.txtAlertS4FanLow, "AlertValueS4FanLow")
'.AddControl(Me.chkAlertIfS4Hash, "AlertIFS4Hash")
'.AddControl(Me.txtAlertS4Hash, "AlertValueS4Hash")
'.AddControl(Me.chkAlertIfS4XCount, "AlertIFS4XCount")
'.AddControl(Me.txtAlertS4XCount, "AlertValueS4XCount")
''C1
'.AddControl(Me.txtAlertC1Temp, "AlertValueC1Temp")
'.AddControl(Me.chkAlertIfC1Temp, "AlertIfC1Temp")
'.AddControl(Me.chkAlertIfC1FanHigh, "AlertIfC1Fan")
'.AddControl(Me.txtAlertC1FanHigh, "AlertValueC1Fan")
'.AddControl(Me.chkAlertIfC1FanLow, "AlertIfC1FanLow")
'.AddControl(Me.txtAlertC1FanLow, "AlertValueC1FanLow")
'.AddControl(Me.chkAlertIfC1Hash, "AlertIFC1Hash")
'.AddControl(Me.txtAlertC1Hash, "AlertValueC1Hash")
'.AddControl(Me.chkAlertIfC1XCount, "AlertIFC1XCount")
'.AddControl(Me.txtAlertC1XCount, "AlertValueC1XCount")
''SP
'.AddControl(Me.txtAlertSPTemp, "AlertValueSPTemp")
'.AddControl(Me.chkAlertIfSPTemp, "AlertIfSPTemp")
'.AddControl(Me.chkAlertIfSPHash, "AlertIFSPHash")
'.AddControl(Me.txtAlertSPHash, "AlertValueSPHash")
.AddControl(Me.chkAlertHighlightField, "AlertHighlightField")
.AddControl(Me.chkAlertShowAnnoyingPopup, "AlertShowAnnoyingPopup")
.AddControl(Me.chkAlertShowNotifyPopup, "AlertShowNotifyPopup")
.AddControl(Me.chkAlertStartProcess, "AlertStartProcess")
.AddControl(Me.txtAlertStartProcessName, "AlertProcessName")
.AddControl(Me.txtAlertStartProcessParms, "AlertProcessParms")
.AddControl(Me.txtAlertEMailGovernor, "AlertEMailGovernorSize")
.AddControl(Me.cmbAlertEMailGovernor, "AlertEMailGovernorValue")
.AddControl(Me.chkAlertSendEMail, "AlertSendEMail")
'email settings
.AddControl(Me.txtSMTPServer, "SMTPServerName")
.AddControl(Me.txtSMTPPort, "SMTPServerPort")
.AddControl(Me.txtSMTPUserName, "SMTPUserName")
.AddControl(Me.txtSMTPPassword, "SMTPUserPassword")
.AddControl(Me.txtSMTPAlertName, "SMTPAlertName")
.AddControl(Me.txtSMTPAlertAddress, "SMTPAlertAddress")
.AddControl(Me.txtSMTPAlertSubject, "SMTPAlertSubject")
.AddControl(Me.txtSMTPFromName, "SMTPFromName")
.AddControl(Me.txtSMTPFromAddress, "SMTPFromAddress")
.AddControl(Me.chkSMTPSSL, "SMTPUseSSL")
'reboots
.AddControl(Me.chkAlertRebootIfXd, "RebootAntIfXd")
.AddControl(Me.chkAlertRebootAntsOnHashAlert, "RebootAntIfHashAlert")
.AddControl(Me.chkRebootAntOnError, "RebootAntIfError")
.AddControl(Me.txtAlertRebootGovernor, "AlertRebootGovernor")
.AddControl(Me.cmbAlertRebootGovernor, "AlertRebootGovernorValue")
.AddControl(Me.chkRebootAllAntsAt, "RebootAllAntsAtOnOff")
.AddControl(Me.txtRebootAllAntsAt, "RebootAllAntsAtValue")
.AddControl(Me.cmbRebootAllAntsAt, "RebootAllAntsAtAMPM")
.AddControl(Me.chkRebootAllAntsAtAlso, "RebootAllAntsAtAlsoOnOff")
.AddControl(Me.txtRebootAllAntsAtAlso, "RebootAllAntsAtAlsoValue")
.AddControl(Me.cmbRebootAllAntsAtAlso, "RebootAllAntsAtAlsoAMPM")
.AddControl(Me.chkRebootAntsByUptime, "RebootAntsByUptimeOnOff")
.AddControl(Me.txtRebootAntsByUptime, "RebootAntsByUptimeValue")
.AddControl(Me.cmbRebootAntsByUptime, "RebootAntsByUptimeSecMinHour")
.SetControlByRegKey(Me.txtRefreshRate, "300")
.SetControlByRegKey(Me.cmbRefreshRate, "Seconds")
.SetControlByRegKey(Me.chkShowBestShare, True)
.SetControlByRegKey(Me.chkShowBlocks, True)
.SetControlByRegKey(Me.chkShowFans, True)
.SetControlByRegKey(Me.chkShowGHs5s, True)
.SetControlByRegKey(Me.chkShowGHsAvg, True)
.SetControlByRegKey(Me.chkShowHWE, True)
.SetControlByRegKey(Me.chkShowPools, True)
.SetControlByRegKey(Me.chkShowStatus, True)
.SetControlByRegKey(Me.chkShowTemps, True)
.SetControlByRegKey(Me.chkShowUptime, True)
.SetControlByRegKey(Me.chkShowFreqs, True)
.SetControlByRegKey(Me.chkShowHighTemp, True)
.SetControlByRegKey(Me.chkShowHighFan, True)
.SetControlByRegKey(Me.chkShowXCount, True)
.SetControlByRegKey(Me.chkShowRej, True)
.SetControlByRegKey(Me.chkShowStale, True)
.SetControlByRegKey(Me.chkShowDifficulty, True)
.SetControlByRegKey(Me.chkShowACount, True)
.SetControlByRegKey(Me.chkShowSelectionColumn)
.SetControlByRegKey(Me.trackThreadCount, 5)
.SetControlByRegKey(Me.txtDisplayRefreshInSecs, "1")
Call txtDisplayRefreshInSecs_Leave(sender, e)
''alerts
''S1
'.SetControlByRegKey(Me.chkAlertIfS1Temp)
'.SetControlByRegKey(Me.txtAlertS1Temp)
'.SetControlByRegKey(Me.chkAlertIfS1FanHigh)
'.SetControlByRegKey(Me.txtAlertS1FanHigh)
'.SetControlByRegKey(Me.chkAlertIfS1FanLow)
'.SetControlByRegKey(Me.txtAlertS1FanLow)
'.SetControlByRegKey(Me.chkAlertIfS1Hash)
'.SetControlByRegKey(Me.txtAlertS1Hash)
'.SetControlByRegKey(Me.chkAlertIfS1XCount)
'.SetControlByRegKey(Me.txtAlertS1XCount)
''S2
'.SetControlByRegKey(Me.chkAlertIfS2Temp)
'.SetControlByRegKey(Me.txtAlertS2Temp)
'.SetControlByRegKey(Me.chkAlertIfS2FanHigh)
'.SetControlByRegKey(Me.txtAlertS2FanHigh)
'.SetControlByRegKey(Me.chkAlertIfS2FanLow)
'.SetControlByRegKey(Me.txtAlertS2FanLow)
'.SetControlByRegKey(Me.chkAlertIfS2Hash)
'.SetControlByRegKey(Me.txtAlertS2Hash)
'.SetControlByRegKey(Me.chkAlertIfS2XCount)
'.SetControlByRegKey(Me.txtAlertS2XCount)
''S3
'.SetControlByRegKey(Me.chkAlertIfS3Temp)
'.SetControlByRegKey(Me.txtAlertS3Temp)
'.SetControlByRegKey(Me.chkAlertIfS3FanHigh)
'.SetControlByRegKey(Me.txtAlertS3FanHigh)
'.SetControlByRegKey(Me.chkAlertIfS3FanLow)
'.SetControlByRegKey(Me.txtAlertS3FanLow)
'.SetControlByRegKey(Me.chkAlertIfS3Hash)
'.SetControlByRegKey(Me.txtAlertS3Hash)
'.SetControlByRegKey(Me.chkAlertIfS3XCount)
'.SetControlByRegKey(Me.txtAlertS3XCount)
''S4
'.SetControlByRegKey(Me.chkAlertIfS4Temp)
'.SetControlByRegKey(Me.txtAlertS4Temp)
'.SetControlByRegKey(Me.chkAlertIfS4FanHigh)
'.SetControlByRegKey(Me.txtAlertS4FanHigh)
'.SetControlByRegKey(Me.chkAlertIfS4FanLow)
'.SetControlByRegKey(Me.txtAlertS4FanLow)
'.SetControlByRegKey(Me.chkAlertIfS4Hash)
'.SetControlByRegKey(Me.txtAlertS4Hash)
'.SetControlByRegKey(Me.chkAlertIfS4XCount)
'.SetControlByRegKey(Me.txtAlertS4XCount)
''C1
'.SetControlByRegKey(Me.chkAlertIfC1Temp)
'.SetControlByRegKey(Me.txtAlertC1Temp)
'.SetControlByRegKey(Me.chkAlertIfC1FanHigh)
'.SetControlByRegKey(Me.txtAlertC1FanHigh)
'.SetControlByRegKey(Me.chkAlertIfC1FanLow)
'.SetControlByRegKey(Me.txtAlertC1FanLow)
'.SetControlByRegKey(Me.chkAlertIfC1Hash)
'.SetControlByRegKey(Me.txtAlertC1Hash)
'.SetControlByRegKey(Me.chkAlertIfC1XCount)
'.SetControlByRegKey(Me.txtAlertC1XCount)
''SP
'.SetControlByRegKey(Me.chkAlertIfSPTemp)
'.SetControlByRegKey(Me.txtAlertSPTemp)
'.SetControlByRegKey(Me.chkAlertIfSPHash)
'.SetControlByRegKey(Me.txtAlertSPHash)
.SetControlByRegKey(Me.chkAlertHighlightField, True)
.SetControlByRegKey(Me.chkAlertShowNotifyPopup, True)
.SetControlByRegKey(Me.chkAlertShowAnnoyingPopup)
.SetControlByRegKey(Me.chkAlertStartProcess)
.SetControlByRegKey(Me.txtAlertStartProcessName)
.SetControlByRegKey(Me.txtAlertStartProcessParms)
.SetControlByRegKey(Me.chkAlertSendEMail)
'reboots
.SetControlByRegKey(Me.chkAlertRebootIfXd, True)
.SetControlByRegKey(Me.chkAlertRebootAntsOnHashAlert)
.SetControlByRegKey(Me.chkRebootAntOnError)
.SetControlByRegKey(Me.txtAlertRebootGovernor, 30)
.SetControlByRegKey(Me.cmbAlertRebootGovernor, "Minutes")
.SetControlByRegKey(Me.chkRebootAllAntsAt)
.SetControlByRegKey(Me.txtRebootAllAntsAt)
.SetControlByRegKey(Me.cmbRebootAllAntsAt)
.SetControlByRegKey(Me.chkRebootAllAntsAtAlso)
.SetControlByRegKey(Me.txtRebootAllAntsAtAlso)
.SetControlByRegKey(Me.cmbRebootAllAntsAtAlso)
.SetControlByRegKey(Me.chkRebootAntsByUptime)
.SetControlByRegKey(Me.txtRebootAntsByUptime)
.SetControlByRegKey(Me.cmbRebootAntsByUptime)
'email settings
Call ctlsByKey.SetControlByRegKey(Me.txtSMTPServer)
Call ctlsByKey.SetControlByRegKey(Me.txtSMTPPort)
Call ctlsByKey.SetControlByRegKey(Me.txtSMTPUserName)
Call ctlsByKey.SetControlByRegKey(Me.txtSMTPPassword)
Call ctlsByKey.SetControlByRegKey(Me.txtSMTPAlertName)
Call ctlsByKey.SetControlByRegKey(Me.txtSMTPAlertAddress)
Call ctlsByKey.SetControlByRegKey(Me.txtSMTPAlertSubject)
Call ctlsByKey.SetControlByRegKey(Me.txtSMTPFromName)
Call ctlsByKey.SetControlByRegKey(Me.txtSMTPFromAddress)
Call ctlsByKey.SetControlByRegKey(Me.chkSMTPSSL)
Call ctlsByKey.SetControlByRegKey(Me.txtAlertEMailGovernor, "10")
Call ctlsByKey.SetControlByRegKey(Me.cmbAlertEMailGovernor, "Minutes")
End With
Using key As Microsoft.Win32.RegistryKey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(csRegKey & "\Pools")
If key Is Nothing Then