示例#1
0
 private void GetHtmlContent(string ip, Uri html)
 {
     try
     {
         IPChange.IPChange.SetProxyIP(ip);
         OriginHtml.Add(HtmlCrawler.GetHtmlContent(html));
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString());
     }
 }
示例#2
0
 /// <summary>
 /// 跟换IP 获取网页
 /// </summary>
 /// <param name="ip"></param>
 /// <param name="html"></param>
 private bool GetHtmlContent(string ip, string html)
 {
     try
     {
         IPChange.IPChange.SetProxyIP(ip);
         if (HtmlCrawler.GetHtmlContent(new Uri(html)) is string content)
         {
             OriginHtml.Add(content);
             return(true);
         }
         else
         {
             return(false);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString());
         return(false);
     }
 }
示例#3
0
        private void HomePageDatadownload()
        {
            //数据初始化
            StrartTime      = DateTime.Now;
            OriginHtml      = new List <string>();
            IsWorkNotRuning = false;
            Worker          = new BackgroundWorker
            {
                WorkerReportsProgress      = true, //支持进度信息获取
                WorkerSupportsCancellation = true  //支持任务终止
            };

            //信息准备
            links  = NovelList.Count;
            IPList = HtmlAnalysis.GetIPList(HtmlCrawler.GetHtmlContent(IPNet));


            Worker.DoWork += Work_DownloadHomePage;
            Worker.RunWorkerAsync(links);
            Worker.ProgressChanged    += Worker_DownloadHomePageProgressChanged;
            Worker.RunWorkerCompleted += Worker_RunDownloadHomePageCompleted;
        }
示例#4
0
        public ReadWndViewModel(object data)
        {
            Book   = data as Novel;
            Reader = (Application.Current.MainWindow.DataContext as StartWinodwViewModel).Reader;

            GetSectionLinks(Book);

            SelectItemChangedCommand = new DelegateCommand <object>((p) =>
            {
                if (p is ListView listView)
                {
                    var htmlContent = HtmlCrawler.GetHtmlContent(Book.Sections[listView.SelectedIndex].Html);
                    CurrentContent  = HtmlAnalysis.AnalysisSectionContent(htmlContent);
                }
            });

            DownloadSectionsCommand = new DelegateCommand(() =>
            {
                SaveFileDialog dialog = new SaveFileDialog
                {
                    Filter     = "txt files(*.txt)|*.txt|word files(*.doc)|*.doc|All files(*.*)|*.*",
                    FileName   = Book.Name,
                    DefaultExt = "txt"
                };
                if (dialog.ShowDialog() == true)
                {
                    path = dialog.FileName;
                    Datadownload();
                }
            });

            int index = 0;

            if (Reader.Level >= 0)
            {
                foreach (var item in Reader.Books)
                {
                    if (Book.Id == item.BookID)
                    {
                        index = item.SectionIndex;
                        break;
                    }
                }
            }

            CurrentContent = HtmlAnalysis.AnalysisSectionContent(HtmlCrawler.GetHtmlContent(Book.Sections[(index - 1) >= 0 ? (index - 1) : 0].Html));

            SysFontFamilies = Fonts.SystemFontFamilies;

            WinCloseCommand = new DelegateCommand <object>((p) =>
            {
                (p as Window).Close();
                Application.Current.MainWindow.Show();
            });

            WinClosingCommand = new DelegateCommand <object>((p) =>
            {
                //若非访客模式
                if (reader.Level >= 0)
                {
                    //若书架上已存在该书 则更新本次阅读进度
                    if (index > 0)
                    {
                        if ((p as ListView).SelectedIndex < 0)
                        {
                            (p as ListView).SelectedIndex = index - 1;
                        }
                        Reader.Books.Find(b => b.BookID == Book.Id).SectionIndex = (p as ListView).SelectedIndex + 1;
                        ElasticSearch.ElasticHelper.Insert(Reader);
                    }
                    //若书架尚不存在此书 则新添加入列表
                    else
                    {
                        if (MessageBox.Show("是否加入书架?") == MessageBoxResult.OK)
                        {
                            if ((p as ListView).SelectedIndex < 0)
                            {
                                (p as ListView).SelectedIndex = index - 1;
                            }

                            Reader.Books.Add(new Model.Book()
                            {
                                BookID       = Book.Id,
                                SectionIndex = (p as ListView).SelectedIndex + 1
                            });
                            ElasticSearch.ElasticHelper.Insert(Reader);
                        }
                    }
                }
            });
        }
示例#5
0
 private void GetSectionLinks(Novel novel)
 {
     novel.Sections = HtmlAnalysis.AnalysisDirectory(HtmlCrawler.GetHtmlContent(new System.Uri(novel.DirectoryUri)));
 }