diff --git a/GUIs.Test.ZUGFeRDTest/App.config b/GUIs.Test.ZUGFeRDTest/App.config index 417e3a18..bb23505f 100644 --- a/GUIs.Test.ZUGFeRDTest/App.config +++ b/GUIs.Test.ZUGFeRDTest/App.config @@ -2,7 +2,6 @@ -
@@ -14,14 +13,6 @@ - - - 172.24.12.50:E:\DataFiles\Firebird\WISAG\EDMI_MASTER.FDB - - - 172.24.12.50 - - 172.24.12.50:E:\DataFiles\Firebird\WISAG\EDMI_MASTER.FDB @@ -33,17 +24,11 @@ - - sysdba - - - dd - - - Server=SDD-VMP04-SQL17\DD_DEVELOP01;Database=DD_ECM;User Id=sa;Password=dd;TrustServerCertificate=true; + + diff --git a/GUIs.Test.ZUGFeRDTest/Form1.vb b/GUIs.Test.ZUGFeRDTest/Form1.vb index a1b94f59..3167408e 100644 --- a/GUIs.Test.ZUGFeRDTest/Form1.vb +++ b/GUIs.Test.ZUGFeRDTest/Form1.vb @@ -1,4 +1,5 @@ -Imports System.Data +Imports System.Configuration +Imports System.Data Imports System.IO Imports System.Reflection Imports System.Security.Cryptography @@ -9,11 +10,11 @@ Imports DigitalData.Modules.Interfaces Imports DigitalData.Modules.Interfaces.ZUGFeRDInterface Imports DigitalData.Modules.Jobs Imports DigitalData.Modules.Logging +Imports Microsoft.Data Public Class Form1 Private _logConfig As LogConfig Private _logger As Logger - Private _firebird As Firebird Private _mssql As MSSQLServer Private _zugferd As ZUGFeRDInterface Private _GDPictureVersion As String @@ -28,12 +29,24 @@ Public Class Form1 .Debug = True } _logger = _logConfig.GetLogger() + My.Settings.Save() Dim oCS = My.Settings.MSSQL_CONNECTIONSTRING - If Not oCS.Contains("TrustServerCertificate") Then - oCS += ";TrustServerCertificate=true" + My.Settings.MSSQL_CONNECTIONSTRING = "Server = SDD-VHP04-SQL19\DD_TESTING01;Database=DD_ECM;User Id=sa;Password=123456789dD!;" + My.Settings.Save() ' Jetzt wird wirklich gespeichert + oCS = My.Settings.MSSQL_CONNECTIONSTRING + + ' + If Not oCS.EndsWith("TrustServerCertificate") Then + oCS += "TrustServerCertificate=true" End If _mssql = New MSSQLServer(_logConfig, oCS) - + If _mssql Is Nothing Then + MsgBox("Could not connect to MSSQL Server. Please check the connection string in the application settings.", MsgBoxStyle.Critical, "Database Connection Error") + Else + If Not _mssql.DBInitialized Then + MsgBox("Could not connect to MSSQL Server. Please check the connection string in the application settings.", MsgBoxStyle.Critical, "Database Connection Error") + End If + End If _GDPictureVersion = "11.2024" _GDPictureLizenz = ConfigDbFunct.GetProductLicense("GDPICTURE", _GDPictureVersion, _logConfig, My.Settings.MSSQL_CONNECTIONSTRING) diff --git a/GUIs.Test.ZUGFeRDTest/My Project/Settings.settings b/GUIs.Test.ZUGFeRDTest/My Project/Settings.settings index b128f7c1..0c90fc98 100644 --- a/GUIs.Test.ZUGFeRDTest/My Project/Settings.settings +++ b/GUIs.Test.ZUGFeRDTest/My Project/Settings.settings @@ -2,23 +2,11 @@ - - 172.24.12.50:E:\DataFiles\Firebird\WISAG\EDMI_MASTER.FDB - - - 172.24.12.50 - - - sysdba - - - dd - - - Server=SDD-VMP04-SQL17\DD_DEVELOP01;Database=DD_ECM;User Id=sa;Password=dd;TrustServerCertificate=true; + + \ No newline at end of file diff --git a/GUIs.Test.ZUGFeRDTest/ZUGFeRDTest.vbproj b/GUIs.Test.ZUGFeRDTest/ZUGFeRDTest.vbproj index 8b3ddbb6..45e3d9f8 100644 --- a/GUIs.Test.ZUGFeRDTest/ZUGFeRDTest.vbproj +++ b/GUIs.Test.ZUGFeRDTest/ZUGFeRDTest.vbproj @@ -10,17 +10,18 @@ ZUGFeRDTest Digital Data GmbH Provides baseclasses, methods and constants for DD Products - 2.0 - 2.0 + 2.0.0.0 + 2.0.0.0 $(AssemblyName) $(AssemblyName) - + + ..\..\DDModules\Config\bin\Debug\DigitalData.Modules.Config.dll @@ -60,15 +61,8 @@ SettingsSingleFileGenerator - - - SettingsSingleFileGenerator - - - SettingsSingleFileGenerator - - - SettingsSingleFileGenerator + Settings.Designer.vb + \ No newline at end of file diff --git a/Service.EDMIService/App.config b/Service.EDMIService/App.config index 4d0338b6..29367ae8 100644 --- a/Service.EDMIService/App.config +++ b/Service.EDMIService/App.config @@ -2,24 +2,6 @@ - - - - - - - - - - - - - - - - - - @@ -35,4 +17,4 @@ - + \ No newline at end of file diff --git a/Service.EDMIService/EDMIService.vb b/Service.EDMIService/EDMIService.vb index b510a553..b88f8f5b 100644 --- a/Service.EDMIService/EDMIService.vb +++ b/Service.EDMIService/EDMIService.vb @@ -388,7 +388,7 @@ Public Class EDMIService If oFullPath = String.Empty Then Dim oDetails As New ObjectDoesNotExistFault(Data.ObjectId) - _Logger.Warn("GetFileByObjectId: " & oDetails.ErrorMessage) + _Logger.Warn("⚠ GetFileByObjectId: " & oDetails.ErrorMessage) Throw New FaultException(Of ObjectDoesNotExistFault)(oDetails, oDetails.ErrorMessage) End If @@ -398,7 +398,7 @@ Public Class EDMIService If Not oFileInfo.Exists Then Dim oDetails As New ObjectDoesNotExistFault(Data.ObjectId) - _Logger.Warn("GetFileByObjectId: " & oDetails.ErrorMessage) + _Logger.Warn("⚠ GetFileByObjectId: " & oDetails.ErrorMessage) Throw New FaultException(Of ObjectDoesNotExistFault)(oDetails, oDetails.ErrorMessage) End If @@ -443,12 +443,12 @@ Public Class EDMIService } _Logger.Debug("End GetFileInfoByObjectId!") Catch ex As FaultException - _Logger.Warn("GetFileInfoByObjectId: " & ex.Message) + _Logger.Warn("⚠ GetFileInfoByObjectId: " & ex.Message) _Logger.Error(ex) Throw ex Catch ex As Exception - _Logger.Warn("GetFileInfoByObjectId: " & ex.Message) + _Logger.Warn("⚠ GetFileInfoByObjectId: " & ex.Message) _Logger.Error(ex) Throw GetFault(ex) @@ -477,14 +477,14 @@ Public Class EDMIService Public Function GetFileList() As DataTable Try If Not GlobalState.TableStore.Tables.Contains(TBIDB_DOC_INFO) Then - _Logger.Warn("GetFileList: Document info table does not exist!") + _Logger.Warn("⚠ GetFileList: Document info table does not exist!") Return Nothing End If Dim oTable As DataTable = GlobalState.TableStore.Tables.Item(TBIDB_DOC_INFO) Return oTable Catch ex As Exception - _Logger.Warn("GetFileList: Unexpected Error while getting file list.") + _Logger.Warn("⚠ GetFileList: Unexpected Error while getting file list.") _Logger.Error(ex) Return Nothing End Try @@ -534,7 +534,7 @@ Public Class EDMIService Private Function GetFullPathForObjectId(ObjectId As Long) As String Try If Not GlobalState.TableStore.Tables.Contains(TBIDB_DOC_INFO) Then - _Logger.Warn("GetFullPathForObjectId: Document info table does not exist!") + _Logger.Warn("⚠ GetFullPathForObjectId: Document info table does not exist!") Return String.Empty End If @@ -544,7 +544,7 @@ Public Class EDMIService Dim oFullPath As String If oRows.Count = 0 Then - _Logger.Warn("GetFullPathForObjectId: Full path does not exist for object [{0}]", ObjectId) + _Logger.Warn("⚠ GetFullPathForObjectId: Full path does not exist for object [{0}]", ObjectId) oFullPath = String.Empty Else Dim oRow As DataRow = oRows.First() @@ -553,7 +553,7 @@ Public Class EDMIService Return oFullPath Catch ex As Exception - _Logger.Warn("GetFullPathForObjectId: Unexpected Error while getting full path for object [{0}].", ObjectId) + _Logger.Warn("⚠ GetFullPathForObjectId: Unexpected Error while getting full path for object [{0}].", ObjectId) _Logger.Error(ex) Return String.Empty End Try @@ -562,7 +562,7 @@ Public Class EDMIService Private Function GetAccessRightForObjectId(UserId As Long, ObjectId As Long) As AccessRight Try If Not GlobalState.TableStore.Tables.Contains(TBIDB_ACCESSRIGHT) Then - _Logger.Warn("GetAccessRightForObjectId: Access right table does not exist!") + _Logger.Warn("⚠ GetAccessRightForObjectId: Access right table does not exist!") Return AccessRight.VIEW_ONLY End If @@ -575,11 +575,11 @@ Public Class EDMIService _Logger.Debug("Parsing AccessRights for ObjectId [{0}]", ObjectId) If oRows.Count = 0 Then - _Logger.Warn("GetAccessRightForObjectId: Access right assignment does not exist for user [{0}] on object [{1}]", UserId, ObjectId) + _Logger.Warn("⚠ GetAccessRightForObjectId: Access right assignment does not exist for user [{0}] on object [{1}]", UserId, ObjectId) Return AccessRight.VIEW_ONLY Else If oRows.Count > 1 Then - _Logger.Warn("GetAccessRightForObjectId: More than one access right assignment found for user [{0}] on object [{1}]", UserId, ObjectId) + _Logger.Warn("⚠ GetAccessRightForObjectId: More than one access right assignment found for user [{0}] on object [{1}]", UserId, ObjectId) End If Dim oRow As DataRow = oRows.First() @@ -593,7 +593,7 @@ Public Class EDMIService Case 4 oRight = AccessRight.FULL Case Else - _Logger.Warn("GetAccessRightForObjectId: Unknown access right [{0}] for user [{1}] on object [{2}]", oRightAsInt, UserId, ObjectId) + _Logger.Warn("⚠ GetAccessRightForObjectId: Unknown access right [{0}] for user [{1}] on object [{2}]", oRightAsInt, UserId, ObjectId) oRight = AccessRight.VIEW_ONLY End Select End If @@ -603,7 +603,7 @@ Public Class EDMIService Return oRight Catch ex As Exception - _Logger.Warn("GetAccessRightForObjectId: Unexpected Error while getting access right for object [{0}].", ObjectId) + _Logger.Warn("⚠ GetAccessRightForObjectId: Unexpected Error while getting access right for object [{0}].", ObjectId) _Logger.Error(ex) Return AccessRight.VIEW_ONLY End Try diff --git a/Service.EDMIService/EDMIService.vbproj b/Service.EDMIService/EDMIService.vbproj index 2347a3b3..1e749d54 100644 --- a/Service.EDMIService/EDMIService.vbproj +++ b/Service.EDMIService/EDMIService.vbproj @@ -81,9 +81,6 @@ ..\..\DDModules\Filesystem\bin\Debug\DigitalData.Modules.Filesystem.dll - - P:\Projekte DIGITAL DATA\DIGITAL DATA - Entwicklung\DLL_Bibliotheken\Digital Data\DigitalData.Modules.Language.dll - ..\..\DDModules\Logging\bin\Debug\DigitalData.Modules.Logging.dll diff --git a/Service.EDMIService/GlobalState.vb b/Service.EDMIService/GlobalState.vb index 8dbf2988..2f77cf98 100644 --- a/Service.EDMIService/GlobalState.vb +++ b/Service.EDMIService/GlobalState.vb @@ -66,13 +66,13 @@ Public Class GlobalState End Function Public Sub LoadDoctypes() - _Logger.Info("Loading Doctypes") + _Logger.Debug("Loading Doctypes") Try Dim oSQL As String = "SELECT * FROM VWIDB_DOCTYPE_HANDLING" Dim oTable As DataTable = _MSSQL_IDB.GetDatatable(oSQL) - _Logger.Info("Found [{0}] Document Types", oTable.Rows.Count) + _Logger.Info("✔ Found [{0}] Document Types", oTable.Rows.Count) Dim oDocTypes As New List(Of Doctype) @@ -82,7 +82,7 @@ Public Class GlobalState .FileChangedAction = oRow.Item("CHANGED_HANDLING") } - _Logger.Info("New Doctype [{0}]", oDoctype.Name) + _Logger.Debug("New Doctype [{0}]", oDoctype.Name) oDocTypes.Add(oDoctype) Next @@ -94,13 +94,12 @@ Public Class GlobalState Public Sub LoadObjectStores() - _Logger.Info("Loading Object Stores") + _Logger.Debug("Loading Object Stores ...") Try Dim oSQL As String = "SELECT * FROM VWIDB_OBJECT_STORE" Dim oTable As DataTable = _MSSQL_IDB.GetDatatable(oSQL) - _Logger.Info("Found [{0}] Object Stores", oTable.Rows.Count) - + Dim oObjectStores As New List(Of ObjectStore) For Each oRow As DataRow In oTable.Rows @@ -110,23 +109,24 @@ Public Class GlobalState .Path = oRow.Item("REL_PATH"), .Title = oRow.Item("Objectstore") } - _Logger.Info("New Object Store [{0}]", oStore.Title) + _Logger.Debug("New Object Store [{0}]", oStore.Title) oObjectStores.Add(oStore) Next ObjectStores = oObjectStores + _Logger.Info("✔ Found [{0}] Object Stores", oObjectStores.Count) Catch ex As Exception _Logger.Error(ex) End Try End Sub Public Sub LoadConnections() - _Logger.Info("Loading Database Connections") + _Logger.Debug("Loading Database Connections ...") Try Dim oSQL As String = "SELECT * FROM TBDD_CONNECTION WITH (NOLOCK)" Dim oTable As DataTable = _MSSQL_ECM.GetDatatable(oSQL) - _Logger.Info("Found [{0}] Connections", oTable.Rows.Count) + _Logger.Debug("Found [{0}] Connections!", oTable.Rows.Count) Dim oConnections As New List(Of DatabaseConnection) @@ -141,23 +141,25 @@ Public Class GlobalState .Server = IIf(IsDBNull(oRow.Item("SERVER")), String.Empty, oRow.Item("SERVER")), .Username = IIf(IsDBNull(oRow.Item("USERNAME")), String.Empty, oRow.Item("USERNAME")) } - _Logger.Info("New Connection [{0}]", oConnection.Title) oConnections.Add(oConnection) + _Logger.Debug("New DB Connection [{0}]", oConnection.Title) Next Connections = oConnections + _Logger.Info("✔ [{0}] DBConnections configured in service!", oConnections.Count) Catch ex As Exception _Logger.Error(ex) End Try End Sub Public Sub LoadClientConfig(pConfig As Config) - _Logger.Info("Loading Client Config") + _Logger.Debug("Loading Client Config") _Logger.Debug("ForceDirectDatabaseAccess: {0}", pConfig.ClientConfig.ForceDirectDatabaseAccess) ClientConfig.ForceDirectDatabaseAccess = pConfig.ClientConfig.ForceDirectDatabaseAccess ClientConfig.DocumentTypes = Doctypes ClientConfig.ConnectionStringECM = _MSSQL_ECM.CurrentConnectionString ClientConfig.ConnectionStringIDB = _MSSQL_IDB.CurrentConnectionString + _Logger.Info("✔ Found Client Config") End Sub Public Class ObjectStore diff --git a/Service.EDMIService/Scheduler/DatatableJob.vb b/Service.EDMIService/Scheduler/DatatableJob.vb index 7f08e9f9..b1c9e193 100644 --- a/Service.EDMIService/Scheduler/DatatableJob.vb +++ b/Service.EDMIService/Scheduler/DatatableJob.vb @@ -97,22 +97,21 @@ Public Class DatatableJob oStopWatch.Stop() oLogger.Debug("[Time] Adding Relations: {0}ms", oStopWatch.ElapsedMilliseconds) - oLogger.Info("Fetched Datatable [{0}]", oDatatableName) + oLogger.Info("✔ Fetched Datatable [{0}]", oDatatableName) oResult.Tables.Add(oResultTable) Catch ex As Exception - oLogger.Warn("Execute: Error while saving Table: [{0}]", oDatatableName) + oLogger.Warn("⚠ Error while saving Table: [{0}]", oDatatableName) oLogger.Error(ex) End Try Next - oLogger.Info("Fetched [{0}] Datatables", oResult.Tables.Count) - ' Das Ergebnis speichern context.Result = oResult + oLogger.Info("✔✔ Fetched [{0}] Datatables ✔✔", oResult.Tables.Count) Catch ex As Exception oLogger.Error(ex) - oLogger.Warn("Execute: Unhandled exception while executing SQL for Datatable {0}", oCronJobTitle) + oLogger.Warn("⚠ Unhandled exception while executing SQL for Datatable {0}", oCronJobTitle) End Try Return Task.FromResult(True) diff --git a/Service.EDMIService/Scheduler/JobListener.vb b/Service.EDMIService/Scheduler/JobListener.vb index 52254915..46da23a3 100644 --- a/Service.EDMIService/Scheduler/JobListener.vb +++ b/Service.EDMIService/Scheduler/JobListener.vb @@ -2,11 +2,11 @@ Imports System.Threading Imports DigitalData.Modules.Database -Imports DigitalData.Modules.Language Imports DigitalData.Modules.Logging Imports Quartz Imports Quartz.Listener - +Imports System.Diagnostics +Imports System.Data Public Class JobListener Inherits JobListenerSupport @@ -121,7 +121,7 @@ Public Class JobListener End If End If - _Logger.Info("Dataset successfully updated with table [{0}]", oName) + _Logger.Info("✔ Dataset successfully updated with table [{0}]", oName) Finally ' ✅ SCHRITT 3: Write-Lock freigeben (so schnell wie möglich!) @@ -129,7 +129,7 @@ Public Class JobListener oStopWatch.Stop() ' ✅ Performance-Warning bei langsamen Updates If oStopWatch.ElapsedMilliseconds > 500 Then - _Logger.Warn("[Performance] Table update took {0}ms (> 500ms threshold)", oStopWatch.ElapsedMilliseconds) + _Logger.Warn("⚠ [Performance] Table update took {0}ms (> 500ms threshold)", oStopWatch.ElapsedMilliseconds) Else _Logger.Debug("[Performance] Table update completed in {0}ms", oStopWatch.ElapsedMilliseconds) End If @@ -142,7 +142,7 @@ Public Class JobListener _MSSQL.ExecuteNonQuery($"INSERT INTO TBAPPSERV_CRON_DETAIL_HISTORY (DETAIL_ID) VALUES ({oDetailId})") Catch ex As Exception - _Logger.Warn("Unexpected error in SaveDataTables: {0}", ex.Message) + _Logger.Warn("⚠ Unexpected error in SaveDataTables: {0}", ex.Message) _Logger.Error(ex) End Try End Sub @@ -256,23 +256,22 @@ Public Class JobListener Catch ex As ArgumentNullException _Logger.Error(ex) - _Logger.Warn("ArgumentNullException in AddRelation: {0}", ex.Message) + _Logger.Warn("⚠ ArgumentNullException in AddRelation: {0}", ex.Message) Catch ex As DuplicateNameException _Logger.Error(ex) - _Logger.Warn("DuplicateNameException in AddRelation: {0}", ex.Message) + _Logger.Warn("⚠ DuplicateNameException in AddRelation: {0}", ex.Message) Catch ex As InvalidConstraintException _Logger.Error(ex) - _Logger.Warn("InvalidConstraintException in AddRelation: {0}", ex.Message) - + _Logger.Warn("⚠ InvalidConstraintException in AddRelation: {0}", ex.Message) Catch ex As ArgumentException _Logger.Error(ex) - _Logger.Warn("ArgumentException in AddRelation: {0}", ex.Message) + _Logger.Warn("⚠ ArgumentException in AddRelation: {0}", ex.Message) Catch ex As Exception _Logger.Error(ex) - _Logger.Warn("Exception in AddRelation: {0}", ex.Message) + _Logger.Warn("⚠ Exception in AddRelation: {0}", ex.Message) End Try End Sub diff --git a/Service.EDMIService/Scheduler/Scheduler.vb b/Service.EDMIService/Scheduler/Scheduler.vb index aa3c3ee1..a3833e4a 100644 --- a/Service.EDMIService/Scheduler/Scheduler.vb +++ b/Service.EDMIService/Scheduler/Scheduler.vb @@ -103,12 +103,13 @@ Public Class Scheduler Logger.Debug("Scheduled a new job for Cron Job [{0}]", oTitle) Next + Logger.Info("✔ Scheduler started with {0} cron jobs", oCronjobs.Rows.Count) Else - Logger.Warn("CronJobs could not be fetched!") + Logger.Warn("⚠ CronJobs could not be fetched!") End If Catch ex As Exception Logger.Error(ex) - Logger.Warn("Unexpected Error while setting up scheduler: " & ex.Message) + Logger.Warn("⚠ Unexpected Error while setting up scheduler: " & ex.Message) End Try End Sub Public Async Function GetCronJobs() As Task(Of DataTable) diff --git a/Service.EDMIService/WindowsService.vb b/Service.EDMIService/WindowsService.vb index f5bd3082..4167d825 100644 --- a/Service.EDMIService/WindowsService.vb +++ b/Service.EDMIService/WindowsService.vb @@ -61,34 +61,38 @@ Public Class WindowsService oTimer.Start() ' Setting Debug Flag - Logger.Info("Setting DEBUG Flag to [{0}]", ConfigManager.Config.Debug) + If ConfigManager.Config.Debug Then + Logger.Info("Debug Flag is set to TRUE. Logging will be more verbose.") + Else + Logger.Info("Debug Flag is set to FALSE. Logging will be less verbose.") + End If LogConfig.Debug = ConfigManager.Config.Debug LogConfigScheduler.Debug = ConfigManager.Config.Debug - Logger.Info("Connecting to Databases..") + Logger.Debug("Connecting to Databases...") Firebird = StartFirebird() MSSQL_ECM = GetMSSQL_ECM(LogConfig) MSSQL_IDB = GetMSSQL_IDB(LogConfig) MSSQL_Config = GetMSSQL_Config(LogConfig) - Logger.Info("Connection to Databases established!") + Logger.Debug("Connection to Databases established!") - Logger.Debug("Initializing EDMI Functions") + Logger.Debug("Initializing EDMI Functions...") Filesystem = New Filesystem.File(LogConfig) GlobalState = New GlobalState(LogConfig, MSSQL_IDB, MSSQL_ECM) Dim oMSSQLServer = GetMSSQL_Config(LogConfigScheduler) Scheduler = New Scheduler(LogConfigScheduler, oMSSQLServer, GlobalState.TableStore, GlobalState) - Logger.Info("Loading Global Data") + Logger.Debug("Loading Global Data ...") GlobalState.LoadObjectStores() GlobalState.LoadConnections() GlobalState.LoadDoctypes() GlobalState.LoadClientConfig(Config) - Logger.Info("Starting Scheduler") + Logger.Debug("Starting Scheduler ...") Scheduler.Start() - Logger.Info("Preparing WCF ServiceHost") + Logger.Debug("Preparing WCF ServiceHost ...") EDMIService.MSSQL_ECM = MSSQL_ECM EDMIService.MSSQL_IDB = MSSQL_IDB EDMIService.Firebird = Firebird @@ -97,11 +101,20 @@ Public Class WindowsService EDMIService.GlobalState = GlobalState EDMIService.Scheduler = Scheduler - Logger.Info("Starting WCF ServiceHost") + Logger.Debug("Starting WCF ServiceHost ...") Dim oBaseAddresses() As Uri = {New Uri(SERVICE_BASE_ADDRESS)} ServiceHost = New ServiceHost(Of EDMIService)(oBaseAddresses) ServiceHost.EnableMetadataExchange(False) + ' MEX-Endpoints explizit entfernen, da sie Port-Konflikte verursachen + Dim oMexEndpoints = ServiceHost.Description.Endpoints _ + .Where(Function(e) e.Contract.ContractType = GetType(IMetadataExchange)) _ + .ToList() + + For Each oEndpoint In oMexEndpoints + ServiceHost.Description.Endpoints.Remove(oEndpoint) + Logger.Debug("OnStart -> Removed MEX endpoint: {0}", oEndpoint.Address.ToString) + Next Logger.Debug("Listing Endpoints:") For Each oEndpoint In ServiceHost.Description.Endpoints @@ -113,12 +126,20 @@ Public Class WindowsService Next Logger.Debug("Starting WFC ServiceHost..") - ServiceHost.Open() - Logger.Debug("WCF ServiceHost started!") - - Logger.Info("Service {0} successfully started!", SERVICE_DISPLAY_NAME) + Try + ServiceHost.Open() + Logger.Debug("WCF ServiceHost started!") + Catch ex As System.ServiceModel.AddressAlreadyInUseException + Logger.Error("Port is already in use! Check if another instance is running. Details: {0}", ex.Message) + GracefullyStop() + Catch ex As Exception + Logger.Warn("⚠ Unexpected error while opening ServiceHost: {0}", ex.Message) + Logger.Error(ex) + GracefullyStop() + End Try + Logger.Info("✔ Service [{0}] started successfully!", SERVICE_DISPLAY_NAME) Catch ex As Exception - Logger.Warn("Unexpected Error while starting the service: {0}", ex.Message) + Logger.Warn("⚠ Unexpected Error while starting the service: {0}", ex.Message) Logger.Error(ex) GracefullyStop() End Try @@ -126,7 +147,7 @@ Public Class WindowsService Private Sub ReloadTimer_Tick() If ConfigManager.Reload() = False Then - Logger.Warn("Could not reload config, check the service and config file.") + Logger.Warn("⚠ Could not reload config, check the service and config file.") End If Config = ConfigManager.Config @@ -153,7 +174,7 @@ Public Class WindowsService Logger.Info("Database connection established.") Return oFirebird Catch ex As Exception - Logger.Warn("StartFirebird: Could not connect to firebird database.") + Logger.Warn("⚠ StartFirebird: Could not connect to firebird database.") Logger.Error(ex) Return Nothing End Try @@ -162,41 +183,41 @@ Public Class WindowsService Private Function GetMSSQL_ECM(pLogConfig As LogConfig) As MSSQLServer Logger.Debug("Connecting to ECM MSSQL") If Config.ConnectionString_ECM = String.Empty Then - Logger.Warn("Configuration for ConnectionString_ECM is missing.") + Logger.Warn("⚠ Configuration for ConnectionString_ECM is missing.") Throw New ArgumentNullException("ConnectionString_ECM") End If Dim oMSSQL = New MSSQLServer(pLogConfig, Config.ConnectionString_ECM) - Logger.Info("Database connection to ECM Database established.") + Logger.Info("✔ Database connection to ECM Database established.") Return oMSSQL End Function Private Function GetMSSQL_IDB(pLogConfig As LogConfig) As MSSQLServer Logger.Debug("Connecting to IDB MSSQL") If Config.ConnectionString_IDB = String.Empty Then - Logger.Warn("Configuration for ConnectionString_IDB is missing.") + Logger.Warn("⚠ Configuration for ConnectionString_IDB is missing.") Throw New ArgumentNullException("ConnectionString_IDB") End If Dim oMSSQL = New MSSQLServer(pLogConfig, Config.ConnectionString_IDB) - Logger.Info("Database connection to IDB Database established.") + Logger.Info("✔ Database connection to IDB Database established.") Return oMSSQL End Function Private Function GetMSSQL_Config(pLogConfig As LogConfig) As MSSQLServer - Logger.Debug("Connecting to Config MSSQL") + Logger.Debug("Connecting to Config MSSQL...") If Config.ConnectionString_Config = String.Empty Then If Config.ConnectionString_ECM <> String.Empty Then - Logger.Info("Using ConnectionString_ECM for Config Database connection.") + Logger.Debug("Using ConnectionString_ECM for Config Database connection!") Return GetMSSQL_ECM(pLogConfig) Else - Logger.Warn("Configuration for ConnectionString_Config is missing and ConnectionString_ECM is also missing.") + Logger.Warn("⚠ Configuration for ConnectionString_Config is missing and ConnectionString_ECM is also missing.") Throw New ArgumentNullException("ConnectionString_Config") End If End If Dim oMSSQL = New MSSQLServer(pLogConfig, Config.ConnectionString_Config) - Logger.Info("Database connection to Config Database established.") + Logger.Info("✔ Database connection to Config Database established.") Return oMSSQL End Function @@ -205,13 +226,28 @@ Public Class WindowsService End Sub Private Sub GracefullyStop() - Logger.Info("Service {0} is stopping!", SERVICE_DISPLAY_NAME) + Logger.Info("GracefullyStop - Service {0} is stopping!", SERVICE_DISPLAY_NAME) If ServiceHost IsNot Nothing Then - ServiceHost.Close() - ServiceHost = Nothing + Try + If ServiceHost.State = CommunicationState.Faulted Then + Logger.Warn("⚠ GracefullyStop - ServiceHost is in Faulted state. Using Abort() instead of Close().") + ServiceHost.Abort() + Else + ServiceHost.Close() + End If + Catch ex As Exception + Logger.Warn("⚠ GracefullyStop - Error while closing ServiceHost: {0}", ex.Message) + Logger.Error(ex) + ServiceHost.Abort() + Finally + ServiceHost = Nothing + End Try End If - Scheduler.Stop() + If Scheduler IsNot Nothing Then + Logger.Info("GracefullyStop - Stopping Scheduler.") + Scheduler.Stop() + End If End Sub End Class