Imports System.ComponentModel Imports DigitalData.Modules.License Imports DigitalData.Modules.Logging Imports DigitalData.Modules.Language.Utils Imports DigitalData.Modules.Config Imports DigitalData.Modules.Database Imports DigitalData.Modules.EDMI.API Imports DigitalData.Modules.EDMI.API.EDMIServiceReference Imports System.Globalization Imports System.Threading Imports DigitalData.Modules.EDMI.API.DatabaseWithFallback Imports DigitalData.Modules.Base Public Class ClassInit Public _lizenzManager As LicenseManagerLegacy Public _database As MSSQLServer Private _DataASorDB As ClassDataASorDB Private Class S Inherits My.Resources.frmMain_Strings End Class Public Sub InitLogger() LogConfig = New LogConfig(LogConfig.PathType.AppData, Nothing, Nothing, Application.CompanyName, Application.ProductName) Logger = LogConfig.GetLogger() _DataASorDB = New ClassDataASorDB(LogConfig) End Sub Public Function InitDatabase() 'clsDatabase.GUI = True Dim Database_ECM As MSSQLServer = Nothing Dim Database_IDB As MSSQLServer = Nothing If MyConnectionString <> String.Empty Then Database_ECM = New MSSQLServer(LogConfig, MyConnectionString) Else MsgBox("No Databaseconnection configured. (First Start or Appdata not accessible)" & vbNewLine & "Basic-Config will be loaded.", MsgBoxStyle.Information) ERROR_INIT = "NO DB-CONNECTION" frmConfig_Basic.ShowDialog() InitBasics() End If If Database_ECM.DBInitialized = True Then DatabaseFallback = New DatabaseWithFallback(LogConfig, _Client, Database_ECM, Database_IDB) Return True Else ERROR_INIT = "FAILED DBCONNECTION" MsgBox("Error in init database. (Connection failed) More information in the logfile.", MsgBoxStyle.Critical) Return False End If End Function Public Function InitDatabase_New() As Boolean If MyConnectionString = String.Empty Then MsgBox("No Databaseconnection configured. (First Start or Appdata not accessible)" & vbNewLine & "Basic-Config will be loaded.", MsgBoxStyle.Information) ERROR_INIT = "NO DB-CONNECTION" frmConfig_Basic.ShowDialog() End If Try MyDB_DDECM = New MSSQLServer(LogConfig, MyConnectionString) If MyDB_DDECM.DBInitialized = True Then Return True Else Return False End If Catch ex As Exception Logger.Error(ex) Return False End Try End Function Public Function InitAppDatabase() As Boolean Try DatabaseAppServ = New MSSQLServer(LogConfig, MyConStringAppserv) If DatabaseAppServ.DBInitialized = True Then Return True Else Return False End If Catch ex As Exception Logger.Error(ex) Return False End Try End Function Public Function InitBasics() Dim oUserAppDataPath As String = Application.UserAppDataPath Dim oLegacyAppDataPath As String = Application.UserAppDataPath Dim oCommonAppDataPath = Application.CommonAppDataPath Dim oStartupPath = Application.StartupPath Dim oConfigPrefix As String = My.Settings.UserConfig_Prefix ' If prefix is configured, use it to create a subfolder in app data and migrate existing data If oConfigPrefix.Length > 0 Then oUserAppDataPath = IO.Path.Combine(Application.UserAppDataPath, oConfigPrefix) Dim oConfigUtils As New ConfigUtils(LogConfig) If oConfigUtils.TestMigrationNeeded(oUserAppDataPath) Then LogConfig.Debug = True oConfigUtils.MigrateConfig(oLegacyAppDataPath, oUserAppDataPath) LogConfig.Debug = False End If End If ' If AppConfig from Startup Path should be forced, rewrite the common app data path If My.Settings.UseAppConfigConString = True Then ' UserAppDataPath = StartupPath oCommonAppDataPath = oStartupPath End If CONFIG = New ConfigManager(Of ClassConfig)(LogConfig, oUserAppDataPath, oCommonAppDataPath, oStartupPath) With CONFIG.Config MyConnectionString = MSSQLServer.DecryptConnectionString(.ConnectionString) LogErrorsOnly = .LogErrorsOnly HotkeySearchKey = .HotkeySearchKey LogConfig.Debug = Not .LogErrorsOnly End With If HotkeySearchKey_via_Server = False Then HotkeyFunctionKey = CONFIG.Config.HotkeyFunctionKey End If If CONFIG.Config.ConnectionStringAppServer <> String.Empty Then MyConStringAppserv = MSSQLServer.DecryptConnectionString(CONFIG.Config.ConnectionStringAppServer) If InitAppDatabase() Then Logger.Debug("ConnectionStringAppServer will be used") End If End If If CONFIG.Config.AppServerConfig <> String.Empty Then Try Dim oDynSplitCharacter As String If CONFIG.Config.AppServerConfig.Contains(":") Then oDynSplitCharacter = ":" ElseIf CONFIG.Config.AppServerConfig.Contains(";") Then oDynSplitCharacter = ";" End If Dim oSplit() As String = CONFIG.Config.AppServerConfig.ToString.Split(oDynSplitCharacter) Dim oAppServerAddress As String = oSplit(0) Dim oAppServerPort As Integer = 9000 If oSplit.Length = 2 Then oAppServerPort = oSplit(1) End If _Client = New Client(LogConfig, oAppServerAddress, oAppServerPort) If Not IsNothing(_Client) Then If _Client.Connect() Then APPSERVER_ACTIVE = True Else Logger.Warn($"###!!!APPServer [{CONFIG.Config.AppServerConfig.ToString}] could not be initialized ") End If End If Catch ex As Exception Logger.Warn($"Could not initialize the AppServer: {ex.Message}") End Try End If Return True End Function Public Function CheckModuleData() Try Dim oSql = String.Format("SELECT * FROM [dbo].[FNDD_LOGIN_USER_MODULE] ('{0}','CW',{1})", USER_USERNAME, CLIENT_SELECTED) Dim DT_CHECKUSER_MODULE As DataTable DT_CHECKUSER_MODULE = MyDB_DDECM.GetDatatable(oSql) If DT_CHECKUSER_MODULE.Rows.Count = 0 Then Logger.Info("DT_CHECKUSER_MODULE.Rows.Count = 0", True) 'ERROR_STATE = "NO USER" MsgBox("Sorry - Something went wrong in getting Your rights." & vbNewLine & "Please contact the system administrator!", MsgBoxStyle.Exclamation) Return False End If If DT_CHECKUSER_MODULE.Rows.Count = 1 Then Logger.Info("Login Username: " & USER_ID, False) Logger.Info("Login time: " & Now.ToShortDateString, False) USER_ID = DT_CHECKUSER_MODULE.Rows(0).Item("USER_ID") USER_SURNAME = ObjectEx.NotNull(DT_CHECKUSER_MODULE.Rows(0).Item("USER_SURNAME"), "") USER_PRENAME = ObjectEx.NotNull(DT_CHECKUSER_MODULE.Rows(0).Item("USER_PRENAME"), "") USER_SHORTNAME = ObjectEx.NotNull(DT_CHECKUSER_MODULE.Rows(0).Item("USER_SHORTNAME"), "") USER_EMAIL = ObjectEx.NotNull(DT_CHECKUSER_MODULE.Rows(0).Item("USER_EMAIL"), "") USER_LANGUAGE = ObjectEx.NotNull(DT_CHECKUSER_MODULE.Rows(0).Item("USER_LANGUAGE"), "de-DE") USER_DATE_FORMAT = ObjectEx.NotNull(DT_CHECKUSER_MODULE.Rows(0).Item("USER_DATE_FORMAT"), "dd.MM.yyyy") USER_IN_MODULE = ObjectEx.NotNull(DT_CHECKUSER_MODULE.Rows(0).Item("MODULE_ACCESS"), False) USER_IS_ADMIN = ObjectEx.NotNull(DT_CHECKUSER_MODULE.Rows(0).Item("IS_ADMIN"), False) ADDITIONAL_TITLE = ObjectEx.NotNull(DT_CHECKUSER_MODULE.Rows(0).Item("ADDITIONAL_TITLE"), "") Logger.Debug("User Id: [{0}]", USER_ID) Logger.Debug("User Email: [{0}]", USER_EMAIL) Logger.Debug("User Language: [{0}]", USER_LANGUAGE) Logger.Debug("User Dateformat: [{0}]", USER_DATE_FORMAT) If ADDITIONAL_TITLE = String.Empty Then ADDITIONAL_TITLE = My.Application.Info.ProductName End If USERCOUNT_LOGGED_IN = DT_CHECKUSER_MODULE.Rows(0).Item("USERCOUNT_LOGGED_IN") USERCOUNT_LOGGED_IN += 1 Try WORKING_MODE = DT_CHECKUSER_MODULE.Rows(0).Item("WORKING_MODE") Catch ex As Exception WORKING_MODE = "" End Try Dim oSplitWorkMode As String() = WORKING_MODE.Split("#") Dim oMode As String For Each oMode In oSplitWorkMode Logger.Debug($"oWorkingMode Parameter [{oMode}]") If oMode = "NO_BASICCONF" Then BASIC_CONF_VISIBLE = False ElseIf oMode.StartsWith("NOMATCH_INFO") Then Try Dim oResult = oMode.Replace("NOMATCH_INFO=", "") Logger.Info($"NOMATCH_INFO: {oResult}") NOMATCH_INFO = CBool(oResult) Catch ex As Exception NOMATCH_INFO = False End Try ElseIf oMode.StartsWith("HotkeySearchKey") Then Try Dim oResult = oMode.Replace("HotkeySearchKey=", "") Logger.Info($"HotkeySearchKey: {oResult}") HotkeySearchKey = oResult HotkeySearchKey_via_Server = True Catch ex As Exception HotkeySearchKey = "d" End Try ElseIf oMode.StartsWith("NotifyMode") Then Try Dim oResult = oMode.Replace("NotifyMode=", "") Logger.Info($"NotifyMode: {oResult}") NOTIFY_MODE = oResult Catch ex As Exception End Try Else Logger.Info($"Wrong oMode: {oMode}") End If Next Return True Else Logger.Info(" - UserId '" & USER_ID & "' not listed in Useradministration!", False) 'MsgBox("Achtung: Sie sind nicht in der Userverwaltung hinterlegt." & vbNewLine & "Bitte setzen Sie sich mit dem Systembetreuer in Verbindung!", MsgBoxStyle.Critical, "Achtung:") 'Me.Close() Dim msg = String.Format("You are not listed in the Useradministration." & vbNewLine & "Please contact the admin.") MsgBox(msg, MsgBoxStyle.Exclamation) Return False End If Catch ex As Exception Logger.Error(ex) Return False End Try End Function Public Function InitUserLogin(Optional _User As String = "") As Boolean Try If _User = "" Then USER_USERNAME = Environment.UserName Else USER_USERNAME = _User End If Try If CheckModuleData() = False Then Return False End If Dim oSQL1 = String.Format("SELECT * FROM VWDD_USER_CLIENT WHERE UPPER(USERNAME) = UPPER('{0}')", USER_USERNAME) DT_CLIENT_USER = _DataASorDB.GetDatatable(oSQL1, "VWDD_USER_CLIENT", $"USER_ID = {USER_ID}", "", "") 'If APPSERVER_ACTIVE = True Then ' Dim oTableResult As TableResult = _Client.GetDatatableByName("VWDD_USER_CLIENT", $"USER_ID = {USER_ID}") ' DT_CLIENT_USER = oTableResult.Table 'Else ' DT_CLIENT_USER = Database.GetDatatable(String.Format("SELECT * FROM VWDD_USER_CLIENT WHERE UPPER(USERNAME) = UPPER('{0}')", Environment.UserName)) 'End If If Not IsNothing(DT_CLIENT_USER) Then If DT_CLIENT_USER.Rows.Count > 1 Then frmClientLogin.ShowDialog() ElseIf DT_CLIENT_USER.Rows.Count = 1 Then CLIENT_SELECTED = DT_CLIENT_USER.Rows(0).Item("CLIENT_ID") Else Logger.Info("User '" & USER_ID & "' not related to a client", True) ERROR_INIT = "NO CLIENT" 'ERROR_STATE = "NO CLIENT" Return False End If Else Logger.Info("User '" & USER_ID & "' not related to a client", True) ERROR_INIT = "NO CLIENT" 'ERROR_STATE = "NO CLIENT" Return False End If Catch ex As Exception Logger.Info("Unexpected error in checking CLIENT: " & ex.Message) CLIENT_SELECTED = 1 End Try If USER_IN_MODULE = False Then If USER_IS_ADMIN = False Then Logger.Info("User: " & USER_ID & " not related to module!", False) Dim msg = String.Format("Sie sind nicht für die Nutzung dieses Moduls freigeschaltet." & vbNewLine & "Bitte setzen Sie sich mit dem Systemadministrator in Verbindung!") If USER_LANGUAGE <> LANGUAGE_GERMAN Then msg = String.Format("You are not authorized for using this module." & vbNewLine & "Please contact the admin.") End If MsgBox(msg, MsgBoxStyle.Exclamation, "Attention:") Return False End If End If 'Am System anmelden ClassLicense.Refresh_Licence(DT_CLIENT_USER.Rows(0).Item("CLIENT_ID")) 'Am System anmelden ' sql = String.Format("UPDATE TBDD_USER SET LOGGED_IN = 1, LOGGED_WHERE = '{0}' WHERE GUID = {1}", Environment.MachineName, USER_ID) 'Database.GetDatatable(sql) Dim oSQL As String oSQL = "DELETE FROM TBDD_USER_MODULE_LOG_IN WHERE USER_ID = " & USER_ID & " AND MODULE = 'Clipboard-Watcher'" MyDB_DDECM.ExecuteNonQuery(oSQL) oSQL = $"INSERT INTO TBDD_USER_MODULE_LOG_IN (USER_ID,CLIENT_ID,MODULE,VERSION_CLIENT,MACHINE_NAME) VALUES ({USER_ID},1,'Clipboard-Watcher','{My.Application.Info.Version.ToString}','Environment.MachineName')" MyDB_DDECM.ExecuteNonQuery(oSQL) If USER_IS_ADMIN = True Then If ESC_Hidden = True Then frmGhostUser.ShowDialog() 'frmLoginUserSelect.ShowDialog() ESC_Hidden = False If USER_USERNAME <> "" And GHOST_USERID <> 0 Then Logger.Info("GHOST USER ACTIVE") InitUserLogin(USER_USERNAME) End If End If ' 'Admin ' pageAdmin.Visible = True End If WD_UNICODE = MyDB_DDECM.GetScalarValue("SELECT WD_UNICODE FROM TBCW_CONFIGURATION WHERE GUID = 1") oSQL = $"SELECT COALESCE(MAX(LICENSE),'') FROM TBDD_3RD_PARTY_MODULES WHERE NAME = 'GDPICTURE' and VERSION = '{My.Settings.GDPICTURE_VERSION}' AND ACTIVE = 1" GDPICTURE_LICENSE = MyDB_DDECM.GetScalarValue(oSQL) If GDPICTURE_LICENSE = String.Empty Then Logger.Info($"ATTENTION: GDPICTURE VERSION is nothing. [{oSQL}]") End If oSQL = "SELECT LANG_CODE FROM TBDD_GUI_LANGUAGE WHERE ACTIVE = 1 ORDER BY LANG_CODE" BASEDATA_DT_LANGUAGE = MyDB_DDECM.GetDatatable(oSQL) Logger.Debug(" >> Count Users logged in: " & USERCOUNT_LOGGED_IN.ToString, False) If LICENSE_COUNT < USERCOUNT_LOGGED_IN And LICENSE_EXPIRED = False Then Dim msg = String.Format("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!") If USER_LANGUAGE <> LANGUAGE_GERMAN Then msg = String.Format("The number of logged Users (" & USERCOUNT_LOGGED_IN.ToString & ") exceeds the number of licenses." & vbNewLine & "Number of licenses: " & LICENSE_COUNT.ToString & vbNewLine & "Please contact Your admin!") End If MsgBox(msg, MsgBoxStyle.Exclamation) Logger.Info(" >> The number of logged Users (" & USERCOUNT_LOGGED_IN.ToString & ") exceeds the number of licenses (" & LICENSE_COUNT & ") ", False) If USER_IS_ADMIN = False Then 'Anmeldung wieder herausnehmen oSQL = "DELETE FROM TBDD_USER_MODULE_LOG_IN WHERE USER_ID = " & USER_ID & " AND MODULE= 'Clipboard-Watcher'" MyDB_DDECM.ExecuteNonQuery(oSQL) Logger.Info(" - logged out the user", False) Return False End If End If Return True Catch ex As Exception Logger.Info("Unexpected Error in InitUserLogin: " & ex.Message, True) MsgBox("Unexpected Error in InitUserLogin: " & ex.Message, MsgBoxStyle.Critical) Return False End Try End Function Public Sub Refresh_Connections() Try Dim oSql = String.Format("SELECT * FROM TBDD_CONNECTION") Dim oDatatable As New MyDataset.TBDD_CONNECTIONDataTable() Dim oResult As DataTable oDatatable = _DataASorDB.GetDatatable(oSql, "TBDD_CONNECTION", "", "", "") 'If APPSERVER_ACTIVE = True Then ' Dim oTableResult As TableResult = _Client.GetDatatableByName("TBDD_CONNECTION") ' oResult = oTableResult.Table 'Else ' oResult = Database.GetDatatable(oSql) 'End If 'oDatatable.Merge(oResult) DT_CONNECTIONS = oDatatable Catch ex As Exception Logger.Error(ex) MsgBox("Unexpected Error in Refresh_Connections: " & ex.Message, MsgBoxStyle.Critical) End Try End Sub Public Shared Function Refresh_Profile_Links() As String Dim ProfileSQL As String = $"SELECT DISTINCT PROFIL_ID [GUID], PROFIL_ID, PROFIL_NAME,REGEX_EXPRESSION,COMMENT,PROFILE_TYPE FROM VWCW_USER_PROFILE WHERE USER_ID = {USER_ID}" Dim oProcessSQL As String = $"SELECT DISTINCT T.GUID, T1.PROFIL_ID, T.PROC_NAME FROM TBCW_PROFILE_PROCESS T, VWCW_USER_PROFILE T1 WHERE T.PROFILE_ID = T1.PROFIL_ID AND USER_ID = {USER_ID}" Dim oWindowSQL As String = $"SELECT DISTINCT T.* FROM VWCW_PROFILE_REL_WINDOW T INNER JOIN VWCW_USER_PROFILE T1 ON T.PROFILE_ID = T1.PROFIL_ID AND T1.USER_ID = T.USER_ID WHERE T.USER_ID = {USER_ID}" Dim oControlSQL As String = $"SELECT DISTINCT T.* FROM VWCW_PROFILE_REL_CONTROL T INNER JOIN VWCW_USER_PROFILE T1 ON T.PROFILE_ID = T1.PROFIL_ID AND T.USER_ID = T1.USER_ID WHERE T1.USER_ID = {USER_ID} " Try DT_USER_PROFILES = MyDB_DDECM.GetDatatable(ProfileSQL) If DT_USER_PROFILES Is Nothing Or DT_USER_PROFILES.Rows.Count = 0 Then Logger.Warn("Keine Profile für den User auswertbar. Konfiuration oder SQL prüfen: " + ProfileSQL) Return S.Es_wurden_noch_keine_Profile_für_den_aktuellen_Benutzer_konfiguriert_ End If Catch ex As Exception Logger.Error(ex) MsgBox("Unexpected Error in Refresh_Profile_Links: " & ex.Message, MsgBoxStyle.Critical) Logger.Warn("SQL so far: " + ProfileSQL) Return S.Fehler_bei_der_Aktualisierung_ End Try Try DTPROFILE_REL_PROCESS = MyDB_DDECM.GetDatatable(oProcessSQL) Catch ex As Exception Logger.Error(ex) MsgBox("Unexpected Error in Refresh_ProcessLinks: " & ex.Message, MsgBoxStyle.Critical) Logger.Warn("SQL so far: " + oProcessSQL) Return S.Fehler_bei_der_Aktualisierung_ End Try Try DTPROFILE_REL_WINDOW = MyDB_DDECM.GetDatatable(oWindowSQL) Catch ex As Exception Logger.Error(ex) MsgBox("Unexpected Error in Refresh_windowLinks: " & ex.Message, MsgBoxStyle.Critical) Logger.Warn("SQL so far: " + oWindowSQL) Return S.Fehler_bei_der_Aktualisierung_ End Try Try DTPROFILE_REL_CONTROL = MyDB_DDECM.GetDatatable(oControlSQL) Catch ex As Exception Logger.Error(ex) MsgBox("Unexpected Error in Refresh_ControlLinks: " & ex.Message, MsgBoxStyle.Critical) Logger.Warn("SQL so far: " + oControlSQL) Return S.Fehler_bei_der_Aktualisierung_ End Try Return S.Aktualisierung_erfolgreich_ End Function End Class