Exemple #1
0
        /// <summary>
        /// 下载书籍
        /// </summary>
        private void Download_Click(object sender, RoutedEventArgs e)
        {
            Thread thread = new Thread(new ThreadStart(delegate
            {
                List <string> Text = new List <string>();
                foreach (KeyValuePair <string, string> keyValuePair in book.ListUrl)
                {
                    string html = GetHtml.GetHttpWebRequest(keyValuePair.Value);
                    Text.Add(keyValuePair.Key + "\r\n" + Tool.HtmlFilter(Tool.GetRegexStr(html, bookSource.ContentRegular)));
                }
                this.Dispatcher.Invoke(new Action(() =>
                {
                    Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
                    dlg.FileName   = book.Name;
                    dlg.DefaultExt = ".txt";
                    dlg.Filter     = "BookSource (.txt)|*.txt";

                    Nullable <bool> result = dlg.ShowDialog();

                    // Process save file dialog box results
                    if (result == true)
                    {
                        // Save document
                        string filename = dlg.FileName;
                        using (StreamWriter sw = new StreamWriter(filename))
                        {
                            sw.Write(string.Join("\r\n", Text));
                        }
                    }
                }));
            }));

            thread.IsBackground = true;  //是否为后台线程
            thread.Start();
        }
Exemple #2
0
        /// <summary>
        /// 正文获取
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void TextObtain_Click(object sender, RoutedEventArgs e)
        {
            string url = TextLink.Text;
            //获取范围化的文本
            string html = GetHtml.GetHttpWebRequest(url);

            string Text = Tool.GetRegexStr(html, ContentRegular.Text).Trim();

            string Title = Tool.GetRegexStr(html, ContentTitleRegular.Text).Trim();

            TextContent.Content = Title;
            New_Text.Text       = Tool.HtmlFilter(Text);
            if (Text.Length > 10)
            {
                state_Text = true;
            }
        }
Exemple #3
0
        /// <summary>
        /// 获取书籍内容
        /// </summary>
        private void ObtainBook_Click(object sender, RoutedEventArgs e)
        {
            Book   book = new Book();
            string html = GetHtml.GetHttpWebRequest(Book_url.Text.Trim());

            book.Name        = Tool.GetRegexStr(html, BookNameRegular.Text).Trim();
            book.UpdateState = Tool.GetRegexStr(html, StateRegular.Text).Trim();
            book.Newest      = Tool.GetRegexStr(html, NewestRegular.Text).Trim();
            book.Update      = Tool.GetRegexStr(html, UpdateRegular.Text).Trim();
            book.Image       = Tool.GetRegexStr(html, ImageRegular.Text).Trim();
            book.Author      = Tool.GetRegexStr(html, AuthorRegular.Text).Trim();
            book.Details     = Tool.GetRegexStr(html, DetailsRegular.Text).Trim();
            //获取所有书籍
            this.DataContext = book;
            if (book.Name.Length > 0 && book.Details.Length > 0)
            {
                state_details = true;
            }
        }
Exemple #4
0
        /// <summary>
        /// 获取目录
        /// </summary>
        private void GetDirectory_Click(object sender, RoutedEventArgs e)
        {
            string url = List_url.Text.Trim();

            //获取范围化的文本
            string html = Tool.GetRegexStr(GetHtml.GetHttpWebRequest(url), DirectoryScopeRegular.Text).Trim();

            //得到被分割的目录
            string[] List = html.Split(new string[] { DirectoryCuttingRegular.Text }, StringSplitOptions.RemoveEmptyEntries);


            //这个是处理的目录
            List <GetDirectory> NewList = new List <GetDirectory>();

            int Newid = 0;

            foreach (string chapter in List)
            {
                string NewUrl = Tool.GetRegexStr(chapter, DirectoryUrlRegular.Text).Trim();
                if (NewUrl.Length > 3)
                {
                    Newid++;
                    string NewTitle = Tool.GetRegexStr(chapter, DirectoryTieleRegular.Text).Trim();
                    NewList.Add(new GetDirectory()
                    {
                        Id = Newid, Title = NewTitle, Url = NewUrl
                    });
                }
            }

            Catalog.ItemsSource = NewList;
            if (NewList.Count > 1)
            {
                state_Catalog = true;
            }
            Tips tips = new Tips("目录获取完毕~");

            tips.Show();
        }
Exemple #5
0
        private void SearchBook(object Search_Book)
        {
            SearchBook  searchBook = (SearchBook)Search_Book;
            string      html       = GetHtml.GetHttpWebRequest(searchBook.BookUrl);
            List <Book> books      = new List <Book>();

            //获取搜索书籍范围
            string htmlRange = Tool.GetRegexStr(html, searchBook.AddressRangeRegular).Trim();

            //分割搜索书籍
            string[] bookList = htmlRange.Split(new string[] { searchBook.AddressCuttingRegular }, StringSplitOptions.RemoveEmptyEntries);

            int i = 0;

            foreach (string str in bookList)
            {
                string url = Tool.GetRegexStr(str, searchBook.AddressRegular).Trim();
                if (url.Length > 3)
                {
                    i++;
                    books.Add(new Book {
                        Id = i, Url = url
                    });
                }
            }

            //Invoke是同步  BeginInvoke是异步
            Dispatcher.Invoke((Action) delegate
            {
                SearchList.ItemsSource = books;
            });

            if (books.Count > 0)
            {
                state_search = true;
            }
        }
Exemple #6
0
        /// <summary>
        /// 跳转到直接章节
        /// </summary>
        /// <param name="page">章节数</param>
        /// <param name="cache">是否缓存  如果是true,代表只是缓存,前台阅读页并不会因此而改变</param>
        private void Jump(int page, bool cache = false)
        {
            if (NewId.Count < page)
            {
                //这里是为了禁止读取不存在的章节
                return;
            }

            try
            {
                //文章html
                string html = string.Empty;
                //章节的标题和文本
                string Title = string.Empty;
                string Text  = string.Empty;
                if (!cache)
                {
                    buffer.Visibility = Visibility.Visible;
                }

                Thread thread = new Thread(new ThreadStart(delegate
                {
                    Title = NewId[page];

                    //判断本章节是否缓存
                    if (NewText.ContainsKey(page))
                    {
                        Text = NewText[page];
                    }
                    else
                    {
                        html          = GetHtml.GetHttpWebRequest(book.ListUrl[NewId[page]]);
                        Text          = Tool.GetRegexStr(html, bookSource.ContentRegular);
                        NewText[page] = Text;
                    }
                    if (!cache)
                    {
                        Dispatcher.BeginInvoke((Action) delegate
                        {
                            newTitle.Text = Title;
                            newText.Document.Blocks.Clear();
                            Run run     = new Run(Tool.HtmlFilter(Text));
                            Paragraph p = new Paragraph();
                            p.Inlines.Add(run);
                            newText.Document.Blocks.Add(p);
                            ///重置翻页数
                            this.newText.ScrollToVerticalOffset(0);
                            buffer.Visibility = Visibility.Hidden;
                            //保存已阅章节数
                            if (book.Id != 0)
                            {
                                DataFetch.UpdateUpdateReadingBook((int)book.Id, page);
                            }
                            NewPages = page;

                            //这里是缓存下面的章节
                            for (int i = 1; i < 10; i++)
                            {
                                Jump(page + i, true);
                            }
                        });
                    }
                }));
                thread.IsBackground = true;  //是否为后台线程
                thread.Start();
            }
            catch (Exception ex)
            {
                new Tips("打开错误,请检查书源是否存在问题?").Show();
                Tool.TextAdditional(ex.Message);
                buffer.Visibility = Visibility.Hidden;
            }
        }