15-12-2022
This commit is contained in:
@@ -1,6 +1,38 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<configuration>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2" />
|
||||
</startup>
|
||||
<system.diagnostics>
|
||||
<sources>
|
||||
<source name="System.ServiceModel"
|
||||
switchValue="Warning"
|
||||
propagateActivity="true" >
|
||||
<listeners>
|
||||
<add name="xml"/>
|
||||
</listeners>
|
||||
</source>
|
||||
<source name="System.ServiceModel.MessageLogging">
|
||||
<listeners>
|
||||
<add name="xml" />
|
||||
</listeners>
|
||||
</source>
|
||||
</sources>
|
||||
<sharedListeners>
|
||||
<add name="xml"
|
||||
type="System.Diagnostics.XmlWriterTraceListener"
|
||||
initializeData="E:\LogFiles\ECMJobRunner.svclog" />
|
||||
</sharedListeners>
|
||||
</system.diagnostics>
|
||||
<system.serviceModel>
|
||||
<diagnostics wmiProviderEnabled="true">
|
||||
<messageLogging
|
||||
logEntireMessage="true"
|
||||
logMalformedMessages="false"
|
||||
logMessagesAtServiceLevel="true"
|
||||
logMessagesAtTransportLevel="false"
|
||||
maxMessagesToLog="3000"
|
||||
maxSizeOfMessageToLog="2000"/>
|
||||
</diagnostics>
|
||||
</system.serviceModel>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2" />
|
||||
</startup>
|
||||
</configuration>
|
||||
@@ -126,7 +126,6 @@
|
||||
<Compile Include="Models\Jobs\JobType.vb" />
|
||||
<Compile Include="Models\Jobs\HistoryItem.vb" />
|
||||
<Compile Include="Models\Jobs\StatusItem.vb" />
|
||||
<Compile Include="Models\Profiles\BaseProfile.vb" />
|
||||
<Compile Include="Models\Profiles\ImportFile.vb" />
|
||||
<Compile Include="Models\Profiles\ImportProfile.vb" />
|
||||
<Compile Include="Models\Profiles\ImportProfileStep.vb" />
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
Public Class BaseProfile
|
||||
Public Property Job As New JobDefinition
|
||||
End Class
|
||||
@@ -1,36 +1,18 @@
|
||||
Imports System.ComponentModel.DataAnnotations
|
||||
|
||||
Public Class ImportProfile
|
||||
Inherits BaseProfile
|
||||
|
||||
Public Property Job As New JobDefinition
|
||||
Public Property Active As Boolean
|
||||
|
||||
<Required>
|
||||
Public Property Id As Integer
|
||||
<Required>
|
||||
Public Property JobId As Integer
|
||||
<Required>
|
||||
Public Property ObjectTypeName As String
|
||||
|
||||
<Required>
|
||||
<StringLength(500)>
|
||||
Public Property ObjectType As ObjectType
|
||||
Public Property SourceFolder As String
|
||||
|
||||
<Required>
|
||||
<StringLength(500)>
|
||||
Public Property TargetFolder As String
|
||||
|
||||
<StringLength(500)>
|
||||
Public Property BackupFolder As String
|
||||
|
||||
<StringLength(50)>
|
||||
Public Property SubfolderDateFormat As String
|
||||
|
||||
<StringLength(5000)>
|
||||
Public Property FileExcludeRegex As String
|
||||
|
||||
Public Property DeleteFiles As Boolean
|
||||
Public Property IncludeSubfolders As Boolean
|
||||
|
||||
Public Property Steps As New List(Of ImportProfileStep)
|
||||
End Class
|
||||
|
||||
@@ -1,26 +1,17 @@
|
||||
Public Class ImportProfileStep
|
||||
Imports System.Runtime.Serialization
|
||||
|
||||
Public Class ImportProfileStep
|
||||
Public Property Active As Boolean
|
||||
Public Property Id As Integer
|
||||
Public Property ProfileId As Integer
|
||||
Public Property IndexName As String
|
||||
Public Property Scope As StepScope
|
||||
Public Property Method As StepMethod
|
||||
|
||||
Public Property Scope As String
|
||||
Public Property Method As String
|
||||
|
||||
Public Property Argument1 As String
|
||||
Public Property Argument2 As String
|
||||
Public Property Argument3 As String
|
||||
|
||||
Public Enum StepMethod
|
||||
SUBSTRING
|
||||
REGEX
|
||||
SPLIT
|
||||
ALL
|
||||
VALUE
|
||||
End Enum
|
||||
|
||||
Public Enum StepScope
|
||||
FILE
|
||||
FOLDER
|
||||
End Enum
|
||||
End Class
|
||||
|
||||
|
||||
|
||||
@@ -120,6 +120,14 @@ Namespace Scheduler.Jobs
|
||||
LogStep(HistoryItem.StepLevel.Debug, "{0} Files filtered out for matching exclusion Regex.", oRegexFilteredCount)
|
||||
oFilteredFiles = oDateFilteredFiles
|
||||
|
||||
'-------------------------------------------------------------------------------------------------
|
||||
' After this point, files are treated as processed and are being deleted before finishing the job
|
||||
'-------------------------------------------------------------------------------------------------
|
||||
|
||||
If oFilteredFiles.Count = 0 Then
|
||||
Return CompleteJob($"No files to process.")
|
||||
End If
|
||||
|
||||
Logger.Info("Importing files..")
|
||||
Dim oImportedFiles As New List(Of ImportFile)
|
||||
For Each oFile In oFilteredFiles
|
||||
@@ -150,6 +158,19 @@ Namespace Scheduler.Jobs
|
||||
Logger.Info("[{0}] files successfully Indexed!", oIndexedFiles.Count)
|
||||
LogStep(HistoryItem.StepLevel.Info, "{0} files successfully Indexed!", oIndexedFiles.Count)
|
||||
|
||||
If oProfile.DeleteFiles = True Then
|
||||
Logger.Debug("Deleting [{0}] files before finishing job.", oFiles.Count)
|
||||
|
||||
For Each oFile In oFilteredFiles
|
||||
Try
|
||||
IO.File.Delete(oFile.FilePathOriginal)
|
||||
Catch ex As Exception
|
||||
Logger.Warn("Could not clean up processed files before finishing Job!")
|
||||
Logger.Error(ex)
|
||||
End Try
|
||||
Next
|
||||
End If
|
||||
|
||||
Return CompleteJob($"{oImportedFiles.Count} files successfully Processed!")
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
@@ -161,7 +182,14 @@ Namespace Scheduler.Jobs
|
||||
End Function
|
||||
|
||||
Private Function FileIsOlderThan(pFile As ImportFile, pMinutes As Integer)
|
||||
Return pFile.FileInfo.CreationTime.AddMinutes(pMinutes) < Now
|
||||
Dim oCreationTime = pFile.FileInfo.CreationTime
|
||||
Dim oTimeSpan = New TimeSpan(0, pMinutes, 0)
|
||||
|
||||
If (Now - oCreationTime) > oTimeSpan Then
|
||||
Return True
|
||||
Else
|
||||
Return False
|
||||
End If
|
||||
End Function
|
||||
|
||||
Private Function FileMatchesRegex(pFile As ImportFile, pRegexList As List(Of Regex))
|
||||
@@ -228,31 +256,52 @@ Namespace Scheduler.Jobs
|
||||
|
||||
' Get the base value by checking scope
|
||||
Select Case oStep.Scope
|
||||
Case ImportProfileStep.StepScope.FILE
|
||||
Case Common.Constants.SCOPE_FILE
|
||||
oValue = pFile.FileInfo.Name
|
||||
Case ImportProfileStep.StepScope.FOLDER
|
||||
Case Common.Constants.SCOPE_FOLDER
|
||||
oValue = pFile.FileInfo.DirectoryName
|
||||
Case Else
|
||||
oValue = pFile.FilePath
|
||||
End Select
|
||||
|
||||
Logger.Info("Running Method [{0}] on Index [{1}]", oStep.Method, oStep.IndexName)
|
||||
Logger.Debug("Value is [{0}]", oValue)
|
||||
Logger.Debug("Scope is [{0}]", oStep.Scope)
|
||||
|
||||
' TODO: Error handling!
|
||||
Select Case oStep.Method
|
||||
Case ImportProfileStep.StepMethod.SUBSTRING
|
||||
Case Common.Constants.METHOD_SUBSTRING
|
||||
Try
|
||||
Dim oIndex1 = Integer.Parse(oStep.Argument1)
|
||||
Dim oLength = Integer.Parse(oStep.Argument2)
|
||||
oValue = oValue.Substring(oIndex1, oLength)
|
||||
Logger.Debug("Parsing Value [{0}] for Parameter 'StartIndex'", oStep.Argument1)
|
||||
Dim oStartIndex = 0
|
||||
If Integer.TryParse(oStep.Argument1, oStartIndex) = False Then
|
||||
Throw New ArgumentException("StartIndex")
|
||||
End If
|
||||
|
||||
Logger.Debug("Parsing Value [{0}] for Parameter 'Length'", oStep.Argument2)
|
||||
Dim oLength = 0
|
||||
If Integer.TryParse(oStep.Argument2, oLength) = False Then
|
||||
Throw New ArgumentException("Length")
|
||||
End If
|
||||
|
||||
oValue = oValue.Substring(oStartIndex, oLength)
|
||||
Catch ex As Exception
|
||||
LogStep(HistoryItem.StepLevel.Error, "Method SUBSTRING could not be applied to Index '{0}'. Error: '{1}'", oStep.IndexName, ex.Message)
|
||||
Dim oMessage = "Method SUBSTRING could not be applied to Index '{0}' and Parameters StartIndex [{1}], Length [{2}]. Error: '{3}'"
|
||||
LogStep(HistoryItem.StepLevel.Error, oMessage, oStep.IndexName, ex.Message, oStep.Argument1, oStep.Argument2)
|
||||
Logger.Error(ex)
|
||||
End Try
|
||||
|
||||
Case ImportProfileStep.StepMethod.SPLIT
|
||||
Case Common.Constants.METHOD_SPLIT
|
||||
Try
|
||||
If String.IsNullOrEmpty(oStep.Argument1) Then
|
||||
Throw New ArgumentException("Separator")
|
||||
End If
|
||||
Dim oSeparator = oStep.Argument1.Substring(0, 1)
|
||||
Dim oIndex = Integer.Parse(oStep.Argument2)
|
||||
|
||||
Dim oIndex = 0
|
||||
If Integer.TryParse(oStep.Argument2, oIndex) = False Then
|
||||
Throw New ArgumentException("Index")
|
||||
End If
|
||||
|
||||
Dim oSplit = oValue.Split(oSeparator)
|
||||
oValue = oSplit(oIndex)
|
||||
Catch ex As Exception
|
||||
@@ -260,7 +309,7 @@ Namespace Scheduler.Jobs
|
||||
Logger.Error(ex)
|
||||
End Try
|
||||
|
||||
Case ImportProfileStep.StepMethod.REGEX
|
||||
Case Common.Constants.METHOD_REGEX
|
||||
Try
|
||||
Dim oRegex = New Regex(oStep.Argument1)
|
||||
Dim oTrueValue = oStep.Argument2
|
||||
@@ -275,10 +324,10 @@ Namespace Scheduler.Jobs
|
||||
Logger.Error(ex)
|
||||
End Try
|
||||
|
||||
Case ImportProfileStep.StepMethod.VALUE
|
||||
Case Common.Constants.METHOD_VALUE
|
||||
oValue = oStep.Argument1
|
||||
|
||||
Case ImportProfileStep.StepMethod.ALL
|
||||
Case Common.Constants.METHOD_ALL
|
||||
'noop
|
||||
Case Else
|
||||
'noop
|
||||
|
||||
@@ -138,42 +138,16 @@ Public Class State
|
||||
For Each oRow As DataRow In oTable.Rows
|
||||
Dim oTypeId = oRow.ItemEx("PROFILE_ID", 0)
|
||||
|
||||
Dim oScope As ImportProfileStep.StepScope
|
||||
Select Case oRow.ItemEx("SCOPE", "FILE")
|
||||
Case "FOLDER"
|
||||
oScope = ImportProfileStep.StepScope.FOLDER
|
||||
Case "FILE"
|
||||
oScope = ImportProfileStep.StepScope.FILE
|
||||
End Select
|
||||
|
||||
Dim oMethod As ImportProfileStep.StepMethod
|
||||
Select Case oRow.ItemEx("METHOD", "ALL")
|
||||
Case "SUBSTRING"
|
||||
oScope = ImportProfileStep.StepMethod.SUBSTRING
|
||||
|
||||
Case "SPLIT"
|
||||
oScope = ImportProfileStep.StepMethod.SPLIT
|
||||
|
||||
Case "REGEX"
|
||||
oScope = ImportProfileStep.StepMethod.REGEX
|
||||
|
||||
Case "STATIC"
|
||||
oScope = ImportProfileStep.StepMethod.VALUE
|
||||
|
||||
Case Else
|
||||
oScope = ImportProfileStep.StepMethod.ALL
|
||||
End Select
|
||||
|
||||
Dim oStep As New ImportProfileStep With {
|
||||
.Id = oRow.ItemEx("GUID", 0),
|
||||
.ProfileId = oRow.ItemEx("PROFILE_ID", 0),
|
||||
.IndexName = oRow.Item("IDX_NAME"),
|
||||
.Method = oMethod,
|
||||
.Argument1 = oRow.ItemEx("ARGUMENT1", ""),
|
||||
.Argument2 = oRow.ItemEx("ARGUMENT2", ""),
|
||||
.Argument3 = oRow.ItemEx("ARGUMENT3", ""),
|
||||
.Scope = oScope,
|
||||
.Active = oRow.ItemEx("ACTIVE", 0)
|
||||
.Active = oRow.ItemEx("ACTIVE", 0),
|
||||
.Method = oRow.ItemEx("METHOD", "ALL"),
|
||||
.Scope = oRow.ItemEx("SCOPE", "FILE")
|
||||
}
|
||||
|
||||
oSteps.Add(oStep)
|
||||
@@ -207,7 +181,6 @@ Public Class State
|
||||
Logger.Info("[{0}] Import Profiles loaded!", oTable.Rows.Count)
|
||||
|
||||
For Each oRow As DataRow In oTable.Rows
|
||||
Dim oTypeId = oRow.ItemEx("JOB_TYPE_ID", 0)
|
||||
Dim oProfile As New ImportProfile With {
|
||||
.Id = oRow.ItemEx("GUID", 0),
|
||||
.JobId = oRow.ItemEx("JR_JOB_ID", 0),
|
||||
@@ -222,12 +195,23 @@ Public Class State
|
||||
.Active = oRow.ItemEx("ACTIVE", 0)
|
||||
}
|
||||
|
||||
Logger.Debug("ProfileId: [{0}]", oProfile.Id)
|
||||
Logger.Debug("JobId: [{0}]", oProfile.JobId)
|
||||
Logger.Debug("ObjectType: [{0}]", oProfile.ObjectTypeName)
|
||||
Logger.Debug("SourceFolder: [{0}]", oProfile.SourceFolder)
|
||||
Logger.Debug("TargetFolder: [{0}]", oProfile.TargetFolder)
|
||||
|
||||
|
||||
oProfiles.Add(oProfile)
|
||||
|
||||
Logger.Debug("Adding Import Profile for Folder [{0}]", oProfile.SourceFolder)
|
||||
Next
|
||||
|
||||
Return oProfiles
|
||||
Return oProfiles.
|
||||
Select(Function(p) FillJobForProfile(p, JobDefinitions)).
|
||||
Select(Function(p) FillStepsForProfile(p, ProfileDefintions.ImportProfileSteps)).
|
||||
Select(Function(p) FillObjectTypeForProfile(p, ObjectTypes)).
|
||||
ToList()
|
||||
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
@@ -236,6 +220,33 @@ Public Class State
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Private Function FillJobForProfile(pProfile As ImportProfile, pJobDefinitions As List(Of JobDefinition)) As ImportProfile
|
||||
Dim oJob = pJobDefinitions.
|
||||
Where(Function(job) job.Id = pProfile.JobId).
|
||||
FirstOrDefault()
|
||||
|
||||
pProfile.Job = oJob
|
||||
Return pProfile
|
||||
End Function
|
||||
|
||||
Private Function FillObjectTypeForProfile(pProfile As ImportProfile, pObjectTypes As List(Of ObjectType)) As ImportProfile
|
||||
Dim oObjectType = pObjectTypes.
|
||||
Where(Function(t) t.Name = pProfile.ObjectTypeName).
|
||||
FirstOrDefault()
|
||||
|
||||
pProfile.ObjectType = oObjectType
|
||||
Return pProfile
|
||||
End Function
|
||||
|
||||
Private Function FillStepsForProfile(pProfile As ImportProfile, pProfileSteps As List(Of ImportProfileStep)) As ImportProfile
|
||||
Dim oSteps = pProfileSteps.
|
||||
Where(Function(s) s.ProfileId = pProfile.Id).
|
||||
ToList()
|
||||
|
||||
pProfile.Steps = oSteps
|
||||
Return pProfile
|
||||
End Function
|
||||
|
||||
Private Function GetJobDefinitions(pJobTypes As List(Of JobType)) As List(Of JobDefinition)
|
||||
Dim oJobs As New List(Of JobDefinition)
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user