Beispiel #1
0
 private void getSearchResult()
 {
     try
     {
         _cursearch = "";
         this.Dispatcher.Invoke(new Action(() =>
         {
             _cursearch = this.searchBox.Text.Replace(" ", "+").Replace("+", "%2B");
         }));
         BookList booklist = new BookList();
         booklist.AddNewBook(_cursearch, _curpage);
         this.loadingLabel.Dispatcher.Invoke(new Action(() =>
         {
             if (booklist.Count == 0)
             {
                 this.loadingLabel.Content    = "找不到相关图书";
                 this.loadingLabel.Visibility = Visibility.Visible;
             }
             else
             {
                 this.loadingLabel.Visibility = Visibility.Hidden;
             }
         }));
         for (int i = 0; i < booklist.Count; i++)
         {
             this.searchResult.Dispatcher.Invoke(new Action(() =>
             {
                 BookElement be      = new BookElement(booklist[i]);
                 be.MouseUp         += new MouseButtonEventHandler(be_MouseUp);
                 be.downloadClicked += new RoutedEventHandler(downloadClicked);
                 searchResult.Children.Add(be);
             }));
         }
         if (booklist.GetMoreable)
         {
             this.searchResult.Dispatcher.Invoke(new Action(() =>
             {
                 LoadingMoreElement load = new LoadingMoreElement();
                 load.MouseUp           += new MouseButtonEventHandler(load_MouseUp);
                 searchResult.Children.Add(load);
             }));
         }
     }
     catch
     {
         this.Dispatcher.Invoke(new Action(() =>
         {
             this.loadingLabel.Content    = "加载失败";
             this.loadingLabel.Visibility = Visibility.Visible;
         }));
     }
 }
        private void getSearchResult()
        {
            try
            {
                _cursearch = "";
                this.Dispatcher.Invoke(new Action(() =>
                {
                    _cursearch = this.searchBox.Text.Replace(" ", "+").Replace("+", "%2B");
                }));
                BookList booklist = new BookList();
                booklist.AddNewBook(_cursearch, _curpage);
                this.loadingLabel.Dispatcher.Invoke(new Action(() =>
                    {

                        if (booklist.Count == 0)
                        {
                            this.loadingLabel.Content = "找不到相关图书";
                            this.loadingLabel.Visibility = Visibility.Visible;
                        }
                        else
                            this.loadingLabel.Visibility = Visibility.Hidden;
                    }));
                for (int i = 0; i < booklist.Count; i++)
                {
                    this.searchResult.Dispatcher.Invoke(new Action(() =>
                        {
                            BookElement be = new BookElement(booklist[i]);
                            be.MouseUp += new MouseButtonEventHandler(be_MouseUp);
                            be.downloadClicked += new RoutedEventHandler(downloadClicked);
                            searchResult.Children.Add(be);
                        }));
                }
                if (booklist.GetMoreable)
                {
                    this.searchResult.Dispatcher.Invoke(new Action(() =>
                        {
                            LoadingMoreElement load = new LoadingMoreElement();
                            load.MouseUp += new MouseButtonEventHandler(load_MouseUp);
                            searchResult.Children.Add(load);
                        }));
                }
            }
            catch
            {
                this.Dispatcher.Invoke(new Action(() =>
                    {
                        this.loadingLabel.Content = "加载失败";
                        this.loadingLabel.Visibility = Visibility.Visible;
                    }));
            }
        }
Beispiel #3
0
        public static void AddNewBook(this BookList booklist, String keyword, int page)
        {
            String url      = String.Format(Setting.searchUrl, UrlEncode(keyword), page);
            String regexStr = "url\" value=\"(.*?)\"[\\s\\S]*?封面 src='(.*?)'[\\s\\S]*?dxid\" value=\"(\\d*)[\\s\\S]*?ssid\" value=\"(\\d*)[\\s\\S]*?《(.*?)》</a>[\\s\\S]*?(/(?:gobaoku.jsp|readDetail.jsp).*?)\"[\\s\\S]*?(作者.*)";
            String html     = HttpWebResponseUtility.GetHtmlByHttpWebRequest(url);

            MatchCollection m = Regex.Matches(html, regexStr);

            m.AsParallel();
            booklist.GetMoreable = html.Contains("下一页");
            string[] s  = new string[10];
            Match[]  ms = new Match[m.Count];
            m.CopyTo(ms, 0);
            Parallel.ForEach(ms, match =>
            {
                booklist.addBook(GetBriefBookInfo(match.Groups));
            });
        }
Beispiel #4
0
 private void getMoreBook()
 {
     try
     {
         BookList booklist = new BookList();
         booklist.AddNewBook(_cursearch, ++_curpage);
         for (int i = 0; i < booklist.Count; i++)
         {
             this.searchResult.Dispatcher.Invoke(new Action(() =>
             {
                 BookElement be      = new BookElement(booklist[i]);
                 be.MouseUp         += new MouseButtonEventHandler(be_MouseUp);
                 be.downloadClicked += new RoutedEventHandler(downloadClicked);
                 int count           = searchResult.Children.Count;
                 searchResult.Children.Insert(count - 1, be);
             }));
         }
         this.searchResult.Dispatcher.Invoke(new Action(() =>
         {
             int count = searchResult.Children.Count;
             LoadingMoreElement load = (LoadingMoreElement)searchResult.Children[count - 1];
             load.changeToGetting();
             if (!booklist.GetMoreable)
             {
                 searchResult.Children.Remove(load);
             }
         }));
     }
     catch (Exception e)
     {
         if (e is ThreadAbortException)
         {
             return;
         }
         this.searchResult.Dispatcher.Invoke(new Action(() =>
         {
             int count = searchResult.Children.Count;
             LoadingMoreElement load = (LoadingMoreElement)searchResult.Children[count - 1];
             load.changeToFailed();
         }));
     }
 }
        private void getMoreBook()
        {
            try
            {
                BookList booklist = new BookList();
                booklist.AddNewBook(_cursearch, ++_curpage);
                for (int i = 0; i < booklist.Count; i++)
                {
                    this.searchResult.Dispatcher.Invoke(new Action(() =>
                    {

                        BookElement be = new BookElement(booklist[i]);
                        be.MouseUp += new MouseButtonEventHandler(be_MouseUp);
                        be.downloadClicked += new RoutedEventHandler(downloadClicked);
                        int count = searchResult.Children.Count;
                        searchResult.Children.Insert(count - 1, be);
                    }));
                }
                this.searchResult.Dispatcher.Invoke(new Action(() =>
                    {
                        int count = searchResult.Children.Count;
                        LoadingMoreElement load = (LoadingMoreElement)searchResult.Children[count - 1];
                        load.changeToGetting();
                        if (!booklist.GetMoreable)
                            searchResult.Children.Remove(load);
                    }));
            }
            catch (Exception e)
            {
                if (e is ThreadAbortException)
                    return;
                this.searchResult.Dispatcher.Invoke(new Action(() =>
                    {
                        int count = searchResult.Children.Count;
                        LoadingMoreElement load = (LoadingMoreElement)searchResult.Children[count - 1];
                        load.changeToFailed();
                    }));
            }
        }