Zooflow: Update clipboard watcher module for zooflow

This commit is contained in:
Jonathan Jenne
2021-12-17 10:25:39 +01:00
parent cb00685085
commit 59d36568ed
16 changed files with 157 additions and 1196 deletions

View File

@@ -1,112 +0,0 @@
Imports Independentsoft
Imports System.Text.RegularExpressions
Public Class ClassEmailHeaderExtractor
''' <summary>
''' Extrahiert die Headerinformationen aus einer .msg Datei mithilfe der MSG.NET Klasse
''' </summary>
''' <param name="path">Der Pfad einer .msg Datei</param>
''' <returns>Headerinformationen als String oder Nothing wenn ein Fehler aufgetreten ist.</returns>
Public Shared Function getMessageHeaders(path As String) As String
Try
Dim msg As New Msg.Message(path)
Dim headers = msg.TransportMessageHeaders.Replace(vbCrLf, " ")
Return headers
Catch ex As Exception
Return Nothing
End Try
End Function
''' <summary>
''' Extrahiert die Headerinformationen aus einem msg Objekt mithilfe der MSG.NET Klasse
''' </summary>
''' <param name="msg">Eine Email vom Typ Msg.Message</param>
''' <returns>Headerinformationen als String oder Nothing wenn ein Fehler aufgetreten ist.</returns>
Public Shared Function getMessageHeaders(msg As Msg.Message) As String
Try
Dim headers = msg.TransportMessageHeaders.Replace(vbCrLf, " ")
Return headers
Catch ex As Exception
Return Nothing
End Try
End Function
''' <summary>
''' Extrahiert aus den Headerinformationen anhand einer Liste von Regular Expressions eine Absenderadresse.
''' </summary>
''' <param name="messageHeaders">Headerinformationen die von getMessageHeaders erzeugt wurden.</param>
''' <param name="RegexList">Eine Liste von Regular Expressions</param>
''' <param name="RegexGroup">Die Ergebnisgruppe, die die Adresse enthält</param>
''' <returns>Eine Emailadresse oder Nothing, wenn keine der Regular Expressions ein Ergebnis lieferte.</returns>
Public Shared Function extractFromAddress(messageHeaders As String, RegexList As List(Of Regex), Optional RegexGroup As Integer = 1) As String
If IsNothing(messageHeaders) Then
Return Nothing
End If
For Each rx In RegexList
Dim match As Match = rx.Match(messageHeaders)
Dim email As String = match.Groups(RegexGroup).Value
If Not String.IsNullOrWhiteSpace(email) Then
Return email
End If
Next
Return Nothing
End Function
Public Shared Function extractFromHeader(messageHeaders As String, Regex As String) As String
Try
Dim result As String = ""
Dim i As Integer = 0
If IsNothing(messageHeaders) Then
Return Nothing
End If
' einen Regulären Ausdruck laden
Dim strRegex As String = Regex
Dim myRegex As New Regex(strRegex, RegexOptions.IgnorePatternWhitespace)
Dim strTargetString As String = messageHeaders.Trim
' die Vorkommen im String auslesen
For Each myMatch As Match In myRegex.Matches(strTargetString)
If myMatch.Success Then
If myMatch.Value <> "" Then
If i = 0 Then
result = myMatch.Value.ToString
Else
result = result & ";" & myMatch.Value.ToString
End If
i += 1
End If
End If
Next
Return result
Catch ex As Exception
MsgBox("Unexpected Error in extractFromHeader: " & vbNewLine & ex.Message, MsgBoxStyle.Critical)
Return Nothing
End Try
End Function
''' <summary>
''' Extrahiert aus den Headerinformationen anhand einer Liste von Regular Expressions eine Empfängeradresse.
''' </summary>
''' <param name="messageHeaders">Headerinformationen die von getMessageHeaders erzeugt wurden.</param>
''' <param name="RegexList">Eine Liste von Regular Expressions</param>
''' <param name="RegexGroup">Die Ergebnisgruppe, die die Adresse enthält</param>
''' <returns>Eine Emailadresse oder Nothing, wenn keine der Regular Expressions ein Ergebnis lieferte.</returns>
Public Shared Function extractToAddress(messageHeaders As String, RegexList As List(Of Regex), Optional RegexGroup As Integer = 1) As String
If IsNothing(messageHeaders) Then
Return Nothing
End If
For Each rx In RegexList
Dim match As Match = rx.Match(messageHeaders)
Dim email As String = match.Groups(RegexGroup).Value
If Not String.IsNullOrWhiteSpace(email) Then
Return email
End If
Next
Return Nothing
End Function
End Class

View File

@@ -20,14 +20,9 @@ Public Class ClassFolderwatcher
'Gestartet also Stoppen
FWFolderWatcher.EnableRaisingEvents = False
My.Application.Globix.Folderwatchstarted = False
'FolderWatch neu instanzieren
FWFolderWatcher = New FileSystemWatcher(My.Application.Globix.CurrentFolderWatchPath, "*.*")
Logger.Info(" >> FolderWatch neu instanziert")
FWFolderWatcher.IncludeSubdirectories = False
FWFolderWatcher.EnableRaisingEvents = True
AddHandler FWFolderWatcher.Created, AddressOf OnCreated
FWFolderWatcher = StartFolderwatcherForPath(My.Application.Globix.CurrentFolderWatchPath)
My.Application.Globix.Folderwatchstarted = True
'SaveConfigValue("my.Application.Globix.Folderwatchstarted", "True")
My.UIConfig.Globix.FolderWatchStarted = True
My.UIConfigManager.Save()
End If
@@ -43,13 +38,10 @@ Public Class ClassFolderwatcher
If FWScan.EnableRaisingEvents = True Then
'Gestartet also Stoppen
FWScan.EnableRaisingEvents = False
'FolderWatch neu instanzieren
FWScan = New System.IO.FileSystemWatcher(My.Application.Globix.CURRENT_SCAN_FOLDERWATCH, "*.*")
Logger.Info(" >> FolderWatchScan neu instanziert")
FWScan.IncludeSubdirectories = False
FWScan.EnableRaisingEvents = True
AddHandler FWScan.Created, AddressOf OnCreated
'SaveConfigValue("FWSCAN_started", "True")
FWScan = StartFolderwatcherForPath(My.Application.Globix.CURRENT_SCAN_FOLDERWATCH)
My.UIConfig.Globix.FolderWatchScanStarted = True
My.UIConfigManager.Save()
End If
@@ -60,28 +52,16 @@ Public Class ClassFolderwatcher
End Sub
Public Sub StartStop_FolderWatch()
Try
If FWFolderWatcher Is Nothing Then
FWFolderWatcher = New System.IO.FileSystemWatcher(My.Application.Globix.CurrentFolderWatchPath, "*.*")
Logger.Info(" >> FolderWatch Gestartet")
FWFolderWatcher.IncludeSubdirectories = False
FWFolderWatcher.EnableRaisingEvents = True
AddHandler FWFolderWatcher.Created, AddressOf OnCreated
If FWFolderWatcher Is Nothing OrElse FWFolderWatcher.EnableRaisingEvents = False Then
' Folderwatch neu instanzieren
FWFolderWatcher = StartFolderwatcherForPath(My.Application.Globix.CurrentFolderWatchPath)
My.Application.Globix.Folderwatchstarted = True
My.UIConfig.Globix.FolderWatchStarted = True
My.UIConfigManager.Save()
End If
If FWFolderWatcher.EnableRaisingEvents = False Then
' Dim watcher As New FileSystemWatcher()
' watcher.Path = CURRENT_FOLDERWATCH
FWFolderWatcher = New System.IO.FileSystemWatcher(My.Application.Globix.CurrentFolderWatchPath, "*.*")
Logger.Info(" >> FolderWatch Gestartet")
FWFolderWatcher.IncludeSubdirectories = False
FWFolderWatcher.EnableRaisingEvents = True
AddHandler FWFolderWatcher.Created, AddressOf OnCreated
My.Application.Globix.Folderwatchstarted = True
My.UIConfig.Globix.FolderWatchStarted = True
My.UIConfigManager.Save()
Else
If FWFolderWatcher.EnableRaisingEvents = True Then
'Gestartet also Stoppen
FWFolderWatcher.EnableRaisingEvents = False
My.Application.Globix.Folderwatchstarted = False
@@ -161,6 +141,21 @@ Public Class ClassFolderwatcher
Return False
End If
End Function
Private Function StartFolderwatcherForPath(pPath As String) As FileSystemWatcher
Dim oWatcher = New FileSystemWatcher(pPath, "*.*") With {
.IncludeSubdirectories = False,
.EnableRaisingEvents = True
}
AddHandler oWatcher.Created, AddressOf OnCreated
Logger.Debug("Folder Watcher started for Path [{0}]", pPath)
My.UIConfig.Globix.FolderWatchScanStarted = True
My.UIConfigManager.Save()
Return oWatcher
End Function
Private Sub OnCreated(source As Object, e As FileSystemEventArgs)
Try
If Not IsNothing(My.Application.Globix.DTEXCLUDE_FILES) Then

View File

@@ -275,7 +275,6 @@
<DesignTime>True</DesignTime>
<DependentUpon>MyDataset.xsd</DependentUpon>
</Compile>
<Compile Include="Globix\ClassEmailHeaderExtractor.vb" />
<Compile Include="Globix\ClassFolderwatcher.vb" />
<Compile Include="Globix\frmGlobixBasicConfig.Designer.vb">
<DependentUpon>frmGlobixBasicConfig.vb</DependentUpon>