public static bool BeginTask(int userID, StepByStepTaskBase taskAction, string param) { Type taskType = taskAction.GetType(); Guid taskID = Guid.NewGuid(); RunningTask task = new RunningTask(taskAction); int totalCount = 0; long offset = 0; string title; if (task.Task.BeforeExecute(userID, param, ref offset, ref totalCount, out title) == false) { return(false); } int result = StepByStepTaskDao.Instance.BeginTask(taskID, taskType, userID, param, totalCount, offset, title, taskAction.InstanceMode); switch (result) { case 0: return(true); case 1: case 2: return(false); default: return(false); } }
/// <summary> /// 执行任务的当前步骤,并返回一个值表示是否继续执行 /// </summary> /// <param name="operatorUserID"></param> /// <param name="taskID"></param> /// <param name="percent"></param> /// <param name="title"></param> /// <returns></returns> public static bool ExecuteTaskStep(int operatorUserID, Guid taskID, out int percent, out string title) { percent = 0; title = string.Empty; bool result = true; lock (executeLocker) { RunningTask task = TaskManager.GetRunningTask(operatorUserID, taskID); if (task == null || task.Task == null) { return(false); } else { bool isLastStep; if (task.Task.StepExecute(task.UserID, task.Param, ref task.Offset, ref task.TotalCount, ref task.FinishedCount, out task.Title, out isLastStep)) { if (isLastStep) { task.Task.AfterExecute(task.UserID, task.Param, true, task.TotalCount, task.FinishedCount, out task.Title); StepByStepTaskDao.Instance.FinishTask(task.TaskID); result = false; } else { StepByStepTaskDao.Instance.UpdateRunnintTaskStatus(task.TaskID, task.Param, task.TotalCount, task.FinishedCount, task.Offset, task.Title); } } else { task.Task.AfterExecute(task.UserID, task.Param, false, task.TotalCount, task.FinishedCount, out task.Title); result = false; } percent = task.Percent; title = task.Title; } } return(result); }