コード例 #1
0
        public async Task Run(IJobExecutionContext context, int jobid)
        {
            if (jobid > 0)
            {
                var model = await _tasksQzServices.QueryById(jobid);

                if (model != null)
                {
                    if (model.IsApiUrl == (int)BoolStatus.True)
                    {
                        if (model.MethodType == 1) //model.MethodType?.ToUpper() == "GET"
                        {
                            var rep = await HttpUtil.HttpGetAsync(model.ApiUrl);
                        }
                        else
                        {
                            string json     = JsonConvert.SerializeObject(model.RequestValue);
                            var    postData = JsonDateTimeFormat(json); //JsonHelper.ToJson(model.RequestValue);
                            var    rep      = await HttpUtil.HttpPostAsync(model.ApiUrl, postData, null, 30000);
                        }
                    }
                    model.RunTimes += 1;
                    var separator = "<br>";
                    model.Remark =
                        $"【{DateTime.Now}】执行任务【Id:{context.JobDetail.Key.Name},组别:{context.JobDetail.Key.Group}】【执行成功】{separator}"
                        + string.Join(separator, StringHelper.GetTopDataBySeparator(model.Remark, separator, 9));
                    await _tasksQzServices.Update(model);
                }
            }
        }
コード例 #2
0
        public async Task <MessageModel <string> > Put([FromBody] TasksQz tasksQz)
        {
            var data = new MessageModel <string>();

            if (tasksQz != null && tasksQz.Id > 0)
            {
                data.success = await _tasksQzServices.Update(tasksQz);

                if (data.success)
                {
                    data.msg      = "更新成功";
                    data.response = tasksQz?.Id.ObjToString();
                }
            }

            return(data);
        }
コード例 #3
0
        public async Task <MessageModel <string> > TasksQzStart(int jobId)
        {
            var data  = new MessageModel <string>();
            var model = await _tasksQzServices.QueryById(jobId);

            if (model != null)
            {
                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);
        }
コード例 #4
0
        /// <summary>
        /// 执行指定任务
        /// </summary>
        /// <param name="context"></param>
        /// <param name="action"></param>
        public async Task <string> ExecuteJob(IJobExecutionContext context, Func <Task> func)
        {
            //记录Job时间
            Stopwatch stopwatch = new Stopwatch();
            //JOBID
            int jobid = context.JobDetail.Key.Name.ObjToInt();
            //JOB组名
            string groupName = context.JobDetail.Key.Group;
            //日志
            string jobHistory = $"【{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}】【执行开始】【Id:{jobid},组别:{groupName}】";
            //耗时
            double taskSeconds = 0;

            try
            {
                stopwatch.Start();
                await func();//执行任务

                stopwatch.Stop();
                jobHistory += $",【{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}】【执行成功】";
            }
            catch (Exception ex)
            {
                JobExecutionException e2 = new JobExecutionException(ex);
                //true  是立即重新执行任务
                e2.RefireImmediately = true;
                jobHistory          += $",【{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}】【执行失败:{ex.Message}】";
            }
            finally
            {
                taskSeconds = Math.Round(stopwatch.Elapsed.TotalSeconds, 3);
                jobHistory += $",【{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}】【执行结束】(耗时:{taskSeconds}秒)";
                if (_tasksQzServices != null)
                {
                    var model = await _tasksQzServices.QueryById(jobid);

                    if (model != null)
                    {
                        model.RunTimes += 1;
                        var separator = "<br>";
                        // 这里注意数据库字段的长度问题,超过限制,会造成数据库remark不更新问题。
                        model.Remark =
                            $"{jobHistory}{separator}" + string.Join(separator, StringHelper.GetTopDataBySeparator(model.Remark, separator, 9));
                        await _tasksQzServices.Update(model);
                    }
                }
            }

            Console.Out.WriteLine(jobHistory);
            return(jobHistory);
        }
コード例 #5
0
        public async Task <MessageModel <string> > Put([FromBody] TasksQz tasksQz)
        {
            var data = new MessageModel <string>();

            if (tasksQz != null && tasksQz.Id > 0)
            {
                _unitOfWork.BeginTran();
                data.success = await _tasksQzServices.Update(tasksQz);

                try
                {
                    if (data.success)
                    {
                        data.msg      = "修改成功";
                        data.response = tasksQz?.Id.ObjToString();
                        if (tasksQz.IsStart)
                        {
                            var ResuleModelStop = await _schedulerCenter.StopScheduleJobAsync(tasksQz);

                            data.msg = $"{data.msg}=>停止:{ResuleModelStop.msg}";
                            var ResuleModelStar = await _schedulerCenter.AddScheduleJobAsync(tasksQz);

                            data.success = ResuleModelStar.success;
                            data.msg     = $"{data.msg}=>启动:{ResuleModelStar.msg}";
                        }
                        else
                        {
                            var ResuleModelStop = await _schedulerCenter.StopScheduleJobAsync(tasksQz);

                            data.msg = $"{data.msg}=>停止:{ResuleModelStop.msg}";
                        }
                    }
                    else
                    {
                        data.msg = "修改失败";
                    }
                }
                catch (Exception)
                {
                    throw;
                }
                finally
                {
                    if (data.success)
                    {
                        _unitOfWork.CommitTran();
                    }
                    else
                    {
                        _unitOfWork.RollbackTran();
                    }
                }
            }
            return(data);
        }
コード例 #6
0
        public async Task Run(IJobExecutionContext context, int jobid)
        {
            string cookie = "CURRENT_FNVAL=80; _uuid=846FF8F2-C882-C1CD-808F-DEEA4719175585066infoc; blackside_state=1; rpdid=|(m)mJumk)R0J'uYuku|kmm|; buvid3=BB379260-46D0-407B-B31A-086227A133E1184999infoc; LIVE_BUVID=AUTO4416177595741756; fingerprint3=5bdd4f9e03267a2fa34c274964a20a2b; buvid_fp=BB379260-46D0-407B-B31A-086227A133E1184999infoc; bp_article_offset_4830365=510771353527463951; fingerprint_s=22fdbf4a2d532409728945361a3a8c15; bp_t_offset_4830365=514104505842011394; bp_video_offset_4830365=514160147147869440; PVID=1; bfe_id=1e33d9ad1cb29251013800c68af42315; fingerprint=bf201b8cab1033a1ec48ac66ca6093a4; buvid_fp_plain=3536A90E-676D-49F6-8195-3D36856858C4138393infoc; SESSDATA=524a2906,1634354147,94f35*41; bili_jct=884c71e8fcc5798e65461d34baaac988; DedeUserID=4830365; DedeUserID__ckMd5=3d3f94374f6dd343; sid=d3a6p9a7";



            BiliCookie cookieentity = _bilicookieservices.DescribeCookie(cookie);
            //获取登录用户信息
            HttpResponse <BiliUserInfo> biliuserinfo = _biliaccountservice.LoginByCookie(cookie);

            //获取每日任务
            HttpResponse <DailyTaskInfo> daily = _biliaccountservice.GetDailyTaskStatus(cookie);

            //领取大会员权益
            BiMessage viprecive = _vipService.ReceiveVipPrivilege(biliuserinfo.Data, cookieentity);

            //漫画签到
            BiMessage mangasign = _managadomainservice.MangaSign(cookie);


            DescibeHttpResponse describe = new DescibeHttpResponse();

            describe.DescibeResponseString(biliuserinfo.Message);
            describe.DescibeResponseString(daily.Message);
            describe.DescibeResponseString(viprecive.Message);
            describe.DescibeResponseString(mangasign.Message);


            if (jobid > 0)
            {
                var model = await _tasksQzServices.QueryById(jobid);

                if (model != null)
                {
                    model.RunTimes += 1;
                    var separator = "<br>";
                    model.Remark =
                        $"【{DateTime.Now}】执行任务【Id:{context.JobDetail.Key.Name},组别:{context.JobDetail.Key.Group}】【执行成功】:{describe.outstring()} {separator}";

                    await _tasksQzServices.Update(model);
                }
            }

            await Console.Out.WriteLineAsync("B站签到结果" + describe.outstring());
        }
コード例 #7
0
ファイル: Job_Synchronous.cs プロジェクト: sunshine223/NET5
        private async Task Run(IJobExecutionContext context, int jobId)
        {
            var list = await roleModulePermissionServices.QueryMuchTable();

            if (jobId > 0)
            {
                var model = await tasksQzServices.QueryById(jobId);

                if (model != null)
                {
                    model.RunTimes += 1;
                    var separator = "<br>";
                    model.Remark =
                        $"【{DateTime.Now}】执行任务【Id:{context.JobDetail.Key.Name},组别:{context.JobDetail.Key.Group}】【执行成功】{separator}"
                        + string.Join(separator, StringHelper.GetTopDataBySeparator(model.Remark, separator, 9));
                    await tasksQzServices.Update(model);
                }
            }
            await Console.Out.WriteLineAsync("菜单总数量" + list.Count.ToString());
        }
コード例 #8
0
        public async Task Run(IJobExecutionContext context, int jobid)
        {
            var list = await _blogArticleServices.Query();

            if (jobid > 0)
            {
                var model = await _tasksQzServices.QueryById(jobid);

                if (model != null)
                {
                    model.RunTimes += 1;
                    var separator = "<br>";
                    model.Remark =
                        $"【{DateTime.Now}】执行任务【Id:{context.JobDetail.Key.Name},组别:{context.JobDetail.Key.Group}】【执行成功】:博客数{list.Count}{separator}"
                        + string.Join(separator, StringHelper.GetTopDataBySeparator(model.Remark, separator, 9));

                    await _tasksQzServices.Update(model);
                }
            }

            await Console.Out.WriteLineAsync("博客总数量" + list.Count.ToString());
        }
コード例 #9
0
        public async Task Execute(IJobExecutionContext context)
        {
            var executeLog = await ExecuteJob(context, async() => await Run(context));

            //var param = context.MergedJobDataMap;
            // 可以直接获取 JobDetail 的值
            var jobKey = context.JobDetail.Key;
            var jobId  = jobKey.Name;

            // 也可以通过数据库配置,获取传递过来的参数
            JobDataMap data = context.JobDetail.JobDataMap;
            //int jobId = data.GetInt("JobParam");

            var model = await _tasksQzServices.QueryById(jobId);

            if (model != null)
            {
                model.RunTimes += 1;
                model.Remark   += $"{executeLog}<br />";
                await _tasksQzServices.Update(model);
            }
        }
コード例 #10
0
        public async Task Run(IJobExecutionContext context, int jobid)
        {
            string csdncookie = "uuid_tt_dd=10_36575270660-1607065853983-192011; UN=u010840685; p_uid=U010000; Hm_ct_6bcd52f51e9b3dce32bec4a3997715ac=6525*1*10_36575270660-1607065853983-192011!5744*1*u010840685; UserName=u010840685; UserInfo=2e1b0c3535df4361b38c567d8878a374; UserToken=2e1b0c3535df4361b38c567d8878a374; UserNick=%E6%AC%B2%E6%80%9D; AU=509; BT=1616394156533; Hm_up_6bcd52f51e9b3dce32bec4a3997715ac=%7B%22islogin%22%3A%7B%22value%22%3A%221%22%2C%22scope%22%3A1%7D%2C%22isonline%22%3A%7B%22value%22%3A%221%22%2C%22scope%22%3A1%7D%2C%22isvip%22%3A%7B%22value%22%3A%220%22%2C%22scope%22%3A1%7D%2C%22uid_%22%3A%7B%22value%22%3A%22u010840685%22%2C%22scope%22%3A1%7D%7D; ssxmod_itna=eqmx0D9Dc73iqxQq0dy7tigYY5APh0xqxqGXxpoDZDiqAPGhDC8ScxD5wEq4KCDy7+xpxCtGRGtW5=7+Tehtyr74GLDmKDy+W6eGGIxBYDQxAYDGDDpXD84DrAxYPG0DiKGRDlIFcDAf=Dbx=2DitSDDUF04G2D7tnzqL42wrDAd+yK7DnD0t5xBdPDcDniQnr=YiTeTNZDBQD7qNnDYo67eDHB2xTeO4f0O+YlPvY0hDG0xfbCY4PbIDei7vYQiOtD8DqQB+d9gkDG3PG2iD===; ssxmod_itna2=eqmx0D9Dc73iqxQq0dy7tigYY5APh0xqxA6b5P4D/iQCDFOYtpcDID5BIcxBM4ZmxwufCrm2qOUQLFIjHq7t+=qrXw0B=DDt0iYd+TIDgSeEyIrWYqYXiRlr0lD9YaW407KFx7=D+OGDD===; __gads=ID=0de619a196a7e516-22ce28af7ec700a4:T=1619073599:RT=1619073599:S=ALNI_MZMiIamo3GoRDRsFpW7RQfIW1wX5g; c_hasSub=true; dc_session_id=10_1619500073751.798823; dc_sid=01fedb8452acf1f00413c34dec3683bd; announcement-new=%7B%22isLogin%22%3Atrue%2C%22announcementUrl%22%3A%22https%3A%2F%2Fblog.csdn.net%2Fblogdevteam%2Farticle%2Fdetails%2F112280974%3Futm_source%3Dgonggao_0107%22%2C%22announcementCount%22%3A0%2C%22announcementExpire%22%3A3600000%7D; c_first_ref=github.com; c_first_page=https%3A//blog.csdn.net/; c_segment=11; Hm_lvt_6bcd52f51e9b3dce32bec4a3997715ac=1619428881,1619430562,1619430574,1619500082; c_ref=https%3A//mp.csdn.net/console/home%3Fspm%3D1001.2100.3001.4503; c_page_id=default; log_Id_click=94; c_pref=https%3A//mp.csdn.net/console/home%3Fspm%3D1001.2100.3001.4503; log_Id_view=739; Hm_lpvt_6bcd52f51e9b3dce32bec4a3997715ac=1619500342; dc_tos=qs7igo; log_Id_pv=427";
            string csdnsign   = _csdnsignservices.CSDNSign(csdncookie);

            if (jobid > 0)
            {
                var model = await _tasksQzServices.QueryById(jobid);

                if (model != null)
                {
                    model.RunTimes += 1;
                    var separator = "<br>";
                    model.Remark =
                        $"【{DateTime.Now}】执行任务【Id:{context.JobDetail.Key.Name},组别:{context.JobDetail.Key.Group}】【执行成功】:{csdnsign}{separator}";

                    await _tasksQzServices.Update(model);
                }
            }

            //await Console.Out.WriteLineAsync("博客总数量" + list.Count.ToString());
        }
コード例 #11
0
        public async Task Run(IJobExecutionContext context, int jobid)
        {
            List <LogInfo> excLogs       = new List <LogInfo>();
            var            exclogContent = LogLock.ReadLog(Path.Combine(_environment.ContentRootPath, "Log"), $"GlobalExceptionLogs_{DateTime.Now.ToString("yyyMMdd")}.log", Encoding.UTF8);

            if (!string.IsNullOrEmpty(exclogContent))
            {
                excLogs = exclogContent.Split("--------------------------------")
                          .Where(d => !string.IsNullOrEmpty(d) && d != "\n" && d != "\r\n")
                          .Select(d => new LogInfo
                {
                    Datetime = (d.Split("|")[0]).Split(',')[0].ObjToDate(),
                    Content  = d.Split("|")[1]?.Replace("\r\n", "<br>"),
                    LogColor = "EXC",
                    Import   = 9,
                }).ToList();
            }

            var filterDatetime = DateTime.Now.AddHours(-1);

            excLogs = excLogs.Where(d => d.Datetime >= filterDatetime).ToList();

            var operateLogs = new List <OperateLog>()
            {
            };

            excLogs.ForEach(m =>
            {
                operateLogs.Add(new OperateLog()
                {
                    LogTime     = m.Datetime,
                    Description = m.Content,
                    IPAddress   = m.IP,
                    UserId      = 0,
                    IsDeleted   = false,
                });
            });


            if (operateLogs.Count > 0)
            {
                var logsIds = await _operateLogServices.Add(operateLogs);
            }

            if (jobid > 0)
            {
                var model = await _tasksQzServices.QueryById(jobid);

                if (model != null)
                {
                    var list = await _operateLogServices.Query(d => d.IsDeleted == false);

                    model.RunTimes += 1;
                    var separator = "<br>";
                    model.Remark =
                        $"【{DateTime.Now}】执行任务【Id:{context.JobDetail.Key.Name},组别:{context.JobDetail.Key.Group}】【执行成功】:异常数{list.Count}{separator}"
                        + string.Join(separator, StringHelper.GetTopDataBySeparator(model.Remark, separator, 9));

                    await _tasksQzServices.Update(model);
                }
            }
        }