EDMIService: Rework NewFile and SetAttributeValue
This commit is contained in:
11
Service.EDMIService/BaseClass.vb
Normal file
11
Service.EDMIService/BaseClass.vb
Normal file
@@ -0,0 +1,11 @@
|
||||
Imports DigitalData.Modules.Logging
|
||||
|
||||
Public Class BaseClass
|
||||
Friend LogConfig As LogConfig
|
||||
Friend Logger As Logger
|
||||
|
||||
Public Sub New(pLogConfig As LogConfig)
|
||||
LogConfig = pLogConfig
|
||||
Logger = pLogConfig.GetLogger()
|
||||
End Sub
|
||||
End Class
|
||||
26
Service.EDMIService/BaseMethod.vb
Normal file
26
Service.EDMIService/BaseMethod.vb
Normal file
@@ -0,0 +1,26 @@
|
||||
Imports DigitalData.Modules.Database
|
||||
Imports DigitalData.Modules.Logging
|
||||
Imports DigitalData.Services.EDMIService.IDB
|
||||
|
||||
Public MustInherit Class BaseMethod
|
||||
Inherits BaseClass
|
||||
|
||||
Friend ReadOnly Database As MSSQLServer
|
||||
Friend ReadOnly Helpers As Helpers
|
||||
|
||||
Public Sub New(pLogConfig As LogConfig, pMSSQLServer As MSSQLServer)
|
||||
MyBase.New(pLogConfig)
|
||||
Database = pMSSQLServer
|
||||
Helpers = New Helpers(pLogConfig, pMSSQLServer)
|
||||
End Sub
|
||||
|
||||
Public Function LogAndThrow(pMessage As String)
|
||||
Logger.Warn(pMessage)
|
||||
Throw New ApplicationException(pMessage)
|
||||
End Function
|
||||
|
||||
Public Function LogAndThrow(pException As Exception)
|
||||
Logger.Error(pException)
|
||||
Throw pException
|
||||
End Function
|
||||
End Class
|
||||
@@ -11,6 +11,7 @@ Imports DigitalData.Modules.EDMI.API.Rights
|
||||
Imports DigitalData.Services.EDMIService.Exceptions
|
||||
Imports DigitalData.Services.EDMIService.GlobalState
|
||||
Imports DigitalData.Services.EDMIService.FileStorage
|
||||
Imports DigitalData.Services.EDMIService.FileStorage.SetAttributeValue
|
||||
|
||||
<ServiceBehavior(InstanceContextMode:=InstanceContextMode.PerSession)>
|
||||
Public Class EDMIService
|
||||
@@ -33,6 +34,9 @@ Public Class EDMIService
|
||||
Private ReadOnly _Debug As Boolean = False
|
||||
Private ReadOnly _Username As String
|
||||
|
||||
Private _IDBHelpers As IDB.Helpers
|
||||
|
||||
|
||||
Public Shared Sub Configure(Config As ServiceConfiguration)
|
||||
Dim oBaseAddress = Config.BaseAddresses.Item(0)
|
||||
Dim oBinding = EDMI.API.Channel.GetBinding()
|
||||
@@ -53,111 +57,21 @@ Public Class EDMIService
|
||||
_Username = oUsername
|
||||
_Logger = LogConfig.GetLogger()
|
||||
_Logger.Debug("New Request by User [{0}]", _Username)
|
||||
|
||||
_IDBHelpers = New IDB.Helpers(LogConfig, MSSQL_IDB)
|
||||
End Sub
|
||||
|
||||
Public Function NewFile(Data As NewFile.NewFileRequest) As NewFile.NewFileResponse Implements IEDMIService.NewFile
|
||||
_Logger.Debug("Start of Method [NewFile]")
|
||||
|
||||
Try
|
||||
Dim oNewObjectIdSQL = $"DECLARE @NEW_IDB_OBJ_ID BIGINT
|
||||
EXEC PRIDB_NEW_OBJECT '{Data.KindType}','{Data.Who}','{Data.BusinessEntity}',0, @IDB_OBJ_ID = @NEW_IDB_OBJ_ID OUTPUT;
|
||||
SELECT @NEW_IDB_OBJ_ID"
|
||||
Dim oObjectId As Long = MSSQL_IDB.GetScalarValue(oNewObjectIdSQL)
|
||||
_Logger.Info("New Object with Id [{0}] created!", oObjectId)
|
||||
|
||||
If IsNothing(oObjectId) Then
|
||||
LogAndThrow("Could not create new ObjectId!")
|
||||
End If
|
||||
|
||||
'---------------------------------------------------------------------------
|
||||
|
||||
' Find ObjectStore by Title
|
||||
_Logger.Debug("Checking for DataStore [{0}].", Data.StoreName)
|
||||
Dim oStore = GlobalState.ObjectStores.
|
||||
Where(Function(store) store.Path.Equals(Data.StoreName, StringComparison.OrdinalIgnoreCase)).
|
||||
SingleOrDefault()
|
||||
|
||||
If oStore Is Nothing Then
|
||||
LogAndThrow($"DataStore [{Data.StoreName}] does not exist. Exiting.")
|
||||
End If
|
||||
|
||||
' Get Store base path
|
||||
Dim oBasePath As String = oStore.Path
|
||||
_Logger.Debug("Store BasePath is [{0}]", oBasePath)
|
||||
|
||||
' Get directory by DateImported or, if not supplied, by current date
|
||||
Dim oSubDirectory As String
|
||||
If IsNothing(Data.FileImportedAt) Then
|
||||
oSubDirectory = GetDateSubDirectory(Now)
|
||||
Else
|
||||
oSubDirectory = GetDateSubDirectory(Data.FileImportedAt)
|
||||
End If
|
||||
_Logger.Debug("Subdirectory is [{0}]", oSubDirectory)
|
||||
|
||||
' Check and create final path, if necessary
|
||||
Dim oFinalPath = Path.Combine(oBasePath, oSubDirectory)
|
||||
If Not Directory.Exists(oFinalPath) Then
|
||||
Try
|
||||
_Logger.Debug("Path does not exist, creating: [{0}]", oFinalPath)
|
||||
Directory.CreateDirectory(oFinalPath)
|
||||
_Logger.Debug("Created folder [{0}]", oFinalPath)
|
||||
Catch ex As Exception
|
||||
Throw GetFault(ex)
|
||||
End Try
|
||||
End If
|
||||
_Logger.Debug("Final Directory is [{0}]", oFinalPath)
|
||||
|
||||
' Get filename
|
||||
Dim oKeepFileName As Boolean = False
|
||||
If oStore.IsArchive Then
|
||||
_Logger.Debug("Object Store is an archive: [{0}]", oStore.IsArchive)
|
||||
oKeepFileName = True
|
||||
End If
|
||||
|
||||
Dim oFileName As String = GetFileObjectFileName(oObjectId, Data.FileName, oKeepFileName)
|
||||
_Logger.Debug("Filename is [{0}]", oFileName)
|
||||
|
||||
Dim oFileObjectPath As String = Path.Combine(oFinalPath, oFileName)
|
||||
Dim oFileObjectInfo As FileInfo = New FileInfo(oFileObjectPath)
|
||||
|
||||
Dim oFileObjectSize As Long = Data.FileContents.Length
|
||||
Dim oFileObjectExtension As String = oFileObjectInfo.Extension.Substring(1)
|
||||
Dim oFileObjectName As String = oFileObjectInfo.Name
|
||||
|
||||
_Logger.Debug("File Information for [{0}]:", oFileObjectName)
|
||||
_Logger.Debug("Size: [{0}]", oFileObjectSize)
|
||||
_Logger.Debug("Extension: [{0}]", oFileObjectExtension)
|
||||
_Logger.Debug("Checksum: [{0}]", Data.FileChecksum)
|
||||
|
||||
Try
|
||||
Using oStream = New FileStream(oFileObjectPath, FileMode.Create, FileAccess.Write)
|
||||
_Logger.Info("ImportFile: Saving file to path [{0}]", oFileObjectPath)
|
||||
_Logger.Info("ImportFile: Content Length: {0}", oFileObjectSize)
|
||||
|
||||
oStream.Write(Data.FileContents, 0, oFileObjectSize)
|
||||
oStream.Flush(True)
|
||||
oStream.Close()
|
||||
End Using
|
||||
Catch ex As Exception
|
||||
_Logger.Error(ex)
|
||||
LogAndThrow("Could not write file to disk!")
|
||||
End Try
|
||||
|
||||
' Insert into DB
|
||||
Dim oSQL As String = $"EXEC PRIDB_NEW_IDBFO '{oFileObjectPath}', '{oFileObjectName}', '{oFileObjectExtension}',{oFileObjectSize},{Data.FileChecksum} ,'{Data.Who}','{oObjectId}',{oStore.Id}"
|
||||
Dim oResult As Boolean = MSSQL_IDB.ExecuteNonQuery(oSQL)
|
||||
|
||||
If oResult = False Then
|
||||
LogAndThrow("IDB FileObject could not be created!")
|
||||
End If
|
||||
|
||||
Return New NewFile.NewFileResponse(oObjectId)
|
||||
Catch ex As FaultException
|
||||
Return New NewFile.NewFileResponse(ex)
|
||||
|
||||
End Try
|
||||
Dim oNewFile As New NewFileMethod(LogConfig, MSSQL_IDB, GlobalState.ObjectStores)
|
||||
Return oNewFile.Run(Data)
|
||||
End Function
|
||||
|
||||
Public Function SetAttributeValue(Data As SetAttributeValue.SetAttributeValueRequest) As SetAttributeValue.SetAttributeValueResponse Implements IEDMIService.SetAttributeValue
|
||||
_Logger.Debug("Start of Method [SetAttributeValue]")
|
||||
Dim oSetAttributeValue As New SetAttributeValueMethod(LogConfig, MSSQL_IDB)
|
||||
Return oSetAttributeValue.Run(Data)
|
||||
End Function
|
||||
|
||||
#Region "=== Heartbeat ==="
|
||||
Public Function Heartbeat() As Boolean Implements IEDMIService.Heartbeat
|
||||
@@ -544,23 +458,17 @@ Public Class EDMIService
|
||||
|
||||
Public Function TestObjectIdExists(Data As TestObjectIdExistsRequest) As TestObjectIdExistsResponse Implements IEDMIService.TestObjectIdExists
|
||||
Try
|
||||
Dim oSQL As String = $"SELECT IDB_OBJ_ID, ACTIVE, DELETED FROM TBIDB_OBJECT WHERE IDB_OBJ_ID = {Data.ObjectId}"
|
||||
Dim oTable As DataTable = MSSQL_IDB.GetDatatable(oSQL)
|
||||
Dim oDeleted As Boolean = False
|
||||
Dim oActive As Boolean = False
|
||||
|
||||
If IsNothing(oTable) OrElse oTable.Rows.Count = 0 Then
|
||||
_Logger.Warn("ObjectId {0} does not exist")
|
||||
If _IDBHelpers.TestObjectIdExists(Data.ObjectId, oDeleted, oActive) = False Then
|
||||
Return New TestObjectIdExistsResponse(False)
|
||||
End If
|
||||
|
||||
Dim oRow As DataRow = oTable.Rows.Item(0)
|
||||
Dim oActive = Utils.NotNull(oRow.Item("ACTIVE"), False)
|
||||
Dim oDeleted = Utils.NotNull(oRow.Item("DELETED"), False)
|
||||
|
||||
Return New TestObjectIdExistsResponse(True) With {
|
||||
.Deleted = oDeleted,
|
||||
.Inactive = Not oActive
|
||||
}
|
||||
|
||||
Catch ex As Exception
|
||||
_Logger.Error(ex)
|
||||
Return New TestObjectIdExistsResponse(False)
|
||||
@@ -574,17 +482,10 @@ Public Class EDMIService
|
||||
#End Region
|
||||
|
||||
#Region "=== Private ==="
|
||||
Private Function GetFileObjectFileName(IDB_OBJ_ID As Long, pFilename As String, pKeepFilename As Boolean) As String
|
||||
If pKeepFilename Then
|
||||
Return pFilename
|
||||
Else
|
||||
Return $"{IDB_OBJ_ID}.ddfo"
|
||||
End If
|
||||
End Function
|
||||
|
||||
Private Function GetDateSubDirectory(pDate As Date) As String
|
||||
Return Path.Combine(pDate.ToString("yyyy"), pDate.ToString("MM"), pDate.ToString("dd"))
|
||||
End Function
|
||||
|
||||
|
||||
|
||||
|
||||
Private Function GetFault(Exception As Exception) As FaultException
|
||||
Dim oFault As New UnexpectedErrorFault(Exception)
|
||||
@@ -674,10 +575,7 @@ Public Class EDMIService
|
||||
End If
|
||||
End Function
|
||||
|
||||
Private Function LogAndThrow(pMessage As String)
|
||||
_Logger.Warn(pMessage)
|
||||
Throw New ApplicationException(pMessage)
|
||||
End Function
|
||||
|
||||
#End Region
|
||||
|
||||
|
||||
|
||||
@@ -127,18 +127,24 @@
|
||||
<Import Include="System.Threading.Tasks" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="BaseClass.vb" />
|
||||
<Compile Include="BaseMethod.vb" />
|
||||
<Compile Include="ClassConstants.vb" />
|
||||
<Compile Include="Config.vb" />
|
||||
<Compile Include="Filestorage\NewFile\NewFileMethod.vb" />
|
||||
<Compile Include="Filestorage\NewFile\NewFileRequest.vb" />
|
||||
<Compile Include="Filestorage\NewFile\NewFileResponse.vb" />
|
||||
<Compile Include="Filestorage\SetAttributeValue\SetAttributeValueMethod.vb" />
|
||||
<Compile Include="Filestorage\SetAttributeValue\SetAttributeValueResponse.vb" />
|
||||
<Compile Include="Filestorage\SetAttributeValue\SetAttributeValueRequest.vb" />
|
||||
<Compile Include="GlobalState.vb" />
|
||||
<Compile Include="Helpers\AccessRightResult.vb" />
|
||||
<Compile Include="Helpers\Messages.vb" />
|
||||
<Compile Include="Helpers\BaseResponse.vb" />
|
||||
<Compile Include="Helpers\Exceptions.vb" />
|
||||
<Compile Include="Helpers\DatabaseResult.vb" />
|
||||
<Compile Include="IDB\Helpers.vb" />
|
||||
<Compile Include="Messages\AccessRightResult.vb" />
|
||||
<Compile Include="Messages\Messages.vb" />
|
||||
<Compile Include="Messages\BaseResponse.vb" />
|
||||
<Compile Include="Exceptions.vb" />
|
||||
<Compile Include="Messages\DatabaseResult.vb" />
|
||||
<Compile Include="EDMIService.vb" />
|
||||
<Compile Include="Helpers\TraceSwitch.vb" />
|
||||
<Compile Include="Scheduler\Scheduler.vb" />
|
||||
<Compile Include="Scheduler\DatatableJob.vb" />
|
||||
<Compile Include="Scheduler\JobListener.vb" />
|
||||
|
||||
200
Service.EDMIService/Filestorage/NewFile/NewFileMethod.vb
Normal file
200
Service.EDMIService/Filestorage/NewFile/NewFileMethod.vb
Normal file
@@ -0,0 +1,200 @@
|
||||
Imports System.Data.SqlClient
|
||||
Imports DigitalData.Modules.Database
|
||||
Imports DigitalData.Modules.Database.MSSQLServer.TransactionMode
|
||||
Imports DigitalData.Modules.Logging
|
||||
Imports DigitalData.Services.EDMIService.FileStorage
|
||||
Imports DigitalData.Services.EDMIService.GlobalState
|
||||
|
||||
Public Class NewFileMethod
|
||||
Inherits BaseMethod
|
||||
|
||||
Private ReadOnly ObjectStores As List(Of ObjectStore)
|
||||
Private ReadOnly Connection As SqlConnection
|
||||
Private ReadOnly Transaction As SqlTransaction
|
||||
|
||||
Public Sub New(pLogConfig As LogConfig, pMSSQLServer As MSSQLServer, pObjectStores As List(Of ObjectStore))
|
||||
MyBase.New(pLogConfig, pMSSQLServer)
|
||||
ObjectStores = pObjectStores
|
||||
|
||||
Connection = Database.GetConnection()
|
||||
Transaction = Connection.BeginTransaction()
|
||||
End Sub
|
||||
|
||||
Public Function Run(pData As NewFile.NewFileRequest) As NewFile.NewFileResponse
|
||||
Dim oConnection As SqlConnection = Nothing
|
||||
Dim oTransaction As SqlTransaction = Nothing
|
||||
Dim oFilePath As String = Nothing
|
||||
|
||||
Dim oExistingObjectId = TestFileChecksumExists(pData.FileChecksum)
|
||||
If oExistingObjectId > 0 Then
|
||||
Return New NewFile.NewFileResponse(oExistingObjectId)
|
||||
End If
|
||||
|
||||
Try
|
||||
|
||||
Dim oObjectId = NewObjectId(pData.KindType, pData.BusinessEntity, pData.Who)
|
||||
If oObjectId = 0 Then
|
||||
LogAndThrow("Could not create new ObjectId!")
|
||||
End If
|
||||
|
||||
' Find ObjectStore by Title
|
||||
Logger.Debug("Checking for DataStore [{0}].", pData.StoreName)
|
||||
Dim oStore = ObjectStores.
|
||||
Where(Function(store) store.Title.Equals(pData.StoreName, StringComparison.OrdinalIgnoreCase)).
|
||||
SingleOrDefault()
|
||||
|
||||
If oStore Is Nothing Then
|
||||
LogAndThrow($"DataStore [{pData.StoreName}] does not exist. Exiting.")
|
||||
End If
|
||||
|
||||
' Get Store base path
|
||||
Dim oBasePath As String = oStore.Path
|
||||
Logger.Debug("Store BasePath is [{0}]", oBasePath)
|
||||
|
||||
' Get directory by DateImported or, if not supplied, by current date
|
||||
Dim oSubDirectory As String
|
||||
If IsNothing(pData.FileImportedAt) Then
|
||||
oSubDirectory = GetDateSubDirectory(Now)
|
||||
Else
|
||||
oSubDirectory = GetDateSubDirectory(pData.FileImportedAt)
|
||||
End If
|
||||
Logger.Debug("Subdirectory is [{0}]", oSubDirectory)
|
||||
|
||||
' Check and create final path, if necessary
|
||||
Dim oFinalPath = IO.Path.Combine(oBasePath, oSubDirectory)
|
||||
If Not IO.Directory.Exists(oFinalPath) Then
|
||||
Try
|
||||
Logger.Debug("Path does not exist, creating: [{0}]", oFinalPath)
|
||||
IO.Directory.CreateDirectory(oFinalPath)
|
||||
Logger.Debug("Created folder [{0}]", oFinalPath)
|
||||
Catch ex As Exception
|
||||
LogAndThrow(ex)
|
||||
End Try
|
||||
End If
|
||||
Logger.Debug("Final Directory is [{0}]", oFinalPath)
|
||||
|
||||
' Get filename
|
||||
Dim oKeepFileName As Boolean = False
|
||||
If oStore.IsArchive Then
|
||||
Logger.Debug("Object Store is an archive: [{0}]", oStore.IsArchive)
|
||||
oKeepFileName = True
|
||||
End If
|
||||
|
||||
Dim oFileName As String = GetFileObjectFileName(oObjectId, pData.FileName, oKeepFileName)
|
||||
Logger.Debug("Filename is [{0}]", oFileName)
|
||||
|
||||
oFilePath = IO.Path.Combine(oFinalPath, oFileName)
|
||||
Dim oFileObjectInfo As IO.FileInfo = New IO.FileInfo(oFilePath)
|
||||
|
||||
Dim oFileObjectSize As Long = pData.FileContents.Length
|
||||
Dim oFileObjectExtension As String = oFileObjectInfo.Extension.Substring(1)
|
||||
Dim oFileObjectName As String = oFileObjectInfo.Name
|
||||
|
||||
Logger.Debug("File Information for [{0}]:", oFileObjectName)
|
||||
Logger.Debug("Size: [{0}]", oFileObjectSize)
|
||||
Logger.Debug("Extension: [{0}]", oFileObjectExtension)
|
||||
Logger.Debug("Checksum: [{0}]", pData.FileChecksum)
|
||||
|
||||
Try
|
||||
Using oStream = New IO.FileStream(oFilePath, IO.FileMode.Create, IO.FileAccess.Write)
|
||||
Logger.Info("Saving file to path [{0}]", oFilePath)
|
||||
oStream.Write(pData.FileContents, 0, oFileObjectSize)
|
||||
oStream.Flush(True)
|
||||
oStream.Close()
|
||||
End Using
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
LogAndThrow($"Could not write file [{oFilePath}] to disk!")
|
||||
End Try
|
||||
|
||||
'---------------------------------------------------------------------------
|
||||
|
||||
Logger.Info("Creating IDB FileObject for ObjectId [{0}].", oObjectId)
|
||||
|
||||
' Insert into DB
|
||||
Dim oSQL As String = $"EXEC PRIDB_NEW_IDBFO '{oFinalPath}', '{oFileObjectName}', '{oFileObjectExtension}',{oFileObjectSize},'{pData.FileChecksum}' ,'{pData.Who}','{oObjectId}',{oStore.Id}"
|
||||
Dim oResult As Boolean = Database.ExecuteNonQueryWithConnectionObject(oSQL,
|
||||
oConnection,
|
||||
MSSQLServer.TransactionMode.ExternalTransaction,
|
||||
oTransaction)
|
||||
|
||||
If oResult = False Then
|
||||
LogAndThrow("IDB FileObject could not be created!")
|
||||
End If
|
||||
|
||||
' Finally, commit the transaction
|
||||
oTransaction?.Commit()
|
||||
|
||||
Return New NewFile.NewFileResponse(oObjectId)
|
||||
Catch ex As Exception
|
||||
Logger.Warn("Error occurred while importing file!")
|
||||
Logger.Error(ex)
|
||||
|
||||
Logger.Info("Cleaning up files.")
|
||||
If Not IsNothing(oFilePath) AndAlso IO.File.Exists(oFilePath) Then
|
||||
Try
|
||||
IO.File.Delete(oFilePath)
|
||||
Catch exInner As Exception
|
||||
Logger.Warn("Error while cleaning up files.")
|
||||
Logger.Error(exInner)
|
||||
End Try
|
||||
End If
|
||||
|
||||
Logger.Info("Rolling back transaction.")
|
||||
oTransaction?.Rollback()
|
||||
|
||||
Return New NewFile.NewFileResponse(ex)
|
||||
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Private Function TestFileChecksumExists(pChecksum As String) As Long
|
||||
Try
|
||||
Dim oChecksumSQL = $"SELECT IDB_OBJ_ID FROM TBIDB_FILE_OBJECT WHERE FILE_HASH = '{pChecksum}'"
|
||||
Dim oExistingObjectId As Long = Database.GetScalarValue(oChecksumSQL)
|
||||
|
||||
If oExistingObjectId > 0 Then
|
||||
Logger.Info("Returning early with ObjectId [{0}] because Checksum [{1}] already exists.", oExistingObjectId, pChecksum)
|
||||
Return oExistingObjectId
|
||||
End If
|
||||
|
||||
Return Nothing
|
||||
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
Return Nothing
|
||||
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Private Function NewObjectId(pKindType As String, pBusinessEntity As String, pWho As String) As Long
|
||||
Try
|
||||
Dim oNewObjectIdSQL = $"DECLARE @NEW_IDB_OBJ_ID BIGINT
|
||||
EXEC PRIDB_NEW_OBJECT '{pKindType}','{pWho}','{pBusinessEntity}',0, @IDB_OBJ_ID = @NEW_IDB_OBJ_ID OUTPUT;
|
||||
SELECT @NEW_IDB_OBJ_ID"
|
||||
Dim oObjectId As Long = Database.GetScalarValueWithConnectionObject(oNewObjectIdSQL, Connection, ExternalTransaction, Transaction)
|
||||
Logger.Info("New Object with Id [{0}] created!", oObjectId)
|
||||
|
||||
If IsNothing(oObjectId) Then
|
||||
LogAndThrow("Could not create new ObjectId!")
|
||||
End If
|
||||
|
||||
Return oObjectId
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
Return Nothing
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Private Function GetFileObjectFileName(IDB_OBJ_ID As Long, pFilename As String, pKeepFilename As Boolean) As String
|
||||
If pKeepFilename Then
|
||||
Return pFilename
|
||||
Else
|
||||
Return $"{IDB_OBJ_ID}.ddfo"
|
||||
End If
|
||||
End Function
|
||||
|
||||
Private Function GetDateSubDirectory(pDate As Date) As String
|
||||
Return IO.Path.Combine(pDate.ToString("yyyy"), pDate.ToString("MM"), pDate.ToString("dd"))
|
||||
End Function
|
||||
End Class
|
||||
@@ -1,9 +1,9 @@
|
||||
Imports System.Runtime.Serialization
|
||||
|
||||
Namespace FileStorage.NewFile
|
||||
Namespace FileStorage.SetAttributeValue
|
||||
<Serializable>
|
||||
<DataContract>
|
||||
Public Class NewFileResponse
|
||||
Public Class SetAttributeValueResponse
|
||||
Inherits Messages.BaseResponse
|
||||
|
||||
<DataMember>
|
||||
@@ -14,8 +14,8 @@ Namespace FileStorage.NewFile
|
||||
ObjectId = pObjectId
|
||||
End Sub
|
||||
|
||||
Public Sub New(pException As Exception)
|
||||
MyBase.New(pException)
|
||||
Public Sub New(pException As Exception, Optional pDetails As String = "")
|
||||
MyBase.New(pException, pDetails)
|
||||
End Sub
|
||||
End Class
|
||||
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
Imports DigitalData.Modules.Logging
|
||||
Imports DigitalData.Modules.Database
|
||||
Imports DigitalData.Services.EDMIService.IDB
|
||||
|
||||
Namespace FileStorage.SetAttributeValue
|
||||
Public Class SetAttributeValueMethod
|
||||
Inherits BaseMethod
|
||||
|
||||
Public Sub New(pLogConfig As LogConfig, pDatabase As MSSQLServer)
|
||||
MyBase.New(pLogConfig, pDatabase)
|
||||
End Sub
|
||||
|
||||
Public Function Run(pData As SetAttributeValueRequest) As SetAttributeValueResponse
|
||||
Try
|
||||
If Helpers.TestObjectIdExists(pData.ObjectId) = False Then
|
||||
LogAndThrow("ObjectId does not exist!")
|
||||
End If
|
||||
|
||||
'TODO: Finish
|
||||
|
||||
|
||||
Return New SetAttributeValueResponse(pData.ObjectId)
|
||||
Catch ex As Exception
|
||||
Logger.Warn("Error occurred while setting attribute value!")
|
||||
|
||||
Return New SetAttributeValueResponse(ex)
|
||||
End Try
|
||||
End Function
|
||||
End Class
|
||||
|
||||
End Namespace
|
||||
@@ -0,0 +1,23 @@
|
||||
Imports System.Runtime.Serialization
|
||||
|
||||
Namespace FileStorage.SetAttributeValue
|
||||
<Serializable>
|
||||
<DataContract>
|
||||
Public Class SetAttributeValueRequest
|
||||
''' <summary>
|
||||
''' Object Id
|
||||
''' </summary>
|
||||
<DataMember>
|
||||
Public Property ObjectId As Long
|
||||
<DataMember>
|
||||
Public Property AttributeName As String
|
||||
<DataMember>
|
||||
Public Property AttributeValue As String
|
||||
<DataMember>
|
||||
Public Property Who As Long
|
||||
End Class
|
||||
|
||||
|
||||
End Namespace
|
||||
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
Imports System.Runtime.Serialization
|
||||
|
||||
Namespace FileStorage.NewFile
|
||||
<Serializable>
|
||||
<DataContract>
|
||||
Public Class NewFileResponse
|
||||
Inherits Messages.BaseResponse
|
||||
|
||||
<DataMember>
|
||||
Public Property ObjectId As Long
|
||||
|
||||
Public Sub New(pObjectId As Long)
|
||||
MyBase.New()
|
||||
ObjectId = pObjectId
|
||||
End Sub
|
||||
|
||||
Public Sub New(pException As Exception, Optional pDetails As String = "")
|
||||
MyBase.New(pException, pDetails)
|
||||
End Sub
|
||||
End Class
|
||||
|
||||
End Namespace
|
||||
@@ -1,34 +0,0 @@
|
||||
Public Class TraceSwitch
|
||||
Inherits SourceSwitch
|
||||
|
||||
Public Sub New(Name As String)
|
||||
MyBase.New("System.ServiceModel")
|
||||
Level = SourceLevels.Information
|
||||
WcfTracesController.Instance.LevelController = AddressOf WcfTracesLevelController
|
||||
End Sub
|
||||
|
||||
Public Sub WcfTracesLevelController(ByVal level As SourceLevels)
|
||||
Me.Level = level
|
||||
End Sub
|
||||
End Class
|
||||
|
||||
Public Class WcfTracesController
|
||||
Private Shared Controller As WcfTracesController = Nothing
|
||||
|
||||
Private Sub New()
|
||||
End Sub
|
||||
|
||||
Public Delegate Sub TraceLevelController(ByVal level As SourceLevels)
|
||||
Public LevelController As TraceLevelController
|
||||
|
||||
Public Shared ReadOnly Property Instance As WcfTracesController
|
||||
Get
|
||||
|
||||
If Controller Is Nothing Then
|
||||
Controller = New WcfTracesController()
|
||||
End If
|
||||
|
||||
Return Controller
|
||||
End Get
|
||||
End Property
|
||||
End Class
|
||||
44
Service.EDMIService/IDB/Helpers.vb
Normal file
44
Service.EDMIService/IDB/Helpers.vb
Normal file
@@ -0,0 +1,44 @@
|
||||
Imports DigitalData.Modules.Database
|
||||
Imports DigitalData.Modules.Language
|
||||
Imports DigitalData.Modules.Logging
|
||||
Imports DigitalData.Services.EDMIService.Messages
|
||||
|
||||
Namespace IDB
|
||||
Public Class Helpers
|
||||
Inherits BaseClass
|
||||
|
||||
Private MSSQLServer As MSSQLServer
|
||||
|
||||
Public Sub New(pLogConfig As LogConfig, pMSSQLServer As MSSQLServer)
|
||||
MyBase.New(pLogConfig)
|
||||
MSSQLServer = pMSSQLServer
|
||||
End Sub
|
||||
|
||||
Public Function TestObjectIdExists(pObjectId As Long, Optional ByRef IsDeleted As Boolean = False, Optional ByRef IsActive As Boolean = False) As Boolean
|
||||
Try
|
||||
Dim oSQL As String = $"SELECT IDB_OBJ_ID, ACTIVE, DELETED FROM TBIDB_OBJECT WHERE IDB_OBJ_ID = {pObjectId}"
|
||||
Dim oTable As DataTable = MSSQLServer.GetDatatable(oSQL)
|
||||
|
||||
If IsNothing(oTable) OrElse oTable.Rows.Count = 0 Then
|
||||
Logger.Warn("ObjectId {0} does not exist")
|
||||
Return False
|
||||
End If
|
||||
|
||||
Dim oRow As DataRow = oTable.Rows.Item(0)
|
||||
Dim oActive = Utils.NotNull(oRow.Item("ACTIVE"), False)
|
||||
Dim oDeleted = Utils.NotNull(oRow.Item("DELETED"), False)
|
||||
|
||||
IsDeleted = oDeleted
|
||||
IsActive = oActive
|
||||
|
||||
Return True
|
||||
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
Return False
|
||||
|
||||
End Try
|
||||
End Function
|
||||
End Class
|
||||
|
||||
End Namespace
|
||||
@@ -66,6 +66,9 @@ Interface IEDMIService
|
||||
<OperationContract>
|
||||
Function NewFile(Data As NewFile.NewFileRequest) As NewFile.NewFileResponse
|
||||
|
||||
<OperationContract>
|
||||
Function SetAttributeValue(Data As SetAttributeValue.SetAttributeValueRequest) As SetAttributeValue.SetAttributeValueResponse
|
||||
|
||||
'-----------------------------------------------------
|
||||
' Everything below this line is subject to change!
|
||||
'-----------------------------------------------------
|
||||
|
||||
@@ -9,6 +9,8 @@ Namespace Messages
|
||||
Public Property OK As Boolean
|
||||
<DataMember>
|
||||
Public Property ErrorMessage As String
|
||||
<DataMember>
|
||||
Public Property ErrorDetails As String
|
||||
|
||||
Public Sub New()
|
||||
OK = True
|
||||
@@ -23,6 +25,12 @@ Namespace Messages
|
||||
OK = False
|
||||
ErrorMessage = Exception.Message
|
||||
End Sub
|
||||
|
||||
Public Sub New(Exception As Exception, Details As String)
|
||||
OK = False
|
||||
ErrorMessage = Exception.Message
|
||||
ErrorDetails = Details
|
||||
End Sub
|
||||
End Class
|
||||
End Namespace
|
||||
|
||||
@@ -38,23 +38,9 @@ Public Class WindowsService
|
||||
Try
|
||||
Dim oServicePath As String = AppDomain.CurrentDomain.BaseDirectory
|
||||
|
||||
_LogConfig = New LogConfig(LogConfig.PathType.CustomPath, IO.Path.Combine(oServicePath, "Log"), Nothing, Nothing, Nothing, 3)
|
||||
_LogConfig = New LogConfig(LogConfig.PathType.CustomPath, IO.Path.Combine(oServicePath, "Log"), FileKeepRangeInDays:=3)
|
||||
_Logger = _LogConfig.GetLogger()
|
||||
|
||||
Try
|
||||
Dim directory As New IO.DirectoryInfo(_LogConfig.LogDirectory)
|
||||
|
||||
For Each file As IO.FileInfo In directory.GetFiles
|
||||
If (Now - file.CreationTime).Days > 29 Then
|
||||
file.Delete()
|
||||
Else
|
||||
Exit For
|
||||
End If
|
||||
Next
|
||||
Catch ex As Exception
|
||||
_Logger.Error(ex)
|
||||
End Try
|
||||
|
||||
_Logger.Info("Service {0} is starting...", SERVICE_DISPLAY_NAME)
|
||||
_Logger.Info("ServiceDirectory: {0}", oServicePath)
|
||||
|
||||
@@ -132,28 +118,6 @@ Public Class WindowsService
|
||||
End Try
|
||||
End Sub
|
||||
|
||||
Private Sub UpdateTraceLogging()
|
||||
Try
|
||||
' Changing Tracelevels programmatically,
|
||||
' See: https://wcfpro.wordpress.com/2010/11/21/how-to-add-wcf-traces-programmatically/
|
||||
_Logger.Debug("UpdateTraceLogging running..")
|
||||
_Logger.Debug("SourceLevels is off by default")
|
||||
|
||||
Dim oTraceLevel = SourceLevels.Off
|
||||
|
||||
_Logger.Debug("Debug is currently set to {0}", _ConfigManager.Config.Debug)
|
||||
If _ConfigManager.Config.Debug Then
|
||||
oTraceLevel = SourceLevels.Warning
|
||||
End If
|
||||
|
||||
_Logger.Debug("Setting TraceLevel to {0}", oTraceLevel)
|
||||
WcfTracesController.Instance.LevelController(oTraceLevel)
|
||||
Catch ex As Exception
|
||||
_Logger.Warn("TraceLogging could not be updated!")
|
||||
_Logger.Error(ex)
|
||||
End Try
|
||||
End Sub
|
||||
|
||||
Private Function StartFirebird() As Firebird
|
||||
_Logger.Debug("Connecting to Firebird")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user