diff --git a/GUIs.Test.TestGUI/App.config b/GUIs.Test.TestGUI/App.config index 428eeb20..901f8a79 100644 --- a/GUIs.Test.TestGUI/App.config +++ b/GUIs.Test.TestGUI/App.config @@ -1,24 +1,36 @@ - + - -
+ +
- + - + - + - + - \ No newline at end of file + + + + + + + + + + + + + diff --git a/GUIs.Test.TestGUI/My Project/Application.Designer.vb b/GUIs.Test.TestGUI/My Project/Application.Designer.vb index 786811bc..ac66efcf 100644 --- a/GUIs.Test.TestGUI/My Project/Application.Designer.vb +++ b/GUIs.Test.TestGUI/My Project/Application.Designer.vb @@ -32,7 +32,7 @@ Namespace My _ Protected Overrides Sub OnCreateMainForm() - Me.MainForm = Global.TestGUI.Form1 + Me.MainForm = Global.TestGUI.frmStart End Sub End Class End Namespace diff --git a/GUIs.Test.TestGUI/My Project/Application.myapp b/GUIs.Test.TestGUI/My Project/Application.myapp index 0f12f323..a1da81d5 100644 --- a/GUIs.Test.TestGUI/My Project/Application.myapp +++ b/GUIs.Test.TestGUI/My Project/Application.myapp @@ -1,7 +1,7 @@  true - Form1 + frmStart false 0 true diff --git a/GUIs.Test.TestGUI/My Project/Resources.Designer.vb b/GUIs.Test.TestGUI/My Project/Resources.Designer.vb index 6d555d65..fa5ddfea 100644 --- a/GUIs.Test.TestGUI/My Project/Resources.Designer.vb +++ b/GUIs.Test.TestGUI/My Project/Resources.Designer.vb @@ -1,40 +1,41 @@ '------------------------------------------------------------------------------ ' -' This code was generated by a tool. -' Runtime Version:4.0.30319.42000 +' Dieser Code wurde von einem Tool generiert. +' Laufzeitversion:4.0.30319.42000 ' -' Changes to this file may cause incorrect behavior and will be lost if -' the code is regenerated. +' Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn +' der Code erneut generiert wird. ' '------------------------------------------------------------------------------ Option Strict On Option Explicit On +Imports System Namespace My.Resources - - 'This class was auto-generated by the StronglyTypedResourceBuilder - 'class via a tool like ResGen or Visual Studio. - 'To add or remove a member, edit your .ResX file then rerun ResGen - 'with the /str option, or rebuild your VS project. + + 'Diese Klasse wurde von der StronglyTypedResourceBuilder automatisch generiert + '-Klasse über ein Tool wie ResGen oder Visual Studio automatisch generiert. + 'Um einen Member hinzuzufügen oder zu entfernen, bearbeiten Sie die .ResX-Datei und führen dann ResGen + 'mit der /str-Option erneut aus, oder Sie erstellen Ihr VS-Projekt neu. ''' - ''' A strongly-typed resource class, for looking up localized strings, etc. + ''' Eine stark typisierte Ressourcenklasse zum Suchen von lokalisierten Zeichenfolgen usw. ''' - _ + _ Friend Module Resources - + Private resourceMan As Global.System.Resources.ResourceManager - + Private resourceCulture As Global.System.Globalization.CultureInfo - + ''' - ''' Returns the cached ResourceManager instance used by this class. + ''' Gibt die zwischengespeicherte ResourceManager-Instanz zurück, die von dieser Klasse verwendet wird. ''' - _ + _ Friend ReadOnly Property ResourceManager() As Global.System.Resources.ResourceManager Get If Object.ReferenceEquals(resourceMan, Nothing) Then @@ -44,17 +45,17 @@ Namespace My.Resources Return resourceMan End Get End Property - + ''' - ''' Overrides the current thread's CurrentUICulture property for all - ''' resource lookups using this strongly typed resource class. + ''' Überschreibt die CurrentUICulture-Eigenschaft des aktuellen Threads für alle + ''' Ressourcenzuordnungen, die diese stark typisierte Ressourcenklasse verwenden. ''' - _ + _ Friend Property Culture() As Global.System.Globalization.CultureInfo Get Return resourceCulture End Get - Set(ByVal value As Global.System.Globalization.CultureInfo) + Set resourceCulture = value End Set End Property diff --git a/GUIs.Test.TestGUI/My Project/Settings.Designer.vb b/GUIs.Test.TestGUI/My Project/Settings.Designer.vb index cc921e74..2fc680a8 100644 --- a/GUIs.Test.TestGUI/My Project/Settings.Designer.vb +++ b/GUIs.Test.TestGUI/My Project/Settings.Designer.vb @@ -15,7 +15,7 @@ Option Explicit On Namespace My _ Partial Friend NotInheritable Class MySettings Inherits Global.System.Configuration.ApplicationSettingsBase diff --git a/GUIs.Test.TestGUI/TestGUI.vbproj b/GUIs.Test.TestGUI/TestGUI.vbproj index 5e1a22d8..729364fc 100644 --- a/GUIs.Test.TestGUI/TestGUI.vbproj +++ b/GUIs.Test.TestGUI/TestGUI.vbproj @@ -11,8 +11,9 @@ TestGUI 512 WindowsForms - v4.6.1 + v4.7.2 true + AnyCPU @@ -63,15 +64,38 @@ bin\Debug\DigitalData.Controls.LookupGrid.dll + + ..\packages\Microsoft.Extensions.Logging.Abstractions.2.1.1\lib\netstandard2.0\Microsoft.Extensions.Logging.Abstractions.dll + ..\packages\NLog.4.7.5\lib\net45\NLog.dll + + ..\packages\Quartz.3.2.3\lib\net461\Quartz.dll + + + ..\packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll + + + ..\packages\System.Diagnostics.DiagnosticSource.4.7.1\lib\net46\System.Diagnostics.DiagnosticSource.dll + + + ..\packages\System.Memory.4.5.4\lib\net461\System.Memory.dll + + + + ..\packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll + + + ..\packages\System.Runtime.CompilerServices.Unsafe.4.5.3\lib\net461\System.Runtime.CompilerServices.Unsafe.dll + + @@ -97,16 +121,16 @@ - - ConfigTest.vb + + frmConfigTest.vb - + Form - - FolderWatcher.vb + + frmFolderWatcher.vb - + Form @@ -116,6 +140,18 @@ Form1.vb Form + + frmRelations.vb + + + Form + + + frmStart.vb + + + Form + True @@ -133,15 +169,21 @@ - - ConfigTest.vb + + frmConfigTest.vb - - FolderWatcher.vb + + frmFolderWatcher.vb Form1.vb + + frmRelations.vb + + + frmStart.vb + VbMyResourcesResXFileCodeGenerator @@ -172,6 +214,10 @@ {44982f9b-6116-44e2-85d0-f39650b1ef99} Config + + {eaf0ea75-5fa7-485d-89c7-b2d843b03a96} + Database + {991d0231-4623-496d-8bd0-9ca906029cbc} Filesystem @@ -184,6 +230,10 @@ {4c86df8f-a280-40d4-85b0-10b1bf66c15c} Windream + + {a8c3f298-76ab-4359-ab3c-986e313b4336} + EDMIService + \ No newline at end of file diff --git a/GUIs.Test.TestGUI/ConfigTest.Designer.vb b/GUIs.Test.TestGUI/frmConfigTest.Designer.vb similarity index 98% rename from GUIs.Test.TestGUI/ConfigTest.Designer.vb rename to GUIs.Test.TestGUI/frmConfigTest.Designer.vb index 5d46d129..8a8759c6 100644 --- a/GUIs.Test.TestGUI/ConfigTest.Designer.vb +++ b/GUIs.Test.TestGUI/frmConfigTest.Designer.vb @@ -1,5 +1,5 @@  _ -Partial Class ConfigTest +Partial Class frmConfigTest Inherits System.Windows.Forms.Form 'Das Formular überschreibt den Löschvorgang, um die Komponentenliste zu bereinigen. diff --git a/GUIs.Test.TestGUI/ConfigTest.resx b/GUIs.Test.TestGUI/frmConfigTest.resx similarity index 100% rename from GUIs.Test.TestGUI/ConfigTest.resx rename to GUIs.Test.TestGUI/frmConfigTest.resx diff --git a/GUIs.Test.TestGUI/ConfigTest.vb b/GUIs.Test.TestGUI/frmConfigTest.vb similarity index 96% rename from GUIs.Test.TestGUI/ConfigTest.vb rename to GUIs.Test.TestGUI/frmConfigTest.vb index 356bc62a..493f74e6 100644 --- a/GUIs.Test.TestGUI/ConfigTest.vb +++ b/GUIs.Test.TestGUI/frmConfigTest.vb @@ -1,7 +1,7 @@ Imports DigitalData.Modules.Config Imports DigitalData.Modules.Logging -Public Class ConfigTest +Public Class frmConfigTest Private _LogConfig As LogConfig Private _config As ConfigManager(Of Config) Private _FilePath As String = IO.Path.Combine(Application.LocalUserAppDataPath, "UserConfig.xml") diff --git a/GUIs.Test.TestGUI/FolderWatcher.Designer.vb b/GUIs.Test.TestGUI/frmFolderWatcher.Designer.vb similarity index 98% rename from GUIs.Test.TestGUI/FolderWatcher.Designer.vb rename to GUIs.Test.TestGUI/frmFolderWatcher.Designer.vb index a0c1cbba..60602bad 100644 --- a/GUIs.Test.TestGUI/FolderWatcher.Designer.vb +++ b/GUIs.Test.TestGUI/frmFolderWatcher.Designer.vb @@ -1,5 +1,5 @@  -Partial Class FolderWatcher +Partial Class frmFolderWatcher Inherits System.Windows.Forms.Form 'Das Formular überschreibt den Löschvorgang, um die Komponentenliste zu bereinigen. diff --git a/GUIs.Test.TestGUI/FolderWatcher.resx b/GUIs.Test.TestGUI/frmFolderWatcher.resx similarity index 100% rename from GUIs.Test.TestGUI/FolderWatcher.resx rename to GUIs.Test.TestGUI/frmFolderWatcher.resx diff --git a/GUIs.Test.TestGUI/FolderWatcher.vb b/GUIs.Test.TestGUI/frmFolderWatcher.vb similarity index 96% rename from GUIs.Test.TestGUI/FolderWatcher.vb rename to GUIs.Test.TestGUI/frmFolderWatcher.vb index aa1dc9c3..f46a3b28 100644 --- a/GUIs.Test.TestGUI/FolderWatcher.vb +++ b/GUIs.Test.TestGUI/frmFolderWatcher.vb @@ -4,7 +4,7 @@ Imports DigitalData.Modules.Filesystem Imports DigitalData.Modules.Filesystem.FileWatcherFilters Imports DigitalData.Modules.Logging -Public Class FolderWatcher +Public Class frmFolderWatcher Private _LogConfig As LogConfig Private _Logger As Logger diff --git a/GUIs.Test.TestGUI/frmRelations.Designer.vb b/GUIs.Test.TestGUI/frmRelations.Designer.vb new file mode 100644 index 00000000..b6dea2be --- /dev/null +++ b/GUIs.Test.TestGUI/frmRelations.Designer.vb @@ -0,0 +1,37 @@ + _ +Partial Class frmRelations + Inherits System.Windows.Forms.Form + + 'Das Formular überschreibt den Löschvorgang, um die Komponentenliste zu bereinigen. + _ + Protected Overrides Sub Dispose(ByVal disposing As Boolean) + Try + If disposing AndAlso components IsNot Nothing Then + components.Dispose() + End If + Finally + MyBase.Dispose(disposing) + End Try + End Sub + + 'Wird vom Windows Form-Designer benötigt. + Private components As System.ComponentModel.IContainer + + 'Hinweis: Die folgende Prozedur ist für den Windows Form-Designer erforderlich. + 'Das Bearbeiten ist mit dem Windows Form-Designer möglich. + 'Das Bearbeiten mit dem Code-Editor ist nicht möglich. + _ + Private Sub InitializeComponent() + Me.SuspendLayout() + ' + 'frmRelations + ' + Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!) + Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font + Me.ClientSize = New System.Drawing.Size(800, 450) + Me.Name = "frmRelations" + Me.Text = "frmRelations" + Me.ResumeLayout(False) + + End Sub +End Class diff --git a/GUIs.Test.TestGUI/frmRelations.resx b/GUIs.Test.TestGUI/frmRelations.resx new file mode 100644 index 00000000..1af7de15 --- /dev/null +++ b/GUIs.Test.TestGUI/frmRelations.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/GUIs.Test.TestGUI/frmRelations.vb b/GUIs.Test.TestGUI/frmRelations.vb new file mode 100644 index 00000000..39a2d208 --- /dev/null +++ b/GUIs.Test.TestGUI/frmRelations.vb @@ -0,0 +1,30 @@ +Imports DigitalData.Modules.Database +Imports DigitalData.Modules.Logging +Imports DigitalData.Services.EDMIService + +Public Class frmRelations + Private DB As MSSQLServer + Private LogConfig As LogConfig + + Private Sub frmRelations_Load(sender As Object, e As EventArgs) Handles MyBase.Load + LogConfig = New LogConfig(LogConfig.PathType.CustomPath, Application.StartupPath) + DB = New MSSQLServer(LogConfig, "Server=SDD-VMP04-SQL17\DD_DEVELOP01;Database=DD_ECM_TEST;User Id=sa;Password=dd;") + + Dim oDataSet As New DataSet() + + Dim oUsers = DB.GetDatatable("SELECT * FROM TBDD_USER") + oUsers.TableName = "TBDD_USER" + Dim oGroupUser = DB.GetDatatable("SELECT * FROM TBDD_GROUPS_USER") + oGroupUser.TableName = "TBDD_GROUPS_USER" + + Dim oCronDetails As DataTable = DB.GetDatatable("SELECT * FROM TBAPPSERV_CRON_DETAIL WHERE DT_NAME = 'TBDD_USER'") + + Dim oListener As New DigitalData.Services.EDMIService.JobListener(LogConfig, DB, oDataSet) + oListener.SaveDataTables(New DigitalData.Services.EDMIService.JobResult() With { + .Table = oUsers, + .TableRelationColumn = "GUID", + .ChildTable = oGroupUser, + .ChildRelationColumn = "USER_ID" + }, oCronDetails.Rows.Item(0)) + End Sub +End Class \ No newline at end of file diff --git a/GUIs.Test.TestGUI/frmStart.Designer.vb b/GUIs.Test.TestGUI/frmStart.Designer.vb new file mode 100644 index 00000000..b5fac931 --- /dev/null +++ b/GUIs.Test.TestGUI/frmStart.Designer.vb @@ -0,0 +1,50 @@ + +Partial Class frmStart + Inherits System.Windows.Forms.Form + + 'Das Formular überschreibt den Löschvorgang, um die Komponentenliste zu bereinigen. + + Protected Overrides Sub Dispose(ByVal disposing As Boolean) + Try + If disposing AndAlso components IsNot Nothing Then + components.Dispose() + End If + Finally + MyBase.Dispose(disposing) + End Try + End Sub + + 'Wird vom Windows Form-Designer benötigt. + Private components As System.ComponentModel.IContainer + + 'Hinweis: Die folgende Prozedur ist für den Windows Form-Designer erforderlich. + 'Das Bearbeiten ist mit dem Windows Form-Designer möglich. + 'Das Bearbeiten mit dem Code-Editor ist nicht möglich. + + Private Sub InitializeComponent() + Me.Button1 = New System.Windows.Forms.Button() + Me.SuspendLayout() + ' + 'Button1 + ' + Me.Button1.Location = New System.Drawing.Point(12, 12) + Me.Button1.Name = "Button1" + Me.Button1.Size = New System.Drawing.Size(236, 55) + Me.Button1.TabIndex = 0 + Me.Button1.Text = "Relations" + Me.Button1.UseVisualStyleBackColor = True + ' + 'frmStart + ' + Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!) + Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font + Me.ClientSize = New System.Drawing.Size(800, 450) + Me.Controls.Add(Me.Button1) + Me.Name = "frmStart" + Me.Text = "frmStart" + Me.ResumeLayout(False) + + End Sub + + Friend WithEvents Button1 As Button +End Class diff --git a/GUIs.Test.TestGUI/frmStart.resx b/GUIs.Test.TestGUI/frmStart.resx new file mode 100644 index 00000000..1af7de15 --- /dev/null +++ b/GUIs.Test.TestGUI/frmStart.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/GUIs.Test.TestGUI/frmStart.vb b/GUIs.Test.TestGUI/frmStart.vb new file mode 100644 index 00000000..5033e556 --- /dev/null +++ b/GUIs.Test.TestGUI/frmStart.vb @@ -0,0 +1,5 @@ +Public Class frmStart + Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click + frmRelations.Show() + End Sub +End Class \ No newline at end of file diff --git a/GUIs.Test.TestGUI/packages.config b/GUIs.Test.TestGUI/packages.config index 6f6bc401..9a1ba8fc 100644 --- a/GUIs.Test.TestGUI/packages.config +++ b/GUIs.Test.TestGUI/packages.config @@ -1,4 +1,11 @@  + + + + + + + \ No newline at end of file diff --git a/Service.EDMIService/App.config b/Service.EDMIService/App.config index add3025c..4d9ba156 100644 --- a/Service.EDMIService/App.config +++ b/Service.EDMIService/App.config @@ -1,5 +1,7 @@  + + @@ -32,11 +34,11 @@ maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"> - diff --git a/Service.EDMIService/EDMIService.vbproj b/Service.EDMIService/EDMIService.vbproj index cf51d68f..0a905b4a 100644 --- a/Service.EDMIService/EDMIService.vbproj +++ b/Service.EDMIService/EDMIService.vbproj @@ -134,6 +134,7 @@ + Component diff --git a/Service.EDMIService/My Project/Settings.settings b/Service.EDMIService/My Project/Settings.settings index 85b890b3..f7f176ac 100644 --- a/Service.EDMIService/My Project/Settings.settings +++ b/Service.EDMIService/My Project/Settings.settings @@ -1,7 +1,5 @@  - - - + - + \ No newline at end of file diff --git a/Service.EDMIService/Scheduler/DatatableJob.vb b/Service.EDMIService/Scheduler/DatatableJob.vb index a2367906..ebf7d330 100644 --- a/Service.EDMIService/Scheduler/DatatableJob.vb +++ b/Service.EDMIService/Scheduler/DatatableJob.vb @@ -1,5 +1,9 @@ -Imports DigitalData.Modules.Database +Option Explicit On + +Imports DigitalData.Modules.Database +Imports DigitalData.Modules.Language.Utils Imports DigitalData.Modules.Logging + Imports Quartz Public Class DatatableJob @@ -9,16 +13,16 @@ Public Class DatatableJob Dim oJobData = context.MergedJobDataMap Dim oLogConfig As LogConfig = oJobData.Item("LogConfig") Dim oLogger As Logger = oLogConfig.GetLogger() + Dim oDetailRow As DataRow = oJobData.Item("CronJobDetails") + Dim oDatatableName As String = NotNull(oDetailRow.Item("DT_NAME"), String.Empty) Try Dim oCronJobTitle As String = oJobData.Item("CronJobTitle") - Dim oDetailRow As DataRow = oJobData.Item("CronJobDetails") Dim oMSSQL As MSSQLServer = oJobData.Item("MSSQL") - Dim oConnectionId As Integer = oDetailRow.Item("CON_ID") - Dim oTitle As String = oDetailRow.Item("TITLE") - Dim oDatatableName As String = oDetailRow.Item("DT_NAME") - Dim oSQL As String = oDetailRow.Item("COMMAND") + Dim oConnectionId As Integer = NotNull(oDetailRow.Item("CON_ID"), String.Empty) + Dim oTitle As String = NotNull(oDetailRow.Item("TITLE"), String.Empty) + Dim oSQL As String = NotNull(oDetailRow.Item("COMMAND"), String.Empty) oLogger.Debug("Running Command-Job [{0}]", oTitle) oLogger.Debug("Datatable Name: {0}", oDatatableName) @@ -26,14 +30,35 @@ Public Class DatatableJob Dim oConnectionString = oMSSQL.Get_ConnectionStringforID(oConnectionId) - Dim oResult = oMSSQL.GetDatatableWithConnection(oSQL, oConnectionString) - oResult.TableName = oDatatableName - oLogger.Debug("Result Datatable contains [{0}] rows", oResult.Rows.Count) + Dim oTable = oMSSQL.GetDatatableWithConnection(oSQL, oConnectionString) + oTable.TableName = oDatatableName + oLogger.Debug("Result Datatable [{0}] contains [{1}] rows", oTable.TableName, oTable.Rows.Count) + + Dim oResult = New JobResult() With { + .Table = oTable + } + + Dim oChildTableNAme As String = NotNull(oDetailRow.Item("CHILD_DT_NAME"), String.Empty) + + If oChildTableNAme <> String.Empty Then + Dim oParentColumn As String = NotNull(oDetailRow.Item("DT_COLUMN"), String.Empty) + Dim oChildColumn As String = NotNull(oDetailRow.Item("CHILD_DT_COLUMN"), String.Empty) + oLogger.Debug("Child Datatable [{0}] defined, Relation: Parent [{1}] -> Child [{2}]", oChildTableName, oParentColumn, oChildColumn) + + Dim oChildTable As DataTable = oMSSQL.GetDatatableWithConnection($"SELECT * FROM {oChildTableName}", oConnectionString) + oChildTable.TableName = oChildTableName + oLogger.Debug("Child Datatable [{0}] contains [{1}] rows", oChildTable.TableName, oChildTable.Rows.Count) + + oResult.ChildTable = oChildTable + oResult.ChildRelationColumn = oChildColumn + oResult.TableRelationColumn = oParentColumn + End If ' Das Ergebnis speichern context.Result = oResult Catch ex As Exception - oLogger.Warn("Unhandled exception while executing SQL for Datatable {}") + oLogger.Error(ex) + oLogger.Warn("Unhandled exception while executing SQL for Datatable {0}", oDatatableName) End Try Return Task.FromResult(True) diff --git a/Service.EDMIService/Scheduler/JobListener.vb b/Service.EDMIService/Scheduler/JobListener.vb index 93c9ecb3..4e8ed886 100644 --- a/Service.EDMIService/Scheduler/JobListener.vb +++ b/Service.EDMIService/Scheduler/JobListener.vb @@ -1,5 +1,8 @@ -Imports System.Threading +Option Explicit On + +Imports System.Threading Imports DigitalData.Modules.Database +Imports DigitalData.Modules.Language Imports DigitalData.Modules.Logging Imports Quartz Imports Quartz.Listener @@ -23,34 +26,120 @@ Public Class JobListener Dataset = ResultDataSet End Sub - Public Overrides Function JobWasExecuted(context As IJobExecutionContext, jobException As JobExecutionException, Optional cancellationToken As CancellationToken = Nothing) As Task - Try - Dim oDataTable As DataTable = context.Result - Dim oDetailRow As DataRow = context.MergedJobDataMap.Item("CronJobDetails") - Dim oDatatableName As String = oDetailRow.Item("DT_NAME") - Dim oDetailId As Integer = oDetailRow.Item("GUID") - Dim oDatatableNameTemp As String = oDatatableName & "-TEMP" + Public Sub ReplaceExistingTable(Name As String, Table As DataTable, DataSet As DataSet) + Dim oDatatableNameTemp As String = Name & "-TEMP" - If Dataset.Tables.Contains(oDatatableName) Then - _Logger.Debug("DataTable [{0}] exists, renaming and replacing in DataSet", oDatatableName) - ' Rename the new table, add TEMP suffix - oDataTable.TableName = oDatatableNameTemp - ' Add the new table to the dataset - Dataset.Tables.Add(oDataTable) - ' Remove the old table - Dataset.Tables.Remove(oDatatableName) - ' Rename the new table - Dataset.Tables.Item(oDatatableNameTemp).TableName = oDatatableName + _Logger.Debug("DataTable [{0}] exists, renaming and replacing in DataSet", Name) + ' Rename the new table, add TEMP suffix + Table.TableName = oDatatableNameTemp + ' Add the new table to the dataset + DataSet.Tables.Add(Table) + ' Remove the old table + DataSet.Tables.Remove(Name) + ' Rename the new table + DataSet.Tables.Item(oDatatableNameTemp).TableName = Name + End Sub + + Public Sub AddNewTable(Name As String, Table As DataTable, DataSet As DataSet) + _Logger.Debug("DataTable [{0}] does not exist, adding to DataSet", Name) + + DataSet.Tables.Add(Table) + End Sub + + Public Sub AddRelation(ParentTableName As String, ParentColumnName As String, ChildTableName As String, ChildColumnName As String) + Dim oChild As DataTable = Dataset.Tables.Item(ChildTableName) + Dim oParent As DataTable = Dataset.Tables.Item(ParentTableName) + + Dim oRelationName As String = $"{ParentTableName}-{ChildTableName}" + Dim oParentColumn As DataColumn = oParent.Columns.Item(ParentColumnName) + Dim oChildColumn As DataColumn = oChild.Columns.Item(ChildColumnName) + + _Logger.Debug("New Relation: {0}/{1} => {2}/{3}", ParentTableName, ParentColumnName, ChildTableName, ChildColumnName) + Try + _Logger.Debug("Creating Relation [{0}]", oRelationName) + _Logger.Debug("ParentColumn exists: {0}", IsNothing(oParentColumn)) + _Logger.Debug("ChildColumn exists: {0}", IsNothing(oChildColumn)) + Dim oRelation As New DataRelation(oRelationName, oParentColumn, oChildColumn) + + _Logger.Debug("Adding Relation [{0}]", oRelationName) + Dataset.Relations.Add(oRelation) + + Catch ex As ArgumentNullException + _Logger.Error(ex) + _Logger.Warn("ArgumentNullException in AddRelation: {0}", ex.Message) + + Catch ex As DuplicateNameException + _Logger.Error(ex) + _Logger.Warn("DuplicateNameException in AddRelation: {0}", ex.Message) + + Catch ex As InvalidConstraintException + _Logger.Error(ex) + _Logger.Warn("DuplicateNameException in AddRelation: {0}", ex.Message) + + Catch ex As ArgumentException + _Logger.Error(ex) + _Logger.Warn("ArgumentException in AddRelation: {0}", ex.Message) + + Catch ex As Exception + _Logger.Error(ex) + _Logger.Warn("Exception in AddRelation: {0}", ex.Message) + + End Try + End Sub + + Public Sub SaveDataTables(Result As JobResult, DetailRow As DataRow) + Try + Dim oTable As DataTable = Result.Table + Dim oName As String = DetailRow.Item("DT_NAME") + Dim oDetailId As Integer = DetailRow.Item("GUID") + Dim oDatatableNameTemp As String = oName & "-TEMP" + + If Dataset.Tables.Contains(oName) Then + If Result.ChildTable IsNot Nothing Then + ReplaceExistingTable(Result.ChildTable.TableName, Result.ChildTable, Dataset) + End If + ReplaceExistingTable(oName, oTable, Dataset) + + If Result.ChildTable IsNot Nothing Then + Dim oRelation = Dataset.Relations.Item($"{oTable.TableName}-{Result.ChildTable.TableName}") + + If oRelation IsNot Nothing Then + Dataset.Relations.Remove(oRelation) + End If + + AddRelation(oName, Result.TableRelationColumn, Result.ChildTable.TableName, Result.ChildRelationColumn) + End If Else - _Logger.Debug("DataTable [{0}] does not exist, adding to DataSet", oDatatableName) - Dataset.Tables.Add(oDataTable) + AddNewTable(oName, oTable, Dataset) + + If Result.ChildTable IsNot Nothing Then + AddNewTable(Result.ChildTable.TableName, Result.ChildTable, Dataset) + + AddRelation(oName, Result.TableRelationColumn, Result.ChildTable.TableName, Result.ChildRelationColumn) + End If End If + _Logger.Debug("Listing Tables in DataSet") + For Each oDataTable As DataTable In Dataset.Tables + _Logger.Debug(oDataTable.TableName) + Next + + _Logger.Debug("Listing Relations in Dataset") + For Each oRelation As DataRelation In Dataset.Relations + _Logger.Debug(oRelation.RelationName) + Next + _MSSQL.ExecuteNonQuery($"INSERT INTO TBAPPSERV_CRON_DETAIL_HISTORY (DETAIL_ID) VALUES ({oDetailId})") Catch ex As Exception _Logger.Warn("Unexpected error in JobListener: {0}", ex.Message) _Logger.Error(ex) End Try + 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") + SaveDataTables(context.Result, oDetailRow) Return MyBase.JobWasExecuted(context, jobException, cancellationToken) End Function diff --git a/Service.EDMIService/Scheduler/JobResult.vb b/Service.EDMIService/Scheduler/JobResult.vb new file mode 100644 index 00000000..dfdfaf10 --- /dev/null +++ b/Service.EDMIService/Scheduler/JobResult.vb @@ -0,0 +1,6 @@ +Public Class JobResult + Public Table As DataTable + Public ChildTable As DataTable + Public TableRelationColumn As String + Public ChildRelationColumn As String +End Class