Beispiel #1
0
 public override bool GetChapters()
 {
     var crawlerParameter = ServiceLocator.Current.GetInstance<MangaCrawlParameter>();
     var isSuccess = true;
     using (DbContext context = (DbContext)ServiceLocator.Current.GetInstance<MangaDataContext>())
     {
         if (!(!crawlerParameter.UseDb || context == null))
             context.Set<MangaSeries>().Attach(this);
         if ((this.MangaChapters == null) || (this.MangaChapters.Count() < 1))
         {
             this.MangaChapters = new List<MangaChapter>();
             HtmlDocument document = new HtmlDocument();
             document.LoadHtml(HttpUtility.GetResponseString(base.SiteUri));
             string chapterListQueryPath = this.HomeSite.ChapterListQueryPath;
             HtmlNodeCollection nodes = document.DocumentNode.SelectNodes(chapterListQueryPath);
             if (nodes != null)
             {
                 try
                 {
                     foreach (HtmlNode node in nodes)
                     {
                         List<HtmlNode> list = (from n in node.ChildNodes
                                                where n.Name == "td"
                                                select n).ToList();
                         MangaChapter chapter = new Manga24hChapter(this.HomeSite.SiteUri + "/" + list[0].ChildNodes[0].Attributes["href"].Value, list[0].ChildNodes[0].InnerText, this, list[2].InnerText, list[1].InnerText);
                         if (context != null)
                             context.Set<MangaChapter>().Add(chapter);
                         this.MangaChapters.Add(chapter);
                     }
                     if (!(!crawlerParameter.UseDb || context == null))
                     {
                         if (context.SaveChanges()<1)
                             isSuccess = false;
                     }
                 }
                 catch (Exception exception)
                 {
                     Logger.Write(exception);
                     isSuccess = false;
                 }
             }
         }
     }
     return isSuccess;
 }
Beispiel #2
0
        public override bool UpdateChapters()
        {
            HtmlDocument document = new HtmlDocument();
            bool isUpdated = false;
            document.LoadHtml(HttpUtility.GetResponseString(base.SiteUri));
            using (DbContext context = (DbContext)ServiceLocator.Current.GetInstance<MangaDataContext>())
            {
                context.Set<MangaSeries>().Attach(this);
                context.Entry(this).Reference<MangaSite>(n => n.HomeSite).Load();
                context.Set<MangaSite>().Attach(this.HomeSite);
                HtmlNodeCollection nodeCollection = document.DocumentNode.SelectNodes(this.HomeSite.ChapterListQueryPath);
                MangaChapter chapter;

                List<HtmlNode> nodes;
                if (nodeCollection != null)
                {
                    foreach (HtmlNodeCollection childNodeCollection in from n in nodeCollection select n.ChildNodes)
                    {
                        try
                        {
                            nodes = new List<HtmlNode>(from n in childNodeCollection
                                                       where n.Name == "td"
                                                       select n);
                            if (!this.CheckDate(this.LastUpdatedSource, nodes[2].InnerText))
                            {
                                break;
                            }
                            isUpdated = true;
                            chapter = new Manga24hChapter(this.HomeSite.SiteUri + "/" + nodes[0].ChildNodes[0].Attributes["href"].Value, nodes[0].ChildNodes[0].InnerText, this, nodes[2].InnerText, nodes[1].InnerText);
                            context.Set<MangaChapter>().Add(chapter);
                            context.SaveChanges();
                            if (chapter.Scan())
                            { }
                        }
                        catch (Exception exception)
                        {
                            Logger.Write(exception);
                        }
                    }
                    this.LastUpdatedSource = context.Entry(this).Collection(n=>n.MangaChapters).Query().Max(m => m.UpdatedDate);
                    context.SaveChanges();
                    Logger.Write(this.Name + " Updated. " + this.LastUpdatedSource);
                }
            }
            return isUpdated;
        }