Example #1
0
        private List <TriggerModel> GetTriggerList(IScheduler scheduler)
        {
            var list           = new List <TriggerModel>();
            var allTriggerKeys = scheduler.GetTriggerKeys(GroupMatcher <TriggerKey> .AnyGroup());

            foreach (var triggerKey in allTriggerKeys)
            {
                ITrigger trigger = scheduler.GetTrigger(triggerKey);

                var model = new TriggerModel()
                {
                    Name        = trigger.Key.Name,
                    Group       = trigger.Key.Group,
                    Description = trigger.Description,
                    //PreviousFireTimeUTC = trigger.GetPreviousFireTimeUtc().ToString(),
                    //NextFireTimeUTC = trigger.GetNextFireTimeUtc().ToString()
                };

                var date = trigger.GetNextFireTimeUtc()?.DateTime;
                if (date.HasValue)
                {
                    model.NextFireTimeUTC = date.Value.ToLocalTime().ToString();
                }

                list.Add(model);
            }

            return(list);
        }
Example #2
0
        public async Task <Message <TriggerModel> > UpdateTrigger(int id, TriggerModel model)
        {
            var requestUrl = CreateRequestUri(string.Format(System.Globalization.CultureInfo.InvariantCulture,
                                                            "Triggers/" + id.ToString()));

            return(await PutAsync <TriggerModel>(requestUrl, model));
        }
 public ActionResult AddTrigger(TriggerModel triggerModel)
 {
     Data.Models.TaskTrigger trigger = new Data.Models.TaskTrigger()
     {
         Crons    = triggerModel.Crons,
         Activate = triggerModel.Activate,
         Expire   = triggerModel.Expire
     };
     trigger.Description = ExpressionDescriptor.GetDescription(triggerModel.Crons, new Options()
     {
         DayOfWeekStartIndexZero = false,
         Use24HourTimeFormat     = true,
         Locale = "zh-CN"
     });
     trigger.Description1 = ExpressionDescriptor.GetDescription(triggerModel.Crons, new Options()
     {
         DayOfWeekStartIndexZero = false,
         Use24HourTimeFormat     = true,
         Locale = "en"
     });
     if (taskTrigger.Insert(trigger) > 0)
     {
         return(new ResponseModel <string>(ErrorCode.success, ""));
     }
     else
     {
         return(new ResponseModel <string>(ErrorCode.server_exception, ""));
     }
 }
Example #4
0
        private void AddProviderAndTitle(TriggerModel model, EmbedObject embedObject)
        {
            if (model == null)
            {
                _logger.LogWarning("Trello Model object is not found. Could be test");
                return;
            }

            if (string.IsNullOrEmpty(model.Url))
            {
                _logger.LogWarning("Trello Model url is not found. Could be test");
            }
            else
            {
                embedObject.Provider.Url = model.Url;
            }

            if (string.IsNullOrEmpty(model.Name))
            {
                _logger.LogWarning("Trello Model name is not found. Could be test");
            }
            else
            {
                embedObject.Title = $"Trello: {model.Name} update";
            }
        }
        private void Append(TriggerModel source, DifferenceModel d)
        {
            string        p  = BuildPath(Path.Combine(this.folderForTarget, source.TableReference.Owner), "Triggers", source.Name);
            StringBuilder sb = new StringBuilder();

            if (!File.Exists(p))
            {
                var file = source.Files.OfType <FileElement>().FirstOrDefault();
                if (file != null && file.Exist(this.rootFolderSource))
                {
                    sb = new StringBuilder(Helpers.ContentHelper.LoadContentFromFile(this.rootFolderSource, file.Path));
                }

                else
                {
                    sb = new StringBuilder(Helpers.ContentHelper.LoadContentFromFile(this.rootFolderSource, file.Path));
                    sb.Append(CreateOrReplace);
                    sb.Append(Utils.Unserialize(source.Code, true));
                }

                if (sb.Length > 0)
                {
                    WriteFile(p, sb.ToString());
                    d.Addfile(p);
                }
            }
        }
Example #6
0
 void IOracleModelVisitor.VisitTrigger(TriggerModel item)
 {
     if (this._filter(item))
     {
         _items.Add(item);
     }
 }
 public override void AppendChange(TriggerModel source, TriggerModel target, string propertyName)
 {
     if (_buckets.Add(source))
     {
         var d = base.AppendDifference(source, target, propertyName);
         Append(source, d);
     }
 }
 public override void AppendMissing(TriggerModel source)
 {
     if (_buckets.Add(source))
     {
         var d = base.AppendDifference(source, false);
         Append(source, d);
     }
 }
Example #9
0
        /// <summary>
        /// 新增job,成功返回success
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public async Task <string> ScheduleJob(TriggerModel model)
        {
            var           json    = JsonSerializer.Serialize(model, JsonSerializerOptions);
            StringContent content = new StringContent(json, Encoding.UTF8, "application/json");

            var response = await httpClient.PostAsync("/Quartz/ScheduleJob", content);

            return(await response.Content.ReadAsStringAsync());
        }
Example #10
0
 public ActionResult DetailTrigger(TriggerModel model)
 {
     ViewBag.del = true;
     if (model != null)
     {
         return(View(model));
     }
     return(NotFound());
 }
Example #11
0
    public IBaseTextModel TriggerModelSolver(string line)
    {
        string[]     splitedStr   = CutOutStrSet(line);
        TriggerModel triggerModel = new TriggerModel(NotNullStr(splitedStr[0]),
                                                     NotNullStr(splitedStr[1]),
                                                     StrToInt(splitedStr[2]));

        return(triggerModel);
    }
Example #12
0
        public override List <TriggerQueryTable_11> Resolve(DbContextOracle context, Action <TriggerQueryTable_11> action)
        {
            List <TriggerQueryTable_11> List = new List <TriggerQueryTable_11>();
            var triggers = context.Database.Triggers;

            this.OracleContext = context;

            if (action == null)
            {
                action =
                    t =>
                {
                    if (!string.IsNullOrEmpty(t.table_name) && t.table_name.ExcludIfStartwith(t.table_owner, Models.Configurations.ExcludeKindEnum.Table))
                    {
                        return;
                    }

                    TriggerModel trigger = new TriggerModel()
                    {
                        ActionType     = t.ACTION_TYPE.Trim(),
                        BaseObjectType = t.base_object_type,
                        Code           = string.Empty,
                        Description    = t.DESCRIPTION,
                        Key            = t.owner + "." + t.trigger_name,
                        Status         = t.status,
                        Name           = t.trigger_name,
                        TriggerStatus  = t.trigger_status,
                        TriggerType    = t.TRIGGER_TYPE,
                    };
                    trigger.TableReference.Owner = t.table_owner;
                    trigger.TableReference.Name  = t.table_name;

                    trigger.Key = trigger.BuildKey();

                    if (triggers.TryGet(trigger.Key, out TriggerModel trigger2))
                    {
                        triggers.Remove(trigger2);
                    }

                    triggers.Add(trigger);
                }
            }
            ;

            TriggerQueryDescriptor_11 Trigger = new TriggerQueryDescriptor_11(context.Manager.ConnectionString);

            sql = string.Format(sql, TableQueryWhereCondition("t", "owner"));

            using (var reader = context.Manager.ExecuteReader(CommandType.Text, sql, QueryBase.DbParams.ToArray()))
            {
                List = Trigger.ReadAll(reader, action).ToList();
            }

            return(List);
        }
    }
Example #13
0
        public virtual void AppendMissing(TriggerModel source)
        {
            AppendDifference(source, false);

            if (generateSource)
            {
                string p = BuildPath(Path.Combine(this.folderForSource, source.TableReference.Owner), "Triggers", source.Name);
                WriteFile(p, CreateOrReplace + Utils.Unserialize(source.Code, true));
            }
        }
Example #14
0
        public static long AddTriggerInfo(DateTime startDate, Repeat repeatType, IEnumerable <int> consumerNotificationSettingIds)
        {
            var triggerModel = new TriggerModel()
            {
                DateStart = startDate,
                ConsumerNotificationSettingIds = consumerNotificationSettingIds.ToList(),
                RepeatType = repeatType
            };

            _triggersInfo.Add(triggerModel);
            return(triggerModel.TriggerId);
        }
        public void ValidateRequestByIntegrationConfig_Test()
        {
            // Arrange
            UserInQueueServiceMock mock = new UserInQueueServiceMock();

            KnownUser._UserInQueueService = (mock);

            TriggerPart triggerPart = new TriggerPart();

            triggerPart.Operator       = "Contains";
            triggerPart.ValueToCompare = "event1";
            triggerPart.UrlPart        = "PageUrl";
            triggerPart.ValidatorType  = "UrlValidator";
            triggerPart.IsNegative     = false;
            triggerPart.IsIgnoreCase   = true;

            TriggerModel trigger = new TriggerModel();

            trigger.LogicalOperator = "And";
            trigger.TriggerParts    = new TriggerPart[] { triggerPart };

            IntegrationConfigModel config = new IntegrationConfigModel();

            config.Name = "event1action";
            //config.ActionType = "Queue";
            config.EventId              = "event1";
            config.CookieDomain         = ".test.com";
            config.LayoutName           = "Christmas Layout by Queue-it";
            config.Culture              = "da-DK";
            config.ExtendCookieValidity = true;
            config.CookieValidityMinute = 20;
            config.Triggers             = new TriggerModel[] { trigger };
            config.QueueDomain          = "knownusertest.queue-it.net";
            config.RedirectLogic        = "AllowTParameter";
            config.ForcedTargetUrl      = "";

            CustomerIntegration customerIntegration = new CustomerIntegration();

            customerIntegration.Integrations = new IntegrationConfigModel[] { config };
            customerIntegration.Version      = 3;

            // Act
            KnownUser.ValidateRequestByIntegrationConfig("http://test.com?event1=true", "queueitToken", customerIntegration, "customerId", "secretKey");

            // Assert
            Assert.True(mock.validateRequestCalls.Count == 1);
            Assert.Equal("http://test.com?event1=true", mock.validateRequestCalls[0][0]);
            Assert.Equal("queueitToken", mock.validateRequestCalls[0][1]);
            Assert.Equal(".test.com:Christmas Layout by Queue-it:da-DK:event1:knownusertest.queue-it.net:true:20:3", mock.validateRequestCalls[0][2]);
            Assert.Equal("customerId", mock.validateRequestCalls[0][3]);
            Assert.Equal("secretKey", mock.validateRequestCalls[0][4]);
        }
Example #16
0
        public async Task <IActionResult> CreateTrigger([Bind("Title, Description, IsNotActive, Position, Table")] TriggerModel trigger)
        {
            if (ModelState.IsValid)
            {
                var respond = await ApiClientFactory.Instance.CreateTrigger(trigger);

                if (respond != null && respond.IsSuccessStatusCode)
                {
                    return(RedirectToAction(nameof(Trigger)));
                }
            }
            return(NotFound());
        }
Example #17
0
        public async Task <IActionResult> EditTrigger(int Id, [Bind("Id, Title, Description, IsNotActive, Position, Table")] TriggerModel trigger)
        {
            if (Id != trigger.Id)
            {
                return(NotFound());
            }
            var respond = await ApiClientFactory.Instance.UpdateTrigger(Id, trigger);

            if (respond != null && respond.IsSuccessStatusCode)
            {
                return(RedirectToAction(nameof(Trigger)));
            }
            return(NotFound());
        }
Example #18
0
        public async Task <List <List <JobModel> > > Get()
        {
            List <JobModel> jobs   = new List <JobModel>();
            var             groups = await QuartzHostedService.Scheduler.GetJobGroupNames();

            foreach (var groupName in groups)
            {
                foreach (var jobKey in  await QuartzHostedService.Scheduler.GetJobKeys(GroupMatcher <JobKey> .GroupEquals(groupName)))
                {
                    JobModel jobModel = new JobModel
                    {
                        JobName  = jobKey.Name,
                        JobGroup = groupName
                    };
                    jobModel.JobUrl = _jobSchedules.First(x => x.JobName == jobKey.Name)?.JobUrl;
                    // string jobName = jobKey.Name;
                    // string jobGroup = jobKey.Group;
                    List <TriggerModel> triggerModels = new List <TriggerModel>();

                    var triggers = await QuartzHostedService.Scheduler.GetTriggersOfJob(jobKey);

                    foreach (ITrigger trigger in triggers)
                    {
                        var state = await QuartzHostedService.Scheduler.GetTriggerState(trigger.Key);

                        TriggerModel triggerModel = new TriggerModel
                        {
                            Name         = trigger.Key.Name,
                            Cron         = trigger.Description,
                            State        = Enum.GetName(state.GetType(), state),
                            NextExecTime = trigger.GetNextFireTimeUtc().Value.ToLocalTime().ToString("yyyy/MM/dd HH:mm:ss"),
                            Result       = _jobTriggerInfo.triggersInfo.FirstOrDefault(x => x.Name == trigger.Key.Name)?.Result
                        };
                        triggerModels.Add(triggerModel);
                        // string name = trigger.Key.Name;
                        // string cron = trigger.Description;
                        // string next_time = trigger.GetNextFireTimeUtc().Value.ToLocalTime().ToString("yyyy/MM/dd HH:mm:ss");
                    }

                    jobModel.Triggers = triggerModels;
                    jobs.Add(jobModel);
                }
            }

            var d = jobs.GroupBy(x => x.JobGroup).Select(x => x.ToList()).ToList();

            return(await Task.FromResult(d));

            //return _jobSchedules;
        }
 public TriggerViewModel(TriggerModel model)
 {
     Name                 = model.TriggerName;
     JobName              = model.JobName;
     Message              = model.Message;
     TriggerType          = model.TriggerType;
     PreviousFireTimeDate = model.PreviousFireTimeDate;
     NextFireTimeDate     = model.NextFireTimeDate;
     StartTimeDate        = model.StartTimeDate;
     EndTimeDate          = model.EndTimeDate;
     CronExpression       = model.CronExpression;
     MailSubject          = model.MailSubject;
     MailBody             = model.MailBody;
     SelectedJobType      = ConvertJobClassNameStringToEnum(model.JobType);
 }
Example #20
0
        public virtual void init(Hex h)
        {
            this.h    = h;
            this.dead = false;

            transform.parent        = h.transform;
            transform.localPosition = new Vector3(0, 0, 0);

            var obj = new GameObject("Trigger Model");

            obj.transform.parent = transform;
            model = obj.AddComponent <TriggerModel>();

            model.init(this);
        }
        private List <TriggerModel> Process(string[] idArray, List <HTMLModel> htmlModels)
        {
            List <TriggerModel> output = new List <TriggerModel>();
            TriggerModel        trigger;

            // TODO - turn html into trigger objects
            for (int i = 0; i < idArray.Length; i++)
            {
                trigger            = new TriggerModel();
                trigger.setValue   = idArray[i];
                trigger.expression = htmlModels[i].visibleIf;
                output.Add(trigger);
            }

            return(output);
        }
Example #22
0
        public virtual void AppendChange(TriggerModel source, TriggerModel target, string propertyName)
        {
            AppendDifference(source, target, propertyName);

            if (generateSource)
            {
                string p = BuildPath(Path.Combine(this.folderForSource, source.TableReference.Owner), "Triggers", source.Name);
                WriteFile(p, CreateOrReplace + Utils.Unserialize(source.Code, true));
            }

            if (generateTarget)
            {
                string p = BuildPath(Path.Combine(this.folderForTarget, target.TableReference.Owner), "Triggers", target.Name);
                WriteFile(p, CreateOrReplace + Utils.Unserialize(target.Code, true));
            }
        }
Example #23
0
        public virtual void AppendMissingReference(TriggerModel trigger, ReferenceTable table)
        {
            var d = new DifferenceModel()
            {
                Source    = trigger,
                Kind      = TypeDifferenceEnum.Orphean,
                Reference = "Table " + table.ToString(),
            };

            this._lst.Add(d);

            if (generateSource)
            {
                string p = BuildPath(Path.Combine(this.folderForSource, trigger.TableReference.Owner), "Triggers", trigger.Name);
                WriteFile(p, CreateOrReplace + Utils.Unserialize(trigger.Code, true));
            }
        }
Example #24
0
        public void SetUp()
        {
            _now     = DateTimeOffset.UtcNow;
            _runTime = DateBuilder.EvenMinuteDate(_now);
            _jobData = new Dictionary <string, object> {
                { "object1", new { PropertyValue = 3 } }
            };
            _jobDataMap = new JobDataMap(_jobData);
            _endTime    = DateTime.UtcNow.AddMonths(1);

            _trigger = TriggerBuilder.Create()
                       .WithIdentity(TriggerName, GroupName)
                       .WithDescription(Description)
                       .StartAt(_runTime)
                       .WithPriority(Priority)
                       .WithSchedule(CalendarIntervalScheduleBuilder.Create().WithIntervalInMinutes(1))
                       .UsingJobData(_jobDataMap)
                       .EndAt(_endTime)
                       .Build();

            _context = new TriggerModel(_trigger);
        }
Example #25
0
 public virtual void AppendToRemove(TriggerModel target)
 {
     AppendDifference(target, true);
 }
Example #26
0
 public void VisitTrigger(TriggerModel item)
 {
     if (InFile(item))
     {
     }
 }
Example #27
0
        public static async Task <IActionResult> ScheduleJob(Controller controller, IScheduler scheduler,
                                                             QRTZ_TRIGGERSService service, TriggerModel model)
        {
            try
            {
                //check;
                if (model?.Key == null || model.JobData == null)
                {
                    return(controller.Ok("key和jobdata不能为空"));
                }

                var key     = new TriggerKey(model.Key.Name, model.Key.Group);
                var builder = TriggerBuilder.Create();
                builder.WithIdentity(key);
                if (!string.IsNullOrEmpty(model.Description))
                {
                    builder.WithDescription(model.Description);
                }

                if (model.StartTime.HasValue)
                {
                    builder.StartAt(model.StartTime.Value);
                }
                else
                {
                    builder.StartNow();
                }

                builder.EndAt(model.EndTime);
                builder.ForJob(HttpJob.JobKey);
                if (model.Priority.HasValue)
                {
                    builder.WithPriority(model.Priority.Value);
                }

                builder.UsingJobData("method", model.JobData.method);
                builder.UsingJobData("timeout", model.JobData.timeout.ToString());
                builder.UsingJobData("url", model.JobData.url);
                builder.UsingJobData("expRefire", model.JobData.expRefire.ToString());
                builder.UsingJobData("expRemove", model.JobData.expRemove.ToString());
                builder.UsingJobData("body", model.JobData.body);

                #region trigger

                if (model.SimpleTrigger != null)
                {
                    builder.WithSimpleSchedule(scheduleBuilder =>
                    {
                        scheduleBuilder
                        .WithRepeatCount(model.SimpleTrigger.RepeatCount)
                        .WithInterval(model.SimpleTrigger.RepeatInterval);
                        switch (model.SimpleTrigger.misfireInstruction)
                        {
                        case -1:
                            scheduleBuilder.WithMisfireHandlingInstructionIgnoreMisfires();
                            break;

                        case 1:
                            scheduleBuilder.WithMisfireHandlingInstructionFireNow();
                            break;

                        case 2:
                            scheduleBuilder.WithMisfireHandlingInstructionNowWithExistingCount();
                            break;

                        case 3:
                            scheduleBuilder.WithMisfireHandlingInstructionNowWithRemainingCount();
                            break;

                        case 4:
                            scheduleBuilder.WithMisfireHandlingInstructionNextWithRemainingCount();
                            break;

                        case 5:
                            scheduleBuilder.WithMisfireHandlingInstructionNextWithExistingCount();
                            break;
                        }
                    });
                }

                if (model.CronTrigger != null)
                {
                    builder.WithCronSchedule(model.CronTrigger.CronExpression, scheduleBuilder =>
                    {
                        switch (model.CronTrigger.MisfireInstruction)
                        {
                        case -1:
                            scheduleBuilder.WithMisfireHandlingInstructionIgnoreMisfires();
                            break;

                        case 1:
                            scheduleBuilder.WithMisfireHandlingInstructionFireAndProceed();
                            break;

                        case 2:
                            scheduleBuilder.WithMisfireHandlingInstructionDoNothing();
                            break;
                        }

                        if (!string.IsNullOrEmpty(model.CronTrigger.TimeZoneId))
                        {
                            scheduleBuilder.InTimeZone(
                                TimeZoneInfo.FindSystemTimeZoneById(model.CronTrigger.TimeZoneId));
                        }
                    });
                }

                if (model.CalendarIntervalTrigger != null)
                {
                    builder.WithCalendarIntervalSchedule(scheduleBuilder =>
                    {
                        scheduleBuilder.WithInterval(model.CalendarIntervalTrigger.RepeatInterval,
                                                     (IntervalUnit)(int)model.CalendarIntervalTrigger.RepeatIntervalUnit);

                        scheduleBuilder.SkipDayIfHourDoesNotExist(model.CalendarIntervalTrigger
                                                                  .SkipDayIfHourDoesNotExist);
                        scheduleBuilder.PreserveHourOfDayAcrossDaylightSavings(model.CalendarIntervalTrigger
                                                                               .PreserveHourOfDayAcrossDaylightSavings);
                        switch (model.CalendarIntervalTrigger.MisfireInstruction)
                        {
                        case -1:
                            scheduleBuilder.WithMisfireHandlingInstructionIgnoreMisfires();
                            break;

                        case 1:
                            scheduleBuilder.WithMisfireHandlingInstructionFireAndProceed();
                            break;

                        case 2:
                            scheduleBuilder.WithMisfireHandlingInstructionDoNothing();
                            break;
                        }

                        if (!string.IsNullOrEmpty(model.CalendarIntervalTrigger.TimeZoneId))
                        {
                            scheduleBuilder.InTimeZone(
                                TimeZoneInfo.FindSystemTimeZoneById(model.CalendarIntervalTrigger.TimeZoneId));
                        }
                    });
                }

                if (model.DailyTimeIntervalTrigger != null)
                {
                    builder.WithDailyTimeIntervalSchedule(scheduleBuilder =>
                    {
                        scheduleBuilder.WithInterval(model.DailyTimeIntervalTrigger.RepeatInterval,
                                                     (IntervalUnit)(int)model.DailyTimeIntervalTrigger.RepeatIntervalUnit);

                        scheduleBuilder.WithRepeatCount(model.DailyTimeIntervalTrigger.RepeatCount);
                        if (model.DailyTimeIntervalTrigger.DaysOfWeek?.Count > 0)
                        {
                            scheduleBuilder.OnDaysOfTheWeek(model.DailyTimeIntervalTrigger.DaysOfWeek);
                        }

                        if (model.DailyTimeIntervalTrigger.StartTimeOfDay != null)
                        {
                            scheduleBuilder.StartingDailyAt(new TimeOfDay(
                                                                model.DailyTimeIntervalTrigger.StartTimeOfDay.Hour,
                                                                model.DailyTimeIntervalTrigger.StartTimeOfDay.Minute,
                                                                model.DailyTimeIntervalTrigger.StartTimeOfDay.Second));
                        }

                        if (model.DailyTimeIntervalTrigger.EndTimeOfDay != null)
                        {
                            scheduleBuilder.EndingDailyAt(new TimeOfDay(
                                                              model.DailyTimeIntervalTrigger.EndTimeOfDay.Hour,
                                                              model.DailyTimeIntervalTrigger.EndTimeOfDay.Minute,
                                                              model.DailyTimeIntervalTrigger.EndTimeOfDay.Second));
                        }

                        switch (model.DailyTimeIntervalTrigger.MisfireInstruction)
                        {
                        case -1:
                            scheduleBuilder.WithMisfireHandlingInstructionIgnoreMisfires();
                            break;

                        case 1:
                            scheduleBuilder.WithMisfireHandlingInstructionFireAndProceed();
                            break;

                        case 2:
                            scheduleBuilder.WithMisfireHandlingInstructionDoNothing();
                            break;
                        }

                        if (!string.IsNullOrEmpty(model.DailyTimeIntervalTrigger.TimeZoneId))
                        {
                            scheduleBuilder.InTimeZone(
                                TimeZoneInfo.FindSystemTimeZoneById(model.DailyTimeIntervalTrigger.TimeZoneId));
                        }
                    });
                }

                #endregion

                var trigger = builder.Build();


                if (model.Reschedule)
                {
                    var oldTrigger = await scheduler.GetTrigger(key);

                    if (oldTrigger == null)
                    {
                        var result = await scheduler.ScheduleJob(trigger);

                        return(controller.Ok("success"));
                    }
                    else
                    {
                        var dbm    = service.SingleTrigger(scheduler.SchedulerName, key.Name, key.Group);
                        var result = await scheduler.RescheduleJob(key, trigger);

                        //如果原来是暂停状态,需要修改成暂停状态
                        if (dbm.TRIGGER_STATE == "PAUSED")
                        {
                            await scheduler.PauseTrigger(key);
                        }

                        return(controller.Ok(result.HasValue ? "success" : "fail"));
                    }
                }
                else
                {
                    var result = await scheduler.ScheduleJob(trigger);

                    return(controller.Ok("success"));
                }
            }
            catch (Exception e)
            {
                //log?
                await Console.Error.WriteLineAsync(e.StackTrace);

                return(controller.Ok(e.Message));
            }
        }
Example #28
0
 public async Task <IActionResult> ScheduleJob([FromBody] TriggerModel model)
 {
     return(await ScheduleJob(this, scheduler, service, model));
 }
Example #29
0
        public async Task <IActionResult> Edit(string name, string group, string type)
        {
            var doc = System.IO.File.ReadAllText("triggerDoc.json");

            ViewBag.doc = doc;

            if (string.IsNullOrEmpty(name))
            {
                var tpl = System.IO.File.ReadAllText("triggerTpl.json");
                ViewBag.tpl = tpl;
            }
            else
            {
                var key     = new TriggerKey(name, group);
                var trigger = await scheduler.GetTrigger(key);

                TriggerModel model = new TriggerModel();
                model.Key         = new TriggerKeyModel(name, group);
                model.Description = trigger.Description;
                model.Reschedule  = true;
                model.Priority    = trigger.Priority;
                model.StartTime   = trigger.StartTimeUtc.ToLocalTime();
                model.EndTime     = trigger.EndTimeUtc?.ToLocalTime();
                model.JobData     = new JobDataInfo()
                {
                    body      = trigger.JobDataMap.TryGetAndReturn("body")?.ToString(),
                    url       = trigger.JobDataMap.GetString("url"),
                    method    = trigger.JobDataMap.GetString("method"),
                    timeout   = trigger.JobDataMap.GetIntValueFromString("timeout"),
                    expRefire = trigger.JobDataMap.GetBooleanValueFromString("expRefire"),
                    expRemove = trigger.JobDataMap.GetBooleanValueFromString("expRemove"),
                };

                if ("CRON".Equals(type, StringComparison.Ordinal))
                {
                    if (trigger is CronTriggerImpl t)
                    {
                        model.CronTrigger = new CronTriggerInfo()
                        {
                            TimeZoneId         = t.TimeZone.Id,
                            CronExpression     = t.CronExpressionString,
                            MisfireInstruction = t.MisfireInstruction
                        };
                    }
                }
                else if ("SIMPLE".Equals(type, StringComparison.Ordinal))
                {
                    if (trigger is SimpleTriggerImpl t)
                    {
                        model.SimpleTrigger = new SimpleTriggerInfo()
                        {
                            RepeatCount        = t.RepeatCount,
                            RepeatInterval     = t.RepeatInterval,
                            misfireInstruction = t.MisfireInstruction
                        };
                    }
                }
                else if ("DAILY_I".Equals(type, StringComparison.Ordinal))
                {
                    if (trigger is DailyTimeIntervalTriggerImpl t)
                    {
                        model.DailyTimeIntervalTrigger = new DailyTimeIntervalTriggerInfo()
                        {
                            RepeatCount        = t.RepeatCount,
                            RepeatInterval     = t.RepeatInterval,
                            RepeatIntervalUnit = (IntervalUnit)(int)t.RepeatIntervalUnit,
                            DaysOfWeek         = new HashSet <DayOfWeek>(t.DaysOfWeek),
                            MisfireInstruction = t.MisfireInstruction,
                            TimeZoneId         = t.TimeZone.Id
                        };
                        if (t.StartTimeOfDay != null)
                        {
                            model.DailyTimeIntervalTrigger.StartTimeOfDay = new TimeOfDayInfo(t.StartTimeOfDay.Hour,
                                                                                              t.StartTimeOfDay.Minute, t.StartTimeOfDay.Second);
                        }

                        if (t.EndTimeOfDay != null)
                        {
                            model.DailyTimeIntervalTrigger.EndTimeOfDay = new TimeOfDayInfo(t.EndTimeOfDay.Hour,
                                                                                            t.EndTimeOfDay.Minute, t.EndTimeOfDay.Second);
                        }
                    }
                }
                else if ("CAL_INT".Equals(type, StringComparison.Ordinal))
                {
                    if (trigger is CalendarIntervalTriggerImpl t)
                    {
                        model.CalendarIntervalTrigger = new CalendarIntervalTriggerInfo()
                        {
                            RepeatInterval     = t.RepeatInterval,
                            RepeatIntervalUnit = (IntervalUnit)(int)t.RepeatIntervalUnit,
                            MisfireInstruction = t.MisfireInstruction,
                            TimeZoneId         = t.TimeZone.Id,
                            PreserveHourOfDayAcrossDaylightSavings = t.PreserveHourOfDayAcrossDaylightSavings,
                            SkipDayIfHourDoesNotExist = t.SkipDayIfHourDoesNotExist
                        };
                    }
                }

                var tpl = JsonSerializer.Serialize(model, new JsonSerializerOptions()
                {
                    IgnoreNullValues = true,
                    WriteIndented    = true,
                    Encoder          = JavaScriptEncoder.Create(UnicodeRanges.All)
                });

                ViewBag.tpl = tpl;
            }

            return(View());
        }
Example #30
0
 public static void DeleteTriggerInfo(TriggerModel trigger) => _triggersInfo.Remove(trigger);