This commit is contained in:
Jonathan Jenne
2018-12-17 14:46:02 +01:00
parent e30bc21cf2
commit 142d9e316c
6 changed files with 61 additions and 25 deletions

View File

@@ -62,29 +62,44 @@ Public Class ImportZUGFeRDFiles
Dim oValues As New Dictionary(Of String, String)
Dim oGuid As String = Path.GetFileNameWithoutExtension(oFile.FullName)
Dim oConnection = _firebird.GetConnection()
Dim oTransaction = oConnection.BeginTransaction()
Try
oDocument = _zugferd.ExtractZUGFeRDFile(oFile.FullName)
For Each mapping In args.PropertyMap
Dim propertyValue As String = PropertyValues.GetPropValue(oDocument, mapping.Value)
_logger.Info("Mapping Property {0} to value {1}. Will be inserted into column {2}", mapping.Value, propertyValue, mapping.Key)
' TODO: Check for missing values
If String.IsNullOrEmpty(propertyValue) Then
Throw New Exception($"Property {mapping.Value} not found or empty.")
End If
'If String.IsNullOrEmpty(propertyValue) Then
' Throw New Exception($"Property {mapping.Value} not found or empty.")
'End If
Console.WriteLine("{0} => {1}", mapping.Key, propertyValue)
oValues.Add(mapping.Key, propertyValue)
' TODO: Insert into scheise
Dim oTableColumnArray = mapping.Key.Split(".")
Dim oTableName = oTableColumnArray.First()
Dim oColumnName = oTableColumnArray.Last()
_logger.Info("Mapping Property {0} to value {1}. Will be inserted into column {2} on table {3}", mapping.Value, propertyValue, oTableName, oColumnName)
Dim oCommand = $"INSERT INTO {oTableName} (FILEID, ""NAME"", ""VALUE"") VALUES ('{oGuid}', '{oColumnName}', '{propertyValue}')"
_firebird.ExecuteNonQueryWithConnection(oCommand, oConnection, Firebird.TransactionMode.ExternalTransaction, oTransaction)
Next
' TODO: Insert into scheise
oTransaction.Commit()
Catch ex As Exception
oTransaction.Rollback()
oMoveDirectory = args.ErrorDirectory
_logger.Error(ex)
_logger.Error(ex, "File {0} was not processesd. Transaction rolled back.")
Finally
_filesystem.MoveTo(oFile.FullName, oMoveDirectory)
oConnection.Close()
'_filesystem.MoveTo(oFile.FullName, oMoveDirectory)
_logger.Info("Finished processing file {0}", oFile.Name)
End Try
Next
End If

View File

@@ -36,6 +36,10 @@ Public Class PropertyValues
Obj = oInfo.GetValue(Obj, Nothing)
If IsNothing(Obj) Then
Return Nothing
End If
If oHasIndex Then
Obj = Obj(0)
End If

View File

@@ -84,6 +84,7 @@
<Compile Include="My Project\AssemblyInfo.vb" />
</ItemGroup>
<ItemGroup>
<Reference Include="FirebirdSql.Data.FirebirdClient, Version=6.4.0.0, Culture=neutral, PublicKeyToken=3750abcc3150b00c" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
<HintPath>..\packages\NLog.4.5.11\lib\net45\NLog.dll</HintPath>