Use ConfigManager for Config
This commit is contained in:
parent
bbd6704262
commit
5b97238d66
@ -1,38 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<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>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
|
||||
</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>
|
||||
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
|
||||
<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" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Config.vb" />
|
||||
<Compile Include="EmailService.Designer.vb">
|
||||
<DependentUpon>EmailService.vb</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="EmailService.vb">
|
||||
<SubType>Component</SubType>
|
||||
</Compile>
|
||||
<Compile Include="EmailServiceOld.vb" />
|
||||
<Compile Include="ModuleRuntime.vb" />
|
||||
<Compile Include="My Project\Application.Designer.vb">
|
||||
<AutoGen>True</AutoGen>
|
||||
@ -166,5 +166,10 @@
|
||||
<None Include="App.config" />
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="MailLicense.xml">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.VisualBasic.targets" />
|
||||
</Project>
|
||||
@ -6,10 +6,14 @@ Imports DigitalData.Modules.Database
|
||||
Imports DigitalData.Modules.Messaging
|
||||
Imports DigitalData.Modules.Language
|
||||
Imports DigitalData.Modules.Encryption
|
||||
Imports DigitalData.Modules.Config
|
||||
|
||||
Public Class EmailService
|
||||
Private _Logger As Logger
|
||||
Private _LogConfig As LogConfig
|
||||
Private _ConfigManager As ConfigManager(Of Config)
|
||||
Private _Config As Config
|
||||
|
||||
Private _Firebird As Firebird
|
||||
Private _MSSQL As MSSQLServer
|
||||
Private _MSSQL_Test As MSSQLServer
|
||||
@ -30,11 +34,15 @@ Public Class EmailService
|
||||
Try
|
||||
' === Initialize Logger ===
|
||||
Dim oLogPath = Path.Combine(My.Application.Info.DirectoryPath, "Log")
|
||||
_LogConfig = New LogConfig(LogConfig.PathType.CustomPath, oLogPath, Nothing, "Digital Data", "EmailService") With {
|
||||
.Debug = My.Settings.DEBUG
|
||||
}
|
||||
_LogConfig = New LogConfig(LogConfig.PathType.CustomPath, oLogPath, Nothing, "Digital Data", "EmailService")
|
||||
|
||||
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
|
||||
|
||||
_Logger = _LogConfig.GetLogger()
|
||||
@ -50,25 +58,25 @@ Public Class EmailService
|
||||
|
||||
_Logger.Info("Inititalize Databases")
|
||||
|
||||
If My.Settings.FB_ConnString <> String.Empty Then
|
||||
_Firebird = New Firebird(_LogConfig, My.Settings.FB_ConnString, My.Settings.FB_DATABASE, My.Settings.FB_USER, My.Settings.FB_PW)
|
||||
If _Config.FirebirdServer <> String.Empty Then
|
||||
_Firebird = New Firebird(_LogConfig, _Config.FirebirdServer, _Config.FirebirdDatabase, _Config.FirebirdUser, _Config.FirebirdPassword)
|
||||
|
||||
If _Firebird._DBInitialized = False Then
|
||||
_Logger.Warn("Firebird Connection could not be established. Check the Error Log")
|
||||
End If
|
||||
End If
|
||||
|
||||
If My.Settings.SQLSERVER_CS <> String.Empty Then
|
||||
_MSSQL = New MSSQLServer(_LogConfig, My.Settings.SQLSERVER_CS)
|
||||
If _Config.SQLServerConnectionString <> String.Empty Then
|
||||
_MSSQL = New MSSQLServer(_LogConfig, _Config.SQLServerConnectionString)
|
||||
|
||||
If _MSSQL.DBInitialized = False Then
|
||||
_Logger.Warn("MSSQL Connection could not be established. Check the Error Log")
|
||||
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
|
||||
_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)
|
||||
Dim oException As Exception = e.ExceptionObject
|
||||
_Logger.Warn("An unhandled exception has occurred.")
|
||||
_Logger.Error(oException)
|
||||
End Sub
|
||||
|
||||
@ -168,6 +177,22 @@ Public Class EmailService
|
||||
End Try
|
||||
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
|
||||
Public Guid As Integer
|
||||
Public Sender As String
|
||||
@ -301,7 +326,6 @@ Public Class EmailService
|
||||
Return False
|
||||
End If
|
||||
|
||||
Dim oMailSMTP, oMailport, oMailUser, oMailPW, oAuthType, oErrorMsg, oMailADDED
|
||||
Dim oGuid, oJobId As Integer
|
||||
|
||||
For Each oAccount In oEmailAccounts
|
||||
@ -345,7 +369,6 @@ Public Class EmailService
|
||||
For Each oRow As DataRow In oAccountQueue
|
||||
'Dim oAccountMatch As Boolean = False
|
||||
Dim oComment As String = String.Empty
|
||||
oErrorMsg = ""
|
||||
|
||||
Dim oAttachment = String.Empty
|
||||
Dim oEmailTo = String.Empty
|
||||
@ -486,19 +509,7 @@ Public Class EmailService
|
||||
End Try
|
||||
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()
|
||||
Try
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user