|
Public MustInherit Class Task
#Region "Properties"
''' <summary>
''' The ID of the task in the DB
''' </summary>
Private _TaskID As Integer
Public Property TaskID() As Integer
Get
Return Me._TaskID
End Get
Set(ByVal value As Integer)
Me._TaskID = value
End Set
End Property
''' <summary>
''' The name of the Class and Assembly class wich run the task
''' </summary>
Private _AssemblyName As String
Public Property AssemblyName() As String
Get
Return Me._AssemblyName
End Get
Set(ByVal value As String)
Me._AssemblyName = value
End Set
End Property
''' <summary>
''' Friendly Name of the Task
''' </summary>
Private _FriendlyName As String
Public Property FriendlyName() As String
Get
Return Me._FriendlyName
End Get
Set(ByVal value As String)
Me._FriendlyName = value
End Set
End Property
''' <summary>
''' Task's Description
''' </summary>
Private _Description As String
Public Property Description() As String
Get
Return Me._Description
End Get
Set(ByVal value As String)
Me._Description = value
End Set
End Property
''' <summary>
''' Determines if the task is enabled or disabled
''' </summary>
Private _Enabled As Boolean
Public Property Enabled() As Boolean
Get
Return Me._Enabled
End Get
Set(ByVal value As Boolean)
Me._Enabled = value
End Set
End Property
''' <summary>
''' Determines when the task will run for the first time
''' </summary>
Private _StartTime As Date
Public Property StartTime() As Date
Get
Return Me._StartTime
End Get
Set(ByVal value As Date)
Me._StartTime = value
End Set
End Property
''' <summary>
''' Determines when will not be runned any more
''' </summary>
Private _EndTime As Nullable(Of Date)
Public Property EndTime() As Nullable(Of Date)
Get
Return Me._EndTime
End Get
Set(ByVal value As Nullable(Of Date))
Me._EndTime = value
End Set
End Property
''' <summary>
''' Determines the Hour when the Task must run for first time that day
''' </summary>
Private _PerformTaskFrom As Nullable(Of Date)
Public Property PerformTaskFrom() As Nullable(Of Date)
Get
Return Me._PerformTaskFrom
End Get
Set(ByVal value As Nullable(Of Date))
Me._PerformTaskFrom = value
End Set
End Property
''' <summary>
''' Determines the Hour when the Task must run for Last time that day
''' </summary>
Private _PerformTaskTo As Nullable(Of Date)
Public Property PerformTaskTo() As Nullable(Of Date)
Get
Return Me._PerformTaskTo
End Get
Set(ByVal value As Nullable(Of Date))
Me._PerformTaskTo = value
End Set
End Property
''' <summary>
''' Determines in minutes when the Task must be repeated
''' </summary>
Private _RepeatEvery As Nullable(Of Integer)
Public Property RepeatEvery() As Nullable(Of Integer)
Get
Return Me._RepeatEvery
End Get
Set(ByVal value As Nullable(Of Integer))
Me._RepeatEvery = value
End Set
End Property
''' <summary>
''' Number of minutes that a task can be running without being Aborted
''' </summary>
Private _AbortAfter As Nullable(Of Integer)
Public Property AbortAfter() As Nullable(Of Integer)
Get
Return Me._AbortAfter
End Get
Set(ByVal value As Nullable(Of Integer))
Me._AbortAfter = value
End Set
End Property
''' <summary>
''' Determines the last time the task was executed
''' </summary>
Private _LastRun As Nullable(Of Date)
Public Property LastRun() As Nullable(Of Date)
Get
Return Me._LastRun
End Get
Set(ByVal value As Nullable(Of Date))
Me._LastRun = value
End Set
End Property
''' <summary>
''' Determines the next time the task will be execured
''' </summary>
Private _NextRun As Nullable(Of Date)
Public Property NextRun() As Nullable(Of Date)
Get
Return Me._NextRun
End Get
Set(ByVal value As Nullable(Of Date))
Me._NextRun = value
End Set
End Property
''' <summary>
''' Current Status of the Task
''' </summary>
Private _TaskStatus As String
Public Property TaskStatus() As String
Get
Return Me._TaskStatus
End Get
Set(ByVal value As String)
Me._TaskStatus = value
End Set
End Property
''' <summary>
''' The date time when the task started to run, used abort tasks
''' </summary>
Private _RunningSince As Nullable(Of Date)
Public Property RunningSince() As Nullable(Of Date)
Get
Return Me._RunningSince
End Get
Set(ByVal value As Nullable(Of Date))
Me._RunningSince = value
End Set
End Property
''' <summary>
''' Physical Path where the Task is running
''' </summary>
Private _RunningPath As String
Public Property RunningPath() As String
Get
Return Me._RunningPath
End Get
Set(ByVal value As String)
Me._RunningPath = value
End Set
End Property
#End Region
#Region "Methods"
''' <summary>
''' The Conctrete implementation of the Task
''' </summary>
Public MustOverride Sub Execute()
''' <summary>
''' This must be implemented by the particular class because the Log can be in a file, database, etc.
''' </summary>
Public MustOverride Sub LogEntry(ByVal Entry As String)
''' <summary>
''' Cancel the Task
''' </summary>
Public MustOverride Sub CancelTask(Optional ByVal Message As String = "")
#End Region
#Region "Events"
''' <summary>
''' Fire this event if you want to implement something in the Scheduler controller
''' </summary>
''' <param name="TaskID">ID of the task </param>
''' <param name="FinishedAt">Date time when the execute method was finished</param>
Public Event TaskFinished(ByVal TaskID As Integer, ByVal FinishedAt As Date)
''' <summary>
''' Fire this event if you want to implement something in the Scheculer controller
''' </summary>
''' <param name="TaskID">ID of the task</param>
''' <param name="FinishedAt">Date and time when the exeption occured</param>
''' <param name="ex">The exception</param>
Public Event TaskException(ByVal TaskID As Integer, ByVal FinishedAt As Date, ByVal ex As Exception)
''' <summary>
''' Used to Raise the TaskFinished Event because in VB.Net you cannot raise base events in derived classes
''' check http://msdn2.microsoft.com/en-us/library/0ecakwbz(vs.80).aspx for more info
''' C# can raise events from derived classes see: http://msdn2.microsoft.com/en-us/library/hy3sefw3(VS.80).aspx
''' </summary>
''' <param name="TaskID">ID of the task </param>
''' <param name="FinishedAt">Date time when the execute method was finished</param>
Protected Sub RaiseTaskFinishedEvent(ByVal TaskID As Integer, ByVal FinishedAt As Date)
RaiseEvent TaskFinished(TaskID, FinishedAt)
End Sub
''' <summary>
''' Used to Raise the TaskException Event because in VB.Net you cannot raise base events in derived classes
''' check http://msdn2.microsoft.com/en-us/library/0ecakwbz(vs.80).aspx for more info
''' C# can raise events from derived classes see: http://msdn2.microsoft.com/en-us/library/hy3sefw3(VS.80).aspx
''' </summary>
''' <param name="TaskID">ID of the task</param>
''' <param name="FinishedAt">Date and time when the exeption occured</param>
''' <param name="ex">The exception</param>
Protected Sub RaiseTaskExceptionEvent(ByVal TaskID As Integer, ByVal FinishedAt As Date, ByVal ex As Exception)
RaiseEvent TaskException(TaskID, FinishedAt, ex)
End Sub
#End Region
End Class
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
I am Pedro Ramirez from mexico, work for
www.sciodev.com, the company is located in Mexico, we do outsourcing and nearshore development, we are focused on SaaS nearshore development, I started with VB.Net, but now I am ambidextrous using VB.Net or C#.