Esempio n. 1
0
        public static void TrackingTest()
        {
            MsSqlContext context = new MsSqlContext(DbHelper.ConnectionString);

            object ret = null;

            var q = context.Query <User>();

            q = q.AsTracking();

            User user = q.First();

            ret = context.Update(user);

            Console.WriteLine(ret);

            context.TrackEntity(user);
            user.Name   = user.Name + "1";
            user.Age    = user.Age;
            user.Gender = null;
            ret         = context.Update(user);

            Console.WriteLine(ret);

            ret = context.Update(user);
            Console.WriteLine(ret);

            ConsoleHelper.WriteLineAndReadKey();
        }
Esempio n. 2
0
        public static void Update()
        {
            object ret = null;

            ret = context.Update <TestEntity>(a => a.Id == 1, a => new TestEntity()
            {
                F_Byte = 1
                ,
                F_Int16 = 16
                ,
                F_Int32 = 32
                ,
                F_Int64 = 64
                ,
                F_Double = 1.123456
                ,
                F_Float = 1.1234F
                ,
                F_Decimal = 1.12345678M
                ,
                F_Bool = true
                ,
                F_DateTime = DateTime.Now
                ,
                F_Guid = Guid.NewGuid()
                ,
                F_String = "12345"
            });

            Console.WriteLine(ret);

            var entity = new TestEntity();

            entity.Id         = 1;
            entity.F_Byte     = 1;
            entity.F_Int16    = 16;
            entity.F_Int32    = 32;
            entity.F_Int64    = 64;
            entity.F_Double   = 1.123456;
            entity.F_Float    = 1.1234F;
            entity.F_Decimal  = 1.12345678M;
            entity.F_Bool     = true;
            entity.F_DateTime = DateTime.Now;
            entity.F_Guid     = Guid.NewGuid();
            entity.F_String   = "12345";

            ret = context.Update(entity);

            Console.WriteLine(ret);

            context.TrackEntity(entity);


            entity.F_String = "lu";
            ret             = context.Update(entity);

            Console.WriteLine(ret);

            ConsoleHelper.WriteLineAndReadKey();
        }
Esempio n. 3
0
        public static void Update()
        {
            context.Update <User>(a => a.Id == 1, a => new User()
            {
                Name = a.Name, Age = a.Age + 1, Gender = Gender.Man, OpTime = DateTime.Now
            });

            /*
             * UPDATE [Users] SET [Name]=[Users].[Name],[Age]=([Users].[Age] + 1),[Gender]=1,[OpTime]=GETDATE() WHERE [Users].[Id] = 1
             */

            //批量更新
            //给所有女性年轻 1 岁
            context.Update <User>(a => a.Gender == Gender.Woman, a => new User()
            {
                Age = a.Age - 1, OpTime = DateTime.Now
            });

            /*
             * UPDATE [Users] SET [Age]=([Users].[Age] - 1),[OpTime]=GETDATE() WHERE [Users].[Gender] = 2
             */

            User user = new User();

            user.Id     = 1;
            user.Name   = "lu";
            user.Age    = 28;
            user.Gender = Gender.Man;
            user.OpTime = DateTime.Now;

            context.Update(user); //会更新所有映射的字段

            /*
             * String @P_0 = 'lu';
             * Gender @P_1 = Man;
             * Int32 @P_2 = 28;
             * Nullable<Int32> @P_3 = NULL;
             * DateTime @P_4 = '2016/8/26 18:18:36';
             * Int32 @P_5 = 1;
             * UPDATE [Users] SET [Name]=@P_0,[Gender]=@P_1,[Age]=@P_2,[CityId]=@P_3,[OpTime]=@P_4 WHERE [Users].[Id] = @P_5
             */


            /*
             * 支持只更新属性值已变的属性
             */

            context.TrackEntity(user); //在上下文中跟踪实体
            user.Name = user.Name + "1";
            context.Update(user);      //这时只会更新被修改的字段

            /*
             * String @P_0 = 'lu1';
             * Int32 @P_1 = 1;
             * UPDATE [Users] SET [Name]=@P_0 WHERE [Users].[Id] = @P_1
             */

            ConsoleHelper.WriteLineAndReadKey();
        }
Esempio n. 4
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();
        }
Esempio n. 5
0
        public void Execute(IJobExecutionContext context)
        {
            //IDbCommandInterceptor interceptor = new DbCommandInterceptor();
            //dbcontext.Session.AddInterceptor(interceptor);
            DateTime         dt        = DateTime.Now;
            string           shortdate = dt.ToString("yyyy-MM-dd");
            IQuery <Page>    cpq       = dbcontext.Query <Page>();
            IQuery <Chapter> cq        = dbcontext.Query <Chapter>();
            List <Page>      plst      = cpq.Where(a => a.pagelocal.Length == 0).Take(20).ToList();
            HttpWebHelper    web       = new HttpWebHelper();

            foreach (var p in plst)
            {
                try
                {
                    Stream stream = web.GetStream("http://cdn.sns.dongmanmanhua.cn/20150119_288/1421677325732TxLNo_JPEG/thumbnail_ipad.jpg");
                    Image  img    = Image.FromStream(stream);
                    stream.Close();
                    string filePath = AppDomain.CurrentDomain.BaseDirectory + "DownLoadImgs/" + p.Id + ".jpg";
                    img.Save(filePath, System.Drawing.Imaging.ImageFormat.Jpeg);
                    string localimg = UcHelper.uploadFile("Page/" + p.Id + ".jpg", filePath);
                    p.pagelocal = localimg;
                    p.modify    = dt;
                    dbcontext.Update(p);
                    dbcontext.Update <Chapter>(a => a.Id == p.chapterid, a => new Chapter()
                    {
                        downstatus = DownChapter.完图片,
                        modify     = dt
                    });
                    File.Delete(filePath);
                }
                catch (Exception ex)
                {
                    logger.Error(ex.Message);
                    //Chapter chapter = cq.Where(x => x.Id == p.chapterid).FirstOrDefault();
                    //chapter.retry = chapter.retry + 1;
                    //chapter.modify = dt;
                    //dbcontext.Update(chapter);
                    dbcontext.Update <Chapter>(a => a.Id == p.chapterid, a => new Chapter()
                    {
                        retry  = a.retry + 1,
                        modify = dt
                    });
                    Err_PageJob err = new Err_PageJob();
                    err.imgurl    = p.pagesource;
                    err.source    = p.source;
                    err.errtype   = ErrPage.限制访问;
                    err.modify    = dt;
                    err.shortdate = shortdate;
                    err.message   = ex.Message;
                    err           = dbcontext.Insert(err);
                    continue;
                }
            }
        }
Esempio n. 6
0
        public static void UpdateTest()
        {
            List <string> names = new List <string>();

            names.Add("so");
            names.Add(null);

            string   name         = "lu1";
            string   stringNull   = null;
            int?     intNull      = null;
            DateTime?dateTimeNull = null;
            //name = null;

            object ret = null;

            int r = -1;

            MsSqlContext context = new MsSqlContext(DbHelper.ConnectionString);

            //var u = context.Query<User>().AsTracking().First(a => a.Id == 3);
            //u.Name = u.Name + "1";
            //ret = context.Update(u);
            //u.ByteArray = new byte[] { 1, 2, 3 };
            //u.Name = "lu";
            //ret = context.Update(u);


            r = context.Update <User>(a => a.Id == 100, a => new User()
            {
                Name = a.Name, Age = a.Age + 100, Gender = Gender.Man, OpTime = DateTime.Now
            });

            //r = context.Update<User>(a => new User() { Name = stringNull, NickName = stringNull, Age = intNull, Gender = null, OpTime = dateTimeNull }, a => false);

            User user = new User();

            user.Id     = 100;
            user.Name   = "shuxin";
            user.Age    = 28;
            user.Gender = Gender.Man;
            //user.OpTime = DateTime.Now;

            object o = user;

            r = context.Update(o);

            ConsoleHelper.WriteLineAndReadKey();
        }
Esempio n. 7
0
        public static void UpdateTest()
        {
            List <string> names = new List <string>();

            names.Add("so");
            names.Add(null);

            string   name         = "lu1";
            string   stringNull   = null;
            int?     intNull      = null;
            DateTime?dateTimeNull = null;
            //name = null;

            int r = -1;

            MsSqlContext context = new MsSqlContext(DbHelper.ConnectionString);

            r = context.Update <User>(a => new User()
            {
                Name = a.Name, Age = a.Age + 100, Gender = Gender.Man, OpTime = DateTime.Now
            }, a => a.Name == name);

            r = context.Update <User>(a => new User()
            {
                Name = stringNull, NickName = stringNull, Age = intNull, Gender = null, OpTime = dateTimeNull
            }, a => false);

            User user = new User()
            {
                Id = 1, Name = "lu", Age = 18, Gender = Gender.Man
            };

            user.Id     = 2;
            user.Name   = "shuxin";
            user.Age    = 28;
            user.Gender = Gender.Man;
            //user.OpTime = DateTime.Now;

            object o = user;

            r = context.Update(o);

            ConsoleHelper.WriteLineAndReadKey();
        }
        public void Execute(IJobExecutionContext context)
        {
            DateTime         dt        = DateTime.Now;
            string           shortdate = dt.ToString("yyyy-MM-dd");
            IQuery <Chapter> cpq       = dbcontext.Query <Chapter>();
            IQuery <Comic>   cq        = dbcontext.Query <Comic>();
            IQuery <Notice>  nq        = dbcontext.Query <Notice>();
            List <Notice>    nqlst     = nq.Where(x => x.noticestatus == NoticeStatus.等待处理).OrderBy(x => x.Id).Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList();//Select(x => x).

            if (nqlst.Count < pageSize)
            {
                pageIndex = 1;
            }
            else
            {
                pageIndex++;
            }
            foreach (var n in nqlst)
            {
                if (n.noticetype == NoticeType.目录变更)
                {
                    List <Chapter> cplst = cpq.Where(x => x.comicid == n.noticeid && x.downstatus != DownChapter.完图片).ToList();
                    if (cplst.Count == 0)
                    {
                        n.noticestatus = NoticeStatus.等待发送;
                        n.modify       = dt;
                        dbcontext.Update(n);
                    }
                }
                else if (n.noticetype == NoticeType.章节更新)
                {
                    Chapter chapter = cpq.Where(x => x.chapterid == n.noticeid).FirstOrDefault();
                    Notice  notice  = nq.Where(x => x.noticeid == chapter.comicid && x.noticetype == NoticeType.目录变更 && x.noticestatus != NoticeStatus.已发送).FirstOrDefault();
                    if (notice == null)
                    {
                        n.noticestatus = NoticeStatus.等待发送;
                        n.modify       = dt;
                        dbcontext.Update(n);
                    }
                }
            }
        }
        public void Execute(IJobExecutionContext context)
        {
            //IDbCommandInterceptor interceptor = new DbCommandInterceptor();
            //dbcontext.Session.AddInterceptor(interceptor);
            DateTime         dt        = DateTime.Now;
            string           shortdate = dt.ToString("yyyy-MM-dd");
            IQuery <Comic>   comicq    = dbcontext.Query <Comic>();
            IQuery <Chapter> cpq       = dbcontext.Query <Chapter>();
            List <Chapter>   plst      = cpq.Where(a => a.chaptersource.Length != 0 && a.chapterlocal.Length == 0).TakePage(1, 20).ToList();
            HttpWebHelper    web       = new HttpWebHelper();

            foreach (var p in plst)
            {
                try
                {
                    string refer = "";
                    if (p.source == Source.dongmanmanhua)
                    {
                        var comic = comicq.Where(x => x.comicid == p.comicid).FirstOrDefault();
                        refer = comic.bookurl;
                    }

                    Stream stream = web.GetStream(p.chaptersource, 300, "", null, refer, null);
                    Image  img    = Image.FromStream(stream);
                    stream.Close();
                    string filePath = AppDomain.CurrentDomain.BaseDirectory + "DownLoadImgs/" + p.Id + ".jpg";
                    img.Save(filePath, System.Drawing.Imaging.ImageFormat.Jpeg);
                    string localimg = UcHelper.uploadFile("Chapter/" + p.Id + ".jpg", filePath);
                    p.chapterlocal = localimg;
                    p.modify       = dt;
                    dbcontext.Update(p);
                }
                catch (Exception ex)
                {
                    Err_ChapterJob err = new Err_ChapterJob();
                    err.bookurl   = p.chapterurl;
                    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");
            IQuery <Page>    cpq       = dbcontext.Query <Page>();
            IQuery <Chapter> cq        = dbcontext.Query <Chapter>();
            List <Chapter>   cqlst     = cq.Where(x => x.downstatus == DownChapter.处理完链接).Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList();

            if (cqlst.Count < pageSize)
            {
                pageIndex = 1;
            }
            else
            {
                pageIndex++;
            }
            List <string> cidlst    = cqlst.Select(x => x.chapterid).ToList();
            List <Page>   pagelst   = cpq.Where(x => cidlst.Contains(x.chapterid)).ToList();
            List <int>    waitidlst = new List <int>();

            foreach (var c in cqlst)
            {
                List <Page> pagedownlst = pagelst.Where(x => x.chapterid == c.chapterid).ToList();

                if (pagedownlst.Count > 0)
                {
                    List <Page> pagenulllst = pagedownlst.Where(x => x.pagelocal == "").ToList();
                    if (pagenulllst.Count == 0)
                    {
                        waitidlst.Add(c.Id);
                    }
                }
                //c.downstatus = pagenulllst.Count > 0 ? DownChapter.处理完链接 : DownChapter.上传完图片;
                //c.modify = dt;
                //dbcontext.Update(c);
            }
            dbcontext.Update <Chapter>(a => waitidlst.Contains(a.Id), a => new Chapter()
            {
                downstatus = DownChapter.完图片,
                modify     = dt
            });
        }
Esempio n. 11
0
        public void Execute(IJobExecutionContext context)
        {
            //IDbCommandInterceptor interceptor = new DbCommandInterceptor();
            //dbcontext.Session.AddInterceptor(interceptor);
            DateTime       dt        = DateTime.Now;
            string         shortdate = dt.ToString("yyyy-MM-dd");
            IQuery <Comic> cpq       = dbcontext.Query <Comic>();
            List <Comic>   plst      = cpq.Where(a => a.comiccoverlocal.Length == 0).TakePage(1, 20).ToList();
            HttpWebHelper  web       = new HttpWebHelper();

            foreach (var p in plst)
            {
                try
                {
                    Stream stream = web.GetStream(p.comiccoversource);
                    Image  img    = Image.FromStream(stream);
                    stream.Close();
                    string filePath = AppDomain.CurrentDomain.BaseDirectory + "DownLoadImgs/" + p.Id + ".jpg";
                    img.Save(filePath, System.Drawing.Imaging.ImageFormat.Jpeg);
                    string localimg = UcHelper.uploadFile("Comic/" + p.Id + ".jpg", filePath);
                    p.comiccoverlocal = localimg;
                    p.modify          = dt;
                    dbcontext.Update(p);
                }
                catch (Exception ex)
                {
                    Err_ComicJob err = new Err_ComicJob();
                    err.bookurl   = p.bookurl;
                    err.errtype   = ErrComic.图片出错;
                    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>();
            List <Chapter>   cplst     = cpq.Where(x => x.source == Source.dongmanmanhua && x.downstatus == DownChapter.待处理链接).Take(200).ToList();
            List <int>       ids       = cplst.Select(x => x.Id).ToList();

            dbcontext.Update <Chapter>(a => ids.Contains(a.Id), a => new Chapter()
            {
                downstatus = DownChapter.处理完链接,
                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.Id,
                            modify     = dt,
                            shortdate  = shortdate,
                            sort       = i + 1,
                            source     = cp.source,
                            pagelocal  = "",
                            pagesource = matches2[i].Groups["key1"].Value
                        });
                    }

                    dbcontext.BulkInsert(pglst);
                }
                catch (Exception ex)
                {
                    logger.Error(ex.Message);
                    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   = ex.Message;
                    err           = dbcontext.Insert(err);
                    continue;
                }
            }
        }
        public void Execute(IJobExecutionContext context)
        {
            DateTime         dt        = DateTime.Now;
            string           shortdate = dt.ToString("yyyy-MM-dd");
            IQuery <Chapter> cpq       = dbcontext.Query <Chapter>();
            List <Chapter>   cplst     = cpq.Where(x => x.source == Source._163 && x.downstatus == DownChapter.待处理链接 && x.isvip == "0").Take(200).ToList();

            List <int> ids = cplst.Select(x => x.Id).ToList();

            dbcontext.Update <Chapter>(a => ids.Contains(a.Id), a => new Chapter()
            {
                downstatus = DownChapter.处理完链接,
                modify     = dt
            });

            foreach (var cp in cplst)
            {
                try
                {
                    string chapterpage = cp.chapterurl.Replace("https://manhua.163.com/", "");
                    var    imgdata     = _helper.Get(null, chapterpage);
                    Regex  rex1        = new Regex("imageId:");
                    var    match1      = rex1.Match(imgdata);

                    if (match1.Value.Trim() != "")
                    {
                        Regex       rex2   = new Regex("url: window.IS_SUPPORT_WEBP (?<key1>.*?),");
                        var         match2 = rex2.Matches(imgdata);
                        List <Page> pglst  = new List <Page>();
                        int         sort   = 0;
                        foreach (var item in match2)
                        {
                            sort = sort + 1;
                            var tt     = ((Match)item).Groups["key1"].Value;
                            var imgurl = tt.Split('"')[3].Substring(0, tt.Split('"')[3].IndexOf("%3D") + 3);
                            pglst.Add(new Page()
                            {
                                pagesource = imgurl,
                                chapterid  = cp.chapterid,
                                modify     = dt,
                                shortdate  = shortdate,
                                sort       = sort,
                                source     = cp.source,
                                pagelocal  = "",
                            });
                        }
                        if (pglst.Count > 0)
                        {
                            dbcontext.BulkInsert(pglst);
                        }
                    }
                    else
                    {
                        cp.downstatus = DownChapter.待处理链接;
                        cp.modify     = dt;
                        dbcontext.Update(cp);
                    }
                }
                catch (Exception ex)
                {
                    logger.Error(ex.Message);
                    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   = ex.Message;
                    err           = dbcontext.Insert(err);
                    continue;
                }
            }
        }
Esempio n. 14
0
        public static void UpdateTest()
        {
            List<string> names = new List<string>();
            names.Add("so");
            names.Add(null);

            string name = "lu1";
            string stringNull = null;
            int? intNull = null;
            DateTime? dateTimeNull = null;
            //name = null;

            int r = -1;

            MsSqlContext context = new MsSqlContext(DbHelper.ConnectionString);
            r = context.Update<User>(a => new User() { Name = a.Name, Age = a.Age + 100, Gender = Gender.Man, OpTime = DateTime.Now }, a => a.Name == name);

            r = context.Update<User>(a => new User() { Name = stringNull, NickName = stringNull, Age = intNull, Gender = null, OpTime = dateTimeNull }, a => false);

            User user = new User() { Id = 1, Name = "lu", Age = 18, Gender = Gender.Man };
            user.Id = 2;
            user.Name = "shuxin";
            user.Age = 28;
            user.Gender = Gender.Man;
            //user.OpTime = DateTime.Now;

            object o = user;
            r = context.Update(o);

            ConsoleHelper.WriteLineAndReadKey();
        }
Esempio n. 15
0
        public static void TrackingTest()
        {
            MsSqlContext context = new MsSqlContext(DbHelper.ConnectionString);

            object ret = null;

            var q = context.Query<User>();
            q = q.AsTracking();

            User user = q.First();
            ret = context.Update(user);

            Console.WriteLine(ret);

            context.TrackEntity(user);
            user.Name = user.Name + "1";
            user.Age = user.Age;
            user.Gender = null;
            ret = context.Update(user);

            Console.WriteLine(ret);

            ret = context.Update(user);
            Console.WriteLine(ret);

            ConsoleHelper.WriteLineAndReadKey();
        }
Esempio n. 16
0
        public void Execute(IJobExecutionContext context)
        {
            DateTime         dt        = DateTime.Now;
            string           shortdate = dt.ToString("yyyy-MM-dd");
            IQuery <Chapter> cpq       = dbcontext.Query <Chapter>();
            List <Chapter>   cplst     = cpq.Where(x => x.source == Source.U17 && x.downstatus == DownChapter.待处理链接 && x.isvip == "0").Take(200).ToList();


            List <int> ids = cplst.Select(x => x.Id).ToList();

            dbcontext.Update <Chapter>(a => ids.Contains(a.Id), a => new Chapter()
            {
                downstatus = DownChapter.处理完链接,
                modify     = dt
            });

            foreach (var cp in cplst)
            {
                try
                {
                    var imgdata = _helper.Get <U17_Page_Api>(null, string.Format(pageurl, cp.chapterid.Replace(cp.comicid + "_", "")));

                    List <Page> pglst = new List <Page>();
                    int         sort  = 0;
                    imgdata.image_list.ForEach(x =>
                    {
                        sort = sort + 1;
                        pglst.Add(new Page()
                        {
                            pagesource = x.src,
                            chapterid  = cp.chapterid,
                            modify     = dt,
                            shortdate  = shortdate,
                            sort       = sort,
                            source     = cp.source,
                            pagelocal  = "",
                        });
                    });
                    if (pglst.Count > 0)
                    {
                        dbcontext.BulkInsert(pglst);
                    }
                }
                catch (Exception ex)
                {
                    logger.Error(ex.Message);
                    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   = ex.Message;
                    err           = dbcontext.Insert(err);
                    continue;
                }
            }
        }
Esempio n. 17
0
        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 <Comic>   q         = dbcontext.Query <Comic>();
            IQuery <Chapter> cpq       = dbcontext.Query <Chapter>();
            List <Comic>     comiclst  = q.Where(a => a.source == Source.mh160 && a.shortdate == shortdate).Take(200).ToList();
            List <int>       ids       = comiclst.Select(x => x.Id).ToList();

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

            foreach (var comic in comiclst)
            {
                List <Chapter> cplst = cpq.Where(a => a.comicid == comic.comicid && a.source == Source.mh160).ToList();
                if (cplst.Count == 0)
                {
                    try
                    {
                        var bookdata = _helper.Get(comic.bookurl, Encoding.GetEncoding("gb2312"));
                        bookdata = StringHelper.MergeSpace(bookdata);
                        //string pattern = "<div class=\"plist pnormal\" id=\"play_0\"><li(?<key1>.*?)><a href=\"(?<key2>.*?)\" title=\"(?<key3>.*?)\" target=\"_blank\">(?<key4>.*?)</a></li>";
                        string          pattern  = "<div class=\"plist pnormal\" id=\"play_0\"> <ul>(?<key1>.*?)</ul> </div>";
                        MatchCollection matches  = Regex.Matches(bookdata, pattern, RegexOptions.IgnoreCase | RegexOptions.Singleline);
                        string          pattern2 = "<a href=\"(?<key1>.*?)\" title=\"(?<key2>.*?)\" target=\"_blank\">(?<key3>.*?)</a>";
                        MatchCollection matches2 = Regex.Matches(matches[0].Groups["key1"].Value, pattern2, RegexOptions.IgnoreCase | RegexOptions.Singleline);

                        for (int i = 0; i < matches2.Count; i++)
                        {
                            string chapterid   = comic.comicid + "_" + matches2[i].Groups["key1"].Value.Split('/').LastOrDefault().Replace(".html", "");
                            string chaptername = matches2[i].Groups["key2"].Value;
                            string chapterurl  = "http://www.mh160.com" + matches2[i].Groups["key1"].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,
                            });
                        }
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex.Message);
                        comic.shortdate = shortdate;
                        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;
                    }
                }
            }

            if (chapterlst.Count > 0)
            {
                dbcontext.BulkInsert(chapterlst);
            }
        }
Esempio n. 18
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;
                    }
                }
            }
        }
Esempio n. 19
0
        public bool BatchInsert(List <Product_Size> list)
        {
            bool v = false;

            string DbType     = Globals.Configuration["db:DbType"].ToString();
            string ConnString = Globals.Configuration["db:ConnString"].ToString();

            if (DbType == "MySql")
            {
                using (MySqlContext context = new MySqlContext(new MySqlConnectionFactory(ConnString)))
                {
                    try
                    {
                        context.Session.BeginTransaction();

                        foreach (var item in list)
                        {
                            //int row = context.Session.ExecuteNonQuery("select 1 from  yd_fdtz where DKBH = '"+item.DKBH+"' limit 1;");
                            if (item.Id == "0")
                            {
                                item.Id = IdHelper.CreateStringSnowflakeId();
                                context.Insert <Product_Size>(item);
                            }
                            else
                            {
                                context.Update <Product_Size>(item);
                            }
                        }
                        context.Session.CommitTransaction();
                    }
                    catch
                    {
                        if (context.Session.IsInTransaction)
                        {
                            context.Session.RollbackTransaction();
                        }
                        throw;
                    }
                }
            }

            if (DbType == "SqlServer")
            {
                using (MsSqlContext context = new MsSqlContext(ConnString))
                {
                    try
                    {
                        context.Session.BeginTransaction();

                        foreach (var item in list)
                        {
                            //int row = context.Session.ExecuteNonQuery("select count(1) from  yd_fdtz where DKBH = '" + item.DKBH + "'");
                            if (item.Id == "0")
                            {
                                item.Id = IdHelper.CreateStringSnowflakeId();
                                context.Insert <Product_Size>(item);
                            }
                            else
                            {
                                context.Update <Product_Size>(item);
                            }
                        }
                        context.Session.CommitTransaction();
                    }
                    catch
                    {
                        if (context.Session.IsInTransaction)
                        {
                            context.Session.RollbackTransaction();
                        }
                        throw;
                    }
                }
            }
            return(v);
        }
Esempio n. 20
0
        public void Execute(IJobExecutionContext context)
        {
            DateTime         dt        = DateTime.Now;
            string           shortdate = dt.ToString("yyyy-MM-dd");
            IQuery <Chapter> cpq       = dbcontext.Query <Chapter>();
            List <Chapter>   cplst     = cpq.Where(x => x.source == Source.Zymk && x.downstatus == DownChapter.待处理链接).Take(200).ToList();

            List <int> ids = cplst.Select(x => x.Id).ToList();

            dbcontext.Update <Chapter>(a => ids.Contains(a.Id), a => new Chapter()
            {
                downstatus = DownChapter.处理完链接,
                modify     = dt
            });
            List <Chapter> chapterlst = new List <Chapter>();

            foreach (var cp in cplst)
            {
                try
                {
                    string      chapterpage = cp.chapterurl.Replace("http://www.zymk.cn/", "");
                    var         imgdata     = _helper.Get(null, chapterpage);
                    Regex       imgpath     = new Regex("chapter_addr:\"(?<key1>.*?)\",");
                    Regex       starindex   = new Regex("start_var:(?<key1>.*?),");
                    Regex       totalimg    = new Regex("end_var:(?<key1>.*?),");
                    Regex       pageid      = new Regex("chapter_id:(?<key1>.*?),");
                    Regex       domain      = new Regex("domain:\"(?<key1>.*?)\",");
                    Regex       comic_size  = new Regex("middle:\"(?<key1>.*?)\"");
                    var         _imgpath    = imgpath.Match(imgdata).Groups["key1"].Value.Replace("\\\\", "#").Replace("\\", "").Replace("#", "\\");
                    var         _totalimg   = totalimg.Match(imgdata).Groups["key1"].Value;
                    var         _pageid     = pageid.Match(imgdata).Groups["key1"].Value;
                    var         _domain     = domain.Match(imgdata).Groups["key1"].Value;
                    var         _comic_size = comic_size.Match(imgdata).Groups["key1"].Value;
                    int         start       = int.Parse(starindex.Match(imgdata).Groups["key1"].Value.Trim());
                    List <Page> pglst       = new List <Page>();
                    int         imgcount    = int.Parse(_totalimg);
                    imgcount = imgcount - start;
                    string imgdecodepath = DecodeHelper.Decode(_imgpath, int.Parse(_pageid));
                    for (int i = 0; i <= imgcount; i++)
                    {
                        string pgsource = "http://mhpic." + _domain + "/comic/" + imgdecodepath + start + ".jpg" + _comic_size;
                        pglst.Add(new Page()
                        {
                            pagesource = pgsource,
                            chapterid  = cp.chapterid,
                            modify     = dt,
                            shortdate  = shortdate,
                            sort       = i + 1,
                            source     = cp.source,
                            pagelocal  = "",
                        });
                        start = start + 1;
                    }

                    dbcontext.BulkInsert(pglst);
                }
                catch (Exception ex)
                {
                    logger.Error(ex.Message);
                    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   = 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>();
            List <Chapter>   cplst = cpq.Where(x => x.source == Source.dongmanmanhua && x.downstatus == DownChapter.待处理链接).Take(200).ToList();

            List <int> ids = cplst.Select(x => x.Id).ToList();

            dbcontext.Update <Chapter>(a => ids.Contains(a.Id), a => new Chapter()
            {
                downstatus = DownChapter.处理完链接,
                modify     = dt
            });
            List <Chapter> chapterlst = new List <Chapter>();

            foreach (var cp in cplst)
            {
                List <Page> pglst = new List <Page>();
                try
                {
                    string chapterpage = cp.chapterurl.Replace("https://www.dongmanmanhua.cn", "");
                    var    imgdata     = _helper.Get(null, chapterpage);
                    Regex  reg1        = new Regex("documentURL: '(?<key1>.*?)'");
                    Match  match1      = reg1.Match(imgdata);
                    string docURl      = match1.Groups["key1"].Value;
                    if (string.IsNullOrEmpty(docURl))
                    {
                        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);

                        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
                            });
                        }
                    }
                    else
                    {
                        Regex           reg2     = new Regex("stillcut: '(?<key1>.*?)'");
                        Match           match2   = reg2.Match(imgdata);
                        string          stillcut = match2.Groups["key1"].Value;
                        var             bookdata = _helper.Get <dongmanmanhua_Page_Api>(null, "https://www.dongmanmanhua.cn" + docURl);
                        string          regstr   = bookdata.assets.image.ToString();
                        string          pattern3 = ": \"(?<key1>.*?)\"";
                        MatchCollection matches3 = Regex.Matches(regstr, pattern3, RegexOptions.IgnoreCase | RegexOptions.Singleline);
                        for (int i = 0; i < matches3.Count; i++)
                        {
                            pglst.Add(new Page()
                            {
                                chapterid  = cp.chapterid,
                                modify     = dt,
                                shortdate  = shortdate,
                                sort       = i + 1,
                                source     = cp.source,
                                pagelocal  = "",
                                pagesource = string.Format(stillcut.Replace("=filename", "0"), matches3[0].Groups["key1"].Value)
                            });
                        }
                    }

                    dbcontext.BulkInsert(pglst);
                }
                catch (Exception ex)
                {
                    logger.Error(ex.Message);
                    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   = 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 <Comic>   q         = dbcontext.Query <Comic>();
            IQuery <Chapter> cpq       = dbcontext.Query <Chapter>();
            List <Comic>     comiclst  = q.Where(a => a.source == Source.dongmanmanhua && a.shortdate == shortdate).Take(200).ToList();
            List <int>       ids       = comiclst.Select(x => x.Id).ToList();

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

            foreach (var comic in comiclst)
            {
                List <Chapter> cplst = cpq.Where(a => a.comicid == comic.Id && a.source == Source.dongmanmanhua).ToList();
                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  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.Id,
                                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  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.Id,
                                    retry         = 0,
                                    source        = comic.source,
                                    downstatus    = DownChapter.待处理链接,
                                    isvip         = "0",
                                    chaptersource = chaptersource,
                                    chapterlocal  = "",
                                    modify        = dt,
                                    shortdate     = shortdate,
                                });
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex.Message);
                        comic.shortdate = shortdate;
                        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;
                    }
                }
            }

            if (chapterlst.Count > 0)
            {
                dbcontext.BulkInsert(chapterlst);
            }
        }
Esempio n. 23
0
        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 <Comic>   q         = dbcontext.Query <Comic>();
            IQuery <Chapter> cpq       = dbcontext.Query <Chapter>();
            List <Comic>     comiclst  = q.Where(a => a.source == Source.QQ && a.shortdate == shortdate).Take(200).ToList();
            List <int>       ids       = comiclst.Select(x => x.Id).ToList();

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

            foreach (var comic in comiclst)
            {
                List <Chapter> cplst = cpq.Where(a => a.comicid == comic.Id && a.source == Source.QQ).ToList();
                if (cplst.Count == 0)
                {
                    try
                    {
                        string bookurl  = comic.bookurl.Replace("http://ac.qq.com/", "");
                        var    bookdata = _helper.Get(null, bookurl);

                        //class=\"chapter-page-all works-(?<key1>.*?)-list\"
                        Regex  reg1       = new Regex("<ol class=\"chapter-page-all works-chapter-list\">(?<key1>.*?)</ol>", RegexOptions.IgnoreCase | RegexOptions.Singleline);
                        Match  match1     = reg1.Match(bookdata);
                        string htmlSource = match1.Groups["key1"].Value;

                        string          pattern = "<a target=\"_blank\" title=\"(?<key1>.*?)\" href=\"(?<key2>.*?)\">(?<key3>.*?)</a>";
                        MatchCollection matches = Regex.Matches(htmlSource, pattern, RegexOptions.IgnoreCase | RegexOptions.Singleline);

                        for (int i = 0; i < matches.Count; i++)
                        {
                            chapterlst.Add(new Chapter()
                            {
                                chapterid     = comic.comicid + "_" + matches[i].Groups["key2"].Value.Split('/').LastOrDefault(),
                                chaptername   = matches[i].Groups["key3"].Value.Trim(),
                                chapterurl    = "http://ac.qq.com" + matches[i].Groups["key2"].Value,
                                sort          = i + 1,
                                comicid       = comic.Id,
                                retry         = 0,
                                source        = comic.source,
                                downstatus    = DownChapter.待处理链接,
                                isvip         = "0",
                                chaptersource = "",
                                chapterlocal  = "",
                                modify        = dt,
                                shortdate     = shortdate,
                            });
                        }
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex.Message);
                        comic.shortdate = shortdate;
                        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;
                    }
                }
            }

            if (chapterlst.Count > 0)
            {
                dbcontext.BulkInsert(chapterlst);
            }
        }
Esempio n. 24
0
        public void Execute(IJobExecutionContext context)
        {
            //string keystr = "meyJjb21pYyI6eyJpZCI6NTM4NzQzLCJ0aXRsZSI6Ilx1NGUwN1x1OTFjY1x1NjY3NFx1NWRkZCIsImNvbGxlY3QiOiI0NzA0MSIsImlzSmFwYW5Db21pYyI6ZmFsc2UsImlzTGlnaHROb3ZlbCI6ZmFsc2UsImlzTGlnaHRDb21pYyI6ZmFsc2UsImlzRmluaXNoIjpmYWxzZSwiaXNSb2FzdGFibGUiOnRydWUsImVJZCI6IktsQlBTVU5BVmxWV0Jnc2ZBUVlPQUF3S0hFUldOQT09In0sImNoYXB0ZXIiOnsiY2lkIjo0OSwiY1RpdGxlIjoiXHU3YjJjMjVcdTU2ZGUgXHU2NDk1XHU4OGMyMlx1ZmYwOFx1NGUwYVx1ZmYwOSIsImNTZXEiOiI0OSIsInZpcFN0YXR1cyI6MiwicHJldkNpZCI6NDgsIm5leHRDaWQiOjUwLCJibGFua0ZpcnN0IjoxLCJjYW5SZWFkIjp0cnVlfSwicGljdHVyZSI6W3sicGlkIjoiMjY1MCIsIndpZHRoIjo4MDAsImhlaWdodCI6MTIwMCwidXJsIjoiaHR0cDpcL1wvYWMudGMucXEuY29tXC9zdG9yZV9maWxlX2Rvd25sb2FkP2J1aWQ9MTUwMTcmdWluPTE1MTA3MDk2NTgmZGlyX3BhdGg9XC8mbmFtZT0xNV8wOV8zNF8wY2E3NjllMDk1YTU0NTYwYzQ5Nzk3ZmEwNGY1NzQ5N18yNjUwLmpwZyJ9LHsicGlkIjoiMjY1MSIsIndpZHRoIjo4MDAsImhlaWdodCI6MTIwMCwidXJsIjoiaHR0cDpcL1wvYWMudGMucXEuY29tXC9zdG9yZV9maWxlX2Rvd25sb2FkP2J1aWQ9MTUwMTcmdWluPTE1MTA3MDk2NzImZGlyX3BhdGg9XC8mbmFtZT0xNV8wOV8zNF8yZmVmYmQ0Mzk3ODY5YmU5MGI4OTQxOTdmYTEwMGZmNF8yNjUxLmpwZyJ9LHsicGlkIjoiMjY1MiIsIndpZHRoIjo4MDAsImhlaWdodCI6MTIwMCwidXJsIjoiaHR0cDpcL1wvYWMudGMucXEuY29tXC9zdG9yZV9maWxlX2Rvd25sb2FkP2J1aWQ9MTUwMTcmdWluPTE1MTA3MDk2NzImZGlyX3BhdGg9XC8mbmFtZT0xNV8wOV8zNF9jODBiMTE0ZDIwOGIzZWMyZDkxNWM3MmRhODIwZDRhYl8yNjUyLmpwZyJ9LHsicGlkIjoiMjY1MyIsIndpZHRoIjo4MDAsImhlaWdodCI6MTIwMCwidXJsIjoiaHR0cDpcL1wvYWMudGMucXEuY29tXC9zdG9yZV9maWxlX2Rvd25sb2FkP2J1aWQ9MTUwMTcmdWluPTE1MTA3MDk2NzImZGlyX3BhdGg9XC8mbmFtZT0xNV8wOV8zNF9kYjI5MjI5MmM4NmVkN2U0MDIwN2Q2MDg4YjU2ODliYl8yNjUzLmpwZyJ9LHsicGlkIjoiMjY1NCIsIndpZHRoIjo4MDAsImhlaWdodCI6MTIwMCwidXJsIjoiaHR0cDpcL1wvYWMudGMucXEuY29tXC9zdG9yZV9maWxlX2Rvd25sb2FkP2J1aWQ9MTUwMTcmdWluPTE1MTA3MDk2NzImZGlyX3BhdGg9XC8mbmFtZT0xNV8wOV8zNF81YjEyOWVmMWJjY2NlZDQ3OWU1NDE3NTliMTIzZWJkNF8yNjU0LmpwZyJ9LHsicGlkIjoiMjY1NSIsIndpZHRoIjo4MDAsImhlaWdodCI6MTIwMCwidXJsIjoiaHR0cDpcL1wvYWMudGMucXEuY29tXC9zdG9yZV9maWxlX2Rvd25sb2FkP2J1aWQ9MTUwMTcmdWluPTE1MTA3MDk2NzImZGlyX3BhdGg9XC8mbmFtZT0xNV8wOV8zNF85MGY2MTg2MjMyNzcxYTE5NzVmOTVlM2RiYTQ3ZGIxZV8yNjU1LmpwZyJ9LHsicGlkIjoiMjY1NiIsIndpZHRoIjo4MDAsImhlaWdodCI6MTIwMCwidXJsIjoiaHR0cDpcL1wvYWMudGMucXEuY29tXC9zdG9yZV9maWxlX2Rvd25sb2FkP2J1aWQ9MTUwMTcmdWluPTE1MTA3MDk2ODYmZGlyX3BhdGg9XC8mbmFtZT0xNV8wOV8zNF9mZGVmMjExZmIxZjRlYWIxNGQzNDE1MjM1ZDNjOWIxNV8yNjU2LmpwZyJ9LHsicGlkIjoiMjY1NyIsIndpZHRoIjo4MDAsImhlaWdodCI6MTIwMCwidXJsIjoiaHR0cDpcL1wvYWMudGMucXEuY29tXC9zdG9yZV9maWxlX2Rvd25sb2FkP2J1aWQ9MTUwMTcmdWluPTE1MTA3MDk2ODYmZGlyX3BhdGg9XC8mbmFtZT0xNV8wOV8zNF9lNmQxZjAwNWQ1OTkxNzRkMjJlODI1MDE3MGVhMTM4N18yNjU3LmpwZyJ9LHsicGlkIjoiMjY1OCIsIndpZHRoIjo4MDAsImhlaWdodCI6MTIwMCwidXJsIjoiaHR0cDpcL1wvYWMudGMucXEuY29tXC9zdG9yZV9maWxlX2Rvd25sb2FkP2J1aWQ9MTUwMTcmdWluPTE1MTA3MDk2ODYmZGlyX3BhdGg9XC8mbmFtZT0xNV8wOV8zNF81NmI3YjI1YjVkZDM5YzdhNmU1OGNhYjY1Njc1MGY3MV8yNjU4LmpwZyJ9LHsicGlkIjoiMjY1OSIsIndpZHRoIjo4MDAsImhlaWdodCI6MTIwMCwidXJsIjoiaHR0cDpcL1wvYWMudGMucXEuY29tXC9zdG9yZV9maWxlX2Rvd25sb2FkP2J1aWQ9MTUwMTcmdWluPTE1MTA3MDk2ODYmZGlyX3BhdGg9XC8mbmFtZT0xNV8wOV8zNF9jODEyNGJiYzk2NTVlODVhMTk0ZTRiNDQwMzA2YTFjYV8yNjU5LmpwZyJ9LHsicGlkIjoiMjY2MCIsIndpZHRoIjo4MDAsImhlaWdodCI6MTIwMCwidXJsIjoiaHR0cDpcL1wvYWMudGMucXEuY29tXC9zdG9yZV9maWxlX2Rvd25sb2FkP2J1aWQ9MTUwMTcmdWluPTE1MTA3MDk2ODYmZGlyX3BhdGg9XC8mbmFtZT0xNV8wOV8zNF85ZDE0ZDYzOTY1Mjg0ZDUzY2MwMDkwN2QxZGIzY2YzNV8yNjYwLmpwZyJ9LHsicGlkIjoiMjY2MSIsIndpZHRoIjo4MDAsImhlaWdodCI6MTIwMCwidXJsIjoiaHR0cDpcL1wvYWMudGMucXEuY29tXC9zdG9yZV9maWxlX2Rvd25sb2FkP2J1aWQ9MTUwMTcmdWluPTE1MTA3MDk2ODYmZGlyX3BhdGg9XC8mbmFtZT0xNV8wOV8zNF9lZmU5OThmYjU1ZDJlZjYyMGFlMmIzYmM3ZjYyY2IzOV8yNjYxLmpwZyJ9LHsicGlkIjoiMjY2MiIsIndpZHRoIjo4NjAsImhlaWdodCI6MTQ1MywidXJsIjoiaHR0cDpcL1wvYWMudGMucXEuY29tXC9zdG9yZV9maWxlX2Rvd25sb2FkP2J1aWQ9MTUwMTcmdWluPTE1MTA3MDk2ODcmZGlyX3BhdGg9XC8mbmFtZT0xNV8wOV8zNF84NmYzY2QzMzgzYjA2N2JhOTRjYWQ4YjZlOThkMGY2NV8yNjYyLmpwZyJ9XSwiYWRzIjp7InRvcCI6eyJ0aXRsZSI6Ilx1NjVmNlx1N2E3YVx1NjA0Ylx1NGViYSIsInBpYyI6Imh0dHBzOlwvXC9tYW5odWEucXBpYy5jblwvb3BlcmF0aW9uXC8wXC8xM18wOV81NF9kOTU4YWYyOGU4NmYzNjhmYjhiN2EwMGMzMDZmODQ4OV8xNTEwNTM4MDQxNTMwLmpwZ1wvMCIsInVybCI6Imh0dHA6XC9cL2FjLnFxLmNvbVwvQ29taWNWaWV3XC9pbmRleFwvaWRcLzU1MDkyMVwvY2lkXC80Iiwid2lkdGgiOiI2NTAiLCJoZWlnaHQiOiIxMTAifSwibGVmdCI6W10sImJvdHRvbSI6eyJ0aXRsZSI6Ilx1NzNiMFx1NGUxNlx1NjBjNVx1NGViYVx1NjYyZlx1NWMzZVx1NzJkMCIsInBpYyI6Imh0dHBzOlwvXC9tYW5odWEucXBpYy5jblwvb3BlcmF0aW9uXC8wXC8xM18wOV81Ml84ZWJjZTJkZmJhMzZhZDhlYTA2YjEyODRkNzY1Mzc0Nl8xNTEwNTM3OTM3NDY2LmpwZ1wvMCIsInVybCI6Imh0dHA6XC9cL2FjLnFxLmNvbVwvQ29taWNWaWV3XC9pbmRleFwvaWRcLzYyNjg1MFwvY2lkXC8yIiwid2lkdGgiOiI2NTAiLCJoZWlnaHQiOiIxMTAifX0sImFydGlzdCI6eyJhdmF0YXIiOiJodHRwOlwvXC9xNC5xbG9nby5jblwvZz9iPXFxJms9d2g1c0ZOazAzUDV6RmlhOGljdGQ4ZW13JnM9NjQwJnQ9MTQ4MzMzOTY3NSIsIm5pY2siOiJcdTc3ZTVcdTk3ZjNcdTc5ZmJcdTUyYThcdTY1NzBcdTViNTciLCJ1aW5DcnlwdCI6IlVUSk1kVkpCZDAxTlFrSkVibGhzWmpOWlJqRjBaejA5In19";
            //var ss = DecodeHelper.QQPageDecode(keystr.Substring(1));
            //var tt = JsonHelper.DeserializeJsonToObject<QQ_Page_Api>(ss);
            //var redis = new RedisProxy();
            //try
            //{
            //    redis.HashSet("QQ_Chapter", "185158", "185157");
            //}
            //catch (Exception ex)
            //{

            //    throw;
            //}


            //var login_key = redis.Get<QQ_Login_Key>("QQ_1434299101");
            DateTime              dt        = DateTime.Now;
            string                ticks     = dt.Ticks.ToString();
            string                shortdate = dt.ToString("yyyy-MM-dd");
            string                yesterday = dt.AddDays(-1).ToString("yyyy-MM-dd");
            IQuery <Chapter>      cpq       = dbcontext.Query <Chapter>();//x.comicid == "1_622585"
            IQuery <VIPFreeComic> vfcq      = dbcontext.Query <VIPFreeComic>();

            List <Chapter> cplst;

            if (QQChapterTotal > 0)
            {
                cplst = cpq.Where(x => x.source == Source.QQ && x.downstatus == DownChapter.待处理链接 && x.isvip == "0" && x.Id % QQChapterTotal == QQChapterIndex).Take(200).ToList();
            }
            else
            {
                cplst = cpq.Where(x => x.source == Source.QQ && x.downstatus == DownChapter.待处理链接 && x.isvip == "0").Take(200).ToList();
            }



            List <int> ids = cplst.Select(x => x.Id).ToList();

            dbcontext.Update <Chapter>(a => ids.Contains(a.Id), a => new Chapter()
            {
                ticks      = ticks,
                downstatus = DownChapter.处理完链接,
                modify     = dt
            });
            List <Chapter> chapterlst = new List <Chapter>();

            foreach (var cp in cplst)
            {
                try
                {
                    //Dictionary<string, string> headers = new Dictionary<string, string>()
                    //{
                    //    {"Cookie","uin=o1434299101; skey="+login_key.skey+";" }
                    //};


                    var imgdata = _helper.Get(cp.chapterurl, Encoding.GetEncoding("UTF-8"), null, "", null, "", null, "application/x-www-form-urlencoded; charset=UTF-8");

                    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;
                        cp.ticks      = ticks;
                        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.canRead)
                    {
                        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  = "",
                                ticks      = ticks,
                                pagesource = t.picture[i].url
                            });
                        }

                        cp.isvip      = "0";
                        cp.ticks      = ticks;
                        cp.downstatus = DownChapter.处理完链接;
                        cp.modify     = dt;
                        dbcontext.Update(cp);
                        dbcontext.BulkInsert(pglst);
                    }
                    else
                    {
                        List <VIPFreeComic> vfclst = vfcq.Where(x => x.source == Source.QQ && x.comicid == cp.comicid).ToList();

                        cp.isvip      = vfclst.Count == 0 ? "1" : "0";
                        cp.ticks      = ticks;
                        cp.downstatus = DownChapter.待处理链接;
                        cp.modify     = dt;
                        dbcontext.Update(cp);
                    }
                }
                catch (Exception ex)
                {
                    cp.downstatus = DownChapter.待处理链接;
                    cp.modify     = dt;
                    cp.ticks      = ticks;
                    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;
                }
            }
        }
Esempio n. 25
0
        public void Execute(IJobExecutionContext context)
        {
            //logger.Info("QQ_page vip begin");
            //string isStart = "IsStartBuyQQ".ValueOfAppSetting();
            //if (isStart != null && isStart.Equals("1"))
            {
                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>();//x.comicid == "1_524356"
                IQuery <PageHis> phisq     = dbcontext.Query <PageHis>();
                //List<Chapter> cplst = cpq.Where(x => x.source == Source.QQ && x.downstatus == DownChapter.待处理链接 && x.isvip.Equals("1")).Take(200).ToList();
                List <Chapter> cplst = cpq.Where(x => x.source == Source.QQ && x.downstatus == DownChapter.完图片 && x.isvip.Equals("1")).Take(200).ToList();
                List <int>     ids   = cplst.Select(x => x.Id).ToList();
                dbcontext.Update <Chapter>(a => ids.Contains(a.Id), a => new Chapter()
                {
                    downstatus = DownChapter.处理中,
                    modify     = dt
                });
                List <Chapter> chapterlst = new List <Chapter>();
                Regex          rex        = new Regex("var DATA        = '(?<key1>.*?)',");
                string         errMsg;
                foreach (var cp in cplst)
                {
                    try
                    {
                        IQuery <PageHis> cpHis = phisq.Where(x => x.chapterid == cp.chapterid);
                        if (cpHis != null && cpHis.Count() > 0)
                        {
                            List <PageHis> cpHisList = cpHis.ToList();

                            List <Page> pglst = new List <Page>();
                            foreach (var page in cpHisList)
                            {
                                pglst.Add(new Page()
                                {
                                    chapterid  = page.chapterid,
                                    modify     = dt,
                                    shortdate  = shortdate,
                                    sort       = page.sort,
                                    source     = page.source,
                                    pagelocal  = "",
                                    pagesource = page.pagesource
                                });
                            }

                            cp.downstatus = DownChapter.处理完链接;
                            cp.modify     = dt;
                            dbcontext.Update(cp);
                            dbcontext.BulkInsert(pglst);
                            logger.Info("QQ_page vip syn history sucess:id=" + cp.Id);
                        }
                        else
                        {
                            errMsg = string.Empty;
                            selenium.Navigate().GoToUrl(cp.chapterurl);
                            IList <IWebElement> frames            = selenium.FindElements(By.TagName("iframe"));
                            IWebElement         controlPanelFrame = null;
                            foreach (var frame in frames)
                            {
                                if (frame.GetAttribute("id") == "iframeAll")
                                {
                                    controlPanelFrame = frame;
                                    break;
                                }
                            }
                            if (controlPanelFrame != null && controlPanelFrame.Displayed == true) //QQ登录
                            {
                                try
                                {
                                    selenium.SwitchTo().Frame(controlPanelFrame);
                                    IReadOnlyCollection <IWebElement> switchtoElement = selenium.FindElements(By.Id("switcher_plogin"));

                                    if (switchtoElement != null && switchtoElement.Count > 0 && switchtoElement.First().Displayed == true)
                                    {
                                        switchtoElement.First().Click();

                                        selenium.FindElement(By.Id("u")).Clear();
                                        selenium.FindElement(By.Id("u")).SendKeys("3283360259");
                                        selenium.FindElement(By.Id("p")).Clear();
                                        selenium.FindElement(By.Id("p")).SendKeys("xxxttt5544");

                                        //selenium.FindElement(By.Id("u")).Clear();
                                        //selenium.FindElement(By.Id("u")).SendKeys("1434299101");
                                        //selenium.FindElement(By.Id("p")).Clear();
                                        //selenium.FindElement(By.Id("p")).SendKeys("zhangyin123");

                                        selenium.FindElement(By.Id("login_button")).Click();
                                    }
                                    selenium.SwitchTo().DefaultContent();
                                }
                                catch (Exception ex)
                                {
                                    errMsg = "QQ 登录失败:" + ex.Message;
                                    logger.Error(errMsg);
                                }
                            }
                            selenium.Navigate().GoToUrl("http://ac.qq.com/Home/buyList");
                            ICookieJar listCookie = selenium.Manage().Cookies;
                            // IList<Cookie> listCookie = selenuim.Manage( ).Cookies.AllCookies;//只是显示 可以用Ilist对象
                            //显示初始Cookie的内容
                            Console.WriteLine("--------------------");
                            Console.WriteLine($"当前Cookie集合的数量:\t{listCookie.AllCookies.Count}");
                            for (int i = 0; i < listCookie.AllCookies.Count; i++)
                            {
                                Console.WriteLine($"Cookie的名称:{listCookie.AllCookies[i].Name}");
                                Console.WriteLine($"Cookie的值:{listCookie.AllCookies[i].Value}");
                                Console.WriteLine($"Cookie的所在域:{listCookie.AllCookies[i].Domain}");
                                Console.WriteLine($"Cookie的路径:{listCookie.AllCookies[i].Path}");
                                Console.WriteLine($"Cookie的过期时间:{listCookie.AllCookies[i].Expiry}");
                                Console.WriteLine("-----");
                            }
                            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 && checkVipFrame.Displayed == true)
                            {
                                try
                                {
                                    //自动购买
                                    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 && checkAutoElement.First().Displayed == true)
                                    {
                                        if (singlBbuyElement.First().Text.IndexOf("点券不足") > -1)
                                        {
                                            //列表中未成功购买的数据还原成待处理
                                            dbcontext.Update <Chapter>(a => ids.Contains(a.Id), a => new Chapter()
                                            {
                                                downstatus = DownChapter.待处理链接,
                                                modify     = dt
                                            });
                                            ////关闭购买,等待修改配置
                                            //"IsStartBuyQQ".SetAppSettingValue("0");
                                            if (isHasMoney)
                                            {
                                                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   = "点券不足,请去充值!";
                                                err           = dbcontext.Insert(err);
                                            }
                                            isHasMoney = false;
                                            //Thread.Sleep(3600000);
                                            continue;
                                        }
                                        else
                                        {
                                            isHasMoney = true;
                                        }

                                        checkAutoElement.First().Click();
                                        singlBbuyElement.First().Click();
                                    }
                                    selenium.SwitchTo().DefaultContent();
                                }
                                catch (Exception ex)
                                {
                                    errMsg = "自动购买失败:" + ex.Message;
                                    logger.Error(errMsg);
                                }
                            }
                            Match  match1 = rex.Match(selenium.PageSource);
                            string key    = match1.Groups["key1"].Value;
                            if (string.IsNullOrEmpty(key) || errMsg != string.Empty)
                            {
                                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   = errMsg != string.Empty ? errMsg : "DATA解析失败";
                                err           = dbcontext.Insert(err);
                                continue;
                            }

                            string s = DecodeHelper.QQPageDecode(key.Substring(1));
                            var    t = JsonHelper.DeserializeJsonToObject <QQ_Page_Api>(s);
                            if (t.picture.Count < 1)
                            {
                                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   = "访问付费章节内容时只存在一张图片";
                                err           = dbcontext.Insert(err);
                                continue;
                            }
                            List <Page> pglst = new List <Page>();
                            for (int i = 0; i < t.picture.Count; i++)
                            {
                                if (pglst.Exists(x => x.pagesource == t.picture[i].url) == false)
                                {
                                    pglst.Add(new Page()
                                    {
                                        chapterid  = cp.chapterid,
                                        modify     = DateTime.Now,
                                        shortdate  = shortdate,
                                        sort       = i + 1,
                                        source     = cp.source,
                                        pagelocal  = "",
                                        pagesource = t.picture[i].url
                                    });
                                }
                                else
                                {
                                    Err_ChapterJob err = new Err_ChapterJob();
                                    err.bookurl   = cp.chapterurl;
                                    err.source    = cp.source;
                                    err.errtype   = ErrChapter.解析出错;
                                    err.modify    = DateTime.Now;
                                    err.shortdate = shortdate;
                                    err.message   = "存在重复图片";
                                    err           = dbcontext.Insert(err);
                                }
                            }

                            cp.downstatus = DownChapter.处理完链接;
                            cp.modify     = dt;
                            dbcontext.Update(cp);
                            dbcontext.BulkInsert(pglst);
                            ids.Remove(cp.Id);

                            logger.Info("QQ_page vip buy sucess:id=" + cp.Id);
                        }
                    }
                    catch (Exception ex)
                    {
                        if (ex.Message.IndexOf("Unexpected error. System.Net.WebException:") > -1)
                        {
                            InitChromeDriver();
                        }
                        logger.Error(ex.Message);
                        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   = ex.Message;
                        err           = dbcontext.Insert(err);
                        continue;
                    }
                }
            }
        }
Esempio n. 26
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.QQ && a.isoffline == false && (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.QQ).ToList();
                List <Chapter> chapterlst = new List <Chapter>();
                if (cplst.Count > 0)
                {
                    try
                    {
                        string bookurl  = comic.bookurl.Replace("http://ac.qq.com/", "");
                        var    bookdata = _helper.Get(null, bookurl);

                        //class=\"chapter-page-all works-(?<key1>.*?)-list\"
                        Regex  reg1       = new Regex("<ol class=\"chapter-page-all works-chapter-list\">(?<key1>.*?)</ol>", RegexOptions.IgnoreCase | RegexOptions.Singleline);
                        Match  match1     = reg1.Match(bookdata);
                        string htmlSource = match1.Groups["key1"].Value;

                        string          pattern = "<a target=\"_blank\" title=\"(?<key1>.*?)\" href=\"(?<key2>.*?)\">(?<key3>.*?)</a>";
                        MatchCollection matches = Regex.Matches(htmlSource, pattern, RegexOptions.IgnoreCase | RegexOptions.Singleline);

                        for (int i = 0; i < matches.Count; i++)
                        {
                            chapterlst.Add(new Chapter()
                            {
                                chapterid     = comic.comicid + "_" + matches[i].Groups["key2"].Value.Split('/').LastOrDefault(),
                                chaptername   = matches[i].Groups["key3"].Value.Trim(),
                                chapterurl    = "http://ac.qq.com" + matches[i].Groups["key2"].Value,
                                sort          = i + 1,
                                comicid       = comic.comicid,
                                retry         = 0,
                                source        = comic.source,
                                downstatus    = DownChapter.待处理链接,
                                isvip         = "0",
                                chaptersource = "",
                                chapterlocal  = "",
                                modify        = dt,
                                shortdate     = shortdate,
                                ticks         = ticks
                            });
                        }
                        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)
        {
            //IDbCommandInterceptor interceptor = new DbCommandInterceptor();
            //dbcontext.Session.AddInterceptor(interceptor);

            DateTime         dt        = DateTime.Now;
            string           shortdate = dt.ToString("yyyy-MM-dd");
            IQuery <Page>    cpq       = dbcontext.Query <Page>();
            IQuery <Chapter> cq        = dbcontext.Query <Chapter>();

            List <Page> plst;

            if (m_DownTotal > 0)
            {
                plst = cpq.Where(a => a.pagestate == PageState.None && a.Id % m_DownTotal == m_DownIndex).Take(100).ToList();
            }
            else
            {
                plst = cpq.Where(a => a.pagestate == PageState.None).Take(100).ToList();
            }

            //if (plst.Count < pageSize)
            //    pageIndex = 1;
            //else
            //    pageIndex++;

            HttpWebHelper web = new HttpWebHelper();

            foreach (var p in plst)
            {
                string filePath = AppDomain.CurrentDomain.BaseDirectory + "DownLoadImgs/" + p.Id + ".jpg";
                try
                {
                    string refer = "";
                    if (p.source == Source.dongmanmanhua || p.source == Source.dmzj)
                    {
                        var chapter = cq.Where(x => x.chapterid == p.chapterid).FirstOrDefault();
                        refer = chapter.chapterurl;
                        Stream stream = web.GetStream(p.pagesource, 3000, "", null, refer, null);
                        Image  img    = Image.FromStream(stream);

                        stream.Close();

                        img.Save(filePath, System.Drawing.Imaging.ImageFormat.Jpeg);
                    }
                    else
                    {
                        WebClient myclient = new WebClient();
                        myclient.DownloadFile(p.pagesource, filePath);
                    }

                    string localimg = UcHelper.uploadFile("Page/" + p.Id + ".jpg", filePath);
                    p.pagelocal = localimg;
                    p.pagestate = PageState.成功;
                    p.modify    = dt;
                    dbcontext.Update(p);

                    File.Delete(filePath);
                }
                catch (Exception ex)
                {
                    try
                    {
                        WebClient myclient = new WebClient();
                        myclient.DownloadFile(p.pagesource, filePath);
                        Bitmap bytes;
                        using (WebP webp = new WebP())
                            bytes = webp.Load(filePath);
                        File.Delete(filePath);
                        bytes.Save(filePath);
                        string localimg = UcHelper.uploadFile("Page/" + p.Id + ".jpg", filePath);
                        p.pagelocal = localimg;
                        p.modify    = dt;
                        p.pagestate = PageState.成功;
                        dbcontext.Update(p);

                        File.Delete(filePath);
                        continue;
                    }
                    catch (Exception)
                    {
                        logger.Error(ex.Message);
                        Chapter chapter = cq.Where(x => x.chapterid == p.chapterid).FirstOrDefault();
                        chapter.retry  = chapter.retry + 1;
                        chapter.modify = dt;
                        if (chapter.retry > 30)
                        {
                            p.pagestate = PageState.失败;
                            p.modify    = dt;
                            dbcontext.Update(p);
                        }
                        dbcontext.Update(chapter);

                        //dbcontext.Update<Chapter>(a => a.chapterid == p.chapterid, a => new Chapter()
                        //{
                        //    retry = a.retry + 1,
                        //    modify = dt
                        //});
                        Err_PageJob err = new Err_PageJob();
                        err.imgurl    = p.pagesource;
                        err.source    = p.source;
                        err.errtype   = ErrPage.限制访问;
                        err.modify    = dt;
                        err.shortdate = shortdate;
                        err.message   = ex.Message;
                        err           = dbcontext.Insert(err);
                        continue;
                    }
                }
            }
        }
Esempio n. 28
0
        public async void Execute(IJobExecutionContext context)
        {
            //List<YueWenIm> bklst = ExcelHelper.Import3(@"C:\Users\Administrator\Desktop\阅文版权商下-未上架追书图书-2017-10-26.xlsx").ToList();
            //http://ubook.3g.qq.com/8/search?key=[民调局异闻录]迷 香
            //http://ubook.3g.qq.com/8/intro?bid=679523
            //List<YueWenIm> bklst = File.ReadAllLines(@"C:\Users\Administrator\Desktop\111111.csv",Encoding.GetEncoding("GB2312")).Select(y => y.Split(',')).Select(x => new { bookid = x[0].Replace("\"",""), bookname = x[1].Replace("\"", ""), authorname = x[2].Replace("\"", "") }).Select(x=> new YueWenIm(x.bookid,x.bookname,x.authorname)).ToList();
            IQuery <YueWen> yq = dbcontext.Query <YueWen>();

            List <YueWen> ywlst = new List <YueWen>();

            //bklst.ForEach(x =>
            //{
            //    ywlst.Add(new YueWen()
            //    {
            //        agreedid = x.agreedid,
            //        agreedment = x.agreedment,
            //        authorname = x.authorname,
            //        bookid = x.bookid,
            //        bookname = x.bookname,
            //        channelname = x.channelname,
            //        merchantname = x.merchantname,
            //        status = "0",
            //        maxfreecount = ""
            //    });
            //});

            //dbcontext.BulkInsert(ywlst, null, 360000);
            ywlst = yq.Where(x => x.status == "0").Take(200).ToList();
            List <int> idlst = ywlst.Select(x => x.Id).ToList();

            dbcontext.Update <YueWen>(a => idlst.Contains(a.Id), a => new YueWen()
            {
                status = "1"
            });


            foreach (var bk in ywlst)
            {
                try
                {
                    Dictionary <string, string> paras = new Dictionary <string, string>();
                    paras.Add("key", bk.bookname);
                    var t = _helper.Get <YueWenApi>(paras, "8/search");
                    if (t.booklist.Count > 0)
                    {
                        Dictionary <string, string> paras2 = new Dictionary <string, string>();
                        paras2.Add("bid", t.booklist[0].id);
                        var t2 = _helper.Get <YueWenDetailApi>(paras2, "8/intro");
                        if (t2.book == null)
                        {
                            continue;
                        }

                        if (t2.book.author.Trim() == bk.authorname.Trim() && t2.book.title.Trim() == bk.bookname.Trim())
                        {
                            bk.bid          = t.booklist[0].id;
                            bk.maxfreecount = t2.book.maxfreechapter;
                        }

                        bk.status = "1";
                        dbcontext.Update(bk);
                    }
                }
                catch (Exception ex)
                {
                    bk.status = "0";
                    bk.bid    = ex.Message;
                    dbcontext.Update(bk);
                    continue;
                }

                //logger.Error(bklst.IndexOf(bk));
            }

            //ExcelHelper.ToExcel(bklst);
        }
        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;
                    }
                }
            }
        }
Esempio n. 30
0
        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>();
            List <Chapter>   cplst     = cpq.Where(x => x.source == Source.QQ && x.downstatus == DownChapter.待处理链接).Take(200).ToList();
            List <int>       ids       = cplst.Select(x => x.Id).ToList();

            dbcontext.Update <Chapter>(a => ids.Contains(a.Id), a => new Chapter()
            {
                downstatus = DownChapter.处理完链接,
                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(dt);
                        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.Id,
                                modify     = dt,
                                shortdate  = shortdate,
                                sort       = i + 1,
                                source     = cp.source,
                                pagelocal  = "",
                                pagesource = t.picture[i].url
                            });
                        }

                        dbcontext.Update(cp);
                        dbcontext.BulkInsert(pglst);
                    }
                }
                catch (Exception ex)
                {
                    logger.Error(ex.Message);
                    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   = 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.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 <Comic>   q         = dbcontext.Query <Comic>();
            IQuery <Chapter> cpq       = dbcontext.Query <Chapter>();
            List <Comic>     comiclst  = q.Where(a => a.source == Source._163 && a.shortdate == shortdate).Take(200).ToList();
            List <int>       ids       = comiclst.Select(x => x.Id).ToList();

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

            foreach (var comic in comiclst)
            {
                List <Chapter> cplst = cpq.Where(a => a.comicid == comic.comicid && a.source == Source._163).ToList();
                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,
                                    });
                                }
                            });
                        }
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex.Message);
                        comic.shortdate = shortdate;
                        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;
                    }
                }
            }

            if (chapterlst.Count > 0)
            {
                dbcontext.BulkInsert(chapterlst);
            }
        }