Ejemplo n.º 1
0
        /// <summary>
        /// 新增Job
        /// </summary>
        /// <param name="model"></param>
        public void Add(JobInfoUpdateInputModel model)
        {
            if (string.IsNullOrWhiteSpace(model.Name) ||
                string.IsNullOrWhiteSpace(model.ServiceUrl) ||
                string.IsNullOrWhiteSpace(model.CronString))
            {
                throw new JIFException("Job 信息不完整");
            }

            if (!CronExpression.IsValidExpression(model.CronString))
            {
                throw new JIFException("Cro-expression 字符串不合规");
            }

            var job = new JobInfo();

            job.Id          = Guid.NewGuid().ToString("N");
            job.Name        = model.Name;
            job.Description = model.Description;
            job.ServiceUrl  = model.ServiceUrl;
            job.CronString  = model.CronString;
            job.Enabled     = true;

            _jobInfoRepository.Insert(job);

            _schedulerContainer.AddScheduler(job.Id, job.ServiceUrl, job.Name, job.CronString);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 修改Job
        /// </summary>
        public void Update(string id, JobInfoUpdateInputModel model)
        {
            if (string.IsNullOrWhiteSpace(id))
            {
                throw new JIFException("Job 编号不能为空");
            }

            var job = Get(id);

            if (job == null)
            {
                throw new JIFException("Job 信息不存在");
            }


            if (string.IsNullOrWhiteSpace(model.Name) ||
                string.IsNullOrWhiteSpace(model.ServiceUrl) ||
                string.IsNullOrWhiteSpace(model.CronString))
            {
                throw new JIFException("Job 信息不完整");
            }

            if (!CronExpression.IsValidExpression(model.CronString))
            {
                throw new JIFException("Cro-expression 字符串不合规");
            }

            job.Name        = model.Name;
            job.Description = model.Description;
            job.ServiceUrl  = model.ServiceUrl;
            job.CronString  = model.CronString;

            _jobInfoRepository.Update(job);

            _schedulerContainer.UpdateScheduler(job.Id, job.CronString);
        }
Ejemplo n.º 3
0
        public ActionResult Add(JobInfoUpdateInputModel model)
        {
            _jobInfoService.Add(model);

            return(RedirectToAction("Index"));
        }
Ejemplo n.º 4
0
        public ActionResult Detail(string id, JobInfoUpdateInputModel model)
        {
            _jobInfoService.Update(id, model);

            return(Detail(id));
        }