EDMIService: first working version with relations

This commit is contained in:
Jonathan Jenne 2020-12-14 16:48:15 +01:00
parent 8a0b849479
commit 7b035bd3f7

View File

@ -27,36 +27,66 @@ Public Class JobListener
End Sub
Public Sub ReplaceExistingTable(Name As String, Table As DataTable, DataSet As DataSet, Optional ChildTable As DataTable = Nothing)
Dim oDatatableNameTemp As String = Name & "-TEMP"
Try
Dim oDatatableNameTemp As String = Name & "-TEMP"
_Logger.Debug("DataTable [{0}] exists, renaming and replacing in DataSet", Name)
' Rename the new table, add TEMP suffix
Table.TableName = oDatatableNameTemp
_Logger.Debug("DataTable [{0}] exists, renaming and replacing in DataSet", Name)
' If child table exists, remove all connections to it
If ChildTable IsNot Nothing Then
' Get name for relations and constraints
Dim oRelationName = GetRelationName(Name, ChildTable.TableName)
' Rename the new table, add TEMP suffix
_Logger.Debug("Renaming new table [{0}] to [{1}]", Name, oDatatableNameTemp)
Table.TableName = oDatatableNameTemp
' Remove the relation
Dim oRelation As DataRelation = DataSet.Relations.Item(oRelationName)
DataSet.Relations.Remove(oRelation)
' If child table exists, remove all connections to it
If ChildTable IsNot Nothing Then
_Logger.Debug("Removing relations/constraints on [{0}] and [{1}]", ChildTable.TableName, Name)
' Remove the constraint
Dim oConstraint As Constraint = ChildTable.Constraints.Item(oRelationName)
ChildTable.Constraints.Remove(oConstraint)
End If
' Remove relations/constraints on child table
Dim oChildTable As DataTable = DataSet.Tables.Item(ChildTable.TableName)
If oChildTable IsNot Nothing Then
oChildTable.Constraints.Clear()
oChildTable.ChildRelations.Clear()
End If
' Remove the temp table if it exists
If DataSet.Tables.Contains(oDatatableNameTemp) Then
DataSet.Tables.Remove(Table)
End If
' Remove relations/constraints on parent table
Dim oParentTable As DataTable = DataSet.Tables.Item(Name)
If oParentTable IsNot Nothing Then
oParentTable.Constraints.Clear()
oParentTable.ChildRelations.Clear()
End If
End If
' Add the new table to the dataset
DataSet.Tables.Add(Table)
' Remove the temp table if it exists
If DataSet.Tables.Contains(oDatatableNameTemp) Then
_Logger.Debug("Removing Table [{0}]", oDatatableNameTemp)
' Rename the new table
DataSet.Tables.Item(oDatatableNameTemp).TableName = Name
DataSet.Tables.Item(oDatatableNameTemp).ChildRelations.Clear()
DataSet.Tables.Item(oDatatableNameTemp).Constraints.Clear()
DataSet.Tables.Remove(oDatatableNameTemp)
Else
_Logger.Debug("Table [{0}] does not exist, skipping removal.", oDatatableNameTemp)
End If
' Remove the current Table
If DataSet.Tables.Contains(Name) Then
_Logger.Debug("Removing Table [{0}]", Name)
DataSet.Tables.Item(Name).Constraints.Clear()
DataSet.Tables.Remove(Name)
Else
_Logger.Debug("Table [{0}] does not exist, skipping removal.", Name)
End If
' Add the new table to the dataset
_Logger.Debug("Adding Table [{0}] to Dataset", Table.TableName)
DataSet.Tables.Add(Table)
' Rename the new table
_Logger.Debug("Renaming new table [{0}] to [{1}]", oDatatableNameTemp, Name)
DataSet.Tables.Item(oDatatableNameTemp).TableName = Name
Catch ex As Exception
_Logger.Error(ex)
Throw ex
End Try
End Sub
Public Sub AddNewTable(Name As String, Table As DataTable, DataSet As DataSet)
@ -118,6 +148,9 @@ Public Class JobListener
Dim oDetailId As Integer = DetailRow.Item("GUID")
Dim oDatatableNameTemp As String = oName & "-TEMP"
' Used for debugging relations and constraints
'ListTables(Dataset)
If Dataset.Tables.Contains(oName) Then
' Replace existing table
If Result.ChildTable IsNot Nothing Then
@ -153,6 +186,25 @@ Public Class JobListener
End Try
End Sub
Private Sub ListTables(dataset As DataSet)
Dim oIndex As Integer = 1
For Each oTable As DataTable In dataset.Tables
_Logger.Debug("Table: [{0}] ({1})", oTable.TableName, oIndex)
_Logger.Debug("-> Listing Constraints for [{0}]:", oTable.TableName)
For Each oConstraint As Constraint In oTable.Constraints
_Logger.Debug("---> Constraint: [{0}]", oConstraint.ConstraintName)
Next
_Logger.Debug("-> Listing Child-Relations for [{0}]:", oTable.TableName)
For Each oRelation As DataRelation In oTable.ChildRelations
_Logger.Debug("---> Relation: [{0}] ", oRelation.RelationName)
Next
oIndex += 1
Next
End Sub
Public Overrides Function JobWasExecuted(context As IJobExecutionContext, jobException As JobExecutionException, Optional cancellationToken As CancellationToken = Nothing) As Task
Dim oDetailRow As DataRow = context.MergedJobDataMap.Item("CronJobDetails")