339 lines
16 KiB
VB.net
339 lines
16 KiB
VB.net
Imports System.ComponentModel
|
|
Imports DLLLicenseManager
|
|
Imports DigitalData.Modules.Logging
|
|
Imports DigitalData.Modules.Config
|
|
Imports DigitalData.Modules.Windream
|
|
Imports DigitalData.Modules.Filesystem
|
|
Imports DigitalData.Modules.Messaging
|
|
|
|
Public Class ClassInit
|
|
Public _lizenzManager As ClassLicenseManager
|
|
|
|
Public Sub InitLogger()
|
|
ClassLogger.Init("", Environment.UserName)
|
|
LOGCONFIG = New LogConfig(LogConfig.PathType.AppData, Nothing, Nothing,
|
|
CompanyName:=My.Application.Info.CompanyName,
|
|
ProductName:=My.Application.Info.ProductName)
|
|
LOGGER = LOGCONFIG.GetLogger("Globix")
|
|
LOGGER.Info("Programmstart: " & Now)
|
|
LOGGER.Info("Username: {0}", Environment.UserName)
|
|
End Sub
|
|
|
|
Public Sub InitConfig()
|
|
CONFIG = New ConfigManager(Of ClassConfig)(LOGCONFIG, Application.UserAppDataPath, Application.CommonAppDataPath)
|
|
LOGCONFIG.Debug = Not CONFIG.Config.LogErrorsOnly
|
|
LOGGER.Info("Debug log set to: [{0}]", LOGCONFIG.Debug)
|
|
|
|
MyConnectionString = DecryptConnectionString(CONFIG.Config.ConnectionString)
|
|
LogErrorsOnly = CONFIG.Config.LogErrorsOnly
|
|
|
|
'myPreviewActive = CONFIG.Config.FilePreview
|
|
FW_started = CONFIG.Config.FolderWatchStarted
|
|
CURR_DELETE_ORIGIN = CONFIG.Config.DeleteOriginalFile
|
|
End Sub
|
|
|
|
Public Function InitDatabase()
|
|
Dim dbResult As Boolean
|
|
'LoadMyConfig()
|
|
If LoadFileExclusion() = False Then
|
|
If USER_LANGUAGE = "de-DE" Then
|
|
MsgBox("Die Ausschlusskriterien für Dateien in Folderwatch konnten nicht angelegt werden!", MsgBoxStyle.Information)
|
|
Else
|
|
MsgBox("File-Exclusions in Folderwatch could not be created!", MsgBoxStyle.Information)
|
|
End If
|
|
|
|
End If
|
|
|
|
If MyConnectionString <> String.Empty Then
|
|
dbResult = ClassDatabase.Init()
|
|
Else
|
|
MsgBox("No Databaseconnection configured. (First Start or Appdata not accessible)" & vbNewLine & "Basic-Config will be loaded.", MsgBoxStyle.Information)
|
|
ERROR_STATE = "NO DB-CONNECTION"
|
|
frmConfig_Basic.ShowDialog()
|
|
dbResult = ClassDatabase.Init()
|
|
End If
|
|
|
|
If dbResult = False Then
|
|
ERROR_STATE = "FAILED DBCONNECTION"
|
|
' Fehler wird in frmSplash abgehandelt
|
|
'MsgBox("Error in init database. (Connection failed) More information in the logfile.", MsgBoxStyle.Critical)
|
|
Return False
|
|
Else
|
|
Return True
|
|
End If
|
|
End Function
|
|
<STAThread()>
|
|
Public Sub InitBasics()
|
|
Dim configResult As Boolean
|
|
configResult = Load_BasicConfig()
|
|
|
|
FILESYSTEM = New File(LOGCONFIG)
|
|
EMAIL = New Email2(LOGCONFIG)
|
|
|
|
If configResult = False Then
|
|
If USER_LANGUAGE = "de-DE" Then
|
|
Throw New Exception("Unerwarteter Fehler beim Initialisieren der Basis-Einstellungen. Weitere Informationen finden Sie in der Logdatei.")
|
|
Else
|
|
Throw New Exception("Unexpected error while initializing basic-settings. More info in the log.")
|
|
End If
|
|
Else
|
|
If IDB_ACTIVE = False Then
|
|
Try
|
|
WINDREAM = New Windream(LOGCONFIG, False, WMDrive, "\\windream\objects", True, "", "", "", "")
|
|
If Not IsNothing(WINDREAM) Then
|
|
If WINDREAM.SessionLoggedin = True Then
|
|
LOGGER.Debug("windream initialisiert")
|
|
Else
|
|
Throw New Exception("Could not create a windream session")
|
|
End If
|
|
End If
|
|
Catch ex As Exception
|
|
LOGGER.Warn("CHECKING WMConnectivity: " & ex.Message)
|
|
Throw New Exception("Unexpected error in CHECKING WMConnectivity")
|
|
End Try
|
|
End If
|
|
|
|
End If
|
|
End Sub
|
|
|
|
Public Function Load_BasicConfig()
|
|
Try
|
|
ClassDatabase.Init()
|
|
Dim oSql As String = "SELECT * FROM TBDD_MODULES WHERE NAME = 'Global-Indexer'"
|
|
Dim DT As DataTable = ClassDatabase.Return_Datatable(oSql)
|
|
If DT.Rows.Count = 1 Then
|
|
GI_withWindream = DT.Rows(0).Item("BIT1")
|
|
'vWLaufwerk = DT.Rows(0).Item("STRING1")
|
|
End If
|
|
oSql = "SELECT * FROM TBDD_BASECONFIG"
|
|
DT = ClassDatabase.Return_Datatable(oSql)
|
|
If DT.Rows.Count = 1 Then
|
|
WMDrive = DT.Rows(0).Item("WM_DRIVE")
|
|
Return True
|
|
Else
|
|
Return False
|
|
End If
|
|
Catch ex As Exception
|
|
MsgBox("Error in Load_BasicConfig" & vbNewLine & ex.Message, MsgBoxStyle.Critical)
|
|
Return False
|
|
End Try
|
|
Return True
|
|
End Function
|
|
|
|
Public Sub Init_Folderwatch()
|
|
Try
|
|
Dim sql As String = "SELECT FOLDER_PATH FROM TBGI_FOLDERWATCH_USER WHERE FOLDER_TYPE = 'DEFAULT' AND USER_ID = " & USER_ID
|
|
Dim folderwatchPath = ClassDatabase.Execute_Scalar(sql, MyConnectionString, True)
|
|
|
|
folderwatchPath = IIf(IsDBNull(folderwatchPath), "", folderwatchPath)
|
|
|
|
If folderwatchPath = String.Empty Then
|
|
LOGGER.Info("Init_Folderwatch: folderwatchPath is empty")
|
|
FW_started = False
|
|
'SaveConfigValue("FW_started", "False")
|
|
CONFIG.Config.FolderWatchStarted = False
|
|
CONFIG.Save()
|
|
|
|
End If
|
|
|
|
If Not IO.Directory.Exists(folderwatchPath) Then
|
|
LOGGER.Info("Init_Folderwatch: folderwatchPath does not exists or is invalid path")
|
|
FW_started = False
|
|
'SaveConfigValue("FW_started", "False")
|
|
CONFIG.Config.FolderWatchStarted = False
|
|
CONFIG.Save()
|
|
|
|
End If
|
|
|
|
CURRENT_FOLDERWATCH = folderwatchPath
|
|
|
|
FW_started = True
|
|
FWFunction_STARTED = True
|
|
ClassFolderWatcher.StartStop_FolderWatch()
|
|
Catch ex As Exception
|
|
MsgBox($"Init_Folderwatch: Unexpected error while starting FolderWatch: {ex.Message}", MsgBoxStyle.Critical)
|
|
LOGGER.Info($"Init_Folderwatch: Unexpected error: {ex.Message}")
|
|
START_INCOMPLETE = True
|
|
End Try
|
|
|
|
Try
|
|
Dim sql As String = "SELECT FOLDER_PATH FROM TBGI_FOLDERWATCH_USER WHERE FOLDER_TYPE = 'SCAN' AND USER_ID = " & USER_ID
|
|
Dim folderwatchScanPath = ClassDatabase.Execute_Scalar(sql, MyConnectionString, True)
|
|
|
|
folderwatchScanPath = IIf(IsDBNull(folderwatchScanPath), "", folderwatchScanPath)
|
|
|
|
If folderwatchScanPath = String.Empty Then
|
|
LOGGER.Info("Init_Folderwatch: folderwatchScanPath is empty")
|
|
CONFIG.Config.FolderWatchStarted = False
|
|
CONFIG.Save()
|
|
Exit Sub
|
|
End If
|
|
|
|
If Not IO.Directory.Exists(folderwatchScanPath) Then
|
|
LOGGER.Info("Init_Folderwatch: folderwatchScanPath does not exists or is invalid path")
|
|
CONFIG.Config.FolderWatchStarted = False
|
|
CONFIG.Save()
|
|
Exit Sub
|
|
End If
|
|
|
|
CURRENT_SCAN_FOLDERWATCH = folderwatchScanPath
|
|
|
|
|
|
FWFunction_STARTED = True
|
|
ClassFolderWatcher.StartStop_FolderWatchSCAN()
|
|
Catch ex As Exception
|
|
MsgBox($"Init_Folderwatch: Unexpected error while starting FolderWatchScan: {ex.Message}", MsgBoxStyle.Critical)
|
|
LOGGER.Info($"Init_Folderwatch: Unexpected error: {ex.Message}")
|
|
START_INCOMPLETE = True
|
|
End Try
|
|
|
|
|
|
|
|
'Try
|
|
' 'Die FolderWatch starten
|
|
'Dim sql1 = "SELECT FOLDER_PATH FROM TBGI_FOLDERWATCH_USER WHERE FOLDER_TYPE = 'DEFAULT' AND USER_ID = " & CURRENT_USER_ID
|
|
' Dim folderwatch = ClassDatabase.Execute_Scalar(sql1, MyConnectionString, True)
|
|
' sql1 = "SELECT FOLDER_PATH FROM TBGI_FOLDERWATCH_USER WHERE FOLDER_TYPE = 'SCAN' AND USER_ID = " & CURRENT_USER_ID
|
|
' Dim folderwatch_SCAN = ClassDatabase.Execute_Scalar(sql1, MyConnectionString, True)
|
|
' If Not folderwatch Is Nothing Then
|
|
' CURRENT_FOLDERWATCH = folderwatch
|
|
' If FW_started = True Then
|
|
' If CURRENT_FOLDERWATCH = "" Then
|
|
' FW_started = False
|
|
' SaveConfigValue("FW_started", "False")
|
|
' Else
|
|
' FW_ISSTARTED = True
|
|
' ClassFolderWatcher.StartStop_FolderWatch()
|
|
' End If
|
|
|
|
' End If
|
|
' Else
|
|
' LOGGER.Info("Init_Folderwatch: folderwatch path is nothing!")
|
|
' End If
|
|
' If Not folderwatch_SCAN Is Nothing Then
|
|
' CURRENT_SCAN_FOLDERWATCH = folderwatch_SCAN
|
|
' If FWSCAN_started = True Then
|
|
' FW_ISSTARTED = True
|
|
' ClassFolderWatcher.StartStop_FolderWatchSCAN()
|
|
' End If
|
|
' Else
|
|
' LOGGER.Info("Init_Folderwatch: folderwatch_SCAN path is nothing!")
|
|
' End If
|
|
'Catch ex As Exception
|
|
' LOGGER.Info("Unexpected Error in Init_Folderwatch: " & ex.Message)
|
|
' START_INCOMPLETE = True
|
|
'End Try
|
|
End Sub
|
|
Public Sub InitUserLogin()
|
|
Try
|
|
Dim oSql As String
|
|
|
|
oSql = String.Format("SELECT * FROM [dbo].[FNDD_CHECK_USER_MODULE] ('{0}','GLOBIX',{1})", Environment.UserName, 1)
|
|
Dim DT_CHECKUSER_MODULE As DataTable = ClassDatabase.Return_Datatable(oSql)
|
|
If DT_CHECKUSER_MODULE.Rows.Count = 0 Then
|
|
LOGGER.Info("DT_CHECKUSER_MODULE.Rows.Count = 0")
|
|
START_INCOMPLETE = True
|
|
ERROR_STATE = "NO USER"
|
|
MsgBox("Sorry - Something went wrong in getting Your rights." & vbNewLine & "Please contact the system administrator!", MsgBoxStyle.Exclamation)
|
|
Exit Sub
|
|
End If
|
|
If DT_CHECKUSER_MODULE.Rows.Count = 1 Then
|
|
If DT_CHECKUSER_MODULE.Rows(0).Item("USER_ID") = 0 And IsDBNull(DT_CHECKUSER_MODULE.Rows(0).Item("USER_SURNAME")) Then
|
|
LOGGER.Info("User '" & Environment.UserName & "' not configured in Useradministration!")
|
|
START_INCOMPLETE = True
|
|
Throw New Exception("You are not configured in the Useradministration." & vbNewLine & "Please contact the system administrator!")
|
|
Exit Sub
|
|
End If
|
|
USER_IN_MODULE = DT_CHECKUSER_MODULE.Rows(0).Item("MODULE_ACCESS")
|
|
USER_ID = DT_CHECKUSER_MODULE.Rows(0).Item("USER_ID")
|
|
USER_SURNAME = IIf(IsDBNull(DT_CHECKUSER_MODULE.Rows(0).Item("USER_SURNAME")), "", DT_CHECKUSER_MODULE.Rows(0).Item("USER_SURNAME"))
|
|
USER_PRENAME = IIf(IsDBNull(DT_CHECKUSER_MODULE.Rows(0).Item("USER_PRENAME")), "", DT_CHECKUSER_MODULE.Rows(0).Item("USER_PRENAME"))
|
|
USER_SHORTNAME = IIf(IsDBNull(DT_CHECKUSER_MODULE.Rows(0).Item("USER_SHORTNAME")), "", DT_CHECKUSER_MODULE.Rows(0).Item("USER_SHORTNAME"))
|
|
USER_EMAIL = IIf(IsDBNull(DT_CHECKUSER_MODULE.Rows(0).Item("USER_EMAIL")), "", DT_CHECKUSER_MODULE.Rows(0).Item("USER_EMAIL"))
|
|
USER_LANGUAGE = DT_CHECKUSER_MODULE.Rows(0).Item("USER_LANGUAGE")
|
|
USER_IN_MODULE = DT_CHECKUSER_MODULE.Rows(0).Item("MODULE_ACCESS")
|
|
USER_IS_ADMIN = DT_CHECKUSER_MODULE.Rows(0).Item("IS_ADMIN")
|
|
USERCOUNT_LOGGED_IN = DT_CHECKUSER_MODULE.Rows(0).Item("USERCOUNT_LOGGED_IN")
|
|
ClassParamRefresh.Refresh_Params(DT_CHECKUSER_MODULE)
|
|
If USER_IN_MODULE = False Then
|
|
LOGGER.Info(" - User: " & Environment.UserName & " nicht für Modul freigegben!")
|
|
START_INCOMPLETE = True
|
|
|
|
Throw New Exception("Your user is not allowed to use this module." & vbNewLine & "Please contact the system administrator!")
|
|
|
|
Exit Sub
|
|
End If
|
|
USER_IS_ADMIN = DT_CHECKUSER_MODULE.Rows(0).Item("IS_ADMIN")
|
|
|
|
ClassLicence.Refresh_Licence()
|
|
|
|
Dim sql1 = "SELECT COUNT(T.GUID) FROM TBDD_DOKUMENTART T, TBDD_DOKUMENTART_MODULE T1 WHERE T.AKTIV = 1 AND T.GUID = T1.DOKART_ID AND T1.MODULE_ID = 1"
|
|
DOCTYPE_COUNT_ACTUAL = ClassDatabase.Execute_Scalar(sql1, MyConnectionString, True)
|
|
If DOCTYPE_COUNT_ACTUAL > LICENSE_DOCTYPE_COUNT Then
|
|
If USER_LANGUAGE = "de-DE" Then
|
|
MsgBox("Ihre Anzahl von konfigurierbaren Dokumentarten ist limitiert auf: '" & LICENSE_DOCTYPE_COUNT.ToString & "'." & vbNewLine & "Bitte kontaktieren Sie Digital Data für weitere Details.", MsgBoxStyle.Information)
|
|
Else
|
|
MsgBox("Your amount of configurable documenttypes is limited to " & LICENSE_DOCTYPE_COUNT.ToString & " doctypes. You can not add more doctypes!" & vbNewLine & "Please contact Digital Data for further licensedetails", MsgBoxStyle.Information)
|
|
End If
|
|
End If
|
|
USER_LANGUAGE = DT_CHECKUSER_MODULE.Rows(0).Item("USER_LANGUAGE")
|
|
|
|
oSql = "DELETE FROM TBDD_USER_MODULE_LOG_IN WHERE USER_ID = " & USER_ID & " AND UPPER(MODULE) = UPPER('Global-Indexer')"
|
|
ClassDatabase.Execute_non_Query(oSql, True)
|
|
oSql = "INSERT INTO TBDD_USER_MODULE_LOG_IN (USER_ID,MODULE, CLIENT_ID) VALUES (" & USER_ID & ",'Global-Indexer', 1)"
|
|
ClassDatabase.Execute_non_Query(oSql)
|
|
oSql = "SELECT COUNT(*) AS Expr1 FROM TBDD_USER_MODULE_LOG_IN WHERE Upper(MODULE) = UPPER('Global-Indexer')"
|
|
' Dim anzahl = ClassDatabase.Execute_Scalar(sql, MyConnectionString, True)
|
|
'LOGGER.Info(" >> Anzahl Angemeldete User: " & anzahl.ToString)
|
|
' UserLoggedin = CInt(anzahl)
|
|
' UserLoggedin += 1
|
|
If LICENSE_COUNT < USERCOUNT_LOGGED_IN And LICENSE_EXPIRED = False Then
|
|
MsgBox("Die Anzahl der aktuell angemeldeten User (" & USERCOUNT_LOGGED_IN.ToString & ") überschreitet die Anzahl der aktuellen Lizenzen!" & vbNewLine & "Anzahl der Lizenzen: " & LICENSE_COUNT.ToString & vbNewLine & "Bitte setzen Sie sich mit dem Systembetreuer in Verbindung!", MsgBoxStyle.Critical, "Achtung:")
|
|
LOGGER.Info(" >> Die Anzahl der aktuell angemeldeten User (" & USERCOUNT_LOGGED_IN.ToString & ") überschreitet die Anzahl der Lizenzen (" & LICENSE_COUNT & ") für Global Indexer!")
|
|
If USER_IS_ADMIN = False Then
|
|
'Anmeldung wieder herausnehmen
|
|
oSql = "DELETE FROM TBDD_USER_MODULE_LOG_IN WHERE USER_ID = " & USER_ID & " AND MODULE= 'Global-Indexer'"
|
|
ClassDatabase.Execute_non_Query(oSql, True)
|
|
LOGGER.Info(" - Wieder abgemeldet")
|
|
START_INCOMPLETE = True
|
|
End If
|
|
End If
|
|
'Alles OK bis hierhin...nun die FolderwatchKonfig laden
|
|
Init_Folderwatch()
|
|
'LabelLoggedIn.Caption = "Anzahl Angemeldete User: " & anzahl.ToString
|
|
End If
|
|
|
|
|
|
Catch ex As Exception
|
|
LOGGER.Info("Unexpected Error in InitUserLogin: " & ex.Message)
|
|
LOGGER.Error(ex)
|
|
MsgBox(ex.Message, MsgBoxStyle.Critical)
|
|
START_INCOMPLETE = True
|
|
End Try
|
|
|
|
End Sub
|
|
|
|
Private Function DecryptConnectionString(EncryptedConnectionString As String) As String
|
|
Dim oBuilder As New SqlClient.SqlConnectionStringBuilder With {
|
|
.ConnectionString = EncryptedConnectionString
|
|
}
|
|
|
|
If oBuilder.ConnectionString.Contains("Password=") Then
|
|
Dim oPlaintextPassword As String
|
|
Dim oDecryptor As New ClassEncryption("!35452didalog=")
|
|
|
|
Try
|
|
oPlaintextPassword = oDecryptor.DecryptData(oBuilder.Password)
|
|
Catch ex As Exception
|
|
LOGGER.Error(ex)
|
|
LOGGER.Debug("Password {0} could not be decrypted. Assuming plaintext password.")
|
|
oPlaintextPassword = oBuilder.Password
|
|
End Try
|
|
Return EncryptedConnectionString.Replace(oBuilder.Password, oPlaintextPassword)
|
|
Else
|
|
Return EncryptedConnectionString
|
|
End If
|
|
End Function
|
|
|
|
End Class
|