Exemple #1
0
        protected override void InternalExecute(InputTypeInput input, InputTypeVariantsOutput output)
        {
            RegisteredInputType inputType = _registeredInputTypes.FirstOrDefault(x => x.InputType.Code == input.InputTypeCode);

            if (inputType == null)
            {
                output.Success      = false;
                output.ErrorMessage = "Unknown input type: " + input.InputTypeCode;
            }
            else if (inputType.VariantsProvider == null)
            {
                output.Success      = false;
                output.ErrorMessage = "Input type " + input.InputTypeCode + " has no variants provided";
            }
            else
            {
                output.Items = inputType.VariantsProvider.GetVariants().ToArray();
            }
        }
        protected override void InternalExecute(AddTriggerInput input, AddTriggerOutput output)
        {
            IDictionary <string, object> jobDataMap = null;

            if (input.JobDataMap != null)
            {
                jobDataMap = new Dictionary <string, object>();

                IDictionary <string, string> validationErrors = new Dictionary <string, string>();

                foreach (JobDataItem item in input.JobDataMap)
                {
                    RegisteredInputType inputType = _registeredInputTypes.FirstOrDefault(x => x.InputType.Code == item.InputTypeCode);
                    if (inputType == null)
                    {
                        /*
                         * We can only get here if client-side input type
                         * definitions are not in sync with server-side.
                         */
                        validationErrors[item.Key] = "Unknown input type: " + item.InputTypeCode;
                    }
                    else
                    {
                        try
                        {
                            var value = inputType.Converter == null
                                ? item.Value
                                : inputType.Converter.Convert(item.Value);

                            jobDataMap[item.Key] = value;
                        }
                        catch (Exception ex)
                        {
                            validationErrors[item.Key] = ex.Message;
                        }
                    }
                }

                if (validationErrors.Any())
                {
                    output.ValidationErrors = validationErrors;

                    return;
                }
            }

            if (!string.IsNullOrEmpty(input.JobClass))
            {
                Type jobType = Type.GetType(input.JobClass, true);

                if (!SchedulerHost.AllowedJobTypesRegistry.List().Contains(jobType))
                {
                    output.Success      = false;
                    output.ErrorMessage = "Job type " + jobType.FullName + " is not allowed";
                    return;
                }

                SchedulerHost.Commander.ScheduleJob(
                    NullIfEmpty(input.Job),
                    NullIfEmpty(input.Group),
                    jobType,
                    input.Name,
                    CreateTriggerType(input),
                    jobDataMap);
            }
            else
            {
                if (string.IsNullOrEmpty(input.Job))
                {
                    output.Success      = false;
                    output.ErrorMessage = "Job Name is required when adding trigger to an existing job";
                }
                else
                {
                    SchedulerHost.Commander.ScheduleJob(
                        input.Job,
                        input.Group,
                        input.Name,
                        CreateTriggerType(input),
                        jobDataMap);
                }
            }
        }
        protected override void InternalExecute(AddTriggerInput input, AddTriggerOutput output)
        {
            IDictionary <string, object> jobDataMap = null;

            if (input.JobDataMap != null)
            {
                jobDataMap = new Dictionary <string, object>();

                IDictionary <string, string> validationErrors = new Dictionary <string, string>();

                foreach (JobDataItem item in input.JobDataMap)
                {
                    //dataMap  input类型
                    RegisteredInputType inputType = _registeredInputTypes.FirstOrDefault(x => x.InputType.Code == item.InputTypeCode);
                    if (inputType == null)
                    {
                        /*
                         *只有当客户端输入类型定义与服务器端不同步时,我们才能到达这里。
                         */
                        validationErrors[item.Key] = "不知道的 input type: " + item.InputTypeCode;
                    }
                    else
                    {
                        try
                        {
                            var value = inputType.Converter == null
                                ? item.Value
                                : inputType.Converter.Convert(item.Value);

                            jobDataMap[item.Key] = value;
                        }
                        catch (Exception ex)
                        {
                            validationErrors[item.Key] = ex.Message;
                        }
                    }
                }

                if (validationErrors.Any())
                {
                    output.ValidationErrors = validationErrors;

                    return;
                }
            }

            if (!string.IsNullOrEmpty(input.JobClass))
            {
                //反射Class
                Type jobType = Type.GetType(input.JobClass, true);

                //if (!SchedulerHost.AllowedJobTypesRegistry.List().Contains(jobType))
                //{
                //    output.Success = false;
                //    output.ErrorMessage = "Job type " + jobType.FullName + " 是不允许的";
                //    return;
                //}

                SchedulerHost.Commander.ScheduleJob(
                    NullIfEmpty(input.Job),
                    NullIfEmpty(input.Group),
                    jobType,
                    input.Name,
                    CreateTriggerType(input),
                    jobDataMap);
            }
            else
            {
                if (string.IsNullOrEmpty(input.Job))
                {
                    output.Success      = false;
                    output.ErrorMessage = "当给一个存在的job 添加触发器时 ,job Name 是必须有值的.";
                }
                else
                {
                    SchedulerHost.Commander.ScheduleJob(
                        input.Job,
                        input.Group,
                        input.Name,
                        CreateTriggerType(input),
                        jobDataMap);
                }
            }
        }