292 lines
10 KiB
VB.net
292 lines
10 KiB
VB.net
Imports DigitalData.Modules.Base
|
|
Imports DigitalData.Modules.Database
|
|
Imports DigitalData.Modules.Logging
|
|
Imports DigitalData.Modules.Language
|
|
Imports ECM.JobRunner.Windows.Scheduler
|
|
Imports DigitalData.Modules.Windream
|
|
Imports ECM.JobRunner.Common
|
|
|
|
Public Class State
|
|
Inherits BaseClass
|
|
|
|
Private ReadOnly Database As MSSQLServer
|
|
Private ReadOnly Windream As Windream
|
|
|
|
Public ReadOnly JobHistory As JobHistory
|
|
Public ReadOnly JobStatus As JobStatus
|
|
|
|
Public ReadOnly Property JobTypes As New List(Of JobType)
|
|
Public ReadOnly Property ObjectTypes As New List(Of ObjectType)
|
|
Public ReadOnly Property JobDefinitions As New List(Of JobDefinition)
|
|
Public ReadOnly Property ProfileDefintions As New ProfileDefinitions
|
|
|
|
Public Class ProfileDefinitions
|
|
Public Property ImportProfiles As New List(Of ImportProfile)
|
|
Public Property ImportProfileSteps As New List(Of ImportProfileStep)
|
|
End Class
|
|
|
|
Public Sub New(pLogConfig As LogConfig, pDatabase As MSSQLServer, pWindream As Windream)
|
|
MyBase.New(pLogConfig)
|
|
Database = pDatabase
|
|
Windream = pWindream
|
|
JobHistory = New JobHistory(pLogConfig)
|
|
JobStatus = New JobStatus(pLogConfig)
|
|
|
|
LoadData()
|
|
End Sub
|
|
|
|
Public Sub Reload()
|
|
LoadData()
|
|
End Sub
|
|
|
|
Private Sub LoadData()
|
|
_JobTypes = GetJobTypes()
|
|
_ObjectTypes = GetObjectTypes()
|
|
|
|
_JobDefinitions = GetJobDefinitions(_JobTypes)
|
|
_ProfileDefintions.ImportProfileSteps = GetImportProfileSteps()
|
|
_ProfileDefintions.ImportProfiles = GetImportProfiles()
|
|
End Sub
|
|
|
|
Private Function GetObjectTypes() As List(Of ObjectType)
|
|
Dim oObjectTypes As New List(Of ObjectType)
|
|
Try
|
|
Logger.Info("Loading Windream Object Types..")
|
|
Dim oObjectTypesNames = Windream.ObjectTypes
|
|
Logger.Info("[{0}] Windream Object Types loaded!", oObjectTypes.Count)
|
|
|
|
For Each oObjectTypeName In oObjectTypesNames
|
|
Dim oObjectType = New ObjectType With {
|
|
.Name = oObjectTypeName,
|
|
.Indexes = GetIndexesFor(oObjectTypeName)
|
|
}
|
|
oObjectTypes.Add(oObjectType)
|
|
Next
|
|
|
|
Return oObjectTypes
|
|
Catch ex As Exception
|
|
Logger.Error(ex)
|
|
Return oObjectTypes
|
|
End Try
|
|
End Function
|
|
|
|
Private Function GetIndexesFor(pObjectType As String) As List(Of String)
|
|
Dim oIndexes As New List(Of String)
|
|
Try
|
|
Logger.Info("Loading Windream Indexes for [{0}]..", pObjectType)
|
|
oIndexes = Windream.GetIndiciesByObjecttype(pObjectType)
|
|
Logger.Info("[{0}] Windream Indexes loaded!", oIndexes.Count)
|
|
|
|
Return oIndexes
|
|
Catch ex As Exception
|
|
Logger.Error(ex)
|
|
Return oIndexes
|
|
End Try
|
|
End Function
|
|
|
|
Private Function GetJobTypes() As List(Of JobType)
|
|
Dim oTypes As New List(Of JobType)
|
|
Try
|
|
Logger.Info("Loading Job Types..")
|
|
|
|
Dim oSQL As String = "SELECT * FROM TBECM_JR_TYPE"
|
|
Dim oTable As DataTable = Database.GetDatatable(oSQL)
|
|
|
|
If oTable Is Nothing Then
|
|
Logger.Warn("Database Error while loading Job Types!")
|
|
Return oTypes
|
|
End If
|
|
|
|
Logger.Info("[{0}] Job Types loaded!", oTable.Rows.Count)
|
|
|
|
For Each oRow As DataRow In oTable.Rows
|
|
Dim oType As New JobType With {
|
|
.Id = oRow.ItemEx("GUID", 0),
|
|
.Name = oRow.ItemEx("JOB_TYPE", ""),
|
|
.Active = oRow.ItemEx("ACTIVE", 0)
|
|
}
|
|
oTypes.Add(oType)
|
|
|
|
Logger.Debug("Adding Job Type [{0}]", oType.Name)
|
|
Next
|
|
|
|
Return oTypes
|
|
|
|
Catch ex As Exception
|
|
Logger.Error(ex)
|
|
Return oTypes
|
|
|
|
End Try
|
|
End Function
|
|
|
|
Private Function GetImportProfileSteps() As List(Of ImportProfileStep)
|
|
Dim oSteps As New List(Of ImportProfileStep)
|
|
|
|
Try
|
|
Logger.Info("Loading Import Profiles Steps..")
|
|
|
|
Dim oSQL As String = "SELECT * FROM TBECM_JR_FIW_STEP"
|
|
Dim oTable As DataTable = Database.GetDatatable(oSQL)
|
|
|
|
If oTable Is Nothing Then
|
|
Logger.Warn("Database Error while loading Import Profile Steps!")
|
|
Return oSteps
|
|
End If
|
|
|
|
Logger.Info("[{0}] Import Profile Steps loaded!", oTable.Rows.Count)
|
|
|
|
|
|
For Each oRow As DataRow In oTable.Rows
|
|
Dim oTypeId = oRow.ItemEx("PROFILE_ID", 0)
|
|
|
|
Dim oStep As New ImportProfileStep With {
|
|
.Id = oRow.ItemEx("GUID", 0),
|
|
.ProfileId = oRow.ItemEx("PROFILE_ID", 0),
|
|
.IndexName = oRow.Item("IDX_NAME"),
|
|
.Argument1 = oRow.ItemEx("ARGUMENT1", ""),
|
|
.Argument2 = oRow.ItemEx("ARGUMENT2", ""),
|
|
.Argument3 = oRow.ItemEx("ARGUMENT3", ""),
|
|
.Active = oRow.ItemEx("ACTIVE", 0),
|
|
.Method = oRow.ItemEx("METHOD", "ALL"),
|
|
.Scope = oRow.ItemEx("SCOPE", "FILE")
|
|
}
|
|
|
|
oSteps.Add(oStep)
|
|
|
|
Logger.Debug("Adding Import Profile Step for Index [{0}]", oStep.IndexName)
|
|
Next
|
|
|
|
Return oSteps
|
|
|
|
Catch ex As Exception
|
|
Logger.Error(ex)
|
|
Return oSteps
|
|
|
|
End Try
|
|
End Function
|
|
|
|
Private Function GetImportProfiles() As List(Of ImportProfile)
|
|
Dim oProfiles As New List(Of ImportProfile)
|
|
|
|
Try
|
|
Logger.Info("Loading Import Profiles..")
|
|
|
|
Dim oSQL As String = "SELECT * FROM TBECM_JR_FIW_PROFILE"
|
|
Dim oTable As DataTable = Database.GetDatatable(oSQL)
|
|
|
|
If oTable Is Nothing Then
|
|
Logger.Warn("Database Error while loading Import Profiles!")
|
|
Return oProfiles
|
|
End If
|
|
|
|
Logger.Info("[{0}] Import Profiles loaded!", oTable.Rows.Count)
|
|
|
|
For Each oRow As DataRow In oTable.Rows
|
|
Dim oProfile As New ImportProfile With {
|
|
.Id = oRow.ItemEx("GUID", 0),
|
|
.JobId = oRow.ItemEx("JR_JOB_ID", 0),
|
|
.ObjectTypeName = oRow.Item("WM_OBJECTTYPE"),
|
|
.SourceFolder = oRow.ItemEx("SOURCE_FOLDER", ""),
|
|
.TargetFolder = oRow.ItemEx("TARGET_FOLDER", ""),
|
|
.BackupFolder = oRow.ItemEx("BACKUP_FOLDER", ""),
|
|
.SubfolderDateFormat = oRow.ItemEx("SF_DATE_FORMAT", ""),
|
|
.DeleteFiles = oRow.ItemEx("DEL_FILE_SUCCESS", 0),
|
|
.FileExcludeRegex = oRow.ItemEx("EXCLUDE_REGEX", ""),
|
|
.IncludeSubfolders = oRow.ItemEx("INCL_SUBFOLDER", 0),
|
|
.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.
|
|
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)
|
|
Return oProfiles
|
|
|
|
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)
|
|
|
|
Try
|
|
Logger.Info("Loading Jobs..")
|
|
|
|
Dim oSQL As String = "SELECT * FROM TBECM_JR_JOB"
|
|
Dim oTable As DataTable = Database.GetDatatable(oSQL)
|
|
|
|
If oTable Is Nothing Then
|
|
Logger.Warn("Database Error while loading Jobs!")
|
|
Return oJobs
|
|
End If
|
|
|
|
Logger.Info("[{0}] Jobs loaded!", oTable.Rows.Count)
|
|
|
|
For Each oRow As DataRow In oTable.Rows
|
|
Dim oTypeId = oRow.ItemEx("JOB_TYPE_ID", 0)
|
|
Dim oJob As New JobDefinition With {
|
|
.Id = oRow.ItemEx("GUID", 0),
|
|
.TypeId = oTypeId,
|
|
.Type = pJobTypes.Where(Function(t) t.Id = oTypeId).SingleOrDefault,
|
|
.Name = oRow.ItemEx("TITLE", ""),
|
|
.Active = oRow.ItemEx("ACTIVE", 0),
|
|
.CronSchedule = oRow.ItemEx("QUARTZ_DEF", "")
|
|
}
|
|
|
|
oJobs.Add(oJob)
|
|
|
|
Logger.Debug("Adding Job [{0}]", oJob.Name)
|
|
Next
|
|
|
|
Return oJobs
|
|
|
|
Catch ex As Exception
|
|
Logger.Error(ex)
|
|
Return oJobs
|
|
|
|
End Try
|
|
End Function
|
|
End Class
|