Skip to content

Commit

Permalink
Added start of schedule tests
Browse files Browse the repository at this point in the history
Added schedule interface and classes
  • Loading branch information
claco committed Oct 26, 2008
1 parent 2bd4c12 commit af5d22d
Show file tree
Hide file tree
Showing 14 changed files with 441 additions and 0 deletions.
84 changes: 84 additions & 0 deletions Siphon/Monitors/DataMonitor.vb
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
35 changes: 35 additions & 0 deletions Siphon/Monitors/IDataMonitor.vb
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
23 changes: 23 additions & 0 deletions Siphon/Monitors/IDirectoryMonitor.vb
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
2 changes: 2 additions & 0 deletions Siphon/My Project/AssemblyInfo.vb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Imports System
Imports System.Reflection
Imports System.Runtime.InteropServices
Imports log4net

' General Information about an assembly is controlled through the following
' set of attributes. Change these attribute values to modify the information
Expand All @@ -14,6 +15,7 @@ Imports System.Runtime.InteropServices
<Assembly: AssemblyProduct("Siphon")>
<Assembly: AssemblyCopyright("Copyright © 2008")>
<Assembly: AssemblyTrademark("")>
<Assembly: log4net.Config.XmlConfigurator(Watch:=True)>

<Assembly: ComVisible(False)>

Expand Down
8 changes: 8 additions & 0 deletions Siphon/Processors/IDataProcessor.vb
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
66 changes: 66 additions & 0 deletions Siphon/Schedules/DailySchedule.vb
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
16 changes: 16 additions & 0 deletions Siphon/Schedules/IMonitorSchedule.vb
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
54 changes: 54 additions & 0 deletions Siphon/Schedules/IntervalSchedule.vb
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
42 changes: 42 additions & 0 deletions Siphon/Schedules/MonitorSchedule.vb
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
8 changes: 8 additions & 0 deletions Siphon/Siphon.vbproj
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@
<Import Include="System.Diagnostics" />
</ItemGroup>
<ItemGroup>
<Compile Include="Monitors\DataMonitor.vb" />
<Compile Include="Monitors\IDataMonitor.vb" />
<Compile Include="Processors\IDataProcessor.vb" />
<Compile Include="Monitors\IDirectoryMonitor.vb" />
<Compile Include="Schedules\DailySchedule.vb" />
<Compile Include="Schedules\IMonitorSchedule.vb" />
<Compile Include="My Project\AssemblyInfo.vb" />
<Compile Include="My Project\Application.Designer.vb">
<AutoGen>True</AutoGen>
Expand All @@ -68,6 +74,8 @@
<DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
<Compile Include="Schedules\IntervalSchedule.vb" />
<Compile Include="Schedules\MonitorSchedule.vb" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="My Project\Resources.resx">
Expand Down
10 changes: 10 additions & 0 deletions SiphonTests/MonitorTests.vb
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

0 comments on commit af5d22d

Please sign in to comment.