Ejemplo n.º 1
0
        public async Task <object> PostTasksQz([FromBody] TasksQz tasksQz)
        {
            var data = new MessageModel <string>();

            tasksQz.JobStatus = tasksQz.IsStart ? JobStatus.运行中 : JobStatus.未启动;
            var id = await _tasksQzSvc.Add(tasksQz);

            data.Success  = id > 0;
            data.Response = id.ToString();
            data.Message  = data.Success ? "添加成功" : "添加失败";
            if (data.Success)
            {
                tasksQz.Id = id;
                if (tasksQz.IsStart)
                {
                    var resuleModel = await _schedulerCenter.AddScheduleJobAsync(tasksQz);

                    data.Success = resuleModel.Success;
                    if (resuleModel.Success)
                    {
                        data.Message = $"{data.Message}=>启动成功=>{resuleModel.Message}";
                    }
                    else
                    {
                        data.Message = $"{data.Message}=>启动失败=>{resuleModel.Message}";
                    }
                }
            }

            return(data);
        }
Ejemplo n.º 2
0
        public async Task <MessageModel <string> > Post([FromBody] TasksQz tasksQz)
        {
            var data = new MessageModel <string>();

            _unitOfWork.BeginTran();
            var id = (await _tasksQzServices.Add(tasksQz));

            data.success = id > 0;
            try
            {
                if (data.success)
                {
                    tasksQz.Id    = id;
                    data.response = id.ObjToString();
                    data.msg      = "添加成功";
                    if (tasksQz.IsStart)
                    {
                        //如果是启动自动
                        var ResuleModel = await _schedulerCenter.AddScheduleJobAsync(tasksQz);

                        data.success = ResuleModel.success;
                        if (ResuleModel.success)
                        {
                            data.msg = $"{data.msg}=>启动成功=>{ResuleModel.msg}";
                        }
                        else
                        {
                            data.msg = $"{data.msg}=>启动失败=>{ResuleModel.msg}";
                        }
                    }
                }
                else
                {
                    data.msg = "添加失败";
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            { if (data.success)
              {
                  _unitOfWork.CommitTran();
              }
              else
              {
                  _unitOfWork.RollbackTran();
              } }
            return(data);
        }
Ejemplo n.º 3
0
        public static void UseQuartzJobMildd(this IApplicationBuilder app, ITasksQzSvc tasksQzSvc, ISchedulerCenter schedulerCenter)
        {
            if (app == null)
            {
                throw new ArgumentNullException(nameof(app));
            }

            try
            {
                if (Appsettings.App("Middleware", "QuartzNetJob", "Enabled").ToBoolReq())
                {
                    var allQzServices = tasksQzSvc.Query().Result;
                    foreach (var item in allQzServices)
                    {
                        if (item.JobStatus == JobStatus.运行中)
                        {
                            var ResuleModel = schedulerCenter.AddScheduleJobAsync(item).Result;
                            if (ResuleModel.Success)
                            {
                                Console.WriteLine($"QuartzNetJob{item.JobName}启动成功!");
                            }
                            else
                            {
                                Console.WriteLine($"QuartzNetJob{item.JobName}启动失败!错误信息:{ResuleModel.Message}");
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                log.Error($"An error was reported when starting the job service.\n{e.Message}");
                throw;
            }
        }
Ejemplo n.º 4
0
        public static void UseQuartzJobMildd(this IApplicationBuilder app, ITasksQzBussiness tasksQzServices, ISchedulerCenter schedulerCenter)
        {
            if (app == null)
            {
                throw new ArgumentNullException(nameof(app));
            }

            try
            {
                if (Appsettings.app("AppSettings", "QuartzNetJob", "Enabled").ObjToBool())
                {
                    var allQzServices = tasksQzServices.QueryAsync().Result;
                    foreach (var item in allQzServices)
                    {
                        if (item.IsStart)
                        {
                            var ResuleModel = schedulerCenter.AddScheduleJobAsync(item).Result;
                            if (ResuleModel.success)
                            {
                                log.Info($"QuartzNetJob{item.Name}启动成功!");
                            }
                            else
                            {
                                log.Error($"QuartzNetJob{item.Name}启动失败!错误信息:{ResuleModel.msg}");
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                log.Fatal($"An error was reported when starting the job service.\n{e.Message}");
                throw;
            }
        }
Ejemplo n.º 5
0
        public async Task <IResponseEntity> UpdateAsync(TaskQzEditRequest req)
        {
            if (req == null || req?.Id == "")
            {
                return(ResponseEntity.Error("更新的实体主键丢失"));
            }
            var entity = _mapper.Map <SysTaskQzEntity>(req);

            if (entity.IsDefaultDatabase)
            {
                DbInfo             dbInfo           = _authUser.Tenant.DbOptions.Where(x => x.Key == Constants.SystemDbKey).FirstOrDefault();
                DbConnectionString connectionString = dbInfo.ConnectionStrings.Where(x => x.UseType == DbUseType.Master).FirstOrDefault();

                entity.ConnectionParam = JsonConvert.SerializeObject(new
                {
                    ConnectionString = connectionString.ConnectionString,
                    DbType           = Convert.ToInt32(dbInfo.DbType)
                });
            }

            await _SysTaskQzRepository.UpdateAsync(entity);

            if (entity.IsStart)
            {
                var res = await _schedulerCenter.AddScheduleJobAsync(entity);
            }
            return(ResponseEntity.Ok("更新成功"));
        }
Ejemplo n.º 6
0
 //private static readonly ILog log = LogManager.GetLogger(typeof(QuartzJobMildd));
 public static void UseQuartzJobMildd(this IApplicationBuilder app, ITasksQzService tasksQzService, ISchedulerCenter schedulerCenter)
 {
     if (app == null)
     {
         throw new ArgumentNullException(nameof(app));
     }
     try
     {
         var allQzServices = tasksQzService.GetAsync().Result;
         foreach (var item in allQzServices)
         {
             if (item.IsStart)
             {
                 var ResuleModel = schedulerCenter.AddScheduleJobAsync(item).Result;
                 if (ResuleModel.success)
                 {
                     Console.WriteLine($"QuartzNetJob{item.Name}启动成功!");
                 }
                 else
                 {
                     Console.WriteLine($"QuartzNetJob{item.Name}启动失败!错误信息:{ResuleModel.msg}");
                 }
             }
         }
     }
     catch (Exception e)
     {
         //log.Error($"An error was reported when starting the job service.\n{e.Message}");
         throw;
     }
 }
Ejemplo n.º 7
0
        public static void UseQuartzJobMiddleware(this IApplicationBuilder app, ITasksQzServices tasksQzServices, ISchedulerCenter schedulerCenter)
        {
            if (app == null)
            {
                throw new ArgumentNullException(nameof(app));
            }

            try
            {
                if (Appsettings.app("Middleware", "QuartzNetJob", "Enabled").ObjToBool())
                {
                    var allQzServices = tasksQzServices.Query().Result;
                    foreach (var item in allQzServices)
                    {
                        if (item.IsStart)
                        {
                            var result = schedulerCenter.AddScheduleJobAsync(item).Result;
                            if (result.success)
                            {
                                Console.WriteLine($"QuartzNetJob{item.Name}启动成功!");
                            }
                            else
                            {
                                Console.WriteLine($"QuartzNetJob{item.Name}启动失败!错误信息:{result.msg}");
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Log.Error($"An error was reported when starting the job service.\n{e.Message}");
                throw;
            }
        }
Ejemplo n.º 8
0
        public async Task <MessageModel <dynamic> > TokenAssig([FromBody] LoginViewModel loginViewModel)
        {
            var data = new MessageModel <dynamic>();

            if (ModelState.IsValid)
            {
                loginViewModel.Password = loginViewModel.Password.ToMD5();
                SysUser Info = await _userserver.CheckUser(loginViewModel.User, loginViewModel.Password);

                await _schedulerCenter.AddScheduleJobAsync(new SysSchedule
                {
                    Name           = "test1",
                    JobGroup       = "test1group",
                    AssemblyName   = "Uwl.QuartzNet.JobCenter",
                    ClassName      = "Simple",
                    IntervalSecond = 5,
                });

                //_rabbitMQ.SendData("hello", Info);
                if (Info == null)
                {
                    data.msg = "账号或者密码错误";
                    return(data);
                }
                else
                {
                    try
                    {
                        //_schedulerCenter.AddScheduleJobAsync<SysSchedule>(new SysSchedule());
                        var RoleName = await _userserver.GetUserRoleByUserId(Info.Id);

                        var claims = new List <Claim>
                        {
                            new Claim(ClaimTypes.Name, Info.Name),                                                                      //设置用户名称
                            new Claim(JwtRegisteredClaimNames.Jti, Info.Id.ToString()),                                                 //设置用户ID
                            new Claim(ClaimTypes.Expiration, DateTime.Now.AddSeconds(_requirement.Expiration.TotalSeconds).ToString()), //设置过期时间
                        };
                        claims.AddRange(RoleName.Split(',').Select(x => new Claim(ClaimTypes.Role, x)));                                //将用户角色填充到claims中
                        //用户标识
                        var identity = new ClaimsIdentity(JwtBearerDefaults.AuthenticationScheme);
                        identity.AddClaims(claims);
                        var token = JwtToken.BuildJwtToken(claims.ToArray(), _requirement);
                        data.response = token;
                        data.msg      = "Token获取成功";
                        data.success  = true;
                        return(data);
                    }
                    catch (Exception ex)
                    {
                        data.msg = "获取角色信息失败" + ex.Message;
                        return(data);
                    }
                }
            }
            data.msg = "账号或者密码错误";
            return(data);
        }
Ejemplo n.º 9
0
        public async Task <IResponseEntity> StartJob(string jobId)
        {
            var job = await _SysTaskQzService.GetSysTaskQzEntity(jobId);

            var res = await _schedulerCenter.AddScheduleJobAsync(job);

            if (res.Success)
            {
                job.IsStart = true;
                await _SysTaskQzService.UpdateTaskQz(job);
            }
            return(res);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// 根据Id查询出一个Job任务实体
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        public async Task <JobResuleModel> StartJob(Guid Id)
        {
            var model = await _scheduleRepositoty.FirstOrDefaultAsync(x => x.Id == Id);

            var ResuleModel = await _schedulerCenter.AddScheduleJobAsync(model);

            if (ResuleModel.IsSuccess)
            {
                model.IsStart = true;
            }
            await UpdateScheduleAsync(model);

            return(ResuleModel);
        }
        public async Task <MessageModel <string> > StartJob(int jobId)
        {
            var data = new MessageModel <string>();

            var model = await _tasksQzService.QueryById(jobId);

            if (model != null)
            {
                var ResuleModel = await _schedulerCenter.AddScheduleJobAsync(model);

                if (ResuleModel.success)
                {
                    model.IsStart = (int)BoolStatus.True;
                    data.success  = await _tasksQzService.Update(model);
                }
                data = ResuleModel;
            }
            return(data);
        }
Ejemplo n.º 12
0
        public async Task <MessageModel <string> > StartJob(int jobId)
        {
            var data = new MessageModel <string>();

            var model = await _tasksQzServices.QueryById(jobId);

            var ResuleModel = await _schedulerCenter.AddScheduleJobAsync(model);

            if (ResuleModel.success)
            {
                model.IsStart = true;
                data.success  = await _tasksQzServices.Update(model);
            }
            if (data.success)
            {
                data.msg      = "启动成功";
                data.response = jobId.ObjToString();
            }
            return(data);
        }
        public async Task <MessageModel <TasksQzDto> > StartJob(int jobId)
        {
            var data = new MessageModel <TasksQzDto>();

            var model = await _tasksQzService.GetAsync(jobId);

            if (model != null)
            {
                if (model.IsDeleted)
                {
                    data.success = false;
                    data.msg     = "此任务无效,无法启动无效的任务项 。";
                    return(data);
                }
                if (model.IsStart)
                {
                    data.success = false;
                    data.msg     = "此任务已经启动,无法再次启动 。";
                    return(data);
                }
                var ResuleModel = await _schedulerCenter.AddScheduleJobAsync(model);

                data.msg = ResuleModel.msg;
                if (ResuleModel.success)
                {
                    model.IsStart = true;
                    data.success  = await _tasksQzService.UpdateAsync(model);
                }
                if (data.success)
                {
                    data.msg      = "启动成功";
                    data.response = _mapper.Map <TasksQzDto>(model);
                }
            }
            return(data);
        }