You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
118 lines
3.7 KiB
118 lines
3.7 KiB
Imports System.IO
|
|
Imports System.Timers
|
|
Imports System
|
|
Imports System.ServiceProcess
|
|
|
|
Public Class EDKB19
|
|
|
|
Dim WithEvents CheckTimer As New Timers.Timer()
|
|
Dim WithEvents CheckTimerIntervall As New Timers.Timer
|
|
Dim timerstopped As Boolean = False
|
|
Dim IsDebug As Boolean
|
|
Protected Overrides Sub OnStart(ByVal args() As String)
|
|
PrintOut("Start EDKB19")
|
|
PrintOut("Verzeichnis:" + My.Settings.ConnectionString)
|
|
CheckTimer.Interval = My.Settings.Check_Timerintervall
|
|
PrintOut("Intervall in MS:" + CheckTimer.Interval.ToString)
|
|
PrintOut("Debug:" + My.Settings.Debug)
|
|
CheckTimer.Start()
|
|
CheckTimerIntervall.Interval = My.Settings.Check_Timerintervall
|
|
CheckTimerIntervall.Start()
|
|
IsDebug = UCase(My.Settings.Debug) = "TRUE"
|
|
End Sub
|
|
|
|
Protected Overrides Sub OnStop()
|
|
' Hier Code zum Ausführen erforderlicher Löschvorgänge zum Beenden des Dienstes einfügen.
|
|
End Sub
|
|
|
|
Shared Sub Main()
|
|
|
|
#If CONFIG = "Release" Then
|
|
Dim ServicesToRun() As System.ServiceProcess.ServiceBase
|
|
ServicesToRun = New System.ServiceProcess.ServiceBase() {New EDKB19()}
|
|
System.ServiceProcess.ServiceBase.Run(ServicesToRun)
|
|
#Else
|
|
Dim myServ As New EDKB19
|
|
myServ.OnStart({""})
|
|
While (True)
|
|
System.Threading.Thread.Sleep(2000)
|
|
End While
|
|
#End If
|
|
|
|
|
|
End Sub
|
|
|
|
Private Sub CheckTimer_Elapsed(sender As Object, e As ElapsedEventArgs) Handles CheckTimer.Elapsed
|
|
If IsDebug Then PrintOut("Verarbeitung")
|
|
Verarbeiten("")
|
|
End Sub
|
|
|
|
Private Sub Verarbeiten(Optional ExpressUser As String = "")
|
|
CheckTimer.Stop()
|
|
timerstopped = True
|
|
|
|
Dim db As New clsdb
|
|
|
|
db.Get_Data()
|
|
If IsDebug Then PrintOut("Anzahl Rows:" + db.data.Rows.Count.ToString)
|
|
|
|
For Each r As DataRow In db.data.Rows
|
|
If IsDebug Then PrintOut(r.Item("Servicename"))
|
|
If r.Item("Start") = True Then
|
|
If IsDebug Then PrintOut("Start")
|
|
HandleService(r.Item("Servicename"), 1)
|
|
End If
|
|
If r.Item("Stop") = True Then
|
|
If IsDebug Then PrintOut("Stop")
|
|
HandleService(r.Item("Servicename"), 2)
|
|
End If
|
|
If r.Item("Restart") = True Then
|
|
If IsDebug Then PrintOut("Restart")
|
|
HandleService(r.Item("Servicename"), 3)
|
|
End If
|
|
If IsDebug Then PrintOut("Update_Entry")
|
|
|
|
db.UpdateEntry(r.Item("nreintrag"))
|
|
Next
|
|
|
|
CheckTimer.Start()
|
|
timerstopped = False
|
|
|
|
End Sub
|
|
|
|
Sub HandleService(ByVal Servicename As String, ByVal Action As Integer)
|
|
Try
|
|
If IsDebug Then PrintOut("HandleService")
|
|
Dim service As ServiceController = New ServiceController(Servicename)
|
|
service.MachineName = Environment.MachineName
|
|
Select Case Action
|
|
Case 1 'Start
|
|
service.Start()
|
|
Case 2 'Stop
|
|
service.Stop()
|
|
Case 3 ' restart
|
|
Try
|
|
service.Stop()
|
|
Catch ex As Exception
|
|
PrintOut("Restart Stop:" + ex.Message)
|
|
End Try
|
|
Try
|
|
System.Threading.Thread.Sleep(10000)
|
|
service.Start()
|
|
Catch ex As Exception
|
|
PrintOut("Restart Start:" + ex.Message)
|
|
End Try
|
|
End Select
|
|
If IsDebug Then PrintOut("Service_Status:" + service.Status.ToString)
|
|
|
|
Catch ex As Exception
|
|
PrintOut("Fehler EDKB19: " + ex.Message)
|
|
End Try
|
|
|
|
End Sub
|
|
|
|
|
|
|
|
|
|
End Class
|