Add Heartbeat Function to Service, Add Timer to ClientSuite Service Startup check
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
Imports System.Threading
|
||||
Imports System.ServiceModel
|
||||
Imports System.Threading
|
||||
Imports System.Timers
|
||||
Imports DigitalData.Modules.EDMIFileOps.EDMIServiceReference
|
||||
Imports DigitalData.Modules.Logging
|
||||
@@ -10,28 +11,56 @@ Public Class ClassTimer
|
||||
Private _Timer As Timers.Timer
|
||||
Private _Channel As IEDMServiceChannel
|
||||
|
||||
Private Const TIMER_START_TIME = 1000
|
||||
Private Const TIMER_INTERVAL = 5000
|
||||
Public Event OnlineChanged As OnlineChangedEventHandler
|
||||
Public Delegate Sub OnlineChangedEventHandler(sender As Object, Online As Boolean)
|
||||
|
||||
Public Sub Callback(sender As Object, e As ElapsedEventArgs)
|
||||
_Logger.Info("Checking if Service is up...")
|
||||
Public Sub New(LogConfig As LogConfig, SynchronizingObject As frmMain, HeartbeatInterval As Integer)
|
||||
Try
|
||||
_LogConfig = LogConfig
|
||||
_Logger = LogConfig.GetLogger()
|
||||
|
||||
' Connect to service and send hearbeat request
|
||||
_Channel = My.ChannelFactory.CreateChannel()
|
||||
_Channel.Open()
|
||||
|
||||
My.Application.Service.Online = True
|
||||
My.Application.Service.LastChecked = DateTime.Now
|
||||
_Timer = New Timers.Timer(HeartbeatInterval) With {
|
||||
.SynchronizingObject = SynchronizingObject,
|
||||
.Enabled = True
|
||||
}
|
||||
|
||||
AddHandler _Timer.Elapsed, AddressOf Callback
|
||||
Catch ex As Exception
|
||||
_Logger.Error(ex)
|
||||
End Try
|
||||
End Sub
|
||||
|
||||
Public Sub New(LogConfig As LogConfig)
|
||||
_LogConfig = LogConfig
|
||||
_Logger = LogConfig.GetLogger()
|
||||
Public Async Sub Callback(sender As Object, e As ElapsedEventArgs)
|
||||
Try
|
||||
_Logger.Debug("Checking if Service is up...")
|
||||
|
||||
_Channel = My.ChannelFactory.CreateChannel()
|
||||
_Channel.Open()
|
||||
If _Channel.State = ServiceModel.CommunicationState.Faulted Then
|
||||
_Channel = My.ChannelFactory.CreateChannel()
|
||||
End If
|
||||
|
||||
_Timer = New Timers.Timer(TIMER_INTERVAL)
|
||||
_Timer.SynchronizingObject = My.MainForm
|
||||
AddHandler _Timer.Elapsed, AddressOf Callback
|
||||
_Timer.Enabled = True
|
||||
' Connect to service and send hearbeat request
|
||||
Dim oResult = Await _Channel.HeartbeatAsync()
|
||||
|
||||
|
||||
_Logger.Debug("Service is online")
|
||||
|
||||
SetOnlineState(True)
|
||||
Catch ex As Exception
|
||||
_Logger.Debug("Service is offline!")
|
||||
|
||||
SetOnlineState(False)
|
||||
Finally
|
||||
My.Application.Service.LastChecked = DateTime.Now
|
||||
End Try
|
||||
End Sub
|
||||
|
||||
Private Sub SetOnlineState(NewState As Boolean)
|
||||
If My.Application.Service.Online <> NewState Then
|
||||
My.Application.Service.Online = NewState
|
||||
RaiseEvent OnlineChanged(Me, NewState)
|
||||
End If
|
||||
End Sub
|
||||
End Class
|
||||
|
||||
Reference in New Issue
Block a user