Imports WINDREAMLib Public Class clsProfil #Region "***** Variablen *****" Public Shared _windream As New clsWindream_allgemein Public Shared _Profilname, _profObjekttyp, _profwdSuche, _profDay, _profRunType As String Public Shared _profGUID As Integer Public Shared _proflastRun As Date Private email As New clsEmail Private Shared CriticalError As Boolean = False Private Shared WD_aktivesDokument As WMObject #End Region Public Shared Function Init(guid As Integer) Try Dim DT As DataTable = clsSQLITE.Return_Datatable("Select * from TBPROFIL where GUID = " & guid & " AND Running = 0") For Each DR As DataRow In DT.Rows _profGUID = guid _Profilname = CStr(DR.Item("Profilname")) ' Überprüfen ob Profil aktiv oder inaktiv If CBool(DR.Item("Aktiv")) = False Then ClassLogger.Add("## Profil '" & _Profilname & "' ist inaktiv geschaltet", False) ClassLogger.Add("", False) Return 0 Else _profObjekttyp = CStr(DR.Item("Objekttyp")) _profwdSuche = CStr(DR.Item("WindreamSuche")) _profDay = CStr(DR.Item("Day")) _profRunType = CStr(DR.Item("Run")) _proflastRun = DR.Item("Letzter_Durchlauf") Return True End If Next Catch ex As Exception ClassLogger.Add(ex.Message, True, "Profil_Init") Return False End Try End Function 'Durchlauf des Profils wird aus dem Service gestartet wenn Init = True war Public Shared Function Profil_Durchlauf() Try Dim Run_Profile As Boolean = False 'Soll die Verarbeitung heute durchgeführt werden?? Dim Dayofweek As Integer = My.Computer.Clock.LocalTime.DayOfWeek If _profDay.Substring(Dayofweek - 1, 1) = 1 Then 'Verarbeitung soll heute durchgeführt werden ClassLogger.AddDetailLog("Verarbeitung soll heute durchgeführt werden!") ClassLogger.AddDetailLog("_RunType: " & _profRunType) Dim arr As String() arr = _profRunType.Split(";") ClassLogger.AddDetailLog("arr(1): " & arr(1).ToString) Select Case _profRunType Case _profRunType.Contains("TIME") Dim Time_last As Date = clsSQLITE.konf_LASTTICK.ToShortTimeString Dim intervall As Integer = clsSQLITE.konf_intervall / 60 Dim Time_next As Date = _proflastRun.AddMinutes(intervall) Dim _RunTime As Date = CDate(arr(1)) Dim msg As String msg = "Time-Angaben: " & vbNewLine msg = msg & "Time_last: " & Time_last & vbNewLine msg = msg & "Time_next: " & Time_next & vbNewLine msg = msg & "ProfilTime: " & _RunTime & vbNewLine ClassLogger.AddDetailLog(msg) 'Ist die Uhrzeit in der Range If _RunTime.ToShortTimeString >= Time_last.ToShortTimeString And _RunTime.ToShortTimeString <= Time_next.ToShortTimeString Then 'Den Durchlauf erlauben Run_Profile = True End If Case _profRunType.Contains("INTV") 'Die Differenz berechnen Dim DiffMin As Integer = DateDiff(DateInterval.Minute, _proflastRun, Date.Now) Dim msg As String msg = "Minutenangaben: " & vbNewLine msg = msg & "DiffMin: " & DiffMin & vbNewLine msg = msg & "Intervall: " & arr(1) ClassLogger.AddDetailLog(msg) If DiffMin >= CInt(arr(1)) Then 'Den Durchlauf erlauben Run_Profile = True End If End Select If Run_Profile = True Then ClassLogger.Add(">> Start des Durchlaufes für Profil '" & _Profilname & "'", False) 'den Durchlaufszeitpunkt speichern clsSQLITE.Execute_non_Query("Update TBPROFIL SET Running = 1 AND LETZTER_DURCHLAUF = DATETIME ('now' , 'localtime') WHERE GUID = " & _profGUID) If clsHelper.file_exists(_profwdSuche) = False Then ClassLogger.Add("Die Windream-Suche '" & _profwdSuche & "' existiert nicht!", True, "clsProfil.Profil_Durchlauf") 'wenn die gesuchte File eine Suche ist: per MAil informierne und Indexierung abbrechen If clsSQLITE.konf_EmailAktiv Then clsEmail.Send_EMail("Fehler in windream-ResultHandler", "
>> Profilname: '" & _Profilname & "'
>> Die windream-Suche : " & _profwdSuche & " konnte nicht gefunden werden!" & _ "
>> Mögliche Fehlerursache: Das W-Laufwerk ist nicht verfügbar!") End If Return False Else ' windream-Suche für Profil starten Dim windreamSucheErgebnisse As WMObjects = _windream.GetSearchDocuments(_profwdSuche) If windreamSucheErgebnisse.Count > 0 Then ClassLogger.Add("- Insgesamt sollen '" & windreamSucheErgebnisse.Count & "' Dateien bearbeitet werden", True, "clsProfil.Profil_Durchlauf") Dim DT_PROFIL_JOB As DataTable = clsSQLITE.Return_Datatable("SELECT * FROM TBPROFIL_JOB WHERE AKTIV = 1 AND PROFIL_ID = " & _profGUID & " ORDER BY REIHENFOLGE") Dim DT_PROFIL_FILE_JOB As DataTable = clsSQLITE.Return_Datatable("SELECT * FROM TBPROFIL_FILE_JOB WHERE AKTIV = 1 AND PROFIL_ID = " & _profGUID & " ORDER BY REIHENFOLGE") If DT_PROFIL_JOB.Rows.Count > 0 Then If clsDateiverarbeitung.InitProfilData = True Then For Each DR_PR_JB As DataRow In DT_PROFIL_JOB.Rows Select Case DR_PR_JB.Item("JOB_TYP").ToString.ToUpper Case "Create Mail Attachment".ToUpper Case "Export HDD".ToUpper 'Für jedes Dokument in der Windream-Ergebnisliste For Each dok As WMObject In windreamSucheErgebnisse ' aktuelles Dokument zum Export bereitstellen If clsDateiverarbeitung.Export_File(dok, DR_PR_JB.Item("STRING1")) Then If DT_PROFIL_FILE_JOB.Rows.Count > 0 Then 'Für jeden File-Job For Each DR_PR_FILE_JOB As DataRow In DT_PROFIL_FILE_JOB.Rows Select Case DR_PR_JB.Item("JOB_TYP").ToString.ToLower Case "Set Index".ToLower End Select Next End If End If Next End Select Next End If Else ClassLogger.Add(">> KEINE JOBS für Profil '" & _Profilname & "' angelegt!", "clsProfil.Profil_Durchlauf", True) End If Else ' keine Dateien zum Importieren ClassLogger.Add(">> Keine windream-Dokumente für Profil '" & _Profilname & "' vorhanden/gefunden.", False) ClassLogger.Add("", False) End If End If clsSQLITE.Execute_non_Query("UPDATE TBPROFIL SET Running = 0 AND LETZTER_DURCHLAUF = DATETIME ('now' , 'localtime') WHERE GUID = " & _profGUID) End If Else ClassLogger.AddDetailLog("Verarbeitung für heute NICHT konfiguriert") End If Return True Catch ex As Exception ClassLogger.Add("Unvorhergesehener Fehler: " & ex.Message, True, "clsProfil.Profil_Durchlauf") CriticalError = False Service1.threadRunner.CancelAsync() Return False End Try End Function End Class