public bool IsSameUser(UserRank otherUser)
 {
     if (this.status == (int)userStatus.notUsed || otherUser.status == (int)userStatus.notUsed)
     {
         return(false);
     }
     foreach (UserInfo user1 in userInfos)
     {
         foreach (UserInfo user2 in otherUser.userInfos)
         {
             if (user1.status == user2.status)
             {
                 if (user1.status == (int)userStatus.fixedNick)
                 {
                     if (user1.IdorIp.Equals(user2.IdorIp))
                     {
                         Console.WriteLine(user1.IdorIp + " 같다 " + user2.IdorIp);
                         return(true);
                     }
                 }
                 else if (user1.status == (int)userStatus.fluidNick)
                 {
                     if (user1.Nick.Equals(user2.Nick) && user1.Nick != "ㅇㅇ")
                     {
                         return(true);
                     }
                 }
             }
         }
     }
     return(false);
 }
        public void Crawler()
        {
            int previousPageGallNum = 1000000000;

            Console.WriteLine(initDate.ToString() + endDate.ToString());

            string url = gallUrl + "&page=";

            var client = new WebClient();

            client.Encoding = System.Text.Encoding.UTF8;
            //Dictionary value => count, replyNum, gallCount, gallRecommend
            Dictionary <UserInfo, int[]> userDic = new Dictionary <UserInfo, int[]>();

            int currentPage = this.initPage;

            while (true)
            {
                string text;
                try
                {
                    text = client.DownloadString(url + currentPage.ToString());
                    if (string.IsNullOrEmpty(text))
                    {
                        continue;
                    }
                }
                catch
                {
                    continue;
                }


                hap.HtmlDocument textHap = new hap.HtmlDocument();
                textHap.LoadHtml(text);

                hap.HtmlNodeCollection nicks = textHap.DocumentNode.SelectNodes("//tr[@class='ub-content us-post']");
                //Console.WriteLine(nicks.Count);
                //Console.WriteLine("==================" + currentPage.ToString() + "==================");
                try
                {
                    foreach (hap.HtmlNode nick in nicks)
                    {
                        int      gallNum, replyNum, gallCount, gallRecommend;
                        DateTime gallDate; string subject;

                        gallNum  = GetOnlyInt(nick.SelectSingleNode("./td[@class='gall_num']").InnerText);
                        gallDate = DateTime.ParseExact(nick.SelectSingleNode("./td[@class='gall_date']").Attributes["title"].Value,
                                                       "yyyy-MM-dd HH:mm:ss", null);
                        Console.WriteLine(gallNum.ToString() + " " + gallDate.ToString());
                        if (gallNum >= previousPageGallNum)
                        {
                            Console.WriteLine(previousPageGallNum.ToString() + " " + gallNum.ToString());
                            Console.WriteLine("번호 에러");
                            continue;
                        }
                        if (DateTime.Compare(gallDate, initDate) < 0 || DateTime.Compare(gallDate, endDate) > 0)
                        {
                            Console.WriteLine("날짜 에러");
                            continue;
                        }

                        hap.HtmlNode user         = nick.SelectSingleNode("./td[@class='gall_writer ub-writer']");
                        UserInfo     tempUserInfo = new UserInfo(user.Attributes["data-nick"].Value);
                        if (user.Attributes["data-uid"].Value == "")
                        {
                            tempUserInfo.setFluidNick(user.Attributes["data-ip"].Value);
                        }
                        else
                        {
                            tempUserInfo.setFixedNick(user.Attributes["data-uid"].Value);
                        }

                        //replyNum and subject are in <td class='gall_tit ub-word'></td>
                        hap.HtmlNode subjectNode = nick.SelectSingleNode("./td[2]");
                        try
                        {
                            if (subjectNode.Attributes["class"].Value == "gall_subject")
                            {
                                subjectNode = nick.SelectSingleNode("./td[3]");
                            }
                            subject = subjectNode.SelectSingleNode("./a[1]").InnerText;
                            if (subjectNode.SelectNodes("./a").Count == 2)
                            {
                                replyNum = GetOnlyInt(subjectNode.SelectSingleNode("./a[@class='reply_numbox']/span").InnerText);
                            }
                            else
                            {
                                replyNum = 0;
                            }
                        }
                        catch
                        {
                            subject  = "NullSubjectException";
                            replyNum = 0;
                        }
                        // Console.WriteLine("댓글: " + replyNum.ToString());
                        gallCount     = GetOnlyInt(nick.SelectSingleNode("./td[@class='gall_count']").InnerText);
                        gallRecommend = GetOnlyInt(nick.SelectSingleNode("./td[@class='gall_recommend']").InnerText);


                        //Dictionary value => count, replyNum, gallCount, gallRecommend
                        if (userDic.ContainsKey(tempUserInfo))
                        {
                            userDic[tempUserInfo][0] += 1;
                            userDic[tempUserInfo][1] += replyNum;
                            userDic[tempUserInfo][2] += gallCount;
                            userDic[tempUserInfo][3] += gallRecommend;
                        }
                        else
                        {
                            int[] tempInts = new int[] { 1, replyNum, gallCount, gallRecommend };
                            userDic.Add(tempUserInfo, tempInts);
                        }
                        UserData tempUserData = new UserData(tempUserInfo);
                        tempUserData.DataInput(gallNum, replyNum, gallCount, gallRecommend, gallDate, subject);
                        //gallDatas.Add(tempUserData);
                    }
                }
                catch
                {
                    if (ErrorOccured != null)
                    {
                        ErrorOccured(text, null);
                    }
                    currentPage++;
                    continue;
                }

                previousPageGallNum = GetOnlyInt(nicks[nicks.Count - 1].SelectSingleNode("./td[@class='gall_num']").InnerText);
                DateTime currentDate = DateTime.ParseExact(nicks[nicks.Count - 1].
                                                           SelectSingleNode("./td[@class='gall_date']").Attributes["title"].Value, "yyyy-MM-dd HH:mm:ss", null);
                if (currentPage >= endPage || DateTime.Compare(currentDate, initDate) < 0)
                {
                    break;
                }
                else
                {
                    System.Collections.ArrayList arr = new System.Collections.ArrayList();
                    string str = currentPage.ToString() + " 페이지, 날짜: " + currentDate.ToString();
                    arr.Add(str); arr.Add(currentDate); arr.Add(currentPage - initPage);
                    if (newPageHappened != null)
                    {
                        newPageHappened(arr, null);
                    }
                    currentPage++;
                }
            }
            //Dictionary value => count, replyNum, gallCount, gallRecommend
            foreach (KeyValuePair <UserInfo, int[]> user in userDic)
            {
                UserInfo tempUser = user.Key;
                tempUser.count         = user.Value[0];
                tempUser.replyNum      = user.Value[1];
                tempUser.gallCount     = user.Value[2];
                tempUser.gallRecommend = user.Value[3];
                UserRank tempUserRank = new UserRank(tempUser, user.Value[0], user.Value[1], user.Value[2], user.Value[3]);
                userList.Add(tempUserRank);
            }
            var sorted = from userRank in userList
                         orderby userRank.count descending
                         select userRank;

            userList = sorted.ToList <UserRank>();
            if (CrawlingEnded != null)
            {
                CrawlingEnded(userList, null);
            }
            string tempDataDir = Directory.GetCurrentDirectory() + "\\temp-data\\";

            Directory.CreateDirectory(tempDataDir);
            string filename = tempDataDir + gallId + DateTime.Now.ToString("_yyyy-MM-dd_HH-mm-ss");

            SaveResult(filename);
        }