7
7
'
8
8
' This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY
9
9
10
- Imports WinNUT_Params = WinNUT_Client_Common.WinNUT_Params
11
- Imports Logger = WinNUT_Client_Common.Logger
12
10
Imports LogLvl = WinNUT_Client_Common.LogLvl
13
11
Imports AppResxStr = WinNUT_Client_Common.AppResxStr
14
- Imports WinNUT_Globals = WinNUT_Client_Common.WinNUT_Globals
12
+ Imports WinNUT_Client_Common
13
+
15
14
Public Class Shutdown_Gui
16
- Private LogFile As Logger
17
15
Private RedText As Boolean = True
18
16
Private ReadOnly Shutdown_PBar As New WinFormControls.CProgressBar
19
- Private Start_Shutdown As DateTime
17
+ Private Start_Shutdown As Date
20
18
Private Offset_STimer As Double = 0
21
19
Private STimer As Double = 0
22
20
Private Remained As Double = 0
23
21
Public Grace_Timer As New Timer
24
22
Public Shutdown_Timer As New Timer
25
23
26
24
Private Sub Grace_Button_Click(sender As Object , e As EventArgs) Handles Grace_Button.Click
27
- Me . Shutdown_Timer.Stop()
28
- Me . Shutdown_Timer.Enabled = False
25
+ Shutdown_Timer.Stop()
26
+ Shutdown_Timer.Enabled = False
29
27
Grace_Button.Enabled = False
30
- Me . Grace_Timer.Enabled = True
31
- Me . Grace_Timer.Start()
32
- Me . Offset_STimer = WinNUT_Params. Arr_Reg_Key.Item("ExtendedShutdownDelay" )
28
+ Grace_Timer.Enabled = True
29
+ Grace_Timer.Start()
30
+ Offset_STimer = Arr_Reg_Key.Item( "ExtendedShutdownDelay" )
33
31
End Sub
34
32
35
33
Private Sub Shutdown_Gui_Load(sender As Object , e As EventArgs) Handles MyBase .Load
36
- Me .Icon = WinNUT.Icon
37
- ' Me.LogFile = WinNUT.LogFile
34
+ Icon = WinNUT.Icon
38
35
LogFile.LogTracing( "Load ShutDown Gui" , LogLvl.LOG_DEBUG, Me )
39
- Me . Grace_Timer.Enabled = False
40
- Me . Grace_Timer.Stop()
36
+ Grace_Timer.Enabled = False
37
+ Grace_Timer.Stop()
41
38
'If ExtendedShutdownDelay = 0 (the default value), the next line fails and the whole shutdown sequence fails - Thus no shutdown
42
39
'Moved next line lower down
43
40
'Me.Grace_Timer.Interval = (WinNUT_Params.Arr_Reg_Key.Item("ExtendedShutdownDelay") * 1000)
44
- Shutdown_Timer.Interval = (WinNUT_Params. Arr_Reg_Key.Item( "DelayToShutdown" ) * 1000 )
45
- Me . STimer = WinNUT_Params. Arr_Reg_Key.Item("DelayToShutdown" )
46
- Me . Remained = Me . STimer
47
- If WinNUT_Params. Arr_Reg_Key.Item("AllowExtendedShutdownDelay" ) Then
41
+ Shutdown_Timer.Interval = (Arr_Reg_Key.Item( "DelayToShutdown" ) * 1000 )
42
+ STimer = Arr_Reg_Key.Item( "DelayToShutdown" )
43
+ Remained = STimer
44
+ If Arr_Reg_Key.Item( "AllowExtendedShutdownDelay" ) Then
48
45
Grace_Button.Enabled = True
49
46
'Moved here so it is only used if grace period is allowed
50
47
Try
51
- Me . Grace_Timer.Interval = (WinNUT_Params. Arr_Reg_Key.Item( "ExtendedShutdownDelay" ) * 1000 )
48
+ Grace_Timer.Interval = (Arr_Reg_Key.Item( "ExtendedShutdownDelay" ) * 1000 )
52
49
Catch ex As Exception
53
50
'Disable Grace peroid option if Interval is set to 0
54
51
Grace_Button.Enabled = False
@@ -76,38 +73,41 @@ Public Class Shutdown_Gui
76
73
.Text = TimeToShow
77
74
.Value = 0
78
75
End With
79
- Me . Controls.Add(Shutdown_PBar)
76
+ Controls.Add(Shutdown_PBar)
80
77
AddHandler Grace_Timer.Tick, AddressOf Grace_Timer_Tick
81
78
AddHandler Shutdown_Timer.Tick, AddressOf Shutdown_Timer_Tick
82
79
End Sub
83
80
84
81
Private Sub Shutdown_Gui_Shown(sender As Object , e As EventArgs) Handles MyBase .Shown
85
- Me .Shutdown_Timer.Enabled = True
86
- Me .Shutdown_Timer.Start()
87
- lbl_UPSStatus.Text = String .Format(WinNUT_Globals.StrLog.Item(AppResxStr.STR_SHUT_STAT), WinNUT.UPS_BattCh.ToString(), WinNUT.Lbl_VRTime.Text)
82
+ Shutdown_Timer.Enabled = True
83
+ Shutdown_Timer.Start()
84
+ lbl_UPSStatus.Text = String .Format(StrLog.Item(AppResxStr.STR_SHUT_STAT), WinNUT.UPS_BattCh.ToString(), WinNUT.Lbl_VRTime.Text)
85
+ LogFile.LogTracing( "Shutdown GUI is shown and timer started for " & Shutdown_Timer.Interval / 1000 & " seconds." , LogLvl.LOG_NOTICE, Me )
88
86
End Sub
89
87
90
88
Private Sub Grace_Timer_Tick(sender As Object , e As EventArgs)
91
- Me . Shutdown_Timer.Interval = Me . Remained * 1000
92
- Me . Shutdown_Timer.Enabled = True
93
- Me . Shutdown_Timer.Start()
89
+ Shutdown_Timer.Interval = Remained * 1000
90
+ Shutdown_Timer.Enabled = True
91
+ Shutdown_Timer.Start()
94
92
End Sub
95
93
96
94
Private Sub ShutDown_Btn_Click(sender As Object , e As EventArgs) Handles ShutDown_Btn.Click
97
95
WinNUT.Shutdown_Action()
98
96
End Sub
99
97
100
98
Private Sub Shutdown_Timer_Tick(sender As Object , e As EventArgs)
99
+ LogFile.LogTracing( "Shutdown timer tick." , LogLvl.LOG_NOTICE, Me )
101
100
Shutdown_PBar.Value = 100
102
- System.Threading.Thread.Sleep( 1000 )
103
- WinNUT.Shutdown_Action()
101
+ Threading.Thread.Sleep( 1000 )
104
102
Run_Timer.Enabled = False
105
- Me .Shutdown_Timer.Stop()
106
- Me .Shutdown_Timer.Enabled = False
107
- Me .Grace_Timer.Stop()
108
- Me .Grace_Timer.Enabled = False
109
- Me .Hide()
110
- Me .Close()
103
+ Shutdown_Timer.Stop()
104
+ Shutdown_Timer.Enabled = False
105
+ Grace_Timer.Stop()
106
+ Grace_Timer.Enabled = False
107
+ Hide()
108
+ WinNUT.Shutdown_Action()
109
+
110
+ Close()
111
111
End Sub
112
112
113
113
Private Sub Run_Timer_Tick(sender As Object , e As EventArgs) Handles Run_Timer.Tick
@@ -118,18 +118,18 @@ Public Class Shutdown_Gui
118
118
lbl_UPSStatus.ForeColor = Color.Black
119
119
RedText = True
120
120
End If
121
- If Me . Shutdown_Timer.Enabled = True And Me . Remained > 0 Then
122
- Me . Remained = Int(STimer + Offset_STimer - Now.Subtract(Start_Shutdown).TotalSeconds)
121
+ If Shutdown_Timer.Enabled = True And Remained > 0 Then
122
+ Remained = Int(STimer + Offset_STimer - Now.Subtract(Start_Shutdown).TotalSeconds)
123
123
Dim NewValue As Integer = 100
124
- If Me . Remained > 0 Then
125
- NewValue -= ( 100 * ( Me . Remained / Me . STimer))
124
+ If Remained > 0 Then
125
+ NewValue -= ( 100 * (Remained / STimer))
126
126
If NewValue > 100 Then
127
127
NewValue = 100
128
128
End If
129
129
End If
130
130
Dim TimeToShow As String
131
- Dim iSpan As TimeSpan = TimeSpan.FromSeconds( Me . Remained)
132
- If Me . Shutdown_Timer.Interval = ( 3600 * 1000 ) Then
131
+ Dim iSpan As TimeSpan = TimeSpan.FromSeconds(Remained)
132
+ If Shutdown_Timer.Interval = ( 3600 * 1000 ) Then
133
133
TimeToShow = iSpan.Hours.ToString.PadLeft( 2 , "0"c ) & ":" &
134
134
iSpan.Minutes.ToString.PadLeft( 2 , "0"c ) & ":" &
135
135
iSpan.Seconds.ToString.PadLeft( 2 , "0"c )
@@ -139,12 +139,12 @@ Public Class Shutdown_Gui
139
139
End If
140
140
Shutdown_PBar.Text = TimeToShow
141
141
Shutdown_PBar.Value = NewValue
142
- lbl_UPSStatus.Text = String .Format(WinNUT_Globals. StrLog.Item(AppResxStr.STR_SHUT_STAT), WinNUT.UPS_BattCh.ToString(), WinNUT.Lbl_VRTime.Text)
142
+ lbl_UPSStatus.Text = String .Format(StrLog.Item(AppResxStr.STR_SHUT_STAT), WinNUT.UPS_BattCh.ToString(), WinNUT.Lbl_VRTime.Text)
143
143
End If
144
144
End Sub
145
145
146
146
Private Sub Shutdown_Gui_FormClosing(sender As Object , e As FormClosingEventArgs) Handles MyBase .FormClosing
147
- If Me . Visible Then
147
+ If Visible Then
148
148
e.Cancel = True
149
149
End If
150
150
End Sub
0 commit comments