Пример #1
0
        /// <summary>
        /// 添加任务
        /// </summary>
        /// <param name="addJobViewModel">添加任务模型</param>
        /// <returns></returns>

        public JsonResult AddJob(AddJobViewModel addJobViewModel)
        {
            if (!ModelState.IsValid)
            {
                return(Json(ResponseDataFactory.CreateAjaxResponseData("-10001", "添加失败", "输入参数错误:" + ModelState.Values.Where(item => item.Errors.Count == 1).Aggregate(string.Empty, (current, item) => current + (item.Errors[0].ErrorMessage + ";   ")))));
            }
            var values     = addJobViewModel.SchedulerHost.Split('/');
            var host       = values[0];
            var name       = string.Empty;
            var instanceId = string.Empty;

            if (host.Length > 1 && host.Length <= 2)
            {
                name = addJobViewModel.SchedulerHost.Split('/')[1];
            }
            else
            {
                instanceId = addJobViewModel.SchedulerHost.Split('/')[2];
            }
            var customeJobInfo = new custom_job_infoes()
            {
                CreateTime = DateTime.Now, Cron = addJobViewModel.CronJob.Cron, CurrentSchedulerHost = host, CurrentSchedulerHostName = name, CurrentSchedulerInstanceId = instanceId, Cycle = addJobViewModel.SimpleJob.Cycle, Deleted = 0, Description = addJobViewModel.JobDescription, DllName = "Quartz.Net_Core.dll", JobName = addJobViewModel.JobName, FullJobName = "Quartz.Net_Core.JobExcute.JobItem", OriginSchedulerHost = host, OriginSchedulerHostName = name, OriginSchedulerInstanceId = instanceId, RepeatCount = addJobViewModel.SimpleJob.RepeatCount, RequestUrl = addJobViewModel.RequestUrl, TriggerState = 0, TriggerType = addJobViewModel.TriggerType
            };
            var jobId = _customerJobInfoRepository.AddCustomerJobInfo(customeJobInfo);

            return(Json(ResponseDataFactory.CreateAjaxResponseData("1", "添加成功", jobId)));
        }
        /// <summary>
        /// 添加任务
        /// </summary>
        /// <param name="addJobViewModel">添加任务模型</param>
        /// <returns></returns>

        public JsonResult AddJob(AddJobViewModel addJobViewModel)
        {
            if (!ModelState.IsValid)
            {
                return(Json(ResponseDataFactory.CreateAjaxResponseData("-10001", "添加失败", "输入参数错误:" + ModelState.Values.Where(item => item.Errors.Count == 1).Aggregate(string.Empty, (current, item) => current + (item.Errors[0].ErrorMessage + ";   ")))));
            }

            if (addJobViewModel.TriggerState == 2)
            {
                var lengh           = addJobViewModel.JobName.Length;
                var originalJobName = addJobViewModel.JobName.Substring(0, lengh - 19);

                var originalJob =
                    _customerJobInfoRepository.LoadCustomerInfo(x => x.JobName == originalJobName);

                var jobInfo = new customer_quartzjobinfo
                {
                    CreateTime       = DateTime.Now,
                    Cron             = originalJob.Cron,
                    Description      = addJobViewModel.JobDescription,
                    JobGroupName     = addJobViewModel.JobGroupName,
                    JobName          = addJobViewModel.JobName,
                    TriggerState     = 2,
                    TriggerName      = addJobViewModel.TriggerName,
                    TriggerGroupName = addJobViewModel.TriggerGroupName,
                    DLLName          = ConfigurationManager.AppSettings["dllName"],
                    FullJobName      = ConfigurationManager.AppSettings["FullJobName"],
                    RequestUrl       = originalJob.RequestUrl,
                    Deleted          = false,
                    Cycle            = originalJob.Cycle,
                    TriggerType      = originalJob.TriggerType,
                    RepeatCount      = originalJob.RepeatCount
                };
                var jobId = _customerJobInfoRepository.AddCustomerJobInfo(jobInfo);
                return(Json(ResponseDataFactory.CreateAjaxResponseData("1", "操作成功", jobId)));
            }
            else
            {
                var jobId = _customerJobInfoRepository.AddCustomerJobInfo(addJobViewModel.JobName, addJobViewModel.JobGroupName, addJobViewModel.TriggerName, addJobViewModel.TriggerGroupName, addJobViewModel.CronJob == null ? null : addJobViewModel.CronJob.Cron, addJobViewModel.JobDescription, addJobViewModel.RequestUrl, addJobViewModel.SimpleJob == null ? null : addJobViewModel.SimpleJob.Cycle, addJobViewModel.SimpleJob == null ? null : addJobViewModel.SimpleJob.RepeatCount, addJobViewModel.TriggerType);
                return(Json(ResponseDataFactory.CreateAjaxResponseData("1", "添加成功", jobId)));
            }
        }
Пример #3
0
        /// <summary>
        /// 添加任务
        /// </summary>
        /// <param name="addJobViewModel">添加任务模型</param>
        /// <returns></returns>

        public JsonResult AddJob(AddJobViewModel addJobViewModel)
        {
            if (!ModelState.IsValid)
            {
                return(Json(ResponseDataFactory.CreateAjaxResponseData("-10001", "添加失败", "输入参数错误:" + ModelState.Values.Where(item => item.Errors.Count == 1).Aggregate(string.Empty, (current, item) => current + (item.Errors[0].ErrorMessage + ";   ")))));
            }

            var jobId = _customerJobInfoRepository.AddCustomerJobInfo(addJobViewModel.JobName, addJobViewModel.JobGroupName, addJobViewModel.TriggerName, addJobViewModel.TriggerGroupName, addJobViewModel.CronJob == null ? null : addJobViewModel.CronJob.Cron, addJobViewModel.JobDescription, addJobViewModel.RequestUrl, addJobViewModel.SimpleJob == null ? null : addJobViewModel.SimpleJob.Cycle, addJobViewModel.SimpleJob == null ? null : addJobViewModel.SimpleJob.RepeatCount, addJobViewModel.TriggerType);

            return(Json(ResponseDataFactory.CreateAjaxResponseData("1", "添加成功", jobId)));
        }