EDMI: Load Object Store Paths
This commit is contained in:
parent
88dfb3fab1
commit
14194248ad
@ -15,7 +15,7 @@ Imports DigitalData.Modules.EDMI
|
||||
Dim oDay = oNow.Day.ToString.PadLeft(2, "0")
|
||||
|
||||
|
||||
Assert.AreEqual(oPath.GetActivePath("TestDocumentType"), $"{oTempPath}EDMI\Active\TestDocumentType\{oYear}\{oMonth}\{oDay}")
|
||||
Assert.AreEqual(oPath.GetFullPath("TestDocumentType"), $"{oTempPath}EDMI\Active\TestDocumentType\{oYear}\{oMonth}\{oDay}")
|
||||
Assert.AreEqual(oPath.GetArchivePath("TestDocumentType"), $"{oTempPath}EDMI\Archive\TestDocumentType\{oYear}\{oMonth}\{oDay}")
|
||||
End Sub
|
||||
|
||||
|
||||
@ -6,38 +6,21 @@ Public Class Path
|
||||
Private ReadOnly _Logger As Logger
|
||||
Private ReadOnly _BasePath As String
|
||||
|
||||
Public Const PATH_ACTIVE As String = "Active"
|
||||
Public Const PATH_ARCHIVE As String = "Archive"
|
||||
Public Const PATH_EDMI As String = "EDMI"
|
||||
|
||||
Public Sub New(LogConfig As LogConfig, DatastoreBasePath As String)
|
||||
_LogConfig = LogConfig
|
||||
_Logger = LogConfig.GetLogger()
|
||||
_BasePath = DatastoreBasePath
|
||||
End Sub
|
||||
|
||||
Public Function GetActivePath(DocumentType As String, Optional FileName As String = "") As String
|
||||
Dim oParts = New List(Of String) From {_BasePath, PATH_EDMI, PATH_ACTIVE}
|
||||
Public Function GetFullPath(DocumentType As String, Optional FileName As String = "") As String
|
||||
Dim oParts = New List(Of String) From {_BasePath}
|
||||
oParts.AddRange(Do_GetRelativePath(DocumentType, FileName))
|
||||
|
||||
Return IO.Path.Combine(oParts.ToArray())
|
||||
End Function
|
||||
|
||||
Public Function GetActivePathFromRelativePath(RelativePath As String) As String
|
||||
Dim oParts = New List(Of String) From {_BasePath, PATH_EDMI, PATH_ACTIVE}
|
||||
oParts.Add(RelativePath)
|
||||
Return IO.Path.Combine(oParts.ToArray)
|
||||
End Function
|
||||
|
||||
Public Function GetArchivePath(DocumentType As String, Optional FileName As String = "") As String
|
||||
Dim oParts = New List(Of String) From {_BasePath, PATH_EDMI, PATH_ARCHIVE}
|
||||
oParts.AddRange(Do_GetRelativePath(DocumentType, FileName))
|
||||
|
||||
Return IO.Path.Combine(oParts.ToArray())
|
||||
End Function
|
||||
|
||||
Public Function GetArchivePathFromRelativePath(RelativePath As String) As String
|
||||
Dim oParts = New List(Of String) From {_BasePath, PATH_EDMI, PATH_ARCHIVE}
|
||||
Public Function GetFullPathFromRelativePath(RelativePath As String) As String
|
||||
Dim oParts = New List(Of String) From {_BasePath}
|
||||
oParts.Add(RelativePath)
|
||||
Return IO.Path.Combine(oParts.ToArray)
|
||||
End Function
|
||||
|
||||
@ -57,7 +57,7 @@ Public Class Form1
|
||||
Await oStream.ReadAsync(oContents, 0, oFileInfo.Length)
|
||||
End Using
|
||||
|
||||
Dim oResult As EDMIServiceReference.DocumentResult = Await _Channel.ImportFileAsync(oFileInfo.Name, oContents, Environment.UserName)
|
||||
Dim oResult As EDMIServiceReference.DocumentResult = Await _Channel.ImportFileAsync(oFileInfo.Name, oContents, 1, "WichtigesDokument", 0)
|
||||
If oResult.OK Then
|
||||
AddLogMessage($"File [{oFileInfo.Name}] with Id [{oResult.Document.FileId}] imported!")
|
||||
Else
|
||||
|
||||
@ -98,6 +98,8 @@ Public Class MSSQLServer
|
||||
Return Nothing
|
||||
End If
|
||||
|
||||
_Logger.Debug("Running Query: {0}", SqlCommand)
|
||||
|
||||
Using oConnection = GetSQLConnection()
|
||||
Using oSQLCOmmand = oConnection.CreateCommand()
|
||||
oSQLCOmmand.CommandText = SqlCommand
|
||||
@ -137,6 +139,8 @@ Public Class MSSQLServer
|
||||
Return Nothing
|
||||
End If
|
||||
|
||||
_Logger.Debug("Running Query: {0}", SQLCommand)
|
||||
|
||||
Using oConnection = GetSQLConnection()
|
||||
Using oSQLCOmmand = oConnection.CreateCommand()
|
||||
oSQLCOmmand.CommandText = SQLCommand
|
||||
@ -166,15 +170,17 @@ Public Class MSSQLServer
|
||||
Return GetScalarValue(ScalarSQL)
|
||||
End Function
|
||||
|
||||
Public Function GetScalarValue(SQLQuery As String, Timeout As Integer) As Object Implements IDatabase.GetScalarValue
|
||||
Public Function GetScalarValue(SQLCommand As String, Timeout As Integer) As Object Implements IDatabase.GetScalarValue
|
||||
Try
|
||||
If TestCanConnect() = False Then
|
||||
Return Nothing
|
||||
End If
|
||||
|
||||
_Logger.Debug("Running Query: {0}", SQLCommand)
|
||||
|
||||
Using oConnection As SqlConnection = GetSQLConnection()
|
||||
Using oSQLCOmmand = oConnection.CreateCommand()
|
||||
oSQLCOmmand.CommandText = SQLQuery
|
||||
oSQLCOmmand.CommandText = SQLCommand
|
||||
oSQLCOmmand.CommandTimeout = Timeout
|
||||
Dim oResult As Object = oSQLCOmmand.ExecuteScalar()
|
||||
Return oResult
|
||||
@ -182,7 +188,7 @@ Public Class MSSQLServer
|
||||
End Using
|
||||
Catch ex As Exception
|
||||
_Logger.Error(ex)
|
||||
_Logger.Warn("SQLQuery: " & SQLQuery)
|
||||
_Logger.Warn("SQLQuery: " & SQLCommand)
|
||||
Return Nothing
|
||||
End Try
|
||||
End Function
|
||||
@ -197,6 +203,8 @@ Public Class MSSQLServer
|
||||
Return Nothing
|
||||
End If
|
||||
|
||||
_Logger.Debug("Running Query: {0}", SQLCommand)
|
||||
|
||||
If SQLCommand.CommandText.Contains(" ") Then
|
||||
SQLCommand.CommandType = CommandType.Text
|
||||
Else
|
||||
@ -227,27 +235,29 @@ Public Class MSSQLServer
|
||||
''' <summary>
|
||||
''' Executes the passed sql-statement in asyncmode
|
||||
''' </summary>
|
||||
''' <param name="executeStatement">the sql statement</param>
|
||||
''' <param name="SqlCommand">the sql statement</param>
|
||||
''' <param name="commandtimeout">Optional Timeout</param>
|
||||
''' <remarks></remarks>
|
||||
Public Sub NewExecuteNonQueryAsync(executeStatement As String, Optional commandtimeout As Integer = 120)
|
||||
Public Sub NewExecuteNonQueryAsync(SqlCommand As String, Optional commandtimeout As Integer = 120)
|
||||
If TestCanConnect() = False Then
|
||||
Exit Sub
|
||||
End If
|
||||
|
||||
_Logger.Debug("Running Query: {0}", SqlCommand)
|
||||
|
||||
Try
|
||||
Dim oCallback As New AsyncCallback(AddressOf NewExecuteNonQueryAsync_Callback)
|
||||
|
||||
Using oConnection As SqlConnection = GetSQLConnection()
|
||||
Using oSQLCOmmand = oConnection.CreateCommand()
|
||||
oSQLCOmmand.CommandText = executeStatement
|
||||
oSQLCOmmand.CommandText = SqlCommand
|
||||
oSQLCOmmand.CommandTimeout = commandtimeout
|
||||
oSQLCOmmand.BeginExecuteNonQuery(oCallback, oSQLCOmmand)
|
||||
End Using
|
||||
End Using
|
||||
Catch ex As Exception
|
||||
_Logger.Error(ex)
|
||||
_Logger.Warn("executeStatement: " & executeStatement)
|
||||
_Logger.Warn("executeStatement: " & SqlCommand)
|
||||
End Try
|
||||
End Sub
|
||||
|
||||
|
||||
@ -174,7 +174,9 @@
|
||||
<xs:sequence>
|
||||
<xs:element minOccurs="0" name="FileName" nillable="true" type="xs:string" />
|
||||
<xs:element minOccurs="0" name="Contents" nillable="true" type="xs:base64Binary" />
|
||||
<xs:element minOccurs="0" name="AddedWho" nillable="true" type="xs:string" />
|
||||
<xs:element minOccurs="0" name="ObjectStoreId" type="xs:long" />
|
||||
<xs:element minOccurs="0" name="DocumentType" nillable="true" type="xs:string" />
|
||||
<xs:element minOccurs="0" name="RetentionDays" type="xs:long" />
|
||||
</xs:sequence>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
|
||||
@ -594,10 +594,10 @@ Namespace EDMIServiceReference
|
||||
Function GetDocumentByContainerIdAsync(ByVal ContainerId As String) As System.Threading.Tasks.Task(Of EDMIServiceReference.DocumentResultOld)
|
||||
|
||||
<System.ServiceModel.OperationContractAttribute(Action:="http://DigitalData.Services.EDMIService/IEDMIService/ImportFile", ReplyAction:="http://DigitalData.Services.EDMIService/IEDMIService/ImportFileResponse")> _
|
||||
Function ImportFile(ByVal FileName As String, ByVal Contents() As Byte, ByVal AddedWho As String) As EDMIServiceReference.DocumentResult
|
||||
Function ImportFile(ByVal FileName As String, ByVal Contents() As Byte, ByVal ObjectStoreId As Long, ByVal DocumentType As String, ByVal RetentionDays As Long) As EDMIServiceReference.DocumentResult
|
||||
|
||||
<System.ServiceModel.OperationContractAttribute(Action:="http://DigitalData.Services.EDMIService/IEDMIService/ImportFile", ReplyAction:="http://DigitalData.Services.EDMIService/IEDMIService/ImportFileResponse")> _
|
||||
Function ImportFileAsync(ByVal FileName As String, ByVal Contents() As Byte, ByVal AddedWho As String) As System.Threading.Tasks.Task(Of EDMIServiceReference.DocumentResult)
|
||||
Function ImportFileAsync(ByVal FileName As String, ByVal Contents() As Byte, ByVal ObjectStoreId As Long, ByVal DocumentType As String, ByVal RetentionDays As Long) As System.Threading.Tasks.Task(Of EDMIServiceReference.DocumentResult)
|
||||
|
||||
'CODEGEN: Der Nachrichtenvertrag wird generiert, da der Wrappername (DocumentStreamRequest) von Nachricht "DocumentStreamRequest" nicht mit dem Standardwert (GetFileByObjectId) übereinstimmt.
|
||||
<System.ServiceModel.OperationContractAttribute(Action:="http://DigitalData.Services.EDMIService/IEDMIService/GetFileByObjectId", ReplyAction:="http://DigitalData.Services.EDMIService/IEDMIService/GetFileByObjectIdResponse")> _
|
||||
@ -788,12 +788,12 @@ Namespace EDMIServiceReference
|
||||
Return MyBase.Channel.GetDocumentByContainerIdAsync(ContainerId)
|
||||
End Function
|
||||
|
||||
Public Function ImportFile(ByVal FileName As String, ByVal Contents() As Byte, ByVal AddedWho As String) As EDMIServiceReference.DocumentResult Implements EDMIServiceReference.IEDMIService.ImportFile
|
||||
Return MyBase.Channel.ImportFile(FileName, Contents, AddedWho)
|
||||
Public Function ImportFile(ByVal FileName As String, ByVal Contents() As Byte, ByVal ObjectStoreId As Long, ByVal DocumentType As String, ByVal RetentionDays As Long) As EDMIServiceReference.DocumentResult Implements EDMIServiceReference.IEDMIService.ImportFile
|
||||
Return MyBase.Channel.ImportFile(FileName, Contents, ObjectStoreId, DocumentType, RetentionDays)
|
||||
End Function
|
||||
|
||||
Public Function ImportFileAsync(ByVal FileName As String, ByVal Contents() As Byte, ByVal AddedWho As String) As System.Threading.Tasks.Task(Of EDMIServiceReference.DocumentResult) Implements EDMIServiceReference.IEDMIService.ImportFileAsync
|
||||
Return MyBase.Channel.ImportFileAsync(FileName, Contents, AddedWho)
|
||||
Public Function ImportFileAsync(ByVal FileName As String, ByVal Contents() As Byte, ByVal ObjectStoreId As Long, ByVal DocumentType As String, ByVal RetentionDays As Long) As System.Threading.Tasks.Task(Of EDMIServiceReference.DocumentResult) Implements EDMIServiceReference.IEDMIService.ImportFileAsync
|
||||
Return MyBase.Channel.ImportFileAsync(FileName, Contents, ObjectStoreId, DocumentType, RetentionDays)
|
||||
End Function
|
||||
|
||||
<System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)> _
|
||||
|
||||
@ -53,12 +53,12 @@ Public Class Document
|
||||
''' </summary>
|
||||
''' <param name="FilePath">The filename to import</param>
|
||||
''' <returns>A document object</returns>
|
||||
Public Async Function ImportFileAsync(FilePath As String, Optional [ReadOnly] As Boolean = False, Optional RetentionPeriod As Integer = 0) As Task(Of DocumentResult)
|
||||
Public Async Function ImportFileAsync(FilePath As String, Optional [ReadOnly] As Boolean = False, Optional RetentionDays As Integer = 0) As Task(Of DocumentResult)
|
||||
Try
|
||||
Using oStream As New FileStream(FilePath, FileMode.Open)
|
||||
Dim oContents As Byte() = {}
|
||||
Dim oBytesRead = Await oStream.ReadAsync(oContents, 0, oStream.Length)
|
||||
Dim oResult = Await _channel.ImportFileAsync(FilePath, oContents, Environment.UserName)
|
||||
Dim oResult = Await _channel.ImportFileAsync(FilePath, oContents, 1, "WichtigesDokument", RetentionDays)
|
||||
|
||||
Return oResult
|
||||
End Using
|
||||
@ -77,7 +77,7 @@ Public Class Document
|
||||
Try
|
||||
Dim oContents As Byte() = File.ReadAllBytes(FilePath)
|
||||
Dim oInfo As New FileInfo(FilePath)
|
||||
Dim oDocObject = _channel.ImportFile(FilePath, oContents, Environment.UserName)
|
||||
Dim oDocObject = _channel.ImportFile(FilePath, oContents, 1, "WichtigesDokument", 0)
|
||||
Return oDocObject
|
||||
Catch ex As Exception
|
||||
_logger.Error(ex)
|
||||
|
||||
@ -1,16 +1,16 @@
|
||||
Imports System.Configuration
|
||||
|
||||
Public Class AppConfig
|
||||
Public Shared FirebirdDataSource As String
|
||||
Public Shared FirebirdDatabase As String
|
||||
Public Shared FirebirdUser As String
|
||||
Public Shared FirebirdPassword As String
|
||||
Public Shared ContainerPath As String
|
||||
Public Shared ContainerPassword As String
|
||||
Public Shared DatastorePath As String
|
||||
Public Shared MSSQLConnectionString As String
|
||||
Public FirebirdDataSource As String
|
||||
Public FirebirdDatabase As String
|
||||
Public FirebirdUser As String
|
||||
Public FirebirdPassword As String
|
||||
Public ContainerPath As String
|
||||
Public ContainerPassword As String
|
||||
Public DatastorePath As String
|
||||
Public MSSQLConnectionString As String
|
||||
|
||||
Public Shared Sub Load()
|
||||
Public Sub New()
|
||||
With ConfigurationManager.AppSettings
|
||||
FirebirdDataSource = .Item("FIREBIRD_DATASOURCE")
|
||||
FirebirdDatabase = .Item("FIREBIRD_DATABASE_NAME")
|
||||
@ -26,12 +26,12 @@ Public Class AppConfig
|
||||
End With
|
||||
End Sub
|
||||
|
||||
Public Shared Function IsFirebirdConfigured() As Boolean
|
||||
Public Function IsFirebirdConfigured() As Boolean
|
||||
Dim oProps As New List(Of String) From {FirebirdDataSource, FirebirdDatabase, FirebirdUser, FirebirdPassword}
|
||||
Return Not oProps.Any(Function(Prop) String.IsNullOrWhiteSpace(Prop))
|
||||
End Function
|
||||
|
||||
Public Shared Function IsMSSQLConfigured() As Boolean
|
||||
Public Function IsMSSQLConfigured() As Boolean
|
||||
Return Not String.IsNullOrWhiteSpace(MSSQLConnectionString)
|
||||
End Function
|
||||
End Class
|
||||
|
||||
@ -1,11 +1,9 @@
|
||||
Imports System.ServiceModel
|
||||
Imports DigitalData.Modules.Database
|
||||
Imports DigitalData.Modules.Database
|
||||
Imports DigitalData.Modules.Logging
|
||||
Imports DigitalData.Modules.Filesystem
|
||||
Imports DigitalData.Modules
|
||||
Imports System.IO
|
||||
Imports System.ServiceModel.Description
|
||||
Imports System.ServiceModel.Channels
|
||||
Imports System.ServiceModel
|
||||
Imports System.Data.SqlClient
|
||||
|
||||
<ServiceBehavior(InstanceContextMode:=InstanceContextMode.PerSession)>
|
||||
@ -17,8 +15,8 @@ Public Class EDMIService
|
||||
Public Shared Firebird As Firebird
|
||||
Public Shared AppConfig As AppConfig
|
||||
Public Shared Filesystem As Filesystem.File
|
||||
Public Shared EDMIPath As EDMI.File.Path
|
||||
Public Shared EDMIArchive As EDMI.File.Archive
|
||||
Public Shared GlobalState As GlobalState
|
||||
|
||||
Private ReadOnly _logger As Logger
|
||||
|
||||
@ -34,7 +32,6 @@ Public Class EDMIService
|
||||
|
||||
_username = oUsername
|
||||
_logger = LogConfig.GetLogger()
|
||||
|
||||
_logger.Debug("New Request by User [{0}]", _username)
|
||||
End Sub
|
||||
|
||||
@ -320,6 +317,16 @@ Public Class EDMIService
|
||||
''' <param name="Contents"></param>
|
||||
''' <returns></returns>
|
||||
Public Function ImportFile(FileName As String, Contents() As Byte, ObjectStoreId As Int64, DocumentType As String, Optional RetentionDays As Int64 = Nothing) As DocumentResult Implements IEDMIService.ImportFile
|
||||
Dim oObjectStore = GlobalState.ObjectStores.
|
||||
Where(Function(s) s.Id = ObjectStoreId).
|
||||
FirstOrDefault()
|
||||
|
||||
If oObjectStore Is Nothing Then
|
||||
Return New DocumentResult($"Object Store with Id [{ObjectStoreId}] does not exist!")
|
||||
End If
|
||||
|
||||
Dim EDMIPath = New EDMI.File.Path(LogConfig, oObjectStore.Path)
|
||||
|
||||
' TODO:
|
||||
' - Get Object Store -> Object Catalog -> Catalog Path
|
||||
' - If IS_ARCHIVE = True And RetentionDays <> Nothing:
|
||||
@ -328,10 +335,9 @@ Public Class EDMIService
|
||||
' and return ObjectStore Path from ObjectStoreId + RelativePath
|
||||
' VWIDB_OBJECTSTORE
|
||||
|
||||
Dim oDocumentType As String = "DummyDocumentType"
|
||||
Dim oRelativePath As String = EDMIPath.GetRelativePath(oDocumentType, FileName)
|
||||
Dim oAbsolutePath As String = EDMIPath.GetActivePath(oDocumentType, FileName)
|
||||
Dim oDirectoryPath = EDMIPath.GetActivePath(oDocumentType)
|
||||
Dim oRelativePath As String = EDMIPath.GetRelativePath(DocumentType, FileName)
|
||||
Dim oAbsolutePath As String = EDMIPath.GetFullPath(DocumentType, FileName)
|
||||
Dim oDirectoryPath = EDMIPath.GetFullPath(DocumentType)
|
||||
Dim oDocument = New DocumentResult.DocumentObject With {.FileName = FileName}
|
||||
|
||||
Try
|
||||
@ -372,14 +378,23 @@ Public Class EDMIService
|
||||
|
||||
Public Function GetFileByObjectId(Data As Messages.DocumentStreamRequest) As Messages.DocumentStreamResponse Implements IEDMIService.GetFileByObjectId
|
||||
Try
|
||||
Dim oSQL As String = $"SELECT DocRelativePath FROM VWIDB_DOC_DATA WHERE IDB_OBJ_ID = {Data.ObjectId}"
|
||||
Dim oPath As String = MSSQL.GetScalarValue(oSQL)
|
||||
Dim oSQL As String = $"SELECT ObjectStoreId FROM VWIDB_DOC_DATA WHERE IDB_OBJ_ID = {Data.ObjectId}"
|
||||
Dim oObjectStoreId = MSSQL.GetScalarValue(oSQL)
|
||||
|
||||
Dim oObjectStore = GlobalState.ObjectStores.
|
||||
Where(Function(s) s.Id = oObjectStoreId).
|
||||
FirstOrDefault()
|
||||
|
||||
Dim oSQL2 As String = $"SELECT DocRelativePath FROM VWIDB_DOC_DATA WHERE IDB_OBJ_ID = {Data.ObjectId}"
|
||||
Dim oPath As String = MSSQL.GetScalarValue(oSQL2)
|
||||
|
||||
|
||||
If IsNothing(oPath) Then
|
||||
Throw New FaultException($"Object [{Data.ObjectId}] does not exist in database!")
|
||||
End If
|
||||
|
||||
Dim oFullPath = EDMIPath.GetActivePathFromRelativePath(oPath)
|
||||
Dim EDMIPath As New EDMI.File.Path(LogConfig, oObjectStore.Path)
|
||||
Dim oFullPath = EDMIPath.GetFullPathFromRelativePath(oPath)
|
||||
|
||||
_logger.Debug("GetFileByObjectId: Loading file [{0}]", oFullPath)
|
||||
|
||||
|
||||
@ -104,6 +104,7 @@
|
||||
<Compile Include="AppConfig.vb" />
|
||||
<Compile Include="Database\IDatabase.vb" />
|
||||
<Compile Include="Database\MSSQL.vb" />
|
||||
<Compile Include="GlobalState.vb" />
|
||||
<Compile Include="Messages.vb" />
|
||||
<Compile Include="Results\BaseResult.vb" />
|
||||
<Compile Include="Results\ContainerResult.vb" />
|
||||
|
||||
46
Service.EDMIService/GlobalState.vb
Normal file
46
Service.EDMIService/GlobalState.vb
Normal file
@ -0,0 +1,46 @@
|
||||
Imports DigitalData.Modules.Database
|
||||
Imports DigitalData.Modules.Logging
|
||||
|
||||
Public Class GlobalState
|
||||
Private _LogConfig As LogConfig
|
||||
Private _Logger As Logger
|
||||
Private _MSSQL As MSSQLServer
|
||||
Public Property ObjectStores As New List(Of ObjectStore)
|
||||
|
||||
Public Sub New(LogConfig As LogConfig, MSSQL As MSSQLServer)
|
||||
_LogConfig = LogConfig
|
||||
_Logger = LogConfig.GetLogger()
|
||||
_MSSQL = MSSQL
|
||||
End Sub
|
||||
|
||||
Public Sub LoadObjectStores()
|
||||
_Logger.Debug("Loading Object Stores")
|
||||
Try
|
||||
Dim oSQL As String = "SELECT * FROM VWIDB_OBJECTSTORE"
|
||||
Dim oDatatable As DataTable = _MSSQL.GetDatatable(oSQL)
|
||||
|
||||
ObjectStores.Clear()
|
||||
|
||||
For Each oRow As DataRow In oDatatable.Rows
|
||||
Dim oStore As New ObjectStore() With {
|
||||
.Id = oRow.Item("OST_ID"),
|
||||
.IsArchive = oRow.Item("OS_IS_ARCHIVE"),
|
||||
.Path = oRow.Item("IDB_PRAEFIX"),
|
||||
.Title = oRow.Item("OS_TITLE")
|
||||
}
|
||||
_Logger.Debug("New Object Store [{0}]", oStore.Title)
|
||||
ObjectStores.Add(oStore)
|
||||
Next
|
||||
Catch ex As Exception
|
||||
_Logger.Error(ex)
|
||||
Throw ex
|
||||
End Try
|
||||
End Sub
|
||||
|
||||
Class ObjectStore
|
||||
Public Id As Int64
|
||||
Public Title As String
|
||||
Public IsArchive As Boolean
|
||||
Public Path As String
|
||||
End Class
|
||||
End Class
|
||||
@ -8,19 +8,18 @@ Imports System.ServiceModel.Description
|
||||
Public Class WindowsService
|
||||
Inherits ServiceBase
|
||||
|
||||
Private _serviceHost As ServiceHost = Nothing
|
||||
Private _edmService As IEDMIService = Nothing
|
||||
Private _ServiceHost As ServiceHost
|
||||
Private _LogConfig As LogConfig
|
||||
Private _Logger As Logger
|
||||
|
||||
Private _logConfig As LogConfig
|
||||
Private _logger As Logger
|
||||
Private _Firebird As Firebird
|
||||
Private _MSSQL As MSSQLServer
|
||||
|
||||
Private _firebird As Firebird
|
||||
Private _mssql As MSSQLServer
|
||||
|
||||
Private _config As AppConfig
|
||||
Private _Config As AppConfig
|
||||
Private _Path As EDMI.File.Path
|
||||
Private _Archive As EDMI.File.Archive
|
||||
Private _filesystem As Filesystem.File
|
||||
Private _Filesystem As Filesystem.File
|
||||
Private _Global As GlobalState
|
||||
|
||||
Public Sub New()
|
||||
ServiceName = SERVICE_NAME
|
||||
@ -32,78 +31,84 @@ Public Class WindowsService
|
||||
|
||||
Protected Overrides Sub OnStart(ByVal args As String())
|
||||
Try
|
||||
AppConfig.Load()
|
||||
|
||||
_logConfig = New LogConfig(LogConfig.PathType.CustomPath, "E:\EDMService") With {
|
||||
_Config = New AppConfig()
|
||||
_LogConfig = New LogConfig(LogConfig.PathType.CustomPath, "E:\EDMService") With {
|
||||
.Debug = True
|
||||
}
|
||||
_Logger = _LogConfig.GetLogger()
|
||||
_Logger.Info("Service {0} is starting...", SERVICE_DISPLAY_NAME)
|
||||
|
||||
_logger = _logConfig.GetLogger()
|
||||
MaybeStartFirebird()
|
||||
MaybeStartMSSQL()
|
||||
|
||||
_logger.Info("Service {0} is starting...", SERVICE_DISPLAY_NAME)
|
||||
_Logger.Debug("Initializing EDMI Functions")
|
||||
|
||||
If AppConfig.IsFirebirdConfigured() Then
|
||||
_logger.Debug("Connecting to Firebird...")
|
||||
_firebird = New Firebird(
|
||||
_logConfig,
|
||||
AppConfig.FirebirdDataSource,
|
||||
AppConfig.FirebirdDatabase,
|
||||
AppConfig.FirebirdUser,
|
||||
AppConfig.FirebirdPassword
|
||||
)
|
||||
_logger.Info("Database connection established.")
|
||||
Else
|
||||
_logger.Info("Firebird is not configured, will not be used!")
|
||||
End If
|
||||
_Archive = New EDMI.File.Archive(_LogConfig)
|
||||
_Filesystem = New Filesystem.File(_LogConfig)
|
||||
_Global = New GlobalState(_LogConfig, _MSSQL)
|
||||
|
||||
If AppConfig.IsMSSQLConfigured() Then
|
||||
_logger.Debug("Connecting to MSSQL...")
|
||||
_mssql = New MSSQLServer(_logConfig, AppConfig.MSSQLConnectionString)
|
||||
_logger.Info("Database connection established.")
|
||||
Else
|
||||
_logger.Info("MSSQL is not configured, will not be used!")
|
||||
End If
|
||||
_Global.LoadObjectStores()
|
||||
|
||||
_logger.Debug("Initializing EDMI Functions")
|
||||
_Logger.Info("EDMI Functions initialized.")
|
||||
|
||||
_Path = New EDMI.File.Path(_logConfig, AppConfig.DatastorePath)
|
||||
_Archive = New EDMI.File.Archive(_logConfig)
|
||||
_filesystem = New Filesystem.File(_logConfig)
|
||||
|
||||
_logger.Info("EDMI Functions initialized.")
|
||||
|
||||
EDMIService.MSSQL = _mssql
|
||||
EDMIService.Firebird = _firebird
|
||||
EDMIService.LogConfig = _logConfig
|
||||
EDMIService.AppConfig = _config
|
||||
EDMIService.MSSQL = _MSSQL
|
||||
EDMIService.Firebird = _Firebird
|
||||
EDMIService.LogConfig = _LogConfig
|
||||
EDMIService.AppConfig = _Config
|
||||
EDMIService.EDMIArchive = _Archive
|
||||
EDMIService.EDMIPath = _Path
|
||||
EDMIService.Filesystem = _filesystem
|
||||
EDMIService.Filesystem = _Filesystem
|
||||
EDMIService.GlobalState = _Global
|
||||
|
||||
_logger.Debug("Starting WCF ServiceHost...")
|
||||
_Logger.Debug("Starting WCF ServiceHost...")
|
||||
|
||||
_serviceHost = New ServiceHost(GetType(EDMIService))
|
||||
_serviceHost.Open()
|
||||
_ServiceHost = New ServiceHost(GetType(EDMIService))
|
||||
_ServiceHost.Open()
|
||||
|
||||
_logger.Info("WCF ServiceHost started.")
|
||||
_Logger.Info("WCF ServiceHost started.")
|
||||
|
||||
_logger.Info("Service {0} successfully started.", SERVICE_DISPLAY_NAME)
|
||||
_Logger.Info("Service {0} successfully started.", SERVICE_DISPLAY_NAME)
|
||||
Catch ex As Exception
|
||||
_logger.Error(ex, "Failed to start the service host!")
|
||||
_Logger.Error(ex, "Failed to start the service host!")
|
||||
GracefullyStop()
|
||||
End Try
|
||||
End Sub
|
||||
|
||||
Private Sub MaybeStartFirebird()
|
||||
If _Config.IsFirebirdConfigured() Then
|
||||
_Logger.Debug("Connecting to Firebird")
|
||||
_Firebird = New Firebird(
|
||||
_LogConfig,
|
||||
_Config.FirebirdDataSource,
|
||||
_Config.FirebirdDatabase,
|
||||
_Config.FirebirdUser,
|
||||
_Config.FirebirdPassword
|
||||
)
|
||||
_Logger.Info("Database connection established.")
|
||||
Else
|
||||
_Logger.Info("Firebird is not configured, will not be used!")
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Private Sub MaybeStartMSSQL()
|
||||
If _Config.IsMSSQLConfigured() Then
|
||||
_Logger.Debug("Connecting to MSSQL")
|
||||
_MSSQL = New MSSQLServer(_LogConfig, _Config.MSSQLConnectionString)
|
||||
_Logger.Info("Database connection established.")
|
||||
Else
|
||||
_Logger.Info("MSSQL is not configured, will not be used!")
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Protected Overrides Sub OnStop()
|
||||
GracefullyStop()
|
||||
End Sub
|
||||
|
||||
Private Sub GracefullyStop()
|
||||
If _serviceHost IsNot Nothing Then
|
||||
_serviceHost.Close()
|
||||
_serviceHost = Nothing
|
||||
If _ServiceHost IsNot Nothing Then
|
||||
_ServiceHost.Close()
|
||||
_ServiceHost = Nothing
|
||||
End If
|
||||
_logger.Info("Service {0} is stopping!", SERVICE_DISPLAY_NAME)
|
||||
_Logger.Info("Service {0} is stopping!", SERVICE_DISPLAY_NAME)
|
||||
End Sub
|
||||
End Class
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user