68 lines
2.1 KiB
VB.net
68 lines
2.1 KiB
VB.net
Imports System.ServiceModel
|
|
Imports System.Threading
|
|
Imports System.Timers
|
|
Imports DigitalData.GUIs.ClientSuite.Base
|
|
Imports DigitalData.Modules.EDMIAPI.EDMIServiceReference
|
|
Imports DigitalData.Modules.Logging
|
|
|
|
Public Class ClassTimer
|
|
Inherits BaseClass
|
|
|
|
Private _Callback As TimerCallback
|
|
Private _LogConfig As LogConfig
|
|
Private _Logger As Logger
|
|
Private _Timer As Timers.Timer
|
|
Private _Channel As IEDMServiceChannel
|
|
|
|
Public Event OnlineChanged As OnlineChangedEventHandler
|
|
Public Delegate Sub OnlineChangedEventHandler(sender As Object, Online As Boolean)
|
|
|
|
Public Sub New(LogConfig As LogConfig, SynchronizingObject As frmMain, HeartbeatInterval As Integer)
|
|
MyBase.New(LogConfig)
|
|
|
|
Try
|
|
_Channel = My.ChannelFactory.CreateChannel()
|
|
_Channel.Open()
|
|
|
|
_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 Async Sub Callback(sender As Object, e As ElapsedEventArgs)
|
|
Try
|
|
Logger.Debug("Checking if Service is up...")
|
|
|
|
If _Channel.State = ServiceModel.CommunicationState.Faulted Then
|
|
_Channel = My.ChannelFactory.CreateChannel()
|
|
End If
|
|
|
|
' 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
|