Ejemplo n.º 1
0
        /// <summary>
        /// 初始化所有任务
        /// </summary>
        public static void SetAllSinceIDToNull()
        {
            string where = "SubscribeStatus>=0";
            var accList = LoginAccountBusiness.GetAllByWhere(where, null, LoginAccountMySqlDAL.OrderColumn.Default);

            foreach (var acc in accList)
            {
                where = string.Format("AccountID='{0}'", acc.AccountID);
                var param = new LoginAccountMySqlDAL.LoginAccountParameter[3];
                param[0] = new LoginAccountMySqlDAL.LoginAccountParameter(Palas.Common.Lib.DTO.LoginAccountDTO.Column.SubscribeSinceID, null);
                param[1] = new LoginAccountMySqlDAL.LoginAccountParameter(Palas.Common.Lib.DTO.LoginAccountDTO.Column.SubscribeNextTime, Utilities.Epoch);
                param[2] = new LoginAccountMySqlDAL.LoginAccountParameter(Palas.Common.Lib.DTO.LoginAccountDTO.Column.Status, Enums.CrawlStatus.Normal);
                LoginAccountBusiness.UpdateWhere(param, where, null);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 定期检查账号情况
        /// </summary>
        private static void NormalizeAccount()
        {
            string where;
            try
            {
                #region 初始化账号
                where = "IsDisabled=FALSE AND SubscribeStatus>=0 AND AuthorID IS NULL";
                var result = LoginAccountBusiness.GetAllByWhere(where, null, LoginAccountMySqlDAL.OrderColumn.Default);
                foreach (var account in result)
                {
                    try
                    {
                        account.AuthorID = WeiboAPI.GetAuthorID(account.UserName);
                        var author = WeiboAPI.GetAuthorInfo(account.AuthorID);
                        var list   = WeiboAPI.GetFriendsIDs(account.AuthorID, Enums.SampleMethod.All);
                        account.FollowCount = 0;
                        foreach (var id in list)
                        {
                            AuthorDBManager.SubscribeAuthor(account.UserName, id);
                            account.FollowCount++;
                        }
                    }
                    catch (Exception ex)
                    {
                        Logger.Error(string.Format("Err@ Account: {0}, message: {1}", account.UserName, ex.ToString()));
                        account.FailCount++;
                        if (account.FailCount > DefaultSettings.MaxFailureCount)
                        {
                            account.IsDisabled = true;
                        }
                        LoginAccountBusiness.UpdateByAccountID(account);
                        continue;
                    }
                    account.FailCount                = 0;
                    account.SubscribeIntervalMins    = 15;
                    account.SubscribeLastTime        = Utilities.Epoch;
                    account.SubscribeNextTime        = Utilities.Epoch;
                    account.SubscribeSinceID         = null;
                    account.FollowCountLastClearTime = DateTime.Now;
                    account.FollowCountToday         = 0;
                    LoginAccountBusiness.UpdateByAccountID(account);
                }
                #endregion

                #region 关注次数和失效次数清零(每天一次)
                DateTime refreshtime = DateTime.Now.Subtract(new TimeSpan(1, 0, 0, 0, 0));
                where  = string.Format("IsDisabled=FALSE AND SubscribeStatus>=0 AND (FollowCountLastClearTime IS NULL OR FollowCountLastClearTime<'{0}')", refreshtime);
                result = LoginAccountBusiness.GetAllByWhere(where, null, LoginAccountMySqlDAL.OrderColumn.Default);
                foreach (var account in result)
                {
                    account.FollowCountLastClearTime = DateTime.Now;
                    account.FollowCountToday         = 0;
                    account.FailCount = 0;
                    LoginAccountBusiness.UpdateByAccountID(account);
                }
                #endregion
            }
            catch (Exception ex)
            {
                Logger.Error(ex.ToString());
            }
        }