Ejemplo n.º 1
0
 public void RunJob(int jobId)
 {
     using (var ctx = new BatchJobDbContext())
     {
         try
         {
             var job = ctx.Jobs.Find(jobId);
             if (job != null)
             {
                 if (job.Triggers == null || job.Triggers.Count <= 0)
                 {
                     throw new BusinessException("当前作业未配置触发器.");
                 }
                 var scheduler = QuartzHelper.GetScheduler(job.JobGroup.Scheduler.Name, job.JobGroup.Scheduler.ThreadPoolSize, (int)job.JobGroup.Scheduler.Priority);
                 foreach (var trigger in job.Triggers)
                 {
                     if (trigger.Type == TriggerType.Cron)
                     {
                         var cronTrigger = DomainContext.Current.Set <CronTriggerEntity>().Find(trigger.Id);
                         if (cronTrigger != null)
                         {
                             scheduler.ScheduleJobIfExists(job.Code, job.JobGroup.Name, cronTrigger.Code, cronTrigger.CronExpression, typeof(ExcuteJob));
                         }
                     }
                 }
                 job.RunJob();
                 ctx.SaveChanges();
             }
         }
         catch (Exception ex)
         {
             throw ex;
         }
     }
 }
Ejemplo n.º 2
0
 public bool ValidateUser(string username, string password)
 {
     using (var ctx = new BatchJobDbContext())
     {
         var result = UserEntity.ValidateUser(username, password);
         ctx.SaveChanges();
         return(result);
     }
 }
Ejemplo n.º 3
0
 public MembershipUser CreateUser(string username, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, object providerUserKey, out MembershipCreateStatus status)
 {
     using (var ctx = new BatchJobDbContext())
     {
         var user = UserEntity.Create(username, password, email);
         ctx.SaveChanges();
         MembershipUser membershipUser = user.ToMembershipUser();
         status = MembershipCreateStatus.Success;
         return(membershipUser);
     }
 }
Ejemplo n.º 4
0
 public void Delete(int id)
 {
     using (var ctx = new BatchJobDbContext(true))
     {
         var entity = ctx.CronTriggers.Find(id);
         if (entity != null)
         {
             ctx.CronTriggers.Remove(entity);
             ctx.SaveChanges();
         }
     }
 }
Ejemplo n.º 5
0
 public void AddService(ServiceDto service)
 {
     using (var ctx = new BatchJobDbContext())
     {
         var job = ctx.Jobs.Find(service.JobId);
         if (job != null)
         {
             job.AddService(service);
         }
         ctx.SaveChanges();
     }
 }
Ejemplo n.º 6
0
 public void ExcuteJob(string jobGroup, string jobCode, DateTime?nextExecuteTime)
 {
     using (var ctx = new BatchJobDbContext())
     {
         var job = ctx.Jobs.Where(a => a.JobGroup.Name.Equals(jobGroup) && a.Code == jobCode).FirstOrDefault();
         if (job != null)
         {
             job.Excute(nextExecuteTime);
             ctx.SaveChanges();
         }
     }
 }
Ejemplo n.º 7
0
 public void AddJobGroup(JobGroupDto dto)
 {
     using (var ctx = new BatchJobDbContext())
     {
         var scheduler = ctx.Schedulers.Find(dto.SchedulerId);
         if (scheduler != null)
         {
             scheduler.AddJobGroup(dto.Name);
             ctx.SaveChanges();
         }
     }
 }
Ejemplo n.º 8
0
 public CronTriggerDto CreateCronTrigger(CronTriggerDto dto)
 {
     using (var ctx = new BatchJobDbContext())
     {
         var entity = Mapper.Map <CronTriggerEntity>(dto);
         entity.Type = TriggerType.Cron;
         entity.SetJob(dto.JobId);
         entity = ctx.CronTriggers.Add(entity);
         ctx.SaveChanges();
         dto = Mapper.Map <CronTriggerDto>(entity);
         return(dto);
     }
 }
Ejemplo n.º 9
0
 public CronTriggerDto UpdateCronTrigger(CronTriggerDto dto)
 {
     using (var ctx = new BatchJobDbContext())
     {
         if (dto.Id.HasValue)
         {
             var entity = ctx.CronTriggers.Find(dto.Id.Value);
             entity = Mapper.Map(dto, entity);
             ctx.SaveChanges();
             dto = Mapper.Map <CronTriggerDto>(entity);
             return(dto);
         }
         return(null);
     }
 }
Ejemplo n.º 10
0
 public bool TryDelete(int jobId, out int?jobGroupId)
 {
     using (var ctx = new BatchJobDbContext())
     {
         var entity = ctx.Jobs.Where(a => a.Id == jobId).FirstOrDefault();
         if (entity != null)
         {
             ctx.Jobs.Remove(entity);
             ctx.SaveChanges();
             jobGroupId = entity.JobGroup.Id;
             return(true);
         }
         jobGroupId = null;
         return(false);
     }
 }
Ejemplo n.º 11
0
 public bool TryRemoveJobGroup(int id, out int?schedulerId)
 {
     using (var ctx = new BatchJobDbContext())
     {
         var entity = ctx.JobGroups.Find(id);
         if (entity != null)
         {
             ctx.JobGroups.Remove(entity);
             ctx.SaveChanges();
             schedulerId = entity.Scheduler.Id;
             return(true);
         }
         schedulerId = null;
         return(false);
     }
 }
Ejemplo n.º 12
0
 public JobDto Create(JobDto dto)
 {
     using (var ctx = new BatchJobDbContext())
     {
         var jobGroup = ctx.JobGroups.Find(dto.GroupId);
         var isExists = jobGroup.Jobs.Any(a => a.Name == dto.Name);
         if (isExists)
         {
             throw new BusinessException("当前工作组下存在重名作业.");
         }
         var entity = Mapper.Map <JobEntity>(dto);
         entity.JobGroup = jobGroup;
         entity          = ctx.Jobs.Add(entity);
         ctx.SaveChanges();
         dto = Mapper.Map <JobDto>(entity);
         return(dto);
     }
 }
Ejemplo n.º 13
0
 public bool TryRemoveService(int serviceId, out int?jobId)
 {
     using (var ctx = new BatchJobDbContext())
     {
         var entity = ctx.Services.Find(serviceId);
         if (entity != null)
         {
             jobId = entity.Job.Id;
             if (entity.ServiceParameters != null)
             {
                 entity.ServiceParameters.Clear();
             }
             ctx.Services.Remove(entity);
             ctx.SaveChanges();
             return(true);
         }
         jobId = null;
         return(false);
     }
 }
Ejemplo n.º 14
0
 public void StopJob(int jobId)
 {
     using (var ctx = new BatchJobDbContext())
     {
         try
         {
             var job = ctx.Jobs.Find(jobId);
             if (job != null)
             {
                 var scheduler = QuartzHelper.GetScheduler(job.JobGroup.Scheduler.Name, job.JobGroup.Scheduler.ThreadPoolSize, (int)job.JobGroup.Scheduler.Priority);
                 scheduler.PauseJob(job.Code, job.JobGroup.Name);
                 job.StopJob();
                 ctx.SaveChanges();
             }
         }
         catch (Exception ex)
         {
             throw ex;
         }
     }
 }