Use ConfigManager for Config
This commit is contained in:
@@ -1,38 +1,10 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<configuration>
|
<configuration>
|
||||||
<configSections>
|
<configSections>
|
||||||
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
|
||||||
<section name="DDEmailService.My.MySettings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
|
|
||||||
</sectionGroup>
|
|
||||||
</configSections>
|
</configSections>
|
||||||
<startup>
|
<startup>
|
||||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
|
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
|
||||||
</startup>
|
</startup>
|
||||||
<applicationSettings>
|
|
||||||
<DDEmailService.My.MySettings>
|
|
||||||
<setting name="FB_ConnString" serializeAs="String">
|
|
||||||
<value>172.24.12.41</value>
|
|
||||||
</setting>
|
|
||||||
<setting name="SQLSERVER_CS" serializeAs="String">
|
|
||||||
<value>Data Source=172.24.12.41\Tests;Initial Catalog=DD_ECM_TEST;Persist Security Info=True;User ID=sa;Password=dd</value>
|
|
||||||
</setting>
|
|
||||||
<setting name="SQLSERVER_CS_TEST" serializeAs="String">
|
|
||||||
<value>Data Source=172.24.12.41\Tests;Initial Catalog=DD_ECM_TEST;Persist Security Info=True;User ID=sa;Password=dd</value>
|
|
||||||
</setting>
|
|
||||||
<setting name="FB_DATABASE" serializeAs="String">
|
|
||||||
<value>172.24.12.41:E:\DB\Firebird\Databases\EDMI_TEMPLATE\EDMI_MASTER.FDB</value>
|
|
||||||
</setting>
|
|
||||||
<setting name="FB_USER" serializeAs="String">
|
|
||||||
<value>sysdba</value>
|
|
||||||
</setting>
|
|
||||||
<setting name="FB_PW" serializeAs="String">
|
|
||||||
<value>dd</value>
|
|
||||||
</setting>
|
|
||||||
<setting name="DEBUG" serializeAs="String">
|
|
||||||
<value>True</value>
|
|
||||||
</setting>
|
|
||||||
</DDEmailService.My.MySettings>
|
|
||||||
</applicationSettings>
|
|
||||||
<runtime>
|
<runtime>
|
||||||
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
|
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
|
||||||
<dependentAssembly>
|
<dependentAssembly>
|
||||||
|
|||||||
19
Services.EmailService/Config.vb
Normal file
19
Services.EmailService/Config.vb
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
Imports DigitalData.Modules.Config.ConfigAttributes
|
||||||
|
|
||||||
|
Public Class Config
|
||||||
|
<ConnectionString>
|
||||||
|
Public Property FirebirdServer As String = ""
|
||||||
|
<ConnectionString>
|
||||||
|
Public Property FirebirdDatabase As String = ""
|
||||||
|
<ConnectionString>
|
||||||
|
Public Property FirebirdUser As String = ""
|
||||||
|
<ConnectionString>
|
||||||
|
Public Property FirebirdPassword As String = ""
|
||||||
|
|
||||||
|
<ConnectionString>
|
||||||
|
Public Property SQLServerConnectionString As String = ""
|
||||||
|
<ConnectionString>
|
||||||
|
Public Property SQLServerTestConnectionString As String = ""
|
||||||
|
|
||||||
|
Public Property Debug As Boolean = False
|
||||||
|
End Class
|
||||||
@@ -112,13 +112,13 @@
|
|||||||
<Import Include="System.Threading.Tasks" />
|
<Import Include="System.Threading.Tasks" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Compile Include="Config.vb" />
|
||||||
<Compile Include="EmailService.Designer.vb">
|
<Compile Include="EmailService.Designer.vb">
|
||||||
<DependentUpon>EmailService.vb</DependentUpon>
|
<DependentUpon>EmailService.vb</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="EmailService.vb">
|
<Compile Include="EmailService.vb">
|
||||||
<SubType>Component</SubType>
|
<SubType>Component</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="EmailServiceOld.vb" />
|
|
||||||
<Compile Include="ModuleRuntime.vb" />
|
<Compile Include="ModuleRuntime.vb" />
|
||||||
<Compile Include="My Project\Application.Designer.vb">
|
<Compile Include="My Project\Application.Designer.vb">
|
||||||
<AutoGen>True</AutoGen>
|
<AutoGen>True</AutoGen>
|
||||||
@@ -166,5 +166,10 @@
|
|||||||
<None Include="App.config" />
|
<None Include="App.config" />
|
||||||
<None Include="packages.config" />
|
<None Include="packages.config" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Content Include="MailLicense.xml">
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
</Content>
|
||||||
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildToolsPath)\Microsoft.VisualBasic.targets" />
|
<Import Project="$(MSBuildToolsPath)\Microsoft.VisualBasic.targets" />
|
||||||
</Project>
|
</Project>
|
||||||
@@ -6,10 +6,14 @@ Imports DigitalData.Modules.Database
|
|||||||
Imports DigitalData.Modules.Messaging
|
Imports DigitalData.Modules.Messaging
|
||||||
Imports DigitalData.Modules.Language
|
Imports DigitalData.Modules.Language
|
||||||
Imports DigitalData.Modules.Encryption
|
Imports DigitalData.Modules.Encryption
|
||||||
|
Imports DigitalData.Modules.Config
|
||||||
|
|
||||||
Public Class EmailService
|
Public Class EmailService
|
||||||
Private _Logger As Logger
|
Private _Logger As Logger
|
||||||
Private _LogConfig As LogConfig
|
Private _LogConfig As LogConfig
|
||||||
|
Private _ConfigManager As ConfigManager(Of Config)
|
||||||
|
Private _Config As Config
|
||||||
|
|
||||||
Private _Firebird As Firebird
|
Private _Firebird As Firebird
|
||||||
Private _MSSQL As MSSQLServer
|
Private _MSSQL As MSSQLServer
|
||||||
Private _MSSQL_Test As MSSQLServer
|
Private _MSSQL_Test As MSSQLServer
|
||||||
@@ -30,11 +34,15 @@ Public Class EmailService
|
|||||||
Try
|
Try
|
||||||
' === Initialize Logger ===
|
' === Initialize Logger ===
|
||||||
Dim oLogPath = Path.Combine(My.Application.Info.DirectoryPath, "Log")
|
Dim oLogPath = Path.Combine(My.Application.Info.DirectoryPath, "Log")
|
||||||
_LogConfig = New LogConfig(LogConfig.PathType.CustomPath, oLogPath, Nothing, "Digital Data", "EmailService") With {
|
_LogConfig = New LogConfig(LogConfig.PathType.CustomPath, oLogPath, Nothing, "Digital Data", "EmailService")
|
||||||
.Debug = My.Settings.DEBUG
|
|
||||||
}
|
|
||||||
|
|
||||||
Dim oCurrentDomain As AppDomain
|
' === Initialize Config ===
|
||||||
|
_ConfigManager = New ConfigManager(Of Config)(_LogConfig, My.Application.Info.DirectoryPath)
|
||||||
|
_Config = _ConfigManager.Config
|
||||||
|
|
||||||
|
_LogConfig.Debug = _Config.Debug
|
||||||
|
|
||||||
|
Dim oCurrentDomain As AppDomain = AppDomain.CurrentDomain
|
||||||
AddHandler oCurrentDomain.UnhandledException, AddressOf AppDomain_UnhandledException
|
AddHandler oCurrentDomain.UnhandledException, AddressOf AppDomain_UnhandledException
|
||||||
|
|
||||||
_Logger = _LogConfig.GetLogger()
|
_Logger = _LogConfig.GetLogger()
|
||||||
@@ -50,25 +58,25 @@ Public Class EmailService
|
|||||||
|
|
||||||
_Logger.Info("Inititalize Databases")
|
_Logger.Info("Inititalize Databases")
|
||||||
|
|
||||||
If My.Settings.FB_ConnString <> String.Empty Then
|
If _Config.FirebirdServer <> String.Empty Then
|
||||||
_Firebird = New Firebird(_LogConfig, My.Settings.FB_ConnString, My.Settings.FB_DATABASE, My.Settings.FB_USER, My.Settings.FB_PW)
|
_Firebird = New Firebird(_LogConfig, _Config.FirebirdServer, _Config.FirebirdDatabase, _Config.FirebirdUser, _Config.FirebirdPassword)
|
||||||
|
|
||||||
If _Firebird._DBInitialized = False Then
|
If _Firebird._DBInitialized = False Then
|
||||||
_Logger.Warn("Firebird Connection could not be established. Check the Error Log")
|
_Logger.Warn("Firebird Connection could not be established. Check the Error Log")
|
||||||
End If
|
End If
|
||||||
End If
|
End If
|
||||||
|
|
||||||
If My.Settings.SQLSERVER_CS <> String.Empty Then
|
If _Config.SQLServerConnectionString <> String.Empty Then
|
||||||
_MSSQL = New MSSQLServer(_LogConfig, My.Settings.SQLSERVER_CS)
|
_MSSQL = New MSSQLServer(_LogConfig, _Config.SQLServerConnectionString)
|
||||||
|
|
||||||
If _MSSQL.DBInitialized = False Then
|
If _MSSQL.DBInitialized = False Then
|
||||||
_Logger.Warn("MSSQL Connection could not be established. Check the Error Log")
|
_Logger.Warn("MSSQL Connection could not be established. Check the Error Log")
|
||||||
End If
|
End If
|
||||||
End If
|
End If
|
||||||
|
|
||||||
If My.Settings.SQLSERVER_CS_TEST <> String.Empty Then
|
If _Config.SQLServerTestConnectionString <> String.Empty Then
|
||||||
|
|
||||||
_MSSQL_Test = New MSSQLServer(_LogConfig, My.Settings.SQLSERVER_CS_TEST)
|
_MSSQL_Test = New MSSQLServer(_LogConfig, _Config.SQLServerTestConnectionString)
|
||||||
|
|
||||||
If _MSSQL_Test.DBInitialized = False Then
|
If _MSSQL_Test.DBInitialized = False Then
|
||||||
_Logger.Warn("MSSQL Test Connection could not be established. Check the Error Log")
|
_Logger.Warn("MSSQL Test Connection could not be established. Check the Error Log")
|
||||||
@@ -130,6 +138,7 @@ Public Class EmailService
|
|||||||
|
|
||||||
Private Sub AppDomain_UnhandledException(sender As Object, e As UnhandledExceptionEventArgs)
|
Private Sub AppDomain_UnhandledException(sender As Object, e As UnhandledExceptionEventArgs)
|
||||||
Dim oException As Exception = e.ExceptionObject
|
Dim oException As Exception = e.ExceptionObject
|
||||||
|
_Logger.Warn("An unhandled exception has occurred.")
|
||||||
_Logger.Error(oException)
|
_Logger.Error(oException)
|
||||||
End Sub
|
End Sub
|
||||||
|
|
||||||
@@ -168,6 +177,22 @@ Public Class EmailService
|
|||||||
End Try
|
End Try
|
||||||
End Sub
|
End Sub
|
||||||
|
|
||||||
|
Private Sub EmailQueue_Completed(sender As Object, e As RunWorkerCompletedEventArgs)
|
||||||
|
Try
|
||||||
|
If e.Cancelled Then
|
||||||
|
_Logger.Warn("EmailQueue has been cancelled manually!")
|
||||||
|
ElseIf e.Error IsNot Nothing Then
|
||||||
|
_Logger.Warn("Unexpected Error in EmailQueue: {0}", e.Error.Message)
|
||||||
|
_Logger.Error(e.Error)
|
||||||
|
Else
|
||||||
|
_Logger.Debug("Email Queue successfully processed.")
|
||||||
|
End If
|
||||||
|
Catch ex As Exception
|
||||||
|
_Logger.Warn("Error while processing result of Worker!")
|
||||||
|
_Logger.Error(e.Error)
|
||||||
|
End Try
|
||||||
|
End Sub
|
||||||
|
|
||||||
Private Class EmailAccount
|
Private Class EmailAccount
|
||||||
Public Guid As Integer
|
Public Guid As Integer
|
||||||
Public Sender As String
|
Public Sender As String
|
||||||
@@ -301,7 +326,6 @@ Public Class EmailService
|
|||||||
Return False
|
Return False
|
||||||
End If
|
End If
|
||||||
|
|
||||||
Dim oMailSMTP, oMailport, oMailUser, oMailPW, oAuthType, oErrorMsg, oMailADDED
|
|
||||||
Dim oGuid, oJobId As Integer
|
Dim oGuid, oJobId As Integer
|
||||||
|
|
||||||
For Each oAccount In oEmailAccounts
|
For Each oAccount In oEmailAccounts
|
||||||
@@ -345,7 +369,6 @@ Public Class EmailService
|
|||||||
For Each oRow As DataRow In oAccountQueue
|
For Each oRow As DataRow In oAccountQueue
|
||||||
'Dim oAccountMatch As Boolean = False
|
'Dim oAccountMatch As Boolean = False
|
||||||
Dim oComment As String = String.Empty
|
Dim oComment As String = String.Empty
|
||||||
oErrorMsg = ""
|
|
||||||
|
|
||||||
Dim oAttachment = String.Empty
|
Dim oAttachment = String.Empty
|
||||||
Dim oEmailTo = String.Empty
|
Dim oEmailTo = String.Empty
|
||||||
@@ -486,19 +509,7 @@ Public Class EmailService
|
|||||||
End Try
|
End Try
|
||||||
End Function
|
End Function
|
||||||
|
|
||||||
Private Sub EmailQueue_Completed(sender As Object, e As RunWorkerCompletedEventArgs)
|
|
||||||
Try
|
|
||||||
If e.Cancelled Then
|
|
||||||
_Logger.Warn("EmailQueue has been cancelled manually!")
|
|
||||||
ElseIf e.Error IsNot Nothing Then
|
|
||||||
_Logger.Warn("Unexpected Error in EmailQueue: {0}", e.Error.Message)
|
|
||||||
_Logger.Error(e.Error)
|
|
||||||
End If
|
|
||||||
Catch ex As Exception
|
|
||||||
_Logger.Warn("Error while processing result of Worker!")
|
|
||||||
_Logger.Error(e.Error)
|
|
||||||
End Try
|
|
||||||
End Sub
|
|
||||||
|
|
||||||
Protected Overrides Sub OnStop()
|
Protected Overrides Sub OnStop()
|
||||||
Try
|
Try
|
||||||
|
|||||||
Reference in New Issue
Block a user