Beispiel #1
0
        public MUser GetNextUser()
        {
            MUser user = db.FirstOrDefault <MUser>("WHERE finished<9 ORDER BY sort DESC");

            return(user);
        }
Beispiel #2
0
 public void UpdateUserFinished(MUser user)
 {
     db.Execute("UPDATE m_user SET finished=@0 WHERE username=@1", user.Finished, user.Username);
 }
Beispiel #3
0
        public void Do()
        {
            Console.WriteLine("现在开始:{0:yyyy/MM/dd HH:mm}", DateTime.Now);

            MUser user = da.GetNextUser();

            while (user != null)
            {
                Console.WriteLine("---------------用户 " + user.Username);

                da.ClearData(user.Username);
                string attachFolder = ConfigurationManager.AppSettings["AttachFolder"] + user.Username;
                if (System.IO.Directory.Exists(attachFolder))
                {
                    System.IO.Directory.Delete(attachFolder, true);
                }
                System.IO.Directory.CreateDirectory(attachFolder);

                string cookie = Login(user.Username);

                if (user.Finished == 0)
                {
                    List <MailFolder> folders = GetFolders(cookie);
                    if (folders.Count == 0)
                    {
                        user = da.GetNextUser();
                        break;
                    }
                    user.Finished = 1;
                    da.AddFolders(user.Username, folders);
                    Console.WriteLine("{0}个归档文件夹", folders.Count);
                }

                if (user.Finished == 1)
                {
                    MFolder folder = da.GetNextFolder(user.Username);

                    while (folder != null)
                    {
                        int           totalPages  = 1;
                        int           currentPage = 1;
                        List <string> mailIds     = GetMailList(cookie, folder.FolderId, currentPage, ref totalPages);
                        if (mailIds.Count > 0)
                        {
                            da.AddMailIds(user.Username, folder.FolderId, mailIds);
                            while (currentPage < totalPages)
                            {
                                currentPage++;
                                mailIds = GetMailList(cookie, folder.FolderId, currentPage, ref totalPages);
                                if (mailIds.Count > 0)
                                {
                                    da.AddMailIds(user.Username, folder.FolderId, mailIds);
                                }
                            }
                        }
                        da.UpdateFolderFinished(folder);
                        folder = da.GetNextFolder(user.Username);
                    }
                    user.Finished = 2;
                }

                if (user.Finished == 2)
                {
                    int mailCount = da.GetMailCount(user.Username);
                    Console.WriteLine("{0}封邮件待下载", mailCount);
                    MMail mail = da.GetNextMail(user.Username);
                    while (mail != null)
                    {
                        GetMailContent(cookie, mail);
                        if (mail.AttachList.Count() > 0)
                        {
                            foreach (MAttachment att in mail.AttachList)
                            {
                                DownloadMailAttach(cookie, att, user.Username);
                            }
                        }
                        da.SaveMail(mail);
                        Console.WriteLine("{2}... {0:yyyy/MM/dd HH:mm} {1}", mail.MailDate, mail.MailSubject, mailCount);
                        mail = da.GetNextMail(user.Username);
                        mailCount--;
                    }

                    user.Finished = 9;
                    da.UpdateUserFinished(user);
                }

                Sleep(20);
                user = da.GetNextUser();
            }
        }