Exemple #1
0
        /// <summary>
        /// Check if a task needs to be run
        /// </summary>
        /// <param name="key">The key of the task</param>
        /// <param name="runAfter">Set a runafter schedule</param>
        public bool NeedsToRun(string key, After runAfter = null)
        {
            if (string.IsNullOrEmpty(key))
            {
                throw new ArgumentException("Once need a key to work with", nameof(key));
            }

            var at = GetPreference(key);

            if (at == null)
            {
                return(true); // probably just a run once task
            }
            else
            {
                return(runAfter != null?ItsTime(runAfter, at.Value) : false);
            }
        }
Exemple #2
0
        /// <summary>
        /// Check if a task needs to be run
        /// </summary>
        /// <param name="key">The key of the task</param>
        /// <param name="task">The Command to run when the time is right</param>
        /// <param name="autoMarkAsDone">Automaticly mark the task as done</param>
        /// <param name="runAfter">Set a runafter schedule</param>
        public void RunWhen(string key, Command task, bool autoMarkAsDone = false, After runAfter = null)
        {
            if (string.IsNullOrEmpty(key))
            {
                throw new ArgumentException("Once need a key to work with", nameof(key));
            }
            if (task is null)
            {
                throw new ArgumentNullException(nameof(task));
            }

            var at = GetPreference(key);

            if (at == null || ItsTime(runAfter, at.Value))
            {
                task.Execute(key);
                if (autoMarkAsDone)
                {
                    SetPreference(key, DateTime.Now);
                }
            }
        }