Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 42 additions & 42 deletions WinNUT_V2/WinNUT-Client/Shutdown_Gui.vb
Original file line number Diff line number Diff line change
Expand Up @@ -7,48 +7,45 @@
'
' This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY

Imports WinNUT_Params = WinNUT_Client_Common.WinNUT_Params
Imports Logger = WinNUT_Client_Common.Logger
Imports LogLvl = WinNUT_Client_Common.LogLvl
Imports AppResxStr = WinNUT_Client_Common.AppResxStr
Imports WinNUT_Globals = WinNUT_Client_Common.WinNUT_Globals
Imports WinNUT_Client_Common

Public Class Shutdown_Gui
Private LogFile As Logger
Private RedText As Boolean = True
Private ReadOnly Shutdown_PBar As New WinFormControls.CProgressBar
Private Start_Shutdown As DateTime
Private Start_Shutdown As Date
Private Offset_STimer As Double = 0
Private STimer As Double = 0
Private Remained As Double = 0
Public Grace_Timer As New Timer
Public Shutdown_Timer As New Timer

Private Sub Grace_Button_Click(sender As Object, e As EventArgs) Handles Grace_Button.Click
Me.Shutdown_Timer.Stop()
Me.Shutdown_Timer.Enabled = False
Shutdown_Timer.Stop()
Shutdown_Timer.Enabled = False
Grace_Button.Enabled = False
Me.Grace_Timer.Enabled = True
Me.Grace_Timer.Start()
Me.Offset_STimer = WinNUT_Params.Arr_Reg_Key.Item("ExtendedShutdownDelay")
Grace_Timer.Enabled = True
Grace_Timer.Start()
Offset_STimer = Arr_Reg_Key.Item("ExtendedShutdownDelay")
End Sub

Private Sub Shutdown_Gui_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.Icon = WinNUT.Icon
' Me.LogFile = WinNUT.LogFile
Icon = WinNUT.Icon
LogFile.LogTracing("Load ShutDown Gui", LogLvl.LOG_DEBUG, Me)
Me.Grace_Timer.Enabled = False
Me.Grace_Timer.Stop()
Grace_Timer.Enabled = False
Grace_Timer.Stop()
'If ExtendedShutdownDelay = 0 (the default value), the next line fails and the whole shutdown sequence fails - Thus no shutdown
'Moved next line lower down
'Me.Grace_Timer.Interval = (WinNUT_Params.Arr_Reg_Key.Item("ExtendedShutdownDelay") * 1000)
Shutdown_Timer.Interval = (WinNUT_Params.Arr_Reg_Key.Item("DelayToShutdown") * 1000)
Me.STimer = WinNUT_Params.Arr_Reg_Key.Item("DelayToShutdown")
Me.Remained = Me.STimer
If WinNUT_Params.Arr_Reg_Key.Item("AllowExtendedShutdownDelay") Then
Shutdown_Timer.Interval = (Arr_Reg_Key.Item("DelayToShutdown") * 1000)
STimer = Arr_Reg_Key.Item("DelayToShutdown")
Remained = STimer
If Arr_Reg_Key.Item("AllowExtendedShutdownDelay") Then
Grace_Button.Enabled = True
'Moved here so it is only used if grace period is allowed
Try
Me.Grace_Timer.Interval = (WinNUT_Params.Arr_Reg_Key.Item("ExtendedShutdownDelay") * 1000)
Grace_Timer.Interval = (Arr_Reg_Key.Item("ExtendedShutdownDelay") * 1000)
Catch ex As Exception
'Disable Grace peroid option if Interval is set to 0
Grace_Button.Enabled = False
Expand Down Expand Up @@ -76,38 +73,41 @@ Public Class Shutdown_Gui
.Text = TimeToShow
.Value = 0
End With
Me.Controls.Add(Shutdown_PBar)
Controls.Add(Shutdown_PBar)
AddHandler Grace_Timer.Tick, AddressOf Grace_Timer_Tick
AddHandler Shutdown_Timer.Tick, AddressOf Shutdown_Timer_Tick
End Sub

Private Sub Shutdown_Gui_Shown(sender As Object, e As EventArgs) Handles MyBase.Shown
Me.Shutdown_Timer.Enabled = True
Me.Shutdown_Timer.Start()
lbl_UPSStatus.Text = String.Format(WinNUT_Globals.StrLog.Item(AppResxStr.STR_SHUT_STAT), WinNUT.UPS_BattCh.ToString(), WinNUT.Lbl_VRTime.Text)
Shutdown_Timer.Enabled = True
Shutdown_Timer.Start()
lbl_UPSStatus.Text = String.Format(StrLog.Item(AppResxStr.STR_SHUT_STAT), WinNUT.UPS_BattCh.ToString(), WinNUT.Lbl_VRTime.Text)
LogFile.LogTracing("Shutdown GUI is shown and timer started for " & Shutdown_Timer.Interval / 1000 & " seconds.", LogLvl.LOG_NOTICE, Me)
End Sub

Private Sub Grace_Timer_Tick(sender As Object, e As EventArgs)
Me.Shutdown_Timer.Interval = Me.Remained * 1000
Me.Shutdown_Timer.Enabled = True
Me.Shutdown_Timer.Start()
Shutdown_Timer.Interval = Remained * 1000
Shutdown_Timer.Enabled = True
Shutdown_Timer.Start()
End Sub

Private Sub ShutDown_Btn_Click(sender As Object, e As EventArgs) Handles ShutDown_Btn.Click
WinNUT.Shutdown_Action()
End Sub

Private Sub Shutdown_Timer_Tick(sender As Object, e As EventArgs)
LogFile.LogTracing("Shutdown timer tick.", LogLvl.LOG_NOTICE, Me)
Shutdown_PBar.Value = 100
System.Threading.Thread.Sleep(1000)
WinNUT.Shutdown_Action()
Threading.Thread.Sleep(1000)
Run_Timer.Enabled = False
Me.Shutdown_Timer.Stop()
Me.Shutdown_Timer.Enabled = False
Me.Grace_Timer.Stop()
Me.Grace_Timer.Enabled = False
Me.Hide()
Me.Close()
Shutdown_Timer.Stop()
Shutdown_Timer.Enabled = False
Grace_Timer.Stop()
Grace_Timer.Enabled = False
Hide()
WinNUT.Shutdown_Action()

Close()
End Sub

Private Sub Run_Timer_Tick(sender As Object, e As EventArgs) Handles Run_Timer.Tick
Expand All @@ -118,18 +118,18 @@ Public Class Shutdown_Gui
lbl_UPSStatus.ForeColor = Color.Black
RedText = True
End If
If Me.Shutdown_Timer.Enabled = True And Me.Remained > 0 Then
Me.Remained = Int(STimer + Offset_STimer - Now.Subtract(Start_Shutdown).TotalSeconds)
If Shutdown_Timer.Enabled = True And Remained > 0 Then
Remained = Int(STimer + Offset_STimer - Now.Subtract(Start_Shutdown).TotalSeconds)
Dim NewValue As Integer = 100
If Me.Remained > 0 Then
NewValue -= (100 * (Me.Remained / Me.STimer))
If Remained > 0 Then
NewValue -= (100 * (Remained / STimer))
If NewValue > 100 Then
NewValue = 100
End If
End If
Dim TimeToShow As String
Dim iSpan As TimeSpan = TimeSpan.FromSeconds(Me.Remained)
If Me.Shutdown_Timer.Interval = (3600 * 1000) Then
Dim iSpan As TimeSpan = TimeSpan.FromSeconds(Remained)
If Shutdown_Timer.Interval = (3600 * 1000) Then
TimeToShow = iSpan.Hours.ToString.PadLeft(2, "0"c) & ":" &
iSpan.Minutes.ToString.PadLeft(2, "0"c) & ":" &
iSpan.Seconds.ToString.PadLeft(2, "0"c)
Expand All @@ -139,12 +139,12 @@ Public Class Shutdown_Gui
End If
Shutdown_PBar.Text = TimeToShow
Shutdown_PBar.Value = NewValue
lbl_UPSStatus.Text = String.Format(WinNUT_Globals.StrLog.Item(AppResxStr.STR_SHUT_STAT), WinNUT.UPS_BattCh.ToString(), WinNUT.Lbl_VRTime.Text)
lbl_UPSStatus.Text = String.Format(StrLog.Item(AppResxStr.STR_SHUT_STAT), WinNUT.UPS_BattCh.ToString(), WinNUT.Lbl_VRTime.Text)
End If
End Sub

Private Sub Shutdown_Gui_FormClosing(sender As Object, e As FormClosingEventArgs) Handles MyBase.FormClosing
If Me.Visible Then
If Visible Then
e.Cancel = True
End If
End Sub
Expand Down
Loading