Exemplo n.º 1
0
        /// <summary>
        /// 开始获取文档数据,返回得到的文档数据
        /// </summary>
        /// <param name="keyWord">指定的关键字</param>
        /// <param name="Token">用户状态数据</param>
        /// <returns>返回搜索到的列表集合</returns>
        public System.Collections.Generic.IEnumerable <IDocumnetContent> DoWork(string keyWord, object Token)
        {
            KeyWord             = keyWord;
            BaiduSearch.KeyWord = keyWord;
            //得到内容页面
            List <ListPageContentUrl> ListPageUrlStrings = BaiduSearch.DoWork(keyWord);
            //用于返回的结果
            List <IDocumnetContent> indexpages = new List <IDocumnetContent>();

            IndexPages = indexpages;
            //将列表页面url转换成为 PageListContent
            ListPageUrlStrings.ForEach((o) =>
            {
                //列表分析实例对象
                SingleListPageAnalyse Analyse = new SingleListPageAnalyse(o.Url.ToString())
                {
                    UserToKen = Token,
                };

                indexpages.Add(new PageListContent()
                {
                    Analyse       = Analyse,
                    KeyWord       = keyWord,
                    PageUrl       = o.Url.ToString(),
                    UserToKen     = Token,
                    StartTime     = DateTime.Now,
                    SearchCompare = Search,
                    Content       = "",
                    OriginContent = o.Url.GetWeb(),
                    Title         = o.Title,
                    CompleteTime  = DateTime.MinValue,
                });

                #region 开始采集文章内容
                //new TextContent()
                //{
                //    Analyse = Analyse,
                //    CompleteTime = DateTime.MaxValue
                //};

                #endregion
            });



            return(indexpages);
        }
Exemplo n.º 2
0
    protected void Page_Load(object sender, EventArgs e)
    {
        TypeStr.Split('\r').ToList().ForEach((o) =>
        {
            o.Trim().Replace("\n", "").Split('\t').ToList().ForEach((p) =>
            {
                Response.Write(p + "<br/>");
            });
            Response.Write("<hr/>");
        });


        Response.Write("1".ToPingYing());



        //搜索工作线程
        BaiduSearchCompare searchCompare = null;



        searchCompare = new BaiduSearchCompare();

        //searchCompare.DoWorkAsync("仙逆", "仙逆");
        //searchCompare.DoWorkAsync("天珠变", "天珠变");
        //searchCompare.DoWorkAsync("遮天", "遮天");
        //searchCompare.DoWorkAsync("吞噬星空", "吞噬星空");
        //searchCompare.DoWorkAnsycComplete += new EventHandler<SearchCompareEventArgs>(searchCompare_DoWorkAnsycComplete);

        System.Threading.Tasks.Task task = System.Threading.Tasks.Task.Factory.StartNew(() =>
        {
            string key = "仙逆";
            var result = searchCompare.DoWork(key);
            searchCompare_DoWorkAnsycComplete(searchCompare, new SearchCompareEventArgs()
            {
                Reslut = result,
                ToKen  = key
            });
        }
                                                                                        );



        task.ContinueWith((xo) =>
        {
            #region 处理异常
            try { xo.Wait(); }
            catch (AggregateException ex) { ex.Handle((exp) => { return(true); }); }
            #endregion

            string key = "凡人修仙传";
            var result = searchCompare.DoWork(key);
            searchCompare_DoWorkAnsycComplete(searchCompare, new SearchCompareEventArgs()
            {
                Reslut = result,
                ToKen  = key
            });

            //表示异步已经处理
            if (xo.Exception != null)
            {
                xo.Exception.Handle((ex) =>
                {
                    System.Diagnostics.Debug.WriteLine(ex.Message + "|||||" + ex.StackTrace);
                    return(true);
                });
            }
        })

        .ContinueWith((xo) =>
        {
            #region 处理异常
            try { xo.Wait(); }
            catch (AggregateException ex) { ex.Handle((exp) => { return(true); }); }
            #endregion
            string key = "仙逆";
            var result = searchCompare.DoWork(key);
            searchCompare_DoWorkAnsycComplete(searchCompare, new SearchCompareEventArgs()
            {
                Reslut = result,
                ToKen  = key
            });

            //表示异步已经处理
            if (xo.Exception != null)
            {
                xo.Exception.Handle((ex) =>
                {
                    System.Diagnostics.Debug.WriteLine(ex.Message + "|||||" + ex.StackTrace);
                    return(true);
                });
            }
        })

        .ContinueWith((xo) =>
        {
            #region 处理异常
            try { xo.Wait(); }
            catch (AggregateException ex) { ex.Handle((exp) => { return(true); }); }
            #endregion
            string key = "天珠变";
            var result = searchCompare.DoWork(key);
            searchCompare_DoWorkAnsycComplete(searchCompare, new SearchCompareEventArgs()
            {
                Reslut = result,
                ToKen  = key
            });

            //表示异步已经处理
            if (xo.Exception != null)
            {
                xo.Exception.Handle((ex) =>
                {
                    System.Diagnostics.Debug.WriteLine(ex.Message + "|||||" + ex.StackTrace);
                    return(true);
                });
            }
        })

        .ContinueWith((xo) =>
        {
            #region 处理异常
            try { xo.Wait(); }
            catch (AggregateException ex) { ex.Handle((exp) => { return(true); }); }
            #endregion
            string key = "遮天";
            var result = searchCompare.DoWork(key);
            searchCompare_DoWorkAnsycComplete(searchCompare, new SearchCompareEventArgs()
            {
                Reslut = result,
                ToKen  = key
            });

            //表示异步已经处理
            if (xo.Exception != null)
            {
                xo.Exception.Handle((ex) =>
                {
                    System.Diagnostics.Debug.WriteLine(ex.Message + "|||||" + ex.StackTrace);
                    return(true);
                });
            }
        })


        .ContinueWith((xo) =>
        {
            #region 处理异常
            try { xo.Wait(); }
            catch (AggregateException ex) { ex.Handle((exp) => { return(true); }); }
            #endregion
            //表示异步已经处理
            if (xo.Exception != null)
            {
                xo.Exception.Handle((ex) =>
                {
                    System.Diagnostics.Debug.WriteLine(ex.Message + "|||||" + ex.StackTrace);
                    return(true);
                });
            }

            System.Diagnostics.Debug.Write("任务完成" + tong.EStr(50, "/"));
        });



        try
        {
            //输出章节结果
            Response.Write(
                string.Join("<br/>\r\n", (from p in searchCompare.DoWork("仙逆")
                                          // orderby p.index
                                          select p.ToString()

                                          ).ToArray()
                            ));
        }
        catch
        {
        }

        //列表页面分析
        SingleListPageAnalyse analyse = null;
        analyse = new SingleListPageAnalyse("http://www.78xs.com/article/7/5319/Default.shtml");//.GetResult<List<string>>();
        //analyse = new SingleListPageAnalyse("http://www.yankuai.com/files/article/html/1/1845/");
        // analyse = new SingleListPageAnalyse("http://www.qidian.com/BookReader/1264634.aspx");
        while (true)
        {
            System.Threading.Thread.Sleep(2);
            if (analyse.ListPageContentUrls.Count > 200)
            {
                //输出章节结果
                Response.Write(
                    string.Join("<br/>\r\n", (from p in analyse.ListPageContentUrls
                                              // orderby p.index
                                              select "" + p.index + "\t " + p.Title + "\t\t " + p.Url

                                              ).ToArray()
                                ));

                break;
            }
        }
        //analyse = new SingleListPageAnalyse("http://www.baidu.com/s?bs=xml+linq+GetElementsByTagName&f=8&rsv_bp=1&wd=xml+linq++TagName&inputT=718");


        //输出Web数据
        // Response.Write("http://www.qlili.com".GetWeb());


        Skybot.Cache.RecordsCacheManager.Instance.UpdateRecord(RecordType.Page, "" + 6);


        // Response.Write();
        Response.Write(tygdb.分类表.Count());
        // 序列化测试();

        #region 处理异常
        try { task.Wait(); }
        catch (AggregateException ex) { ex.Handle((exp) => { return(true); }); }
        #endregion


        return;

        Skybot.Cache.TabPageEntity page = new TabPageEntity()
        {
            Record = tygdb.文章表.First()
        };
    }