Exemple #1
0
      public void TimedExecuteJob(object source, System.Timers.ElapsedEventArgs e)
      {
          try
          {
              SchedulerHelper op = new SchedulerHelper();
              //查询变动的数据
              List <SchedulerConfigModel> list = SchedulerConfigDB.GetSchedulerRecord((int)JobEnum.DataType.UpdateData);

              if (list != null && list.Count > 0)
              {
                  for (var i = 0; i < list.Count; i++)
                  {
                      //新增|更新
                      if (list[i].Status == (int)JobEnum.DataState.Insert || list[i].Status == (int)JobEnum.DataState.Update)
                      {
                          //判断Job是否存在,存在并删除
                          var _delete = op.IsExistsDelJob(list[i].JobName, list[i].JobGroup);
                          if (_delete)
                          {
                              //启用新的Job
                              var _update = ExecuteWebApi(list[i]);
                              if (_update)
                              {
                                  //将数据状态更新为0
                                  SchedulerConfigDB.UpdateStatus(list[i].ID);
                              }
                          }
                      }
                      //禁用Job
                      else if (list[i].Status == (int)JobEnum.DataState.Delete)
                      {
                          //判断Job是否存在,存在并删除
                          var _delete = op.IsExistsDelJob(list[i].JobName, list[i].JobGroup);

                          if (_delete)
                          {
                              //将数据状态更新为0
                              SchedulerConfigDB.UpdateStatus(list[i].ID);
                          }
                      }
                  }
              }
          }
          catch (Exception ex)
          {
          }
      }
Exemple #2
0
 //string filePath = @"D:\软件测试\jobtest.txt";
 protected override void OnStart(string[] args)
 {
     try
     {
         List <SchedulerConfigModel> list = SchedulerConfigDB.GetSchedulerRecord((int)JobEnum.DataType.EnableData);
         if (list != null && list.Count > 0)
         {
             for (var i = 0; i < list.Count; i++)
             {
                 ExecuteWebApi(list[i]);
             }
         }
     }
     catch (Exception ex)
     {
     }
 }
Exemple #3
0
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        static void Main()
        {
            //ServiceBase[] ServicesToRun;
            //ServicesToRun = new ServiceBase[]
            //{
            //    new JobManager()
            //};
            //ServiceBase.Run(ServicesToRun);

            //test Code
            //FileJob job = new FileJob();
            //job.Execute(null);

            #region
            List <SchedulerConfigModel> list1 = SchedulerConfigDB.GetSchedulerRecord((int)JobEnum.DataType.UpdateData);
            if (list1.Count > 0)
            {
                for (int i = 0; i < list1.Count; i++)
                {
                    var              list      = list1[i];
                    SchedulerHelper  scheduler = new SchedulerHelper();
                    var              flag      = true;
                    SchedulerRequest request   = new SchedulerRequest();
                    request.JobName          = list.JobName;
                    request.JobGroup         = list.JobGroup;
                    request.TriggerName      = list.JobName + "Trigger";
                    request.TriggerGroupName = list.JobGroup + "Trigger";
                    request.CronTab          = list.CronTab;
                    request.StartTime        = list.StartTime;
                    if (list.EndTime != null)
                    {
                        request.EndTime = list.EndTime;
                    }
                    else
                    {
                        request.EndTime = null;
                    }
                    request.RequestType = list.RequestType;
                    request.RequestUrl  = list.RequestUrl;
                    var json = JsonConvert.SerializeObject(request);
                    scheduler.IsExistsDelJob(request.JobName, request.JobGroup);
                    if (flag)
                    {
                        IJobDetail jobDetail = JobBuilder.Create <FileJob>()
                                               .WithIdentity(request.JobName, request.JobGroup)
                                               .UsingJobData("jobJson", json)
                                               .Build();

                        CronTriggerImpl tigger = (CronTriggerImpl)TriggerBuilder.Create()
                                                 .WithIdentity(request.TriggerName, request.TriggerGroupName)
                                                 .WithCronSchedule(request.CronTab)
                                                 .ForJob(request.JobName, request.JobGroup)
                                                 .StartNow()
                                                 .Build();

                        DateTimeOffset dt = scheduler.scheduleJob(jobDetail, tigger);
                    }
                }
            }
            #endregion
        }