Projektdateien hinzufügen.
This commit is contained in:
57
FileinterfaceCronScheduler/Scheduler/SchedulerRuntime.cs
Normal file
57
FileinterfaceCronScheduler/Scheduler/SchedulerRuntime.cs
Normal file
@@ -0,0 +1,57 @@
|
||||
using System;
|
||||
|
||||
namespace FileInterface.Scheduler
|
||||
{
|
||||
public sealed class SchedulerRuntime : IDisposable
|
||||
{
|
||||
private readonly CronScheduler _scheduler;
|
||||
private readonly FileSystemWatcherManager _watcherManager;
|
||||
private readonly WebAdminServer _web;
|
||||
private readonly IDisposable _ownedResource;
|
||||
private bool _disposed;
|
||||
|
||||
public SchedulerRuntime(ICustomFunctionInvoker invoker, SchedulerOptions options)
|
||||
: this(invoker, options, null)
|
||||
{
|
||||
}
|
||||
|
||||
public SchedulerRuntime(ICustomFunctionInvoker invoker, SchedulerOptions options, IDisposable ownedResource)
|
||||
{
|
||||
if (invoker == null) throw new ArgumentNullException("invoker");
|
||||
if (options == null) options = new SchedulerOptions();
|
||||
|
||||
_ownedResource = ownedResource;
|
||||
var cronRepository = new CronJobRepository(options.ConfigFile);
|
||||
var watcherRepository = new WatcherJobRepository(options.WatcherConfigFile);
|
||||
var log = new JobLog(5000);
|
||||
var cronExecutor = new CronJobExecutor(invoker, log);
|
||||
var watcherExecutor = new WatcherJobExecutor(invoker, log);
|
||||
_scheduler = new CronScheduler(cronRepository, cronExecutor, log);
|
||||
_watcherManager = new FileSystemWatcherManager(watcherRepository, watcherExecutor, log);
|
||||
_web = new WebAdminServer(cronRepository, _scheduler, watcherRepository, _watcherManager, log, options);
|
||||
}
|
||||
|
||||
public void Start()
|
||||
{
|
||||
_scheduler.Start();
|
||||
_watcherManager.Start();
|
||||
_web.Start();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (_disposed) return;
|
||||
_disposed = true;
|
||||
try { _web.Dispose(); }
|
||||
finally
|
||||
{
|
||||
try { _watcherManager.Dispose(); }
|
||||
finally
|
||||
{
|
||||
try { _scheduler.Dispose(); }
|
||||
finally { if (_ownedResource != null) _ownedResource.Dispose(); }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user