Beispiel #1
0
        public static void DeleteTest()
        {
            string name = "so2";
            //name = null;

            MsSqlContext context = new MsSqlContext(DbHelper.ConnectionString);
            int          r       = -1;
            int?         age     = null;

            //r = context.Delete<User>(a => a.Gender == Gender.Man);
            r = context.Delete <User>(a => a.Age == r);
            //r = context.Delete<User>(a => a.Gender == null);
            //r = context.Delete<User>(a => a.Age == age);
            //r = context.Delete<User>(a => age == a.Age);

            User user = new User();

            user.Id = 6;
            r       = context.Delete(user);
            context.Delete(new User()
            {
                Id = 1
            });
            Console.WriteLine(1);
        }
Beispiel #2
0
        public static void Delete()
        {
            context.Delete <User>(a => a.Id == 1);

            /*
             * DELETE [Users] WHERE [Users].[Id] = 1
             */

            //批量删除
            //删除所有不男不女的用户
            context.Delete <User>(a => a.Gender == null);

            /*
             * DELETE [Users] FROM [Users] WHERE [Users].[Gender] IS NULL
             */

            User user = new User();

            user.Id = 1;
            context.Delete(user);

            /*
             * Int32 @P_0 = 1;
             * DELETE [Users] WHERE [Users].[Id] = @P_0
             */

            ConsoleHelper.WriteLineAndReadKey(1);
        }
Beispiel #3
0
        static void SpecifiedTableTest()
        {
            object ret = null;

            User user = null;

            ret = context.Query <User>().Where(a => a.Id > -1).TakePage(1, 20).ToList();
            ret = context.Query <User>("Users_1").Where(a => a.Id > -1).TakePage(1, 20).ToList();

            ret = context.Query <User>().Where(a => a.Id > -1).Select(a => a.Name).TakePage(1, 20).ToList();
            ret = context.Query <User>("Users_1").Where(a => a.Id > -1).Select(a => a.Name).TakePage(1, 20).ToList();


            ret = context.Query <User>().InnerJoin <User>(context.Query <User>("Users_1"), (u1, u2) => u1.Id == u2.Id).Select((u1, u2) => new { u1, u2 }).Where(a => a.u1.Id > -1 && a.u2.Id > -2).ToList();

            user = new User()
            {
                Id = 100, Name = "Users_1", Gender = Gender.Man, Age = 180, OpTime = DateTime.Now
            };
            context.Insert <User>(user);
            context.Insert <User>(user, "Users_1");

            context.Insert <User>(() => new User()
            {
                Name = "Users_1_123", Gender = Gender.Woman, Age = 1800, OpTime = DateTime.Now
            });
            context.Insert <User>(() => new User()
            {
                Name = "Users_1_123", Gender = Gender.Woman, Age = 1800, OpTime = DateTime.Now
            }, "Users_1");

            user      = context.Query <User>().Where(a => a.Id == 0).First();
            user.Name = user.Name + "1";
            context.Update(user);
            context.Update(user, "Users_1");

            context.Update <User>(a => a.Id == 0, a => new User()
            {
                Age = a.Age + 1
            });
            context.Update <User>(a => a.Id == 0, a => new User()
            {
                Age = a.Age + 1
            }, "Users_1");


            user = new User()
            {
                Id = 2114
            };
            context.Delete(user);
            context.Delete(user, "Users_1");

            context.Delete <User>(a => a.Id == 2115);
            context.Delete <User>(a => a.Id == 2115, "Users_1");


            ConsoleHelper.WriteLineAndReadKey();
        }
Beispiel #4
0
        public static void Delete()
        {
            object ret = null;

            ret = context.Delete <TestEntity>(a => a.Id == 0);

            TestEntity entity = new TestEntity();

            entity.Id = 0;

            ret = context.Delete(entity);

            ConsoleHelper.WriteLineAndReadKey();
        }
Beispiel #5
0
        public void Execute(IJobExecutionContext context)
        {
            try
            {
                DateTime dt                  = DateTime.Now;
                string   shortdate           = dt.ToString("yyyy-MM-dd");
                var      bookdata            = _helper.Get(null, "http://ac.qq.com/Comic/all/search/time/vip/3/page/1");
                IQuery <VIPFreeComic> vfcq   = dbcontext.Query <VIPFreeComic>();
                string          pattern_page = "共<em>(?<key1>.*?)</em>个结果";
                MatchCollection matches_page = Regex.Matches(bookdata, pattern_page, RegexOptions.IgnoreCase | RegexOptions.Singleline);

                int pagecount = (int)Math.Ceiling(int.Parse(matches_page[0].Groups[1].Value) / 12.0);
                List <VIPFreeComic> vfclst = new List <VIPFreeComic>();
                for (int i = 1; i <= pagecount; i++)
                {
                    var bookdata2 = _helper.Get(null, "http://ac.qq.com/Comic/all/search/time/vip/3/page/" + i);
                    bookdata2 = StringHelper.MergeSpace(bookdata2);
                    string          pattern2 = "<h3 class=\"ret-works-title clearfix\"> <a href=\"(?<key1>.*?)\" target=\"_blank\" title=\"(?<key2>.*?)\">(?<key3>.*?)</a>";
                    MatchCollection matches2 = Regex.Matches(bookdata2, pattern2, RegexOptions.IgnoreCase | RegexOptions.Singleline);

                    for (int j = 0; j < matches2.Count; j++)
                    {
                        string bookurl   = "http://ac.qq.com" + matches2[j].Groups["key1"].Value;
                        string comicname = matches2[j].Groups["key2"].Value;
                        string comicid   = (int)Source.QQ + "_" + bookurl.Split('/').LastOrDefault();


                        vfclst.Add(new VIPFreeComic()
                        {
                            bookurl   = bookurl,
                            comicid   = comicid,
                            comicname = comicname,
                            modify    = dt,
                            shortdate = shortdate,
                            source    = Source.QQ
                        });
                    }
                }
                List <VIPFreeComic> vfcdblst = vfcq.Where(x => x.source == Source.QQ).ToList();
                if (vfclst.Count > 0)
                {
                    List <VIPFreeComic> delete = vfcdblst.Except(vfclst, new VIPFreeComic_Comparer()).ToList();
                    List <VIPFreeComic> add    = vfclst.Except(vfcdblst, new VIPFreeComic_Comparer()).ToList();
                    if (delete.Count > 0)
                    {
                        List <string> deleteidlst = delete.Select(x => x.comicid).ToList();
                        dbcontext.Delete <VIPFreeComic>(x => deleteidlst.Contains(x.comicid));
                    }
                    if (add.Count > 0)
                    {
                        dbcontext.BulkInsert(add);
                    }
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Beispiel #6
0
        public static void DeleteTest1()
        {
            MsSqlContext context = new MsSqlContext(DbHelper.ConnectionString);

            context.Delete <User>(a => a.Id == 1);

            /*
             * DELETE [Users] WHERE [Users].[Id] = 1
             */

            //批量删除
            //删除所有不男不女的用户
            context.Delete <User>(a => a.Gender == null);

            /*
             * DELETE [Users] WHERE [Users].[Gender] IS NULL
             */

            User user = new User();

            user.Id = 1;
            context.Delete(user);

            /*
             * Int32 @P_0 = 1;
             * DELETE [Users] WHERE [Users].[Id] = @P_0
             */

            IDbSession dbSession = context.Session;

            try
            {
                dbSession.BeginTransaction();

                //to do somethings here...

                dbSession.CommitTransaction();
            }
            catch
            {
                dbSession.RollbackTransaction();
            }

            ConsoleHelper.WriteLineAndReadKey(1);
        }
Beispiel #7
0
        public static void DeleteTest()
        {
            string name = "so2";
            //name = null;

            MsSqlContext context = new MsSqlContext(DbHelper.ConnectionString);
            int r = -1;
            int? age = null;

            //r = context.Delete<User>(a => a.Gender == Gender.Man);
            r = context.Delete<User>(a => a.Age == r);
            //r = context.Delete<User>(a => a.Gender == null);
            //r = context.Delete<User>(a => a.Age == age);
            //r = context.Delete<User>(a => age == a.Age);

            User user = new User();
            user.Id = 6;
            r = context.Delete(user);
            context.Delete(new User() { Id = 1 });
            Console.WriteLine(1);
        }
        public void Execute(IJobExecutionContext context)
        {
            DateTime         dt             = DateTime.Now;
            string           ticks          = dt.Ticks.ToString();
            string           shortdate      = dt.ToString("yyyy-MM-dd");
            string           updatedatetime = shortdate + " " + ((dt.Hour / 0.5 + 1) * 0.5).ToString();
            string           yesterday      = dt.AddDays(-1).ToString("yyyy-MM-dd");
            IQuery <Comic>   q        = dbcontext.Query <Comic>();
            IQuery <Chapter> cpq      = dbcontext.Query <Chapter>();
            IQuery <PageHis> phisq    = dbcontext.Query <PageHis>();
            IQuery <Page>    pq       = dbcontext.Query <Page>();
            IQuery <Notice>  nq       = dbcontext.Query <Notice>();
            List <Comic>     comiclst = q.Where(a => a.source == Source.dongmanmanhua && (a.updatedatetime == null || a.updatedatetime != updatedatetime)).Take(200).ToList();
            List <int>       ids      = comiclst.Select(x => x.Id).ToList();

            dbcontext.Update <Comic>(a => ids.Contains(a.Id), a => new Comic()
            {
                updatedatetime = updatedatetime,
                modify         = dt
            });

            foreach (var comic in comiclst)
            {
                List <Chapter> cplst      = cpq.Where(a => a.comicid == comic.comicid && a.source == Source.dongmanmanhua).ToList();
                List <Chapter> chapterlst = new List <Chapter>();
                if (cplst.Count > 0)
                {
                    try
                    {
                        string          bookurl  = comic.bookurl.Replace("https://www.dongmanmanhua.cn/", "");
                        var             bookdata = _helper.Get(null, bookurl);
                        string          pattern  = "<li id=\"episode_(?<key1>.*?)\" data-episode-no=\"(?<key2>.*?)\">(?<key3>.*?)</li>";
                        MatchCollection matches  = Regex.Matches(bookdata, pattern, RegexOptions.IgnoreCase | RegexOptions.Singleline);

                        int pagecount = (int)Math.Ceiling(int.Parse(matches[0].Groups[1].Value) / 10.0);
                        for (int i = 0; i < matches.Count; i++)
                        {
                            var    lihtml     = matches[i].Groups["key3"].Value;
                            Regex  reg1       = new Regex("href=\"(?<key1>.*?)\"");
                            Match  match1     = reg1.Match(lihtml);
                            string chapterurl = match1.Groups["key1"].Value;
                            Regex  reg2       = new Regex("<span class=\"tx\">#(?<key1>.*?)</span>");
                            Match  match2     = reg2.Match(lihtml);
                            int    sort       = int.Parse(match2.Groups["key1"].Value);
                            //Regex reg3 = new Regex("<span class=\"subj\"><span>(?<key1>.*?)</span></span>");
                            //Match match3 = reg3.Match(lihtml);
                            //string chaptername = match3.Groups["key1"].Value;
                            Regex  reg3          = new Regex("alt=\"(?<key1>.*?)\"");
                            Match  match3        = reg3.Match(lihtml);
                            string chaptername   = match3.Groups["key1"].Value;
                            Regex  reg4          = new Regex("src=\"(?<key1>.*?)\"");
                            Match  match4        = reg4.Match(lihtml);
                            string chaptersource = match4.Groups["key1"].Value;

                            chapterlst.Add(new Chapter()
                            {
                                chapterid   = comic.comicid + "_" + sort,
                                chaptername = chaptername,
                                chapterurl  = "https:" + chapterurl,
                                sort        = sort,

                                comicid       = comic.comicid,
                                retry         = 0,
                                source        = comic.source,
                                downstatus    = DownChapter.待处理链接,
                                isvip         = "0",
                                chaptersource = chaptersource,
                                chapterlocal  = "",
                                modify        = dt,
                                shortdate     = shortdate,
                            });
                        }

                        for (int i = 2; i <= pagecount; i++)
                        {
                            var             bookdata2 = _helper.Get(null, bookurl + "&page=" + i);
                            string          pattern2  = "<li id=\"episode_(?<key1>.*?)\" data-episode-no=\"(?<key2>.*?)\">(?<key3>.*?)</li>";
                            MatchCollection matches2  = Regex.Matches(bookdata2, pattern2, RegexOptions.IgnoreCase | RegexOptions.Singleline);

                            for (int j = 0; j < matches2.Count; j++)
                            {
                                var    lihtml     = matches2[j].Groups["key3"].Value;
                                Regex  reg1       = new Regex("href=\"(?<key1>.*?)\"");
                                Match  match1     = reg1.Match(lihtml);
                                string chapterurl = match1.Groups["key1"].Value;
                                Regex  reg2       = new Regex("<span class=\"tx\">#(?<key1>.*?)</span>");
                                Match  match2     = reg2.Match(lihtml);
                                int    sort       = int.Parse(match2.Groups["key1"].Value);
                                //Regex reg3 = new Regex("<span class=\"subj\"><span>(?<key1>.*?)</span></span>");
                                //Match match3 = reg3.Match(lihtml);
                                //string chaptername = match3.Groups["key1"].Value;
                                Regex  reg3          = new Regex("alt=\"(?<key1>.*?)\"");
                                Match  match3        = reg3.Match(lihtml);
                                string chaptername   = match3.Groups["key1"].Value;
                                Regex  reg4          = new Regex("src=\"(?<key1>.*?)\"");
                                Match  match4        = reg4.Match(lihtml);
                                string chaptersource = match4.Groups["key1"].Value;

                                chapterlst.Add(new Chapter()
                                {
                                    chapterid   = comic.comicid + "_" + sort,
                                    chaptername = chaptername,
                                    chapterurl  = "https:" + chapterurl,
                                    sort        = sort,

                                    comicid       = comic.comicid,
                                    retry         = 0,
                                    source        = comic.source,
                                    downstatus    = DownChapter.待处理链接,
                                    isvip         = "0",
                                    chaptersource = chaptersource,
                                    chapterlocal  = "",
                                    modify        = dt,
                                    shortdate     = shortdate,
                                });
                            }
                        }
                        bool contextChange = false;

                        if (chapterlst.Count > 0)
                        {
                            chapterlst = chapterlst.OrderBy(x => x.sort).ToList();
                            int cmpCount = cplst.Count >= chapterlst.Count ? chapterlst.Count : cplst.Count;
                            for (int i = 0; i < cmpCount; i++)
                            {
                                if (cplst[i].chapterid != chapterlst[i].chapterid)
                                {
                                    contextChange = true;
                                }
                            }
                        }
                        else
                        {
                            continue;
                        }

                        if (contextChange)
                        {
                            dbcontext.Delete <Chapter>(x => x.comicid == comic.comicid);
                            if (chapterlst.Count > 0)
                            {
                                dbcontext.BulkInsert(chapterlst);
                                Notice notice = new Notice();
                                notice.noticeid     = comic.comicid;
                                notice.noticestatus = NoticeStatus.等待处理;
                                notice.noticetype   = NoticeType.目录变更;
                                notice.source       = comic.source;
                                notice.shortdate    = shortdate;
                                notice.modify       = dt;
                                //var nqwait = nq.Where(x => x.noticeid == comic.comicid && x.noticestatus == NoticeStatus.等待处理 && x.noticetype == NoticeType.目录变更).FirstOrDefault();
                                //if (nqwait == null)
                                //{
                                dbcontext.Insert(notice);
                                //}
                            }
                        }
                        else
                        {
                            if (cplst.Count == chapterlst.Count)
                            {
                                continue;
                            }

                            if (cplst.Count > chapterlst.Count)
                            {
                                List <Chapter> needrmvlst = cplst.Except(chapterlst, new Chapter_Comparer()).ToList();
                                List <int>     rmvidlst   = needrmvlst.Select(x => x.Id).ToList();
                                logger.Error(string.Join(",", needrmvlst.Select(x => x.chapterid).ToArray()));
                                dbcontext.Delete <Chapter>(x => rmvidlst.Contains(x.Id));
                            }

                            if (cplst.Count < chapterlst.Count)
                            {
                                List <Chapter> needaddlst = chapterlst.Except(cplst, new Chapter_Comparer()).ToList();
                                dbcontext.BulkInsert(needaddlst);
                            }
                        }

                        //int delete = cplst.Except(chapterlst, new Chapter_Comparer()).Count(); // 删章
                        //List<Chapter> add = chapterlst.Except(cplst, new Chapter_Comparer()).ToList();  // 新增

                        //Chapter maxChapter = cplst.OrderBy(x => x.sort).Max();


                        //if (delete > 0)
                        //{
                        //    List<string> idlst = cplst.Select(x => x.chapterid).ToList();

                        //    dbcontext.Delete<Page>(x => idlst.Contains(x.chapterid));
                        //    dbcontext.Delete<Chapter>(x => idlst.Contains(x.chapterid));
                        //    if (chapterlst.Count > 0)
                        //    {
                        //        dbcontext.BulkInsert(chapterlst);
                        //    }
                        //    Notice notice = new Notice();
                        //    notice.noticeid = comic.comicid;
                        //    notice.noticestatus = NoticeStatus.等待处理;
                        //    notice.noticetype = NoticeType.目录变更;
                        //    notice.source = comic.source;
                        //    notice.shortdate = shortdate;
                        //    notice.modify = dt;
                        //    var nqwait = nq.Where(x => x.noticeid == comic.comicid && x.noticestatus == NoticeStatus.等待处理 && x.noticetype == NoticeType.目录变更).FirstOrDefault();
                        //    if (nqwait == null)
                        //    {
                        //        dbcontext.Insert(notice);
                        //    }

                        //    continue;
                        //}
                        //else
                        //{
                        //    List<Chapter> mvadd = chapterlst.Except(add, new Chapter_Comparer()).ToList();
                        //    string cplststr = string.Join(",", cplst.Select(x => x.chapterid).ToArray());
                        //    string chapterlststr = string.Join(",", mvadd.Select(x => x.chapterid).ToArray());
                        //    if (cplststr != chapterlststr) // 调序
                        //    {
                        //        List<string> idlst = cplst.Select(x => x.chapterid).ToList();

                        //        dbcontext.Delete<Page>(x => idlst.Contains(x.chapterid));
                        //        dbcontext.Delete<Chapter>(x => idlst.Contains(x.chapterid));
                        //        if (chapterlst.Count > 0)
                        //        {
                        //            dbcontext.BulkInsert(chapterlst);
                        //        }
                        //        Notice notice = new Notice();
                        //        notice.noticeid = comic.comicid;
                        //        notice.noticestatus = NoticeStatus.等待处理;
                        //        notice.noticetype = NoticeType.目录变更;
                        //        notice.source = comic.source;
                        //        notice.shortdate = shortdate;
                        //        notice.modify = dt;
                        //        var nqwait = nq.Where(x => x.noticeid == comic.comicid && x.noticestatus == NoticeStatus.等待处理 && x.noticetype == NoticeType.目录变更).FirstOrDefault();
                        //        if (nqwait == null)
                        //        {
                        //            dbcontext.Insert(notice);
                        //        }

                        //        continue;
                        //    }
                        //}
                        //if (add.Count > 0)
                        //{
                        //    //int addsort = cplst.Count();
                        //    //foreach (var item in add)
                        //    //{
                        //    //    item.sort = item.sort + addsort;
                        //    //}
                        //    dbcontext.BulkInsert(add);
                        //}
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex.Message);
                        comic.updatedatetime = "";
                        comic.modify         = dt;
                        dbcontext.Update(comic);
                        Err_ChapterJob err = new Err_ChapterJob();
                        err.bookurl   = comic.bookurl;
                        err.source    = comic.source;
                        err.errtype   = ErrChapter.解析出错;
                        err.modify    = dt;
                        err.shortdate = shortdate;
                        err.message   = ex.Message;
                        err           = dbcontext.Insert(err);
                        continue;
                    }
                }
            }
        }
        public void Execute(IJobExecutionContext context)
        {
            DateTime         dt        = DateTime.Now;
            string           shortdate = dt.ToString("yyyy-MM-dd");
            string           yesterday = dt.AddDays(-1).ToString("yyyy-MM-dd");
            IQuery <Chapter> cpq       = dbcontext.Query <Chapter>();
            IQuery <Page>    pq        = dbcontext.Query <Page>();
            IQuery <Notice>  nq        = dbcontext.Query <Notice>();
            List <Chapter>   cplst     = cpq.Where(x => x.source == Source.dongmanmanhua && x.downstatus == DownChapter.完图片 && x.updatedate != shortdate).Take(200).ToList();
            List <int>       ids       = cplst.Select(x => x.Id).ToList();

            dbcontext.Update <Chapter>(a => ids.Contains(a.Id), a => new Chapter()
            {
                updatedate = shortdate,
                modify     = dt
            });
            List <Chapter> chapterlst = new List <Chapter>();

            foreach (var cp in cplst)
            {
                try
                {
                    string          chapterpage = cp.chapterurl.Replace("https://www.dongmanmanhua.cn", "");
                    var             imgdata     = _helper.Get(null, chapterpage);
                    string          pattern     = "<div class=\"(?<key1>.*?)\" id=\"_imageList\">(?<key2>.*?)</div>";
                    MatchCollection matches     = Regex.Matches(imgdata, pattern, RegexOptions.IgnoreCase | RegexOptions.Singleline);
                    string          imghtml     = matches[0].Groups["key2"].Value;
                    string          pattern2    = "data-url=\"(?<key1>.*?)\"";
                    MatchCollection matches2    = Regex.Matches(imghtml, pattern2);
                    List <Page>     pglst       = new List <Page>();
                    for (int i = 0; i < matches2.Count; i++)
                    {
                        pglst.Add(new Page()
                        {
                            chapterid  = cp.chapterid,
                            modify     = dt,
                            shortdate  = shortdate,
                            sort       = i + 1,
                            source     = cp.source,
                            pagelocal  = "",
                            pagesource = matches2[i].Groups["key1"].Value
                        });
                    }
                    List <Page> pgdblst = pq.Where(x => x.chapterid == cp.chapterid).ToList();
                    if (pgdblst.Count != pglst.Count)
                    {
                        List <int> idlst = pgdblst.Select(x => x.Id).ToList();
                        dbcontext.Delete <Page>(x => idlst.Contains(x.Id));
                        dbcontext.BulkInsert(pglst);
                        cp.downstatus = DownChapter.处理完链接;
                        cp.modify     = dt;
                        dbcontext.Update(cp);
                        Notice notice = new Notice();
                        notice.noticeid     = cp.chapterid;
                        notice.noticestatus = NoticeStatus.等待处理;
                        notice.noticetype   = NoticeType.章节更新;
                        notice.source       = cp.source;
                        notice.shortdate    = shortdate;
                        notice.modify       = dt;
                        var nqwait = nq.Where(x => x.noticeid == cp.chapterid && x.noticestatus == NoticeStatus.等待处理 && x.noticetype == NoticeType.章节更新).FirstOrDefault();
                        if (nqwait == null)
                        {
                            dbcontext.Insert(notice);
                        }
                        continue;
                    }
                }
                catch (Exception ex)
                {
                    logger.Error(ex.Message);
                    cp.updatedate = yesterday;
                    cp.modify     = dt;
                    dbcontext.Update(cp);
                    Err_ChapterJob err = new Err_ChapterJob();
                    err.bookurl   = cp.chapterurl;
                    err.source    = cp.source;
                    err.errtype   = ErrChapter.解析出错;
                    err.modify    = dt;
                    err.shortdate = shortdate;
                    err.message   = ex.Message;
                    err           = dbcontext.Insert(err);
                    continue;
                }
            }
        }
Beispiel #10
0
        public void Execute(IJobExecutionContext context)
        {
            DateTime         dt             = DateTime.Now;
            string           ticks          = dt.Ticks.ToString();
            string           shortdate      = dt.ToString("yyyy-MM-dd");
            string           updatedatetime = shortdate + " " + ((dt.Hour / 0.5 + 1) * 0.5).ToString();
            string           yesterday      = dt.AddDays(-1).ToString("yyyy-MM-dd");
            IQuery <Comic>   q        = dbcontext.Query <Comic>();
            IQuery <Chapter> cpq      = dbcontext.Query <Chapter>();
            IQuery <PageHis> phisq    = dbcontext.Query <PageHis>();
            IQuery <Page>    pq       = dbcontext.Query <Page>();
            IQuery <Notice>  nq       = dbcontext.Query <Notice>();
            List <Comic>     comiclst = q.Where(a => a.source == Source._163 && (a.updatedatetime == null || a.updatedatetime != updatedatetime)).Take(200).ToList();
            List <int>       ids      = comiclst.Select(x => x.Id).ToList();

            dbcontext.Update <Comic>(a => ids.Contains(a.Id), a => new Comic()
            {
                updatedatetime = updatedatetime,
                modify         = dt
            });

            foreach (var comic in comiclst)
            {
                List <Chapter> cplst      = cpq.Where(a => a.comicid == comic.comicid && a.source == Source._163).ToList();
                List <Chapter> chapterlst = new List <Chapter>();
                if (cplst.Count > 0)
                {
                    try
                    {
                        int sort = 0;

                        var bookdata = _helper.Get <_163_Chapter_Api>(null, string.Format(chapterurl, comic.comicid.Replace("6_", "")));
                        if (bookdata.code == 200)
                        {
                            bookdata.catalog.sections.ForEach(x =>
                            {
                                foreach (var item in x.sections)
                                {
                                    sort = sort + 1;
                                    chapterlst.Add(new Chapter()
                                    {
                                        chapterid     = comic.comicid + "_" + item.sectionId,
                                        chaptername   = item.fullTitle,
                                        chapterurl    = $"https://manhua.163.com/reader/{item.bookId}/{item.sectionId}#imgIndex=0",
                                        sort          = sort,
                                        comicid       = comic.comicid,
                                        retry         = 0,
                                        source        = comic.source,
                                        downstatus    = DownChapter.待处理链接,
                                        isvip         = item.needPay == 0 ? "0" : "1",
                                        chaptersource = "",
                                        chapterlocal  = "",
                                        modify        = dt,
                                        shortdate     = shortdate,
                                    });
                                }
                            });
                        }
                        int            delete = cplst.Except(chapterlst, new Chapter_Comparer()).Count();  // 删章
                        List <Chapter> add    = chapterlst.Except(cplst, new Chapter_Comparer()).ToList(); // 新增

                        if (delete > 0)
                        {
                            List <string> idlst        = cplst.Select(x => x.chapterid).ToList();
                            int           phislstcount = phisq.Where(x => idlst.Contains(x.chapterid)).Count();
                            if (phislstcount == 0)
                            {
                                List <Page> pglst = pq.Where(x => idlst.Contains(x.chapterid)).ToList();
                                if (pglst.Count > 0)
                                {
                                    List <PageHis> phislst = new List <PageHis>();
                                    pglst.ForEach(x =>
                                    {
                                        phislst.Add(new PageHis()
                                        {
                                            chapterid  = x.chapterid,
                                            modify     = x.modify,
                                            pagelocal  = x.pagelocal,
                                            pagesource = x.pagesource,
                                            pagestate  = x.pagestate,
                                            shortdate  = x.shortdate,
                                            sort       = x.sort,
                                            source     = x.source,
                                            ticks      = x.ticks
                                        });
                                    });
                                    dbcontext.BulkInsert(phislst);
                                }
                            }


                            dbcontext.Delete <Page>(x => idlst.Contains(x.chapterid));
                            dbcontext.Delete <Chapter>(x => idlst.Contains(x.chapterid));
                            if (chapterlst.Count > 0)
                            {
                                dbcontext.BulkInsert(chapterlst);
                            }
                            Notice notice = new Notice();
                            notice.noticeid     = comic.comicid;
                            notice.noticestatus = NoticeStatus.等待处理;
                            notice.noticetype   = NoticeType.目录变更;
                            notice.source       = comic.source;
                            notice.shortdate    = shortdate;
                            notice.modify       = dt;
                            var nqwait = nq.Where(x => x.noticeid == comic.comicid && x.noticestatus == NoticeStatus.等待处理 && x.noticetype == NoticeType.目录变更).FirstOrDefault();
                            if (nqwait == null)
                            {
                                dbcontext.Insert(notice);
                            }

                            continue;
                        }
                        else
                        {
                            List <Chapter> mvadd         = chapterlst.Except(add, new Chapter_Comparer()).ToList();
                            string         cplststr      = string.Join(",", cplst.Select(x => x.chapterid).ToArray());
                            string         chapterlststr = string.Join(",", mvadd.Select(x => x.chapterid).ToArray());
                            if (cplststr != chapterlststr) // 调序
                            {
                                List <string> idlst        = cplst.Select(x => x.chapterid).ToList();
                                int           phislstcount = phisq.Where(x => idlst.Contains(x.chapterid)).Count();
                                if (phislstcount == 0)
                                {
                                    List <Page> pglst = pq.Where(x => idlst.Contains(x.chapterid)).ToList();
                                    if (pglst.Count > 0)
                                    {
                                        List <PageHis> phislst = new List <PageHis>();
                                        pglst.ForEach(x =>
                                        {
                                            phislst.Add(new PageHis()
                                            {
                                                chapterid  = x.chapterid,
                                                modify     = x.modify,
                                                pagelocal  = x.pagelocal,
                                                pagesource = x.pagesource,
                                                pagestate  = x.pagestate,
                                                shortdate  = x.shortdate,
                                                sort       = x.sort,
                                                source     = x.source,
                                                ticks      = x.ticks
                                            });
                                        });
                                        dbcontext.BulkInsert(phislst);
                                    }
                                }

                                dbcontext.Delete <Page>(x => idlst.Contains(x.chapterid));
                                dbcontext.Delete <Chapter>(x => idlst.Contains(x.chapterid));
                                if (chapterlst.Count > 0)
                                {
                                    dbcontext.BulkInsert(chapterlst);
                                }
                                Notice notice = new Notice();
                                notice.noticeid     = comic.comicid;
                                notice.noticestatus = NoticeStatus.等待处理;
                                notice.noticetype   = NoticeType.目录变更;
                                notice.source       = comic.source;
                                notice.shortdate    = shortdate;
                                notice.modify       = dt;
                                var nqwait = nq.Where(x => x.noticeid == comic.comicid && x.noticestatus == NoticeStatus.等待处理 && x.noticetype == NoticeType.目录变更).FirstOrDefault();
                                if (nqwait == null)
                                {
                                    dbcontext.Insert(notice);
                                }

                                continue;
                            }
                        }
                        if (add.Count > 0)
                        {
                            dbcontext.BulkInsert(add);
                        }
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex.Message);
                        comic.updatedatetime = "";
                        comic.modify         = dt;
                        dbcontext.Update(comic);
                        Err_ChapterJob err = new Err_ChapterJob();
                        err.bookurl   = comic.bookurl;
                        err.source    = comic.source;
                        err.errtype   = ErrChapter.解析出错;
                        err.modify    = dt;
                        err.shortdate = shortdate;
                        err.message   = ex.Message;
                        err           = dbcontext.Insert(err);
                        continue;
                    }
                }
            }
        }
        public void Execute(IJobExecutionContext context)
        {
            DateTime         dt             = DateTime.Now;
            string           ticks          = dt.Ticks.ToString();
            string           shortdate      = dt.ToString("yyyy-MM-dd");
            string           updatedatetime = shortdate + " " + ((dt.Hour / 0.5 + 1) * 0.5).ToString();
            string           yesterday      = dt.AddDays(-1).ToString("yyyy-MM-dd");
            IQuery <Comic>   q        = dbcontext.Query <Comic>();
            IQuery <Chapter> cpq      = dbcontext.Query <Chapter>();
            IQuery <PageHis> phisq    = dbcontext.Query <PageHis>();
            IQuery <Page>    pq       = dbcontext.Query <Page>();
            IQuery <Notice>  nq       = dbcontext.Query <Notice>();
            List <Comic>     comiclst = q.Where(a => a.source == Source.Manhuatai && (a.updatedatetime == null || a.updatedatetime != updatedatetime)).Take(200).ToList();
            List <int>       ids      = comiclst.Select(x => x.Id).ToList();

            dbcontext.Update <Comic>(a => ids.Contains(a.Id), a => new Comic()
            {
                updatedatetime = updatedatetime,
                modify         = dt
            });

            foreach (var comic in comiclst)
            {
                List <Chapter> cplst      = cpq.Where(a => a.comicid == comic.comicid && a.source == Source.Manhuatai).ToList();
                List <Chapter> chapterlst = new List <Chapter>();
                if (cplst.Count > 0)
                {
                    try
                    {
                        string          bookurl  = comic.bookurl.Replace("http://www.manhuatai.com", "");
                        var             bookdata = _helper.Get(null, bookurl);
                        string          pattern  = "<li><a title=\"(?<key1>.*?)\" href=\"(?<key2>.*?)\"><span>(?<key3>.*?)</span></a></li>";
                        MatchCollection matches  = Regex.Matches(bookdata, pattern, RegexOptions.IgnoreCase | RegexOptions.Singleline);
                        for (int i = 0; i < matches.Count; i++)
                        {
                            string chapterid   = comic.comicid + "_" + matches[i].Groups["key2"].Value.Replace(".html", "");
                            string chaptername = matches[i].Groups["key1"].Value;
                            string chapterurl  = comic.bookurl + matches[i].Groups["key2"].Value;
                            int    sort        = matches.Count - i;
                            chapterlst.Add(new Chapter()
                            {
                                chapterid   = chapterid,
                                chaptername = chaptername,
                                chapterurl  = chapterurl,
                                sort        = sort,

                                comicid       = comic.comicid,
                                retry         = 0,
                                source        = comic.source,
                                downstatus    = DownChapter.待处理链接,
                                isvip         = "0",
                                chaptersource = "",
                                chapterlocal  = "",
                                modify        = dt,
                                shortdate     = shortdate,
                            });
                        }

                        int            delete = cplst.Except(chapterlst, new Chapter_Comparer()).Count();  // 删章
                        List <Chapter> add    = chapterlst.Except(cplst, new Chapter_Comparer()).ToList(); // 新增

                        if (delete > 0)
                        {
                            List <string> idlst = cplst.Select(x => x.chapterid).ToList();
                            dbcontext.Delete <Page>(x => idlst.Contains(x.chapterid));
                            dbcontext.Delete <Chapter>(x => idlst.Contains(x.chapterid));
                            if (chapterlst.Count > 0)
                            {
                                dbcontext.BulkInsert(chapterlst);
                            }
                            Notice notice = new Notice();
                            notice.noticeid     = comic.comicid;
                            notice.noticestatus = NoticeStatus.等待处理;
                            notice.noticetype   = NoticeType.目录变更;
                            notice.source       = comic.source;
                            notice.shortdate    = shortdate;
                            notice.modify       = dt;
                            var nqwait = nq.Where(x => x.noticeid == comic.comicid && x.noticestatus == NoticeStatus.等待处理 && x.noticetype == NoticeType.目录变更).FirstOrDefault();
                            if (nqwait == null)
                            {
                                dbcontext.Insert(notice);
                            }

                            continue;
                        }
                        else
                        {
                            List <Chapter> mvadd         = chapterlst.Except(add, new Chapter_Comparer()).ToList();
                            string         cplststr      = string.Join(",", cplst.Select(x => x.chapterid).ToArray());
                            string         chapterlststr = string.Join(",", mvadd.Select(x => x.chapterid).ToArray());
                            if (cplststr != chapterlststr) // 调序
                            {
                                List <string> idlst = cplst.Select(x => x.chapterid).ToList();

                                dbcontext.Delete <Page>(x => idlst.Contains(x.chapterid));
                                dbcontext.Delete <Chapter>(x => idlst.Contains(x.chapterid));
                                if (chapterlst.Count > 0)
                                {
                                    dbcontext.BulkInsert(chapterlst);
                                }
                                Notice notice = new Notice();
                                notice.noticeid     = comic.comicid;
                                notice.noticestatus = NoticeStatus.等待处理;
                                notice.noticetype   = NoticeType.目录变更;
                                notice.source       = comic.source;
                                notice.shortdate    = shortdate;
                                notice.modify       = dt;
                                var nqwait = nq.Where(x => x.noticeid == comic.comicid && x.noticestatus == NoticeStatus.等待处理 && x.noticetype == NoticeType.目录变更).FirstOrDefault();
                                if (nqwait == null)
                                {
                                    dbcontext.Insert(notice);
                                }

                                continue;
                            }
                        }
                        if (add.Count > 0)
                        {
                            dbcontext.BulkInsert(add);
                        }
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex.Message);
                        comic.updatedatetime = "";
                        comic.modify         = dt;
                        dbcontext.Update(comic);
                        Err_ChapterJob err = new Err_ChapterJob();
                        err.bookurl   = comic.bookurl;
                        err.source    = comic.source;
                        err.errtype   = ErrChapter.解析出错;
                        err.modify    = dt;
                        err.shortdate = shortdate;
                        err.message   = ex.Message;
                        err           = dbcontext.Insert(err);
                        continue;
                    }
                }
            }
        }
        public void Execute(IJobExecutionContext context)
        {
            DateTime         dt        = DateTime.Now;
            string           shortdate = dt.ToString("yyyy-MM-dd");
            string           yesterday = dt.AddDays(-1).ToString("yyyy-MM-dd");
            IQuery <Page>    pq        = dbcontext.Query <Page>();
            IQuery <Notice>  nq        = dbcontext.Query <Notice>();
            IQuery <Chapter> cpq       = dbcontext.Query <Chapter>();//x.comicid == "1_622585"
            List <Chapter>   cplst     = cpq.Where(x => x.source == Source.QQ && x.downstatus == DownChapter.完图片 && x.updatedate != shortdate).Take(200).ToList();
            List <int>       ids       = cplst.Select(x => x.Id).ToList();

            dbcontext.Update <Chapter>(a => ids.Contains(a.Id), a => new Chapter()
            {
                updatedate = shortdate,
                modify     = dt
            });
            List <Chapter> chapterlst = new List <Chapter>();

            foreach (var cp in cplst)
            {
                try
                {
                    string chapterpage = cp.chapterurl.Replace("http://ac.qq.com", "");
                    var    imgdata     = _helper.Get(null, chapterpage);
                    Regex  rex         = new Regex("var DATA        = '(?<key1>.*?)',");
                    Match  match       = rex.Match(imgdata);
                    string key         = match.Groups["key1"].Value;
                    if (string.IsNullOrEmpty(key))
                    {
                        cp.downstatus = DownChapter.待处理链接;
                        cp.modify     = dt;
                        dbcontext.Update(cp);
                        Err_ChapterJob err = new Err_ChapterJob();
                        err.bookurl   = cp.chapterurl;
                        err.source    = cp.source;
                        err.errtype   = ErrChapter.解析出错;
                        err.modify    = dt;
                        err.shortdate = shortdate;
                        err.message   = "DATA解析失败";
                        err           = dbcontext.Insert(err);
                        continue;
                    }
                    var s = DecodeHelper.QQPageDecode(key.Substring(1));
                    var t = JsonHelper.DeserializeJsonToObject <QQ_Page_Api>(s);
                    if (t.chapter.vipStatus == 1)
                    {
                        List <Page> pglst = new List <Page>();
                        for (int i = 0; i < t.picture.Count; i++)
                        {
                            pglst.Add(new Page()
                            {
                                chapterid  = cp.chapterid,
                                modify     = dt,
                                shortdate  = shortdate,
                                sort       = i + 1,
                                source     = cp.source,
                                pagelocal  = "",
                                pagesource = t.picture[i].url
                            });
                        }

                        List <Page> pgdblst = pq.Where(x => x.chapterid == cp.chapterid).ToList();
                        if (pgdblst.Count != pglst.Count)
                        {
                            List <int> idlst = pgdblst.Select(x => x.Id).ToList();
                            dbcontext.Delete <Page>(x => idlst.Contains(x.Id));
                            dbcontext.BulkInsert(pglst);
                            cp.downstatus = DownChapter.处理完链接;
                            cp.modify     = dt;
                            dbcontext.Update(cp);
                            Notice notice = new Notice();
                            notice.noticeid     = cp.chapterid;
                            notice.noticestatus = NoticeStatus.等待处理;
                            notice.noticetype   = NoticeType.章节更新;
                            notice.source       = cp.source;
                            notice.shortdate    = shortdate;
                            notice.modify       = dt;
                            var nqwait = nq.Where(x => x.noticeid == cp.chapterid && x.noticestatus == NoticeStatus.等待处理 && x.noticetype == NoticeType.章节更新).FirstOrDefault();
                            if (nqwait == null)
                            {
                                dbcontext.Insert(notice);
                            }
                            continue;
                        }
                    }
                    else
                    {
                        selenium.Navigate().GoToUrl(cp.chapterurl);
                        IList <IWebElement> frames            = selenium.FindElements(By.TagName("iframe"));
                        IWebElement         controlPanelFrame = null; //commentFrame  ptlogin_iframe
                        foreach (var frame in frames)
                        {
                            if (frame.GetAttribute("id") == "iframeAll")
                            {
                                controlPanelFrame = frame;
                                break;
                            }
                        }
                        if (controlPanelFrame != null) //QQ登录
                        {
                            selenium.SwitchTo().Frame(controlPanelFrame);

                            IReadOnlyCollection <IWebElement> switchtoElement = selenium.FindElements(By.Id("switcher_plogin"));
                            if (switchtoElement != null && switchtoElement.Count > 0)
                            {
                                switchtoElement.First().Click();

                                selenium.FindElement(By.Id("u")).Clear();
                                selenium.FindElement(By.Id("u")).SendKeys("2806126975");
                                selenium.FindElement(By.Id("p")).Clear();
                                selenium.FindElement(By.Id("p")).SendKeys("rby123456");

                                selenium.FindElement(By.Id("login_button")).Click();
                            }
                            selenium.SwitchTo().DefaultContent();
                        }

                        frames = selenium.FindElements(By.TagName("iframe"));
                        IWebElement checkVipFrame = null;
                        foreach (var frame in frames)
                        {
                            if (frame.GetAttribute("id") == "checkVipFrame")
                            {
                                checkVipFrame = frame;
                                break;
                            }
                        }
                        if (checkVipFrame != null)
                        {
                            selenium.SwitchTo().Frame(checkVipFrame);
                            //自动购买
                            IReadOnlyCollection <IWebElement> checkAutoElement = selenium.FindElements(By.Id("check_auto_next"));
                            IReadOnlyCollection <IWebElement> singlBbuyElement = selenium.FindElements(By.ClassName("single_buy"));
                            if (checkAutoElement != null && singlBbuyElement != null && checkAutoElement.Count > 0 && singlBbuyElement.Count > 0)
                            {
                                if (singlBbuyElement.First().Text.Trim().StartsWith("点券不足"))
                                {
                                    MailMessage msg = new MailMessage();
                                    continue;
                                }
                                else
                                {
                                    checkAutoElement.First().Click();
                                    singlBbuyElement.First().Click();
                                }
                            }
                        }
                        Match match1 = rex.Match(selenium.PageSource);
                        key = match1.Groups["key1"].Value;
                        if (string.IsNullOrEmpty(key))
                        {
                            cp.downstatus = DownChapter.待处理链接;
                            cp.modify     = dt;
                            dbcontext.Update(cp);
                            Err_ChapterJob err = new Err_ChapterJob();
                            err.bookurl   = cp.chapterurl;
                            err.source    = cp.source;
                            err.errtype   = ErrChapter.解析出错;
                            err.modify    = dt;
                            err.shortdate = shortdate;
                            err.message   = "DATA解析失败";
                            err           = dbcontext.Insert(err);
                            continue;
                        }

                        s = DecodeHelper.QQPageDecode(key.Substring(1));
                        t = JsonHelper.DeserializeJsonToObject <QQ_Page_Api>(s);
                        List <Page> pglst = new List <Page>();
                        for (int i = 0; i < t.picture.Count; i++)
                        {
                            pglst.Add(new Page()
                            {
                                chapterid  = cp.chapterid,
                                modify     = dt,
                                shortdate  = shortdate,
                                sort       = i + 1,
                                source     = cp.source,
                                pagelocal  = "",
                                pagesource = t.picture[i].url
                            });
                        }

                        List <Page> pgdblst = pq.Where(x => x.chapterid == cp.chapterid).ToList();
                        if (pgdblst.Count != pglst.Count)
                        {
                            List <int> idlst = pgdblst.Select(x => x.Id).ToList();
                            dbcontext.Delete <Page>(x => idlst.Contains(x.Id));
                            dbcontext.BulkInsert(pglst);
                            cp.downstatus = DownChapter.处理完链接;
                            cp.modify     = dt;
                            dbcontext.Update(cp);
                            Notice notice = new Notice();
                            notice.noticeid     = cp.chapterid;
                            notice.noticestatus = NoticeStatus.等待处理;
                            notice.noticetype   = NoticeType.章节更新;
                            notice.source       = cp.source;
                            notice.shortdate    = shortdate;
                            notice.modify       = dt;
                            var nqwait = nq.Where(x => x.noticeid == cp.chapterid && x.noticestatus == NoticeStatus.等待处理 && x.noticetype == NoticeType.章节更新).FirstOrDefault();
                            if (nqwait == null)
                            {
                                dbcontext.Insert(notice);
                            }
                            continue;
                        }
                    }
                }
                catch (Exception ex)
                {
                    logger.Error(ex.Message);
                    cp.updatedate = yesterday;
                    cp.modify     = dt;
                    dbcontext.Update(cp);
                    Err_ChapterJob err = new Err_ChapterJob();
                    err.bookurl   = cp.chapterurl;
                    err.source    = cp.source;
                    err.errtype   = ErrChapter.解析出错;
                    err.modify    = dt;
                    err.shortdate = shortdate;
                    err.message   = ex.Message;
                    err           = dbcontext.Insert(err);
                    continue;
                }
            }
        }