ZooFlow: Use BaseClass in Globix classes

This commit is contained in:
Jonathan Jenne 2021-12-14 11:40:24 +01:00
parent 2436fd296f
commit a595a75065
5 changed files with 74 additions and 101 deletions

View File

@ -5,9 +5,10 @@ Imports DigitalData.Modules.Logging
Imports Microsoft.Office.Interop
Public Class ClassFileDrop
Public files_dropped As String()
Private _LOGGER As Logger
Private clsFilehandle As ClassFilehandle
Inherits Base.BaseClass
Public Property files_dropped As List(Of String)
Private ReadOnly FileHandle As ClassFilehandle
Public Class DroppedFile
Public FilePath As String
@ -18,20 +19,21 @@ Public Class ClassFileDrop
End Enum
End Class
Public Sub New(LogConfig As LogConfig)
_LOGGER = LogConfig.GetLogger()
clsFilehandle = New ClassFilehandle()
Public Sub New(pLogConfig As LogConfig)
MyBase.New(pLogConfig)
FileHandle = New ClassFilehandle(pLogConfig)
End Sub
Public Function Drop_File(e As DragEventArgs) As Boolean
Try
_LOGGER.Info("Available Drop Formats:")
Logger.Info("Available Drop Formats:")
For Each oFormat As String In e.Data.GetFormats()
_LOGGER.Debug(oFormat)
Logger.Debug(oFormat)
Next
_LOGGER.Info(">> Drop_File")
files_dropped = Nothing
Logger.Info(">> Drop_File")
files_dropped = New List(Of String)
If e.Data.GetDataPresent(DataFormats.FileDrop) Then
Dim MyFiles() As String
Dim i As Integer
@ -39,10 +41,8 @@ Public Class ClassFileDrop
MyFiles = DirectCast(e.Data.GetData(DataFormats.FileDrop), String())
' Loop through the array and add the files to the list.
For i = 0 To MyFiles.Length - 1
_LOGGER.Info(">> Simple FileDrop - File: " & MyFiles(i))
ReDim Preserve files_dropped(i)
files_dropped(i) = "|DROPFROMFSYSTEM|" & MyFiles(i)
' ListBox1.Items.Add(MyFiles(i))
Logger.Info(">> Simple FileDrop - File: " & MyFiles(i))
files_dropped.Add("|DROPFROMFSYSTEM|" & MyFiles(i))
Next
Return True
ElseIf (e.Data.GetDataPresent("FileGroupDescriptor")) AndAlso (e.Data.GetDataPresent("FileContents")) Then
@ -66,7 +66,7 @@ Public Class ClassFileDrop
Loop
stmInput.Close()
'Sonderzeichen entfernen
Dim Tempfilename = clsFilehandle.InvalidCharacters(stbFileName.ToString)
Dim Tempfilename = FileHandle.InvalidCharacters(stbFileName.ToString)
Dim anhaenge = e.Data.GetDataPresent("FileContents")
'Dim path As String = "C:\VBProjekte\Dateien"
'// put the zip file into the temp directory
@ -89,19 +89,21 @@ Public Class ClassFileDrop
Dim fsOutput As IO.FileStream = New IO.FileStream(strOutFile, IO.FileMode.Create) ';
fsOutput.Write(aryFileBytes, 0, aryFileBytes.Length)
fsOutput.Close() ' // close the file
Dim resultVersion = clsFilehandle.Versionierung_Datei(strOutFile)
Dim resultVersion = FileHandle.Versionierung_Datei(strOutFile)
If resultVersion <> "" Then
strOutFile = resultVersion
End If
Dim finTemp As IO.FileInfo = New IO.FileInfo(strOutFile)
'// always good to make sure we actually created the file
If (finTemp.Exists = True) Then
ReDim Preserve files_dropped(0)
files_dropped(0) = "|OUTLOOK_ATTACHMENT|" & strOutFile
_LOGGER.Info(">> Drop an Attachment - File: " & strOutFile)
files_dropped.Add("|OUTLOOK_ATTACHMENT|" & strOutFile)
'ReDim Preserve files_dropped(0)
'files_dropped(0) = "|OUTLOOK_ATTACHMENT|" & strOutFile
Logger.Info(">> Drop an Attachment - File: " & strOutFile)
Return True
Else
_LOGGER.Info(">> Attachment File from Outlook could not be created")
Logger.Info(">> Attachment File from Outlook could not be created")
End If
End If
End If
@ -113,7 +115,7 @@ Public Class ClassFileDrop
MsgBox("Unexpected error in Initialisieren von Outlook-API:" & vbNewLine & ex.Message & vbNewLine & vbNewLine & "Evtl ist Outlook nicht in der dafür vorgesehenen For")
End Try
_LOGGER.Info(">> Drop of msg")
Logger.Info(">> Drop of msg")
'supports a drop of a Outlook message
Dim myobj As Object
For i As Integer = 1 To oApp.ActiveExplorer.Selection.Count
@ -129,14 +131,14 @@ Public Class ClassFileDrop
subj = subj.Replace("/", "-")
End If
'Sonderzeichen entfernen
subj = clsFilehandle.InvalidCharacters(subj)
subj = FileHandle.InvalidCharacters(subj)
'hardcode a destination path for testing
Dim strFile As String = IO.Path.Combine(Path.GetTempPath, subj + ".msg")
strFile = strFile.Replace("?", "")
strFile = strFile.Replace("!", "")
strFile = strFile.Replace("%", "")
strFile = strFile.Replace("$", "")
_LOGGER.Info(">> Drop of msg - File:" & strFile)
Logger.Info(">> Drop of msg - File:" & strFile)
Try
myobj.SaveAs(strFile)
Catch ex As Exception
@ -144,8 +146,9 @@ Public Class ClassFileDrop
Return False
End Try
ReDim Preserve files_dropped(i)
files_dropped(i) = "|OUTLOOK_MESSAGE|" & strFile
'ReDim Preserve files_dropped(i)
'files_dropped(i) = "|OUTLOOK_MESSAGE|" & strFile
files_dropped.Add("|OUTLOOK_MESSAGE|" & strFile)
Next
Return True
'Drop eines Outlook Attachments

View File

@ -6,10 +6,12 @@ Imports DigitalData.Modules.Logging
Imports Independentsoft
Public Class ClassFilehandle
Private _LOGGER As Logger
Public Sub New()
_LOGGER = My.LogConfig.GetLogger
Inherits Base.BaseClass
Public Sub New(pLogConfig As LogConfig)
MyBase.New(pLogConfig)
End Sub
''' <summary>
''' Diese Funktion entfernt alle Zeichen aus dem übergebenen String
''' die in Dateinamen nicht erlaubt sind.
@ -85,6 +87,7 @@ Public Class ClassFilehandle
Return Insert_GI_File(filename, handletype)
Catch ex As Exception
Logger.Error(ex)
MsgBox("Unexpected Error in Decide_FileHandle: " & ex.Message, MsgBoxStyle.Critical)
Return False
End Try
@ -103,7 +106,7 @@ Public Class ClassFilehandle
If Not msg.InternetMessageId Is Nothing Then
My.Application.Globix.CurrMessageID = msg.InternetMessageId
Else
_LOGGER.Info(">> Email_Decay: Es konnte keine Message-ID gelesen werden. Eine GUID wird erzeugt!")
Logger.Info(">> Email_Decay: Es konnte keine Message-ID gelesen werden. Eine GUID wird erzeugt!")
Dim sGUID As String
sGUID = System.Guid.NewGuid.ToString()
My.Application.Globix.CurrMessageID = sGUID
@ -127,7 +130,7 @@ Public Class ClassFilehandle
Dim _msg As New Msg.Message(msgname)
Dim i1 As Integer = 1
_LOGGER.Info(">> Anzahl der Attachments: " & _msg.Attachments.Count)
Logger.Info(">> Anzahl der Attachments: " & _msg.Attachments.Count)
For Each attachment As Independentsoft.Msg.Attachment In _msg.Attachments
If erfolgreich = False Then
Exit For
@ -147,7 +150,7 @@ Public Class ClassFilehandle
Dim oMessage = attachment.EmbeddedMessage
oMessage.Save(tempfile)
My.Application.Globix.TEMP_FILES.Add(tempfile)
_LOGGER.Info(">> Attachment (" & i1 & "):" & tempfile)
Logger.Info("Attachment (" & i1 & "):" & tempfile)
erfolgreich = Insert_GI_File(tempfile, ATT_EXTR)
i1 += 1
End If
@ -160,7 +163,7 @@ Public Class ClassFilehandle
attachment.Save(tempfile)
'Datei in Array zum Templöschen speichern
My.Application.Globix.TEMP_FILES.Add(tempfile)
_LOGGER.Info(">> Attachment (" & i1 & "):" & tempfile)
Logger.Info("Attachment (" & i1 & "):" & tempfile)
'nun der Insert des Anhanges
erfolgreich = Insert_GI_File(tempfile, ATT_EXTR)
i1 += 1
@ -170,7 +173,9 @@ Public Class ClassFilehandle
End If
Return erfolgreich
Catch ex As Exception
Logger.Error(ex)
MsgBox("Error in Email_Decay: " & ex.Message, MsgBoxStyle.Critical)
Return False
End Try
End Function
@ -200,19 +205,20 @@ Public Class ClassFilehandle
' Ist ein Fehler aufgetreten, so wird nach außen hin generell
' davon ausgegangen, dass die Datei in Benutzung ist (obwohl
' auch andere Ursachen, etwa Rechteprobleme, möglich sind).
_LOGGER.Info(">> FileInUse Message: " & ex.Message)
IsFileInUse = True
Logger.Info(">> FileInUse Message: " & ex.Message)
Return True
Finally
' Die eventuell geöffnete Datei schließen
FileClose(ff)
End Try
Return False
Else
Return False
End If
End Function
Public Function Versionierung_Datei(Dateiname As String) As String
Dim extension As String
Dim _NewFileString As String
Dim _NewFileString As String = ""
Try
Dim version As Integer = 1
@ -233,36 +239,10 @@ Public Class ClassFilehandle
End If
Return _NewFileString & extension
Catch ex As Exception
_LOGGER.Info(" - Error in versioning file - error: " & vbNewLine & ex.Message)
_LOGGER.Error(ex.Message)
Logger.Info(" - Error in versioning file - error: " & vbNewLine & ex.Message)
Logger.Error(ex)
MsgBox(ex.Message, MsgBoxStyle.Critical, "Error in versioning file:")
Return ""
End Try
End Function
''' <summary>
'''' Ersetzt alle nicht zulässigen Zeichen im angegebenen Dateinamen
'''' </summary>
'''' <param name="sFilename">Dateiname ohne Pfadangabe</param>
'''' <param name="sChar">Ersatzzeichen für alle unzulässigen Zeichen
'''' im Dateinamen</param>
'Public Function CleanFilename(ByVal sFilename As String, Optional ByVal REPLACEChar As String = "") As String
' _LOGGER.Info(" Filename before CleanFilename: '" & sFilename & "'")
' If sFilename.Contains(".\") Then
' sFilename = sFilename.Replace(".\", "\")
' End If
' 'If sFilename.Contains("'") Then
' ' sFilename = sFilename.Replace("'", "")
' 'End If
' 'If sFilename.Contains("..") Then
' ' sFilename = sFilename.Replace("..", ".")
' 'End If
' ' alle nicht zulässigen Zeichen ersetzen
' sFilename = System.Text.RegularExpressions.Regex.Replace(sFilename, My.Application.Globix.REGEX_CLEAN_FILENAME, REPLACEChar)
' sFilename = System.Text.RegularExpressions.Regex.Replace(sFilename, "[\\/:*?""<>|\r\n]", "", System.Text.RegularExpressions.RegexOptions.Singleline)
' 'Dim oCleanFileName As String = String.Join(REPLACEChar, sFilename.Split(Path.GetInvalidFileNameChars()))
' Dim oCleanFileName As New System.IO.FileInfo(System.Text.RegularExpressions.Regex.Replace(sFilename, String.Format("[{0}]", String.Join(String.Empty, Path.GetInvalidFileNameChars)), REPLACEChar))
' _LOGGER.Info("Filename after CleanFilename: '" & sFilename & "'")
' Return sFilename
'End Function
End Class

View File

@ -2,14 +2,16 @@
Imports DigitalData.Modules.Logging
Public Class ClassFolderwatcher
Inherits Base.BaseClass
Public Shared FWFolderWatcher As FileSystemWatcher
Public Shared FWScan As FileSystemWatcher
Private clsFilehandle As ClassFilehandle
Private Logger As Logger
Public Sub New()
Logger = My.LogConfig.GetLogger()
clsFilehandle = New ClassFilehandle()
Private ReadOnly FileHandle As ClassFilehandle
Public Sub New(pLogConfig As LogConfig)
MyBase.New(pLogConfig)
FileHandle = New ClassFilehandle(pLogConfig)
End Sub
Public Function Restart_FolderWatch() As Boolean
@ -19,7 +21,7 @@ Public Class ClassFolderwatcher
FWFolderWatcher.EnableRaisingEvents = False
My.Application.Globix.Folderwatchstarted = False
'FolderWatch neu instanzieren
FWFolderWatcher = New System.IO.FileSystemWatcher(My.Application.Globix.CurrentFolderWatchPath, "*.*")
FWFolderWatcher = New FileSystemWatcher(My.Application.Globix.CurrentFolderWatchPath, "*.*")
Logger.Info(" >> FolderWatch neu instanziert")
FWFolderWatcher.IncludeSubdirectories = False
FWFolderWatcher.EnableRaisingEvents = True
@ -65,7 +67,6 @@ Public Class ClassFolderwatcher
FWFolderWatcher.EnableRaisingEvents = True
AddHandler FWFolderWatcher.Created, AddressOf OnCreated
My.Application.Globix.Folderwatchstarted = True
'SaveConfigValue("my.Application.Globix.Folderwatchstarted", "True")
My.UIConfig.Globix.FolderWatchStarted = True
My.UIConfigManager.Save()
End If
@ -78,7 +79,6 @@ Public Class ClassFolderwatcher
FWFolderWatcher.EnableRaisingEvents = True
AddHandler FWFolderWatcher.Created, AddressOf OnCreated
My.Application.Globix.Folderwatchstarted = True
'SaveConfigValue("my.Application.Globix.Folderwatchstarted", "True")
My.UIConfig.Globix.FolderWatchStarted = True
My.UIConfigManager.Save()
Else
@ -86,7 +86,6 @@ Public Class ClassFolderwatcher
FWFolderWatcher.EnableRaisingEvents = False
My.Application.Globix.Folderwatchstarted = False
Logger.Info(" >> FolderWatch gestoppt")
'SaveConfigValue("my.Application.Globix.Folderwatchstarted", "False")
My.UIConfig.Globix.FolderWatchStarted = False
My.UIConfigManager.Save()
End If
@ -183,8 +182,8 @@ Public Class ClassFolderwatcher
'Die Datei übergeben
Logger.Info(">> OnCreated-File:" & e.FullPath)
If clsFilehandle.CheckDuplicateFiles(e.FullPath, "FolderWatch/Scan") Then
clsFilehandle.Decide_FileHandle(e.FullPath, handleType)
If FileHandle.CheckDuplicateFiles(e.FullPath, "FolderWatch/Scan") Then
FileHandle.Decide_FileHandle(e.FullPath, handleType)
Else
Logger.Info(">> Folderwatcher: File already exists:" & e.FullPath)
End If

View File

@ -762,7 +762,7 @@ Public Class frmGlobix_Index
Dim oFilePath As String = My.Application.Globix.CurrentWorkfile.FilePath
Dim oObjectStore As String = "WORK"
Dim oObjectStore As String = SelectedDocType.Name
Dim oObjectKind As String = "DOC"
Dim oBusinessEntity As String = "DEFAULT"
Dim oProfileId As Integer = SelectedDocType.Guid

View File

@ -72,6 +72,7 @@ Public Class frmFlowForm
' === Initialize AppServer Database Connection with Failover
AppServerOrDB = New ClassDataASorDB(My.LogConfig)
' === Initialization ===
Init = New ClassInit(My.LogConfig, Me)
AddHandler Init.Completed, AddressOf Init_Completed
@ -110,7 +111,7 @@ Public Class frmFlowForm
AddHandler Watcher.ClipboardChanged, AddressOf Watcher_ClipboardChanged
Dim oSQL = My.Queries.Common.FNIDB_GET_SEARCH_PROFILES(My.Application.User.UserId, My.Application.User.Language)
Dim oDatatable As DataTable = My.DatabaseIDB.GetDatatable(oSql)
Dim oDatatable As DataTable = My.DatabaseIDB.GetDatatable(oSQL)
PictureBoxSearch1.Visible = False
If Not IsNothing(oDatatable) OrElse oDatatable.Rows.Count > 0 Then
IDBSearchActive = True
@ -161,9 +162,8 @@ Public Class frmFlowForm
If My.Application.ModulesActive.Contains(MODULE_GLOBAL_INDEXER) Then
FileDrop = New ClassFileDrop(My.LogConfig)
FileHandle = New ClassFilehandle()
FolderWatch = New ClassFolderwatcher()
NNRefresh_RegexTable()
FileHandle = New ClassFilehandle(My.LogConfig)
FolderWatch = New ClassFolderwatcher(My.LogConfig)
Dim oFileExclusions As New ClassExclusions()
If oFileExclusions.Load(My.Application.Globix.PATH_FileExclusions) = False Then
@ -180,9 +180,10 @@ Public Class frmFlowForm
GlobixToolStripMenuItem.Visible = True
End If
oSQL = "SELECT * FROM TBIDB_ATTRIBUTE"
oSQL = "SELECT * FROM TBIDB_ATTRIBUTE"
My.Tables.DTIDB_ATTRIBUTE = AppServerOrDB.GetDatatable("IDB", oSQL, "TBIDB_ATTRIBUTE", "", "")
Me.Cursor = Cursors.Default
End Sub
@ -204,7 +205,6 @@ Public Class frmFlowForm
If oFolderWatchPath = String.Empty Then
Logger.Info("Init_Folderwatch: folderwatchPath is empty")
My.Application.Globix.Folderwatchstarted = False
'SaveConfigValue("my.Application.Globix.Folderwatchstarted", "False")
My.UIConfig.Globix.FolderWatchStarted = False
My.UIConfigManager.Save()
@ -213,7 +213,6 @@ Public Class frmFlowForm
If Not IO.Directory.Exists(oFolderWatchPath) Then
Logger.Info("Init_Folderwatch: folderwatchPath does not exists or is invalid path")
My.Application.Globix.Folderwatchstarted = False
'SaveConfigValue("my.Application.Globix.Folderwatchstarted", "False")
My.UIConfig.Globix.FolderWatchStarted = False
My.UIConfigManager.Save()
@ -493,21 +492,18 @@ Public Class frmFlowForm
End Sub
Sub Globix_Check_Dropped_Files()
Try
My.DatabaseECM.ExecuteNonQuery("DELETE FROM TBGI_FILES_USER WHERE WORKED = 1 AND UPPER(USER@WORK) = UPPER('" & Environment.UserName & "')")
My.DatabaseECM.ExecuteNonQuery($"DELETE FROM TBGI_FILES_USER WHERE WORKED = 1 AND UPPER(USER@WORK) = UPPER('{Environment.UserName}')")
Dim i As Integer
For Each Str As Object In FileDrop.files_dropped
If Not Str Is Nothing Then
Logger.Info(" Check Drop-File: " & Str.ToString)
Dim handleType As String = Str.Substring(0, Str.LastIndexOf("|") + 1)
Dim filename As String = Str.Substring(Str.LastIndexOf("|") + 1)
For Each pFile As String In FileDrop.files_dropped
If Not pFile Is Nothing Then
Logger.Info(" Check Drop-File: " & pFile.ToString)
Dim handleType As String = pFile.Substring(0, pFile.LastIndexOf("|") + 1)
Dim filename As String = pFile.Substring(pFile.LastIndexOf("|") + 1)
If FileHandle.CheckDuplicateFiles(filename, "Manuelle Ablage") Then
FileHandle.Decide_FileHandle(filename, handleType)
i += 1
Else
' Console.WriteLine("File gibt es bereits")
End If
End If
Next
@ -530,11 +526,12 @@ Public Class frmFlowForm
My.Application.Globix.DTACTUAL_FILES = My.DatabaseECM.GetDatatable(sql)
End If
For Each oFileRow As DataRow In My.Application.Globix.DTACTUAL_FILES.Rows
Dim oFilePath As String = oFileRow.Item("FILENAME2WORK").ToString
For Each oRow As DataRow In My.Application.Globix.DTACTUAL_FILES.Rows
Dim oFilePath As String = oRow.Item("FILENAME2WORK").ToString
Dim oFileId As Integer = oRow.Item("GUID")
My.Application.Globix.CurrentWorkfile = New Globix.Models.WorkFile With {
.Id = oFileRow.Item(0),
.Id = oFileId,
.FilePath = oFilePath
}
@ -597,12 +594,6 @@ Public Class frmFlowForm
End If
If My.Application.Globix.CurrentFolderWatchPath <> "" Or My.Application.Globix.CURRENT_SCAN_FOLDERWATCH <> "" Then
'If My.Application.Globix.Folderwatchstarted = True Then
' tslblFW.Visible = True
'Else
' tslblFW.Visible = False
'End If
Try
If My.UIConfigManager.Config.Globix.FolderWatchScanStarted = True Then
Logger.Info("FWSCAN started - Checking file:" & My.Application.Globix.CURRENT_SCAN_FOLDERWATCH)