-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added schedule interface and classes
- Loading branch information
Showing
14 changed files
with
441 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
Imports System.Timers | ||
|
||
''' <summary> | ||
''' Base class for all DataMonitor based classes. | ||
''' </summary> | ||
''' <remarks></remarks> | ||
Public MustInherit Class DataMonitor | ||
Implements IDataMonitor | ||
|
||
Private _disposed As Boolean = False | ||
Private _processor As IDataProcessor = Nothing | ||
Private _schedule As IMonitorSchedule = Nothing | ||
Private _timer As System.Timers.Timer | ||
|
||
Public Sub New(ByVal processor As IDataProcessor, ByVal schedule As IMonitorSchedule) | ||
Me.Processor = processor | ||
Me.Schedule = schedule | ||
End Sub | ||
|
||
Public Overridable Property Processor() As IDataProcessor Implements IDataMonitor.Processor | ||
Get | ||
Return _processor | ||
End Get | ||
Set(ByVal value As IDataProcessor) | ||
_processor = value | ||
End Set | ||
End Property | ||
|
||
Public Overridable Sub Start() Implements IDataMonitor.Start | ||
Timer.Start() | ||
End Sub | ||
|
||
Public Overridable Sub [Stop]() Implements IDataMonitor.Stop | ||
Timer.Stop() | ||
End Sub | ||
|
||
''' <summary> | ||
''' Returns the internal timer used for the current monitor. | ||
''' </summary> | ||
''' <value></value> | ||
''' <returns>Timer</returns> | ||
''' <remarks></remarks> | ||
Protected Overridable ReadOnly Property Timer() As Timer | ||
Get | ||
If _timer Is Nothing Then | ||
_timer = New Timer | ||
_timer.AutoReset = False | ||
End If | ||
|
||
Return _timer | ||
End Get | ||
End Property | ||
|
||
''' <summary> | ||
''' Gets/sets the schedule for the current monitor instance. | ||
''' </summary> | ||
''' <value></value> | ||
''' <returns>IMonitorSchedule</returns> | ||
''' <remarks></remarks> | ||
Public Overridable Property Schedule() As IMonitorSchedule Implements IDataMonitor.Schedule | ||
Get | ||
Return _schedule | ||
End Get | ||
Set(ByVal value As IMonitorSchedule) | ||
_schedule = value | ||
End Set | ||
End Property | ||
|
||
Protected Overridable Sub Dispose(ByVal disposing As Boolean) | ||
If Not _disposed Then | ||
If disposing Then | ||
|
||
End If | ||
End If | ||
|
||
_disposed = True | ||
End Sub | ||
|
||
Public Sub Dispose() Implements IDisposable.Dispose | ||
Dispose(True) | ||
GC.SuppressFinalize(Me) | ||
End Sub | ||
|
||
End Class |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
''' <summary> | ||
''' Interface that defines a data monitoring instance. | ||
''' </summary> | ||
''' <remarks></remarks> | ||
Public Interface IDataMonitor | ||
Inherits IDisposable | ||
|
||
''' <summary> | ||
''' Starts the data monitoring instance. | ||
''' </summary> | ||
''' <remarks></remarks> | ||
Sub Start() | ||
|
||
''' <summary> | ||
''' Stops the data monitoring instance. | ||
''' </summary> | ||
''' <remarks></remarks> | ||
Sub [Stop]() | ||
|
||
''' <summary> | ||
''' Gets/sets the data processor to use when new data is found. | ||
''' </summary> | ||
''' <value></value> | ||
''' <returns>IDataProcessor</returns> | ||
''' <remarks></remarks> | ||
Property Processor() As IDataProcessor | ||
|
||
''' <summary> | ||
''' Gets/sets the data monitor schedule to be used. | ||
''' </summary> | ||
''' <value></value> | ||
''' <returns>IMonitorSchedule</returns> | ||
''' <remarks></remarks> | ||
Property Schedule() As IMonitorSchedule | ||
End Interface |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
''' <summary> | ||
''' Interface that defines a directory monitoring instance. | ||
''' </summary> | ||
''' <remarks></remarks> | ||
Public Interface IDirectoryMonitor | ||
Inherits IDataMonitor | ||
|
||
''' <summary> | ||
''' Gets/sets the file name filter to apply to the directorys contents | ||
''' </summary> | ||
''' <value></value> | ||
''' <returns>String</returns> | ||
''' <remarks>The default should be *, or all files.</remarks> | ||
Property Filter() As String | ||
|
||
''' <summary> | ||
''' Gets/sets the full path of the directory to monitor. | ||
''' </summary> | ||
''' <value></value> | ||
''' <returns></returns> | ||
''' <remarks>The path should take either a local system path or a file uri.</remarks> | ||
Property Path() As String | ||
End Interface |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
''' <summary> | ||
''' Interface that defines a data processor instance. | ||
''' </summary> | ||
''' <remarks></remarks> | ||
Public Interface IDataProcessor | ||
Inherits IDisposable | ||
|
||
End Interface |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
Imports log4net | ||
|
||
''' <summary> | ||
''' Class for schedules based on times of day. | ||
''' </summary> | ||
''' <remarks></remarks> | ||
Public Class DailySchedule | ||
Inherits MonitorSchedule | ||
|
||
Private Shared ReadOnly Log As ILog = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod.DeclaringType) | ||
Private _times() As TimeSpan = {} | ||
|
||
''' <summary> | ||
''' Creates a new daily schedule instance. | ||
''' </summary> | ||
''' <param name="times">TimePan. An array of times to run the events each day.</param> | ||
''' <remarks></remarks> | ||
Public Sub New(ByVal ParamArray times() As TimeSpan) | ||
Me.Times = times | ||
End Sub | ||
|
||
''' <summary> | ||
''' Gets/sets the times of day for the events. | ||
''' </summary> | ||
''' <value></value> | ||
''' <returns>TimeSpan</returns> | ||
''' <remarks></remarks> | ||
Public Overridable Property Times() As TimeSpan() | ||
Get | ||
Return _times | ||
End Get | ||
Set(ByVal value() As TimeSpan) | ||
_times = value | ||
End Set | ||
End Property | ||
|
||
''' <summary> | ||
''' Gets the next schedule event after the given start date/time. | ||
''' </summary> | ||
''' <param name="start">DateTime. The schedules start date/time.</param> | ||
''' <value></value> | ||
''' <returns>DateTime</returns> | ||
''' <remarks></remarks> | ||
Public Overloads Overrides ReadOnly Property NextEvent(ByVal start As DateTime) As DateTime | ||
Get | ||
Array.Sort(Me.Times) | ||
|
||
Dim max As New TimeSpan(0, 23, 59, 59, 999) | ||
|
||
For Each tp As TimeSpan In Me.Times | ||
If tp > max Then | ||
Log.WarnFormat("Skipping TimeSpan greater than 24 hours {0}", tp) | ||
Else | ||
If tp >= start.TimeOfDay Then | ||
Return New DateTime(start.Year, start.Month, start.Day, tp.Hours, tp.Minutes, tp.Seconds) | ||
End If | ||
End If | ||
Next | ||
|
||
Dim tomorow As DateTime = start.AddDays(1) | ||
Dim time As TimeSpan = Me.Times(0) | ||
|
||
Return New DateTime(tomorow.Year, tomorow.Month, tomorow.Day, time.Hours, time.Minutes, time.Seconds) | ||
End Get | ||
End Property | ||
End Class |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
''' <summary> | ||
''' Interface that defines a monitoring schedule. | ||
''' </summary> | ||
''' <remarks></remarks> | ||
Public Interface IMonitorSchedule | ||
Inherits IDisposable | ||
|
||
''' <summary> | ||
''' Gets the next schedule event after the given start date/time. | ||
''' </summary> | ||
''' <param name="start">DateTime. The schedules start date/time.</param> | ||
''' <value></value> | ||
''' <returns>DateTime</returns> | ||
''' <remarks></remarks> | ||
ReadOnly Property NextEvent(ByVal start As DateTime) As DateTime | ||
End Interface |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
''' <summary> | ||
''' Class for schedules based on time intervals. | ||
''' </summary> | ||
''' <remarks></remarks> | ||
Public Class IntervalSchedule | ||
Inherits MonitorSchedule | ||
|
||
Private _interval As New TimeSpan(0, 1, 0) | ||
|
||
''' <summary> | ||
''' Creates a new interval schedule instance. | ||
''' </summary> | ||
''' <remarks></remarks> | ||
Public Sub New() | ||
|
||
End Sub | ||
|
||
''' <summary> | ||
''' Creates a new interval schedule instance. | ||
''' </summary> | ||
''' <param name="interval">TimeSpan. The interval to wait between schedule events.</param> | ||
''' <remarks></remarks> | ||
Public Sub New(ByVal interval As TimeSpan) | ||
Me.Interval = interval | ||
End Sub | ||
|
||
''' <summary> | ||
''' Gets/sets the interval to wait between schedule events. | ||
''' </summary> | ||
''' <value></value> | ||
''' <returns>TimeSpan</returns> | ||
''' <remarks></remarks> | ||
Public Overridable Property Interval() As TimeSpan | ||
Get | ||
Return _interval | ||
End Get | ||
Set(ByVal value As TimeSpan) | ||
_interval = value | ||
End Set | ||
End Property | ||
|
||
''' <summary> | ||
''' Gets the next schedule event after the given start date/time. | ||
''' </summary> | ||
''' <param name="start">DateTime. The schedules start date/time.</param> | ||
''' <value></value> | ||
''' <returns>DateTime</returns> | ||
''' <remarks></remarks> | ||
Public Overrides ReadOnly Property NextEvent(ByVal start As DateTime) As DateTime | ||
Get | ||
Return start.Add(Me.Interval) | ||
End Get | ||
End Property | ||
End Class |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
''' <summary> | ||
''' Base class for monitoring schedules. | ||
''' </summary> | ||
''' <remarks></remarks> | ||
Public MustInherit Class MonitorSchedule | ||
Implements IMonitorSchedule | ||
|
||
Private _disposed As Boolean = False | ||
|
||
''' <summary> | ||
''' Gets the next schedule event after the given start date/time. | ||
''' </summary> | ||
''' <param name="start">DateTime. The schedules start date/time.</param> | ||
''' <value></value> | ||
''' <returns>DateTime</returns> | ||
''' <remarks></remarks> | ||
Public MustOverride ReadOnly Property NextEvent(ByVal start As DateTime) As DateTime Implements IMonitorSchedule.NextEvent | ||
|
||
''' <summary> | ||
''' Disposes the current schedule instance. | ||
''' </summary> | ||
''' <param name="disposing">Boolean. True if we're disposing.</param> | ||
''' <remarks></remarks> | ||
Protected Overridable Sub Dispose(ByVal disposing As Boolean) | ||
If Not _disposed Then | ||
If disposing Then | ||
|
||
End If | ||
End If | ||
|
||
_disposed = True | ||
End Sub | ||
|
||
''' <summary> | ||
''' Disposes the current schedule instance. | ||
''' </summary> | ||
''' <remarks></remarks> | ||
Public Sub Dispose() Implements IDisposable.Dispose | ||
Dispose(True) | ||
GC.SuppressFinalize(Me) | ||
End Sub | ||
End Class |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
Imports NUnit.Framework | ||
|
||
Public Class MonitorTests | ||
|
||
<Test()> _ | ||
Public Sub DirectoryMonitor() | ||
|
||
End Sub | ||
|
||
End Class |
Oops, something went wrong.