예제 #1
0
        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
                );
        }
예제 #2
0
        private static void Continue()
        {
            Console.WriteLine("CONTINUING!");

            var storageEngine = new SimpleFileStorageEngine($"./timer.txt", false);

            var scheduler = new PoormansExecutionEngine();

            scheduler.Start(storageEngine, true);
        }
예제 #3
0
        public PersistentTimer(DateTime expiration, Action action, bool hasBeenExecuted, PoormansExecutionEngine executionEngine)
        {
            _expiration      = expiration;
            _action          = action;
            _hasBeenExecuted = hasBeenExecuted;
            _executionEngine = executionEngine;

            if (!_hasBeenExecuted)
            {
                executionEngine.Schedule(Start);
            }
        }
예제 #4
0
        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));
        }