EDMI: Add generic ImportFile Method

This commit is contained in:
Jonathan Jenne
2022-03-29 11:05:59 +02:00
parent 3714308da1
commit 665a23d8a7
25 changed files with 838 additions and 364 deletions

View File

@@ -148,56 +148,7 @@ Namespace IDB
Return oFinalPath
End Function
Public Function GetObject(pObjectId As Long) As IDBObject
Try
Dim oGetObjectSQL = $"SELECT * FROM VWIDB_OBJECT WHERE IDB_OBJ_ID = {pObjectId}"
Dim oRow As DataTable = Database.GetDatatable(oGetObjectSQL)
If oRow Is Nothing Then
Logger.Warn("Object with Id [{0}] not found.", pObjectId)
Return Nothing
End If
'TODO: Return object data
Catch ex As Exception
Logger.Error(ex)
Return Nothing
End Try
End Function
'Public Function GetAttributesForObject(pObjectId As Long, pLanguage As String) As List(Of ObjectAttribute)
' Dim oAttributes As New List(Of ObjectAttribute)
' Try
' Dim oTable As DataTable = Database.GetDatatable($"EXEC [PRIDB_GET_VALUE_DT] {pObjectId}, '{pLanguage}'")
' If oTable Is Nothing OrElse oTable.Rows.Count = 0 Then
' Return Nothing
' End If
' For Each oRow As DataRow In oTable.Rows
' Dim oAttribute As New ObjectAttribute With {
' .Id = oRow.Item("AttributeId"),
' .Title = oRow.Item("AttributeTitle"),
' .Type = oRow.Item("AttributeType"),
' .ValueBigInt = Utils.NotNull(oRow.Item("ValueBigInt"), Nothing),
' .ValueDate = Utils.NotNull(oRow.Item("ValueDate"), Nothing),
' .ValueDecimal = Utils.NotNull(oRow.Item("ValueDecimal"), Nothing),
' .ValueText = Utils.NotNull(oRow.Item("ValueText"), Nothing)
' }
' oAttributes.Add(oAttribute)
' Next
' Return oAttributes
' Catch ex As Exception
' Logger.Error(ex)
' Return Nothing
' End Try
'End Function
Public Function SetAttributeValue(pConnection As SqlConnection, pTransaction As SqlTransaction, pObjectId As Long, pAttributeName As String, pValue As String, pLanguage As String, pWho As String) As Boolean
Public Function SetAttributeValueWithTransaction(pConnection As SqlConnection, pTransaction As SqlTransaction, pObjectId As Long, pAttributeName As String, pValue As String, pLanguage As String, pWho As String) As Boolean
Logger.Info("Setting value of Attribute [{0}]", pAttributeName)
Dim oSql = $"
DECLARE @NEW_OBJ_MD_ID BIGINT
@@ -210,6 +161,31 @@ Namespace IDB
Return True
End Function
Public Sub SetAttributeValuesWithTransaction(pConnection As SqlConnection, pTransaction As SqlTransaction, pObjectId As Long, pAttributes As Dictionary(Of String, List(Of String)), pLanguage As String, pWho As String)
For Each oAttribute As KeyValuePair(Of String, List(Of String)) In pAttributes
Try
' TODO: This works only for simple attributes for now!!!
Dim oValue = oAttribute.Value.FirstOrDefault()
' Dont write empty attributes
If oValue Is Nothing Then
Continue For
End If
' Now make the call to the database
Dim oSuccess = SetAttributeValueWithTransaction(pConnection, pTransaction, pObjectId, oAttribute.Key, oValue, pLanguage, pWho)
If oSuccess Then
Logger.Info("Attribute written [{0}] => [{1}]", oAttribute.Key, oAttribute.Value.First())
Else
Logger.Warn("Attribute value could not be written")
End If
Catch ex As Exception
LogAndThrow(ex, $"Attribute [{oAttribute.Key}] could not be written!")
End Try
Next
End Sub
Public Function NewDynamicFolderForObject(pObjectId As Long, pFolder As String, pWho As String, pLangCode As String) As Boolean
Logger.Info("Setting Dynamic Folder [{0}]", pFolder)
Dim oSql = $"