Ejemplo n.º 1
0
        public Model.OperationResult AddJob(string name, string description, bool active, StartType startType, Trigger trigger, string className)
        {
            string message;

            if (string.IsNullOrWhiteSpace(name))
            {
                return OperationResult.Failure("Job名称不能为空");
            }
            if (string.IsNullOrWhiteSpace(className))
            {
                return OperationResult.Failure("Job类型名称不能为空");
            }
            if (!ValidataeTrigger(trigger, out message))
            {
                return OperationResult.Failure(message);
            }

            bool success = JobManager.Instance.AddJob(name, description, active, (StartType)startType, className, trigger, out message);

            return new Model.OperationResult
            {
                Success = success,
                Message = message
            };
        }
Ejemplo n.º 2
0
        public Model.OperationResult EditJob(Guid id, string description, bool active, StartType startType, Trigger trigger, string className)
        {
            string message;

            if (string.IsNullOrWhiteSpace(className))
            {
                return OperationResult.Failure("Job类型名称不能为空");
            }
            if (!ValidataeTrigger(trigger, out message))
            {
                return OperationResult.Failure(message);
            }

            var job = JobManager.Instance.GetJob(id);

            if (job == null)
            {
                return OperationResult.Failure("Job不存在");
            }

            bool success = job.Edit(description, active, startType, trigger, className, out message);

            return new Model.OperationResult
            {
                Success = success,
                Message = message
            };
        }
Ejemplo n.º 3
0
        private void Submit()
        {
            if (this.IsLoading)
            {
                return;
            }

            this.IsLoading = true;

            Task.Factory.StartNew(() =>
            {
                OperationResult result = null;

                var trigger = new JobConsole.Model.Trigger();

                if (this.Model.IsSimpleTrigger)
                {
                    trigger.Simple = new SimpleTrigger
                    {
                        RepeatCount = this.Model.RepeatForever ? -1 : this.Model.RepeatCount
                    };

                    int interval = this.Model.IntervalDays * 24 * 60 * 60 + this.Model.IntervalHours * 60 * 60 + this.Model.IntervalMinutes * 60 + this.Model.IntervalSeconds;
                    trigger.Simple.RepeatInterval = interval * 1000;
                }
                else
                {
                    trigger.Cron = new CronTrigger
                    {
                        Expression = this.Model.CronExpression
                    };
                }
                trigger.StartTime = this.Model.StartTime;
                trigger.EndTime = this.Model.EndTime;

                if (this.ID.HasValue)
                {
                    result = this.ClientService.JobService.EditJob(this.ID.Value, this.Model.Description, this.Model.Active, this.Model.StartType, trigger, this.Model.ClassName);
                }
                else
                {
                    result = this.ClientService.JobService.AddJob(this.Model.Name, this.Model.Description, this.Model.Active, this.Model.StartType, trigger, this.Model.ClassName);
                }

                this.IsLoading = false;

                if (result.Success)
                {
                    this.InvokeOnUIDispatcher(() =>
                    {
                        this.NavigationService.Journal.GoBack();
                    });
                }
                else
                {
                    MessageBox.Show(result.Message);
                }
            });
        }
Ejemplo n.º 4
0
 private bool ValidataeTrigger(Trigger trigger, out string message)
 {
     if (trigger == null)
     {
         message = "请指定触发器";
         return false;
     }
     if (trigger.Simple == null && trigger.Cron == null)
     {
         message = "请指定触发器";
         return false;
     }
     if (!(trigger.StartTime.HasValue && trigger.EndTime.HasValue) && !(trigger.StartTime == null && trigger.EndTime == null))
     {
         message = "若要指定开始/结束时间,则两者必须同时指定";
         return false;
     }
     if (trigger.StartTime > trigger.EndTime)
     {
         message = "触发器开始时间不能大于结束时间";
         return false;
     }
     message = null;
     return true;
 }