public static void CompleteTask() { List <BackgroundTask> tasks = TaskController.GetTasks(Guid); if (tasks.Count == 0) { return; } BackgroundTask topTask = tasks[tasks.Count - 1]; // call event handler CallTaskEventHandler(topTask, true); // finish task topTask.FinishDate = DateTime.Now; topTask.Completed = true; // write task execution result to database if (tasks.Count == 1) // single task { // write to database AddAuditLog(topTask); } TaskController.UpdateTask(topTask); StopProcess(topTask); }
private static void WriteLogRecord(Guid guid, int severity, string text, string stackTrace, params string[] textParameters) { List <BackgroundTask> tasks = TaskController.GetTasks(guid); if (tasks.Count > 0) { BackgroundTask rootTask = tasks[0]; BackgroundTaskLogRecord log = new BackgroundTaskLogRecord( rootTask.Id, tasks.Count - 1, false, text, stackTrace, textParameters); TaskController.AddLog(log); if (severity > rootTask.Severity) { rootTask.Severity = severity; TaskController.UpdateTask(rootTask); } } }
public static void StartTask(string taskId, string source, string taskName, object itemName, int itemId, int scheduleId, int packageId, int maximumExecutionTime, List <BackgroundTaskParameter> parameters) { if (String.IsNullOrEmpty(taskId)) { taskId = Guid.NewGuid().ToString("N"); } var user = SecurityContext.User; int userId = user.OwnerId == 0 ? user.UserId : user.OwnerId; int effectiveUserId = user.UserId; String itemNameStr = itemName != null ? itemName.ToString() : String.Empty; //: itemId > 0 ? "(Id = " + itemId + ")" : String.Empty; BackgroundTask task = new BackgroundTask(Guid, taskId, userId, effectiveUserId, source, taskName, itemNameStr, itemId, scheduleId, packageId, maximumExecutionTime, parameters); List <BackgroundTask> tasks = TaskController.GetTasks(Guid); if (tasks.Count > 0) { BackgroundTask rootTask = tasks[0]; BackgroundTaskLogRecord log = new BackgroundTaskLogRecord( rootTask.Id, tasks.Count - 1, true, String.Format("{0}_{1}", source, taskName), new string[] { itemNameStr }); TaskController.AddLog(log); } // call event handler CallTaskEventHandler(task, false); AddTaskThread(TaskController.AddTask(task), Thread.CurrentThread); }
public static Dictionary <int, BackgroundTask> GetScheduledTasks() { Dictionary <int, BackgroundTask> scheduledTasks = new Dictionary <int, BackgroundTask>(); try { foreach (BackgroundTask task in TaskController.GetTasks()) { if (task.ScheduleId > 0 && !task.Completed && (task.Status == BackgroundTaskStatus.Run || task.Status == BackgroundTaskStatus.Starting) && !scheduledTasks.ContainsKey(task.ScheduleId)) { scheduledTasks.Add(task.ScheduleId, task); } } } catch { } return(scheduledTasks); }
public static List <BackgroundTask> GetUserTasks(int userId) { List <BackgroundTask> list = new List <BackgroundTask>(); // try to get user first UserInfo user = UserController.GetUser(userId); if (user == null) { return(list); // prohibited user } // get user tasks foreach (BackgroundTask task in TaskController.GetTasks(user.IsPeer ? user.OwnerId : user.UserId)) { if (task.UserId == userId && !task.Completed && task.Status == BackgroundTaskStatus.Run) { list.Add(task); } } return(list); }
public static int GetTasksNumber() { return(TaskController.GetTasks().Count); }