/// <summary> /// Queue up an action to run at given intervals. /// </summary> public static void Register(TaskWrapperEntry entry) { if (string.IsNullOrWhiteSpace(entry.Name)) { throw new Exception("Name is required."); } if (entry.Action == null) { throw new Exception("Action is required."); } if (Entries.SingleOrDefault(n => n.Name == entry.Name) != null) { throw new Exception("Task with same name already exists."); } Entries.Add(entry); Log( entry, "Registered new TaskWrapperEntry.", TaskWrapperLogType.Info); if (entry.RunAtRegister) { entry.Run(); } else { entry.QueueNextRun(null); } }
/// <summary> /// Add a new log entry. /// </summary> public static void Log(TaskWrapperEntry entry, string message, TaskWrapperLogType logType, Exception exception = null) { foreach (var logAction in LogActions) { logAction.Invoke( entry, message, logType, exception); } }