48 lines
1.6 KiB
C#
48 lines
1.6 KiB
C#
using System;
|
|
using System.Configuration;
|
|
using System.IO;
|
|
using FileInterface.Scheduler;
|
|
|
|
namespace FileinterfaceCronScheduler
|
|
{
|
|
internal static class RuntimeFactory
|
|
{
|
|
public static SchedulerRuntime Create()
|
|
{
|
|
string baseDir = AppDomain.CurrentDomain.BaseDirectory;
|
|
string cronConfigFile = Get("Scheduler.ConfigFile", "cronjobs.json");
|
|
string watcherConfigFile = Get("Watcher.ConfigFile", "watcherjobs.json");
|
|
|
|
if (!Path.IsPathRooted(cronConfigFile)) cronConfigFile = Path.Combine(baseDir, cronConfigFile);
|
|
if (!Path.IsPathRooted(watcherConfigFile)) watcherConfigFile = Path.Combine(baseDir, watcherConfigFile);
|
|
|
|
var options = new SchedulerOptions
|
|
{
|
|
ConfigFile = cronConfigFile,
|
|
WatcherConfigFile = watcherConfigFile,
|
|
WebPrefix = Get("Scheduler.WebPrefix", "http://127.0.0.1:8095/"),
|
|
WebUser = Get("Scheduler.WebUser", "admin"),
|
|
WebPassword = Get("Scheduler.WebPassword", "admin")
|
|
};
|
|
|
|
var invoker = new ImsCustomFunctionInvoker();
|
|
try
|
|
{
|
|
invoker.Connect();
|
|
return new SchedulerRuntime(invoker, options, invoker);
|
|
}
|
|
catch
|
|
{
|
|
invoker.Dispose();
|
|
throw;
|
|
}
|
|
}
|
|
|
|
private static string Get(string key, string fallback)
|
|
{
|
|
string value = ConfigurationManager.AppSettings[key];
|
|
return String.IsNullOrWhiteSpace(value) ? fallback : value.Trim();
|
|
}
|
|
}
|
|
}
|