public static void LoadCollectionIDsFormFile()
        {
            string filePath = System.Environment.CurrentDirectory + @"\CollectionID.txt";

            if (File.Exists(filePath))
            {
                string fileStr = File.ReadAllText(filePath);
                IEnumerable <CollectionInfo> infos = CollectionDB.GetAllCollectionInfos().ToList();
                foreach (var ci in infos)
                {
                    fileStr = fileStr.Replace(ci.CollectionID.ToString() + ":" + ci.QuestionCount, "");
                }
                string[] collectionIds = fileStr.Replace(";", "|").Split('|');
                foreach (string id in collectionIds)
                {
                    if (!String.IsNullOrEmpty(id))
                    {
                        string[]       ids = id.Split(':');
                        CollectionInfo ci  = CollectionDB.GetCollectionInfoById(ids[0]);
                        if (ci != null)
                        {
                            ci.QuestionCount = int.Parse(ids[1]);
                            CollectionDB.SaveOrUpdateCollectionInfo(ci);
                        }
                        else
                        {
                            string url = string.Format(CollectionInfoBaseUrl, ids[0]);
                            GetCollectionInfoFormHtml(BusinessUtils.GetByUrl(url), ids[0]);
                        }
                    }
                }
            }
        }
        public static bool GetQuestionListByPage(int pageNo)
        {
            bool   result = false;
            string url    = String.Format(questionPageUrl, pageNo);

            GetQuestionInfoFormHtml(BusinessUtils.GetByUrl(url));
            return(result);
        }
 public static void GetCollectionAnswerInfos(CollectionInfo ci)
 {
     if (CollectionDB.GetAnswerCountByCollectionId(ci.CollectionID.ToString()) != ci.QuestionCount)
     {
         int count = GetCollectionPageCount(ci);
         ci.QuestionCount = count;
         CollectionDB.SaveOrUpdateCollectionInfo(ci);
         for (int i = count; i >= 1; i--)
         {
             string url = string.Format(CollectionInfoAnswerUrl, ci.CollectionID, i);
             GetCollectionAnswerInfoFromHtml(BusinessUtils.GetByUrl(url), ci);
             Thread.Sleep(1000 * 5);
         }
     }
 }
        public static void RefreshQuestionPageCount()
        {
            Console.WriteLine("更新问题总页数于" + DateTime.Now.ToString() + "开始");
            string result = BusinessUtils.GetByUrl(questionPageCountUrl);

            if (!String.IsNullOrWhiteSpace(result))
            {
                try
                {
                    HtmlDocument doc = new HtmlDocument();
                    doc.LoadHtml(result);
                    List <HtmlNode> rootNode = doc.DocumentNode.SelectNodes(@"//div[@class='zm-invite-pager']").ToList();
                    int             count    = 0;
                    List <HtmlNode> nodes    = rootNode[0].ChildNodes.ToList();
                    nodes.RemoveAll(p => p.InnerText.Replace("\n", "") == "");
                    if (nodes.Count == 7)
                    {
                        HtmlNode countNode = nodes[5];
                        count = int.Parse(countNode.FirstChild.InnerText);
                    }
                    else
                    {
                        foreach (var node in nodes)
                        {
                            if (node.InnerHtml.Contains("下一页"))
                            {
                                HtmlNode countNode = nodes[nodes.IndexOf(node) - 1];
                                count = int.Parse(countNode.FirstChild.InnerText);
                            }
                        }
                    }
                    SysDictDB.SaveOrUpdateQuestionCount(count);
                    Console.WriteLine("更新问题总页数于" + DateTime.Now.ToString() + "成功,目前问题总页数为" + count);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("更新问题总页数于" + DateTime.Now.ToString() + "失败,失败原因:" + ex.Message);
                }
            }
            else
            {
                Console.WriteLine("更新问题总页数于" + DateTime.Now.ToString() + "失败,失败原因:没有获取到数据。");
            }
        }
        public static int GetCollectionPageCount(CollectionInfo ci)
        {
            int    pageCount = 0;
            string url       = string.Format(CollectionInfoBaseUrl, ci.CollectionID);
            string res       = BusinessUtils.GetByUrl(url);

            if (!String.IsNullOrWhiteSpace(res))
            {
                try
                {
                    HtmlDocument doc = new HtmlDocument();
                    doc.LoadHtml(res);
                    List <HtmlNode> rootNode = doc.DocumentNode.SelectNodes(@"//div[@class='zm-invite-pager']").ToList();
                    List <HtmlNode> nodes    = rootNode[0].ChildNodes.ToList();
                    nodes.RemoveAll(p => p.InnerText.Replace("\n", "") == "");
                    if (nodes.Count == 7)
                    {
                        HtmlNode countNode = nodes[5];
                        pageCount = int.Parse(countNode.FirstChild.InnerText);
                    }
                    else
                    {
                        foreach (var node in nodes)
                        {
                            if (node.InnerHtml.Contains("下一页"))
                            {
                                HtmlNode countNode = nodes[nodes.IndexOf(node) - 1];
                                pageCount = int.Parse(countNode.FirstChild.InnerText);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                }
            }
            return(pageCount);
        }