public static void Do() { var @continue = File.Exists(@"./timer.txt"); if (@continue) { Continue(); return; } var storageEngine = new SimpleFileStorageEngine(@"./timer.txt", false); var scheduler = new PoormansExecutionEngine(); scheduler.Start(storageEngine, false); scheduler.Schedule(() => Console.WriteLine("Hello From Anonymous Function")); var cw = new ConsoleWriter("Hello From Console Writer"); new PersistentTimer( DateTime.Now + TimeSpan.FromSeconds(10), cw.Do, false, scheduler ); }
private static void Continue() { Console.WriteLine("CONTINUING!"); var storageEngine = new SimpleFileStorageEngine($"./timer.txt", false); var scheduler = new PoormansExecutionEngine(); scheduler.Start(storageEngine, true); }
public PersistentTimer(DateTime expiration, Action action, bool hasBeenExecuted, PoormansExecutionEngine executionEngine) { _expiration = expiration; _action = action; _hasBeenExecuted = hasBeenExecuted; _executionEngine = executionEngine; if (!_hasBeenExecuted) { executionEngine.Schedule(Start); } }
private static PersistentTimer Deserialize(IReadOnlyDictionary <string, object> sd, PoormansExecutionEngine executionEngine) { var expiration = sd.Get <DateTime>(nameof(_expiration)); var action = sd.Get <Action>(nameof(_action)); var hasBeenExecuted = sd.Get <bool>(nameof(_hasBeenExecuted)); return(new PersistentTimer(expiration, action, hasBeenExecuted, executionEngine)); }