コード例 #1
0
        public static object ModifyTaskEntity(this TaskOptions taskOptions, ISchedulerFactory schedulerFactory,
                                              JobAction action)
        {
            TaskOptions options = null;
            object      result  = null;

            switch (action)
            {
            case JobAction.除:
                for (var i = 0; i < _taskList.Count; i++)
                {
                    options = _taskList[i];
                    if (options.TaskName == taskOptions.TaskName && options.GroupName == taskOptions.GroupName)
                    {
                        _taskList.RemoveAt(i);
                    }
                }

                break;

            case JobAction.修改:
                options = _taskList
                          .FirstOrDefault(x => x.TaskName == taskOptions.TaskName && x.GroupName == taskOptions.GroupName);
                //移除以前的配置
                if (options != null)
                {
                    _taskList.Remove(options);
                }

                //生成任务并添加新配置
                result = taskOptions.AddJob(schedulerFactory).GetAwaiter().GetResult();
                break;

            case JobAction.暂停:
            case JobAction.开启:
            case JobAction.停止:
            case JobAction.立即执行:
                options = _taskList
                          .FirstOrDefault(x => x.TaskName == taskOptions.TaskName && x.GroupName == taskOptions.GroupName);
                if (action == JobAction.暂停)
                {
                    options.Status = (int)TriggerState.Paused;
                }
                else if (action == JobAction.停止)
                {
                    options.Status = (int)action;
                }
                else
                {
                    options.Status = (int)TriggerState.Normal;
                }
                break;
            }

            //生成配置文件
            FileQuartz.WriteJobConfig(_taskList);
            FileQuartz.WriteJobAction(action, taskOptions.TaskName, taskOptions.GroupName,
                                      "操作对象:" + JsonConvert.SerializeObject(taskOptions));
            return(result);
        }
コード例 #2
0
        public static object ModifyTaskEntity(this TaskOptions taskOptions, ISchedulerFactory schedulerFactory, TaskAction action)
        {
            object result = null;
            switch (action)
            {
                case TaskAction.删除:
                    TaskRepository.DeleteTask(new List<string> { taskOptions.id });
                    break;
                case TaskAction.修改:
                    result = taskOptions.AddJob(schedulerFactory, true).GetAwaiter().GetResult();
                    break;
                case TaskAction.暂停:
                case TaskAction.开启:
                case TaskAction.停止:
                case TaskAction.立即执行:
                    if (action == TaskAction.暂停)
                    {
                        taskOptions.status = (int)TriggerState.Paused;
                    }
                    else if (action == TaskAction.停止)
                    {
                        taskOptions.status = (int)action;
                    }
                    else
                    {
                        taskOptions.status = (int)TriggerState.Normal;
                    }
                    break;
            }
            if (action != TaskAction.删除)
            {
                TaskRepository.UpdateTask(taskOptions);
            }

            return result;
        }
コード例 #3
0
 public async Task <IActionResult> Add(TaskOptions taskOptions)
 {
     return(Json(await taskOptions.AddJob(_schedulerFactory)));
 }
コード例 #4
0
 public async Task <IActionResult> Add([FromQuery] TaskOptions taskOptions, string id, string name)
 {
     return(Ok(await taskOptions.AddJob(_schedulerFactory)));
 }
コード例 #5
0
 public async Task <IActionResult> AddAsyn(TaskOptions taskOptions)
 {
     //TODO:作业信息入库
     return(Json(await taskOptions.AddJob(_schedulerFactory)));
 }