EDMI: Client Server Changes to prepare for initial Release

This commit is contained in:
Jonathan Jenne
2021-11-30 16:09:51 +01:00
parent 706d6b0cef
commit 61a15d472b
23 changed files with 426 additions and 32 deletions

View File

@@ -0,0 +1,29 @@
Imports DigitalData.Modules.Database
Imports DigitalData.Modules.Logging
Namespace FileStorage.GetAttributeValue
Public Class GetAttributeValueMethod
Inherits BaseMethod
Public Sub New(pLogConfig As LogConfig, pDatabase As MSSQLServer)
MyBase.New(pLogConfig, pDatabase)
End Sub
Public Function Run(pData As GetAttributeValueRequest) As GetAttributeValueResponse
Try
If Helpers.TestObjectIdExists(pData.ObjectId) = False Then
LogAndThrow("ObjectId does not exist!")
End If
Dim oValue As Object
Return New GetAttributeValueResponse(pData.ObjectId, oValue)
Catch ex As Exception
Logger.Warn("Error occurred while getting attribute value!")
Return New GetAttributeValueResponse(ex)
End Try
End Function
End Class
End Namespace

View File

@@ -0,0 +1,5 @@
Namespace FileStorage.GetAttributeValue
Public Class GetAttributeValueRequest
Public Property ObjectId As Long
End Class
End Namespace

View File

@@ -0,0 +1,26 @@
Imports System.Runtime.Serialization
Namespace FileStorage.GetAttributeValue
<Serializable>
<DataContract>
Public Class GetAttributeValueResponse
Inherits Messages.BaseResponse
<DataMember>
Public Property ObjectId As Long
Public Property Value As Object
Public Sub New(pObjectId As Long, pValue As Object)
MyBase.New()
ObjectId = pObjectId
Value = pValue
End Sub
Public Sub New(pException As Exception, Optional pDetails As String = "")
MyBase.New(pException, pDetails)
End Sub
End Class
End Namespace

View File

@@ -21,8 +21,6 @@ Public Class NewFileMethod
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)
@@ -68,7 +66,7 @@ Public Class NewFileMethod
IO.Directory.CreateDirectory(oFinalPath)
Logger.Debug("Created folder [{0}]", oFinalPath)
Catch ex As Exception
LogAndThrow(ex)
LogAndThrow(ex, $"Store Directory [{oFinalPath}] could not be created!")
End Try
End If
Logger.Debug("Final Directory is [{0}]", oFinalPath)
@@ -103,8 +101,7 @@ Public Class NewFileMethod
oStream.Close()
End Using
Catch ex As Exception
Logger.Error(ex)
LogAndThrow($"Could not write file [{oFilePath}] to disk!")
LogAndThrow(ex, $"Could not write file [{oFilePath}] to disk!")
End Try
'---------------------------------------------------------------------------
@@ -113,17 +110,44 @@ Public Class NewFileMethod
' 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)
Dim oResult As Boolean = Database.ExecuteNonQueryWithConnectionObject(oSQL, Connection, ExternalTransaction, Transaction)
If oResult = False Then
LogAndThrow("IDB FileObject could not be created!")
End If
'---------------------------------------------------------------------------
'TODO: File dates in try catch
Dim oDefaultAttributes As New Dictionary(Of String, Object) From {
{"OriginFileName", pData?.FileName},
{"OriginCreationDatetime", pData?.FileCreatedAt},
{"OriginChangedDatetime", pData?.FileChangedAt}
}
For Each oAttribute As KeyValuePair(Of String, Object) In oDefaultAttributes
Try
' Dont write empty attributes
If oAttribute.Value Is Nothing Then
Continue For
End If
Dim oSuccess = Helpers.SetAttributeValue(Connection, Transaction, oObjectId, oAttribute.Key, oAttribute.Value, "de-DE", pData.Who)
If oSuccess Then
Logger.Debug("Default Attribute [{0}] written with value [{1}]", oAttribute.Key, oAttribute.Value)
Else
Logger.Warn("Default attribute value could not be written")
End If
Catch ex As Exception
LogAndThrow(ex, $"System attribute [{oAttribute.Key}] could not be written!")
End Try
Next
'---------------------------------------------------------------------------
' Finally, commit the transaction
oTransaction?.Commit()
Transaction?.Commit()
Return New NewFile.NewFileResponse(oObjectId)
Catch ex As Exception
@@ -141,7 +165,7 @@ Public Class NewFileMethod
End If
Logger.Info("Rolling back transaction.")
oTransaction?.Rollback()
Transaction?.Rollback()
Return New NewFile.NewFileResponse(ex)

View File

@@ -63,6 +63,13 @@ Namespace FileStorage.NewFile
''' </summary>
<DataMember>
Public Property Who As String
''' <summary>
''' The language of the user
''' </summary>
''' <returns></returns>
<DataMember>
Public Property Language As String
End Class
End Namespace

View File

@@ -1,13 +1,20 @@
Imports DigitalData.Modules.Logging
Imports DigitalData.Modules.Database
Imports DigitalData.Services.EDMIService.IDB
Imports System.Data.SqlClient
Namespace FileStorage.SetAttributeValue
Public Class SetAttributeValueMethod
Inherits BaseMethod
Private Connection As SqlConnection
Private Transaction As SqlTransaction
Public Sub New(pLogConfig As LogConfig, pDatabase As MSSQLServer)
MyBase.New(pLogConfig, pDatabase)
Connection = Database.GetConnection()
Transaction = Connection.BeginTransaction()
End Sub
Public Function Run(pData As SetAttributeValueRequest) As SetAttributeValueResponse
@@ -16,13 +23,16 @@ Namespace FileStorage.SetAttributeValue
LogAndThrow("ObjectId does not exist!")
End If
'TODO: Finish
Dim oResult = Helpers.SetAttributeValue(Connection, Transaction,
pData.ObjectId, pData.AttributeName, pData.AttributeValue, pData.Language, pData.Who)
If oResult = False Then
LogAndThrow("Attribute value could not be set!")
End If
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

View File

@@ -15,6 +15,8 @@ Namespace FileStorage.SetAttributeValue
Public Property AttributeValue As String
<DataMember>
Public Property Who As Long
<DataMember>
Public Property Language As String
End Class