Ejemplo n.º 1
0
        public ContentResult Task_API()
        {
            scheMod = scheBll.SelReturnModel(DataConvert.CLng(ids));
            if (scheMod == null)
            {
                return(Content("任务不存在"));
            }
            switch (action)
            {
            case "del":
            {
                scheBll.Delete(scheMod.ID);
                RecurringJob.RemoveIfExists(scheMod.TaskFlag);
            }
            break;

            case "stop":
            {
                if (scheMod.Status != -1)
                {
                    scheMod.Status = -1;
                    scheBll.Update(scheMod);
                }
                RecurringJob.RemoveIfExists(scheMod.TaskFlag);
            }
            break;

            case "start":
            {
                if (scheMod.Status == -1)
                {
                    scheMod.Status = 0;
                    scheBll.Update(scheMod);
                    HFHelper.AddTask(scheMod);
                }
            }
            break;

            case "execute":
            {
                BackgroundJob.Enqueue <HF_Task_ExecuteSql>(x => x.Execute(scheMod));
            }
            break;
            }
            return(Content(Success.ToString()));
        }
Ejemplo n.º 2
0
        public IActionResult TaskAdd_Submit()
        {
            if (Mid > 0)
            {
                scheMod = scheBll.GetModel(Mid);
            }
            scheMod.TaskName = RequestEx["TaskName_T"];
            //scheMod.ExecuteTime = ExecuteTime_T1.Text;
            scheMod.Interval = DataConvert.CLng(RequestEx["Interval_T"]);
            string taskContent = RequestEx["TaskContent_T"].Trim();

            if (taskContent.StartsWith("/"))//任务内容为脚本路径时
            {
                if (!System.IO.File.Exists(function.VToP(taskContent)))
                {
                    return(WriteErr("脚本不存在"));
                }
                else
                {
                    scheMod.TaskContent = taskContent;
                }
            }
            else
            {
                scheMod.TaskContent = taskContent;
            }
            scheMod.Remind = RequestEx["Remind_T"];
            //任务类型不允许修改
            if (Mid <= 0)
            {
                scheMod.TaskType = DataConvert.CLng(Request.Form["taskType_rad"]);
            }
            scheMod.ExecuteType = DataConvert.CLng(Request.Form["executeType_rad"]);
            scheMod.Status      = DataConvert.CLng(Request.Form["status_rad"]);
            if (scheMod.ExecuteType == (int)M_Content_ScheTask.ExecuteTypeEnum.Interval)
            {
                if (scheMod.Interval <= 0)
                {
                    return(WriteErr("未指定正确的间隔时间"));
                }
            }
            else if (scheMod.ExecuteType == (int)M_Content_ScheTask.ExecuteTypeEnum.JustOnce)
            {
                scheMod.ExecuteTime = RequestEx["ExecuteTime_T1"];
                if (DataConvert.CDate(scheMod.ExecuteTime) < DateTime.Now)
                {
                    return(WriteErr("执行时间无效"));
                }
            }
            else if (scheMod.ExecuteType == (int)M_Content_ScheTask.ExecuteTypeEnum.EveryDay)
            {
                scheMod.ExecuteTime = RequestEx["ExecuteTime_T2"];
            }
            else if (scheMod.ExecuteType == (int)M_Content_ScheTask.ExecuteTypeEnum.EveryMonth)
            {
                scheMod.ExecuteTime = RequestEx["ExecuteTime_T1"];
            }
            if (Mid > 0)
            {
                scheBll.Update(scheMod);
            }
            else
            {
                scheMod.CDate   = DateTime.Now;
                scheMod.AdminID = adminMod.AdminId;
                scheMod.ID      = scheBll.Add(scheMod);
            }
            HFHelper.AddTask(scheMod);
            return(WriteOK("操作成功", "TaskList"));
        }