EDMIService: first working version with relations
This commit is contained in:
parent
8a0b849479
commit
7b035bd3f7
@ -27,36 +27,66 @@ Public Class JobListener
|
|||||||
End Sub
|
End Sub
|
||||||
|
|
||||||
Public Sub ReplaceExistingTable(Name As String, Table As DataTable, DataSet As DataSet, Optional ChildTable As DataTable = Nothing)
|
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)
|
_Logger.Debug("DataTable [{0}] exists, renaming and replacing in DataSet", Name)
|
||||||
' Rename the new table, add TEMP suffix
|
|
||||||
Table.TableName = oDatatableNameTemp
|
|
||||||
|
|
||||||
' If child table exists, remove all connections to it
|
' Rename the new table, add TEMP suffix
|
||||||
If ChildTable IsNot Nothing Then
|
_Logger.Debug("Renaming new table [{0}] to [{1}]", Name, oDatatableNameTemp)
|
||||||
' Get name for relations and constraints
|
Table.TableName = oDatatableNameTemp
|
||||||
Dim oRelationName = GetRelationName(Name, ChildTable.TableName)
|
|
||||||
|
|
||||||
' Remove the relation
|
' If child table exists, remove all connections to it
|
||||||
Dim oRelation As DataRelation = DataSet.Relations.Item(oRelationName)
|
If ChildTable IsNot Nothing Then
|
||||||
DataSet.Relations.Remove(oRelation)
|
_Logger.Debug("Removing relations/constraints on [{0}] and [{1}]", ChildTable.TableName, Name)
|
||||||
|
|
||||||
' Remove the constraint
|
' Remove relations/constraints on child table
|
||||||
Dim oConstraint As Constraint = ChildTable.Constraints.Item(oRelationName)
|
Dim oChildTable As DataTable = DataSet.Tables.Item(ChildTable.TableName)
|
||||||
ChildTable.Constraints.Remove(oConstraint)
|
If oChildTable IsNot Nothing Then
|
||||||
End If
|
oChildTable.Constraints.Clear()
|
||||||
|
oChildTable.ChildRelations.Clear()
|
||||||
|
End If
|
||||||
|
|
||||||
' Remove the temp table if it exists
|
' Remove relations/constraints on parent table
|
||||||
If DataSet.Tables.Contains(oDatatableNameTemp) Then
|
Dim oParentTable As DataTable = DataSet.Tables.Item(Name)
|
||||||
DataSet.Tables.Remove(Table)
|
If oParentTable IsNot Nothing Then
|
||||||
End If
|
oParentTable.Constraints.Clear()
|
||||||
|
oParentTable.ChildRelations.Clear()
|
||||||
|
End If
|
||||||
|
End If
|
||||||
|
|
||||||
' Add the new table to the dataset
|
' Remove the temp table if it exists
|
||||||
DataSet.Tables.Add(Table)
|
If DataSet.Tables.Contains(oDatatableNameTemp) Then
|
||||||
|
_Logger.Debug("Removing Table [{0}]", oDatatableNameTemp)
|
||||||
|
|
||||||
' Rename the new table
|
DataSet.Tables.Item(oDatatableNameTemp).ChildRelations.Clear()
|
||||||
DataSet.Tables.Item(oDatatableNameTemp).TableName = Name
|
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
|
End Sub
|
||||||
|
|
||||||
Public Sub AddNewTable(Name As String, Table As DataTable, DataSet As DataSet)
|
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 oDetailId As Integer = DetailRow.Item("GUID")
|
||||||
Dim oDatatableNameTemp As String = oName & "-TEMP"
|
Dim oDatatableNameTemp As String = oName & "-TEMP"
|
||||||
|
|
||||||
|
' Used for debugging relations and constraints
|
||||||
|
'ListTables(Dataset)
|
||||||
|
|
||||||
If Dataset.Tables.Contains(oName) Then
|
If Dataset.Tables.Contains(oName) Then
|
||||||
' Replace existing table
|
' Replace existing table
|
||||||
If Result.ChildTable IsNot Nothing Then
|
If Result.ChildTable IsNot Nothing Then
|
||||||
@ -153,6 +186,25 @@ Public Class JobListener
|
|||||||
End Try
|
End Try
|
||||||
End Sub
|
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
|
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")
|
Dim oDetailRow As DataRow = context.MergedJobDataMap.Item("CronJobDetails")
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user