15-12-2022

This commit is contained in:
Jonathan Jenne
2022-12-15 11:53:59 +01:00
parent 8d6d81f488
commit e4c5658c13
31 changed files with 1020 additions and 274 deletions

View File

@@ -16,8 +16,8 @@ Namespace WCF
<OperationContract>
Function GetJobStatus() As GetJobStatusResponse
'TODO: implement
Function RunJob() As RunJobResponse
<OperationContract>
Function RunJob(pdata As RunJobRequest) As RunJobResponse
<OperationContract>
Function UpdateJob(pData As UpdateJobRequest) As UpdateJobResponse

View File

@@ -57,7 +57,7 @@ Namespace WCF
Return oMethod.Run(pData)
End Function
Public Function RunJob() As RunJob.RunJobResponse Implements IJobRunner.RunJob
Public Function RunJob(pData As RunJob.RunJobRequest) As RunJob.RunJobResponse Implements IJobRunner.RunJob
'Dim oMethod As New RunJob.RunJobMethod(LogConfig, Database, State, Scheduler)
'Return oMethod.Run(pData)
End Function

View File

@@ -13,36 +13,22 @@ Public Class GetJobConfig
End Sub
Public Function Run() As GetJobConfigResponse
Return New GetJobConfigResponse With {
.JobTypes = State.JobTypes,
.JobDefinitions = State.JobDefinitions,
.ProfileDefinitions = New GetJobConfigResponse.ProfileDefinitionConfig With {
.ImportProfiles = State.ProfileDefintions.ImportProfiles.
Select(AddressOf FillJobForProfile).
Select(AddressOf FillStepsForProfile).
ToList()
},
.WindreamObjectTypes = State.ObjectTypes
}
Try
Return New GetJobConfigResponse With {
.JobTypes = State.JobTypes,
.JobDefinitions = State.JobDefinitions,
.ProfileDefinitions = New GetJobConfigResponse.ProfileDefinitionConfig With {
.ImportProfiles = State.ProfileDefintions.ImportProfiles
},
.WindreamObjectTypes = State.ObjectTypes
}
Catch ex As Exception
Logger.Error(ex)
Return New GetJobConfigResponse() With {.OK = False, .ErrorMessage = ex.Message}
End Try
End Function
Private Function FillJobForProfile(pProfile As ImportProfile) As ImportProfile
Dim oJob = State.JobDefinitions.
Where(Function(job) job.Id = pProfile.JobId).
FirstOrDefault()
pProfile.Job = oJob
Return pProfile
End Function
Private Function FillStepsForProfile(pProfile As ImportProfile) As ImportProfile
Dim oSteps = State.ProfileDefintions.ImportProfileSteps.
Where(Function(s) s.ProfileId = pProfile.Id).
ToList()
pProfile.Steps = oSteps
Return pProfile
End Function
End Class
Public Class GetJobConfigResponse
@@ -61,6 +47,7 @@ Public Class GetJobConfig
Public Property ProfileDefinitions As New ProfileDefinitionConfig
Public Class ProfileDefinitionConfig
<DataMember>
Public Property ImportProfiles As List(Of ImportProfile)
End Class
End Class

View File

@@ -15,7 +15,10 @@ Public Class RunJob
End Sub
Public Async Function Run(pData As RunJobRequest) As Task(Of RunJobResponse)
Await Scheduler.ScheduleJob(pData.JobId)
' This is calling the async function ScheduleJob synchronous, so that we can return a value to the caller
' This means that the job might or might not be scheduled when this method returns.
Task.Run(Function() Scheduler.ScheduleJob(pData.JobId))
Return New RunJobResponse()
End Function

View File

@@ -30,9 +30,15 @@ Public Class UpdateProfile
Return New UpdateProfileResponse With {.OK = False}
End If
Logger.Debug("Executing Action [{0}]", pData.Action)
Select Case pData.Action
Case UpdateProfileRequest.UpdateProfileAction.Update
oResponse = DoUpdateImportProfile(pData)
If DoUpdateImportProfile(pData) Then
oResponse = UpdateImportProfileSteps(pData)
Else
oResponse = False
End If
Case UpdateProfileRequest.UpdateProfileAction.Create
oResponse = DoCreateImportProfile(pData)
@@ -42,6 +48,8 @@ Public Class UpdateProfile
End Select
Logger.Debug("Action successful: [{0}]", oResponse)
If oResponse Then
Scheduler.Reload()
Else
@@ -133,8 +141,153 @@ Public Class UpdateProfile
Return Database.ExecuteNonQuery(oCommand)
End Function
Private Function UpdateImportProfileSteps(pData As UpdateProfileRequest) As Boolean
Dim oProfile = pData.ImportProfile
Dim oSQL As String = "UPDATE"
' Get the existing steps from the database
Dim oExistingStepsSQL = $"SELECT GUID FROM TBECM_JR_FIW_STEP WHERE PROFILE_ID = {oProfile.Id}"
Dim oExistingSteps = Database.GetDatatable(oExistingStepsSQL)
Dim oExistingStepsIds = oExistingSteps.Rows.Cast(Of DataRow).Select(Of Integer)(Function(r) r.Item("GUID")).ToList()
Logger.Debug("Existing steps: [{0}]", oExistingStepsIds.Count)
' Get the updated steps from the sent data
Dim oUpdatedSteps = oProfile.Steps
Dim oUpdatedStepsIds = oUpdatedSteps.Select(Function(s) s.Id).ToList()
Logger.Debug("Updated steps: [{0}]", oUpdatedStepsIds.Count)
' Calculate differences
' =======================
' These ids did not exist in the database but in the sent data,
' they will be created.
Dim oNewIds = oUpdatedStepsIds.Except(oExistingStepsIds).ToList()
Logger.Debug("Steps that will be created: [{0}]", oNewIds.Count)
Dim oCreateSuccessful = DoCreateImportProfileSteps(pData, oNewIds)
Logger.Debug("Create Successful: [{0}]", oCreateSuccessful)
' These ids existed in the database but not in the sent data,
' they will be deleted.
Dim oDeletedIds = oExistingStepsIds.Except(oUpdatedStepsIds).ToList()
Logger.Debug("Steps that will be deleted: [{0}]", oDeletedIds.Count)
Dim oDeleteSuccessful = DoDeleteImportProfileSteps(pData, oDeletedIds)
Logger.Debug("Delete Successful: [{0}]", oDeleteSuccessful)
' These ids exist in both datasets, so they were not deleted or created,
' they will be updated in case their values changed.
Dim oUnchangedIds = oExistingStepsIds.Union(oUpdatedStepsIds).
Except(oNewIds).
Except(oDeletedIds).
Distinct().
ToList()
Logger.Debug("Steps that will be updated: [{0}]", oUnchangedIds.Count)
Dim oUpdateSuccessful = DoUpdateImportProfileSteps(pData, oUnchangedIds)
Logger.Debug("Update Successful: [{0}]", oUpdateSuccessful)
' If all operations were successful, only then we return true.
Return New List(Of Boolean) From {oDeleteSuccessful, oCreateSuccessful, oUpdateSuccessful}.All(Function(b) b)
End Function
Private Function DoUpdateImportProfileSteps(pData As UpdateProfileRequest, pIdList As List(Of Integer)) As Boolean
Dim oProfile = pData.ImportProfile
Dim oSQL As String = "UPDATE TBECM_JR_FIW_STEP
SET IDX_NAME = @IDX_NAME,
METHOD = @METHOD,
ARGUMENT1 = @ARGUMENT1,
ARGUMENT2 = @ARGUMENT2,
ARGUMENT3 = @ARGUMENT3,
SCOPE = @SCOPE,
ACTIVE = @ACTIVE
WHERE GUID = @GUID"
Dim oResults As New List(Of Boolean)
For Each oId In pIdList
Try
Dim oStep = pData.ImportProfile.Steps.Where(Function(s) s.Id = oId).SingleOrDefault()
Dim oCommand As New SqlClient.SqlCommand(oSQL)
oCommand.Parameters.Add("IDX_NAME", SqlDbType.NVarChar, 100).Value = oStep.IndexName
oCommand.Parameters.Add("METHOD", SqlDbType.NVarChar, 100).Value = oStep.Method
oCommand.Parameters.Add("ARGUMENT1", SqlDbType.NVarChar, 500).Value = oStep.Argument1
oCommand.Parameters.Add("ARGUMENT2", SqlDbType.NVarChar, 500).Value = oStep.Argument2
oCommand.Parameters.Add("ARGUMENT3", SqlDbType.NVarChar, 500).Value = oStep.Argument3
oCommand.Parameters.Add("SCOPE", SqlDbType.NVarChar, 50).Value = oStep.Scope
oCommand.Parameters.Add("ACTIVE", SqlDbType.Bit).Value = oStep.Active
oCommand.Parameters.Add("GUID", SqlDbType.Int).Value = oStep.Id
oResults.Add(Database.ExecuteNonQuery(oCommand))
Catch ex As Exception
oResults.Add(False)
Logger.Error(ex)
End Try
Next
Return oResults.All(Function(r) r)
End Function
Private Function DoCreateImportProfileSteps(pData As UpdateProfileRequest, pIdList As List(Of Integer)) As Boolean
Dim oProfile = pData.ImportProfile
Dim oSQL As String = "INSERT INTO TBECM_JR_FIW_STEP
(PROFILE_ID, IDX_NAME, METHOD, ARGUMENT1, ARGUMENT2, ARGUMENT3, SCOPE, ACTIVE) VALUES
(@PROFILE_ID, @IDX_NAME, @METHOD, @ARGUMENT1, @ARGUMENT2, @ARGUMENT3, @SCOPE, @ACTIVE)"
Dim oResults As New List(Of Boolean)
For Each oId In pIdList
Try
Dim oStep = pData.ImportProfile.Steps.Where(Function(s) s.Id = oId).SingleOrDefault()
Dim oCommand As New SqlClient.SqlCommand(oSQL)
oCommand.Parameters.Add("PROFILE_ID", SqlDbType.Int).Value = oStep.ProfileId
oCommand.Parameters.Add("IDX_NAME", SqlDbType.NVarChar, 100).Value = oStep.IndexName
oCommand.Parameters.Add("METHOD", SqlDbType.NVarChar, 100).Value = oStep.Method
oCommand.Parameters.Add("ARGUMENT1", SqlDbType.NVarChar, 500).Value = oStep.Argument1
oCommand.Parameters.Add("ARGUMENT2", SqlDbType.NVarChar, 500).Value = oStep.Argument2
oCommand.Parameters.Add("ARGUMENT3", SqlDbType.NVarChar, 500).Value = oStep.Argument3
oCommand.Parameters.Add("SCOPE", SqlDbType.NVarChar, 50).Value = oStep.Scope
oCommand.Parameters.Add("ACTIVE", SqlDbType.Bit).Value = oStep.Active
oResults.Add(Database.ExecuteNonQuery(oCommand))
Catch ex As Exception
oResults.Add(False)
Logger.Error(ex)
End Try
Next
Return oResults.All(Function(r) r)
End Function
Private Function DoDeleteImportProfileSteps(pData As UpdateProfileRequest, pIdList As List(Of Integer)) As Boolean
Dim oProfile = pData.ImportProfile
Dim oSQL As String = "DELETE FROM TBECM_JR_FIW_STEP WHERE GUID = @GUID"
Dim oResults As New List(Of Boolean)
For Each oId In pIdList
Try
Dim oStep = pData.ImportProfile.Steps.Where(Function(s) s.Id = oId).SingleOrDefault()
Dim oCommand As New SqlClient.SqlCommand(oSQL)
oCommand.Parameters.Add("GUID", SqlDbType.Int).Value = oStep.Id
oResults.Add(Database.ExecuteNonQuery(oCommand))
Catch ex As Exception
oResults.Add(False)
Logger.Error(ex)
End Try
Next
Return oResults.All(Function(r) r)
End Function
End Class
Public Class UpdateProfileRequest
Public Enum UpdateProfileAction
Create

View File

@@ -13,6 +13,7 @@ Namespace WCF
Public Sub New(singletonInstance As Object, baseAddresses As Uri())
MyBase.New(singletonInstance, baseAddresses)
End Sub
Public Sub EnableMetadataExchange(ByVal Optional EnableHttpGet As Boolean = True)