MS Service und WMDLL

This commit is contained in:
Digital Data - Marlon Schreiber 2018-08-21 10:36:59 +02:00
parent 379a36fba2
commit 8cde9f0119
5 changed files with 44 additions and 30 deletions

View File

@ -44,6 +44,7 @@ Partial Class MyNewService
' '
'MyNewService 'MyNewService
' '
Me.CanPauseAndContinue = True
Me.CanShutdown = True Me.CanShutdown = True
Me.ServiceName = "MyNewService" Me.ServiceName = "MyNewService"

View File

@ -5,17 +5,32 @@ Public Class MyNewService
Private Shared _MyLoggerConfig As LogConfig Private Shared _MyLoggerConfig As LogConfig
Public Shared threadRunner As BackgroundWorker Public Shared threadRunner As BackgroundWorker
Private Shared Logger As Logger = LogManager.GetCurrentClassLogger Private Shared Logger As Logger = LogManager.GetCurrentClassLogger
Private eventId As Integer = 1
Protected Overrides Sub OnStart(ByVal args() As String) Protected Overrides Sub OnStart(ByVal args() As String)
' Code zum Starten des Dienstes hier einfügen. Diese Methode sollte Vorgänge ' Code zum Starten des Dienstes hier einfügen. Diese Methode sollte Vorgänge
' ausführen, damit der Dienst gestartet werden kann. ' ausführen, damit der Dienst gestartet werden kann.
_MyLoggerConfig = New LogConfig(LogConfig.PathType.CurrentDirectory) _MyLoggerConfig = New LogConfig(LogConfig.PathType.CurrentDirectory)
' clsLogger.Init(My.Application.Info.DirectoryPath & "\Log", "_SERVICEResultHandler") ' clsLogger.Init(My.Application.Info.DirectoryPath & "\Log", "_SERVICEResultHandler")
Logger.Info("Service started") Logger.Info("Service started")
' Set up a timer to trigger every minute.
Dim timer As System.Timers.Timer = New System.Timers.Timer()
timer.Interval = 60000 ' 60 seconds
AddHandler timer.Elapsed, AddressOf Me.OnTimer
timer.Start()
End Sub
Private Sub OnTimer(sender As Object, e As Timers.ElapsedEventArgs)
' TODO: Insert monitoring activities here.
Logger.Info("Monitoring the System - eventId: " & eventId)
eventId = eventId + 1
End Sub End Sub
Protected Overrides Sub OnStop() Protected Overrides Sub OnStop()
' Hier Code zum Ausführen erforderlicher Löschvorgänge zum Beenden des Dienstes einfügen. ' Hier Code zum Ausführen erforderlicher Löschvorgänge zum Beenden des Dienstes einfügen.
Logger.Info("Service stopped") Logger.Info("Service stopped")
End Sub End Sub
Protected Overrides Sub OnPause()
Logger.Info("In OnPause...")
End Sub
Protected Overrides Sub OnContinue()
Logger.Info("In OnContinue...")
End Sub
End Class End Class

View File

@ -18,17 +18,14 @@ Public Class Email
'Für jeden Empfänger eine Neue Mail erzeugen 'Für jeden Empfänger eine Neue Mail erzeugen
For Each _mailempfaenger As String In empfaenger For Each _mailempfaenger As String In empfaenger
Try Try
Dim message As New Message With { Dim message As New Message()
.From = New Mailbox(mailfrom, mailfrom) message.From = New Mailbox(mailfrom, mailfrom)
}
message.[To].Add(New Mailbox(_mailempfaenger)) message.[To].Add(New Mailbox(_mailempfaenger))
message.Subject = mailSubject message.Subject = mailSubject
Dim textBodyPart As New BodyPart()
Dim textBodyPart As New BodyPart With { textBodyPart.ContentType = New ContentType("text", "html", "utf-8")
.ContentType = New ContentType("text", "plain", "utf-8"), textBodyPart.ContentTransferEncoding = ContentTransferEncoding.QuotedPrintable
.ContentTransferEncoding = ContentTransferEncoding.QuotedPrintable, textBodyPart.Body = mailBody
.Body = mailBody
}
message.BodyParts.Add(textBodyPart) message.BodyParts.Add(textBodyPart)
If attment <> String.Empty Then If attment <> String.Empty Then
If System.IO.File.Exists(attment) Then If System.IO.File.Exists(attment) Then

View File

@ -595,11 +595,14 @@ Public Class Windream
''' <returns>Returns datatable</returns> ''' <returns>Returns datatable</returns>
''' <remarks></remarks> ''' <remarks></remarks>
Public Function GetSearchDocuments(ByVal wdfLocation As String, NameIndexDocID As String) As DataTable Public Function GetSearchDocuments(ByVal wdfLocation As String, NameIndexDocID As String) As DataTable
Dim dt As New DataTable Dim dtresult As New DataTable
dt.Columns.Add("DOC_ID", GetType(Integer)) dtresult.Columns.Add("DOC_ID", GetType(Integer))
dt.Columns.Add("PATH", GetType(String)) dtresult.Columns.Add("PATH", GetType(String))
If CurrentSession.aLoggedin Then If Not CurrentSession.aLoggedin Then
dt Return dtresult
End If
If TestWMFileExists(wdfLocation) = False Then
Return dtresult
End If End If
Try Try
Dim ProfileName = wdfLocation.Substring(wdfLocation.LastIndexOf("\") + 1) Dim ProfileName = wdfLocation.Substring(wdfLocation.LastIndexOf("\") + 1)
@ -654,7 +657,7 @@ Public Class Windream
Case Else Case Else
Logger.Warn("No valid WM-SearchType") Logger.Warn("No valid WM-SearchType")
Return dt Return dtresult
End Select End Select
Dim WMObjects As Object Dim WMObjects As Object
WMObjects = oSearch.Execute WMObjects = oSearch.Execute
@ -665,15 +668,15 @@ Public Class Windream
Dim path As String = dok.aPath Dim path As String = dok.aPath
Dim DOC_ID = dok.GetVariableValue(NameIndexDocID) Dim DOC_ID = dok.GetVariableValue(NameIndexDocID)
Logger.Info("Adding DocInfo for DocID: " & DOC_ID.ToString) Logger.Info("Adding DocInfo for DocID: " & DOC_ID.ToString)
dt.Rows.Add(DOC_ID, path) dtresult.Rows.Add(DOC_ID, path)
Next Next
dt.AcceptChanges() dtresult.AcceptChanges()
End If End If
Return dt Return dtresult
Catch ex As Exception Catch ex As Exception
Logger.Error(ex) Logger.Error(ex)
Return dt Return dtresult
End Try End Try
End Function End Function
''' <summary> ''' <summary>
@ -825,7 +828,7 @@ Public Class Windream
Public Function GetWMObjectForFile(ByVal WMPath As String) As WMObject Public Function GetWMObjectForFile(ByVal WMPath As String) As WMObject
Try Try
If CurrentSession.aLoggedin Then If CurrentSession.aLoggedin Then
Return False Return Nothing
End If End If
WMPath = NormalizePath(WMPath) WMPath = NormalizePath(WMPath)
Dim oWMObject As WINDREAMLib.WMObject Dim oWMObject As WINDREAMLib.WMObject
@ -872,19 +875,17 @@ Public Class Windream
''' <param name="WMPath">full path to the file</param> ''' <param name="WMPath">full path to the file</param>
''' <returns>Returns true when file was deleted, false if not</returns> ''' <returns>Returns true when file was deleted, false if not</returns>
''' <remarks></remarks> ''' <remarks></remarks>
Public Function TestFileExists(ByVal WMPath As String) Public Function TestWMFileExists(ByVal WMPath As String)
Try Try
If CurrentSession.aLoggedin Then If CurrentSession.aLoggedin Then
Return False Return False
End If End If
WMPath = NormalizePath(WMPath) WMPath = NormalizePath(WMPath)
Try If IsNothing(GetWMObjectForFile(WMPath)) Then
Dim WMObject As WINDREAMLib.WMObject = CurrentSession.GetWMObjectByPath(WINDREAMLib.WMEntity.WMEntityDocument, WMPath)
Catch ex As Exception
Logger.Warn("Could not create WMObject for file '" & WMPath & "' - so it is not existing")
Return False Return False
End Try Else
Return True Return True
End If
Catch ex As Exception Catch ex As Exception
Logger.Error(ex) Logger.Error(ex)
Return False Return False

View File

@ -17,7 +17,7 @@ Public Class Form1
End Sub End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
MyLogger = New LogConfig(LogConfig.PathType.CurrentDirectory) MyLogger = New LogConfig(LogConfig.PathType.AppData,)
End Sub End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles GetValue.Click Private Sub Button2_Click(sender As Object, e As EventArgs) Handles GetValue.Click