Esempio n. 1
0
        public void DownloadAndParseWebSiteBookIndexPage(Book book)
        {
            var downloader = new HttpContentDownloader();
            downloader.Download(book.IndexPage,
                ar =>
                {
                    try
                    {
                        //At this step, we can get the index page in the search engine 
                        var state = (RequestState)ar.AsyncState;
                        var response = (HttpWebResponse)state.Request.EndGetResponse(ar);
                        response.GetResponseStream();
                        book.RootUrl = UrlHelper.GetRootUrlString(response.ResponseUri);
                        var parser = new WebsiteBookIndexPageParser();
                        try
                        {
                            ProgressIndicatorHelper.CrossThreadStartProgressIndicator(true, "下载完成,解析目录中");
                            parser.Parse(response.GetResponseStream(), book);
                            SelectedBook = book;
                            ModelManager.GetBookIndexModel().Book = SelectedBook;

                            if (GetBookIndexPageCompleted != null)
                            {
                                GetBookIndexPageCompleted(this, null);
                            }
                        }
                        catch (Exception e)
                        {
                            ExceptionHandler.HandleException(e);
                        }
                    }
                    catch (WebException e)
                    {
                        if (e.Status == WebExceptionStatus.RequestCanceled)
                        {
                            throw new TimeoutException(String.Format("连接{0}目录页超时", book.WebSite.WebSiteName));
                        }
                    }
              
                });
        }
Esempio n. 2
0
        public void Refresh()
        {
            ProgressIndicatorHelper.StartProgressIndicator(true , "更新本书目录");
            var downloader = new HttpContentDownloader();
            DownloaderList.Add(downloader);
            downloader.Download(Book.IndexPage,
                ar =>
                {
                    //At this step, we can get the index page in the search engine 
                    var state = (RequestState)ar.AsyncState;
                    state.stopTimer = true;
                    var response = (HttpWebResponse)state.Request.EndGetResponse(ar);
                    response.GetResponseStream();

                    Book.RootUrl = UrlHelper.GetRootUrlString(response.ResponseUri);
                    var parser = new WebsiteBookIndexPageParser();

                    var temp = new Book {RootUrl = Book.RootUrl};
                    parser.Parse(response.GetResponseStream(), temp );

                    var newChapters = new List<Chapter>();
                    newChapters.AddRange(
                            temp.Chapters.Where
                            (
                                chapter => !Book.Chapters.Any(c => c.ChapterName == chapter.ChapterName)
                            ));

                    if (newChapters.Count > 0)
                    {
                        var totalChapters = new List<Chapter>();
                        totalChapters.AddRange(Book.Chapters);
                        totalChapters.AddRange(newChapters);
                        _storage.SaveChapters(newChapters);
                        Book.Chapters = totalChapters.ToArray();
                        LastPage();
                    }
                    else
                    {
                        CrossThreadHelper.CrossThreadMethodCall(() => MessageBox.Show("本书尚未有新的章节"));
                    }

                    ProgressIndicatorHelper.StopProgressIndicator();
                });
        }