Exemple #1
0
        public static int GetEmailIndex(string[] values, LogManagerBase logManager)
        {
            if (values.Length == 0)
            {
                logManager.Error(string.Format("GetEmailIndex():the raw data is incorrect ,this is a empty line"));
                return(-1);
            }

            for (int i = values.Length - 1; i >= 0; i--)
            {
                if (TextHelper.IsMail(values[i]))
                {
                    return(i);
                }
            }

            string valueStr = string.Empty;

            foreach (string item in values)
            {
                valueStr += item;
            }
            logManager.Error(string.Format("GetEmailIndex({0}):不是用效的邮箱格式,请检查数据格式是否正确", valueStr));
            return(-1);
        }
Exemple #2
0
 private static bool RunSql(string sql)
 {
     if (!string.IsNullOrEmpty(sql))
     {
         try
         {
             using (SQLiteCommand cmd = sqlCon.CreateCommand())
             {
                 cmd.CommandText = sql;
                 cmd.ExecuteNonQuery();
             }
             return(true);
         }
         catch (Exception ex)
         {
             LogManager.Error(string.Format("执行Insert sql时出错:{0}", ex.Message));
         }
     }
     return(false);
 }
Exemple #3
0
 public void Save()
 {
     LogManager.Info("Start write params to params file");
     try
     {
         this.XmlFile.SaveFile();
     }
     catch (System.Exception ex)
     {
         LogManager.Error(string.Format("Save params file error:{0}", ex.Message));
     }
 }
Exemple #4
0
        /// <summary>
        /// Index from last
        /// </summary>
        /// <param name="rawContent"></param>
        /// <param name="subString"></param>
        /// <returns></returns>
        public static string GetUser(string rawContent, string subString, LogManagerBase logManager)
        {
            int index = rawContent.LastIndexOf(subString);

            if (index >= 0)
            {
                return(rawContent.Substring(0, index));
            }

            logManager.Error(string.Format("GetUser({0}): password index must bigger than 0", rawContent));
            return(string.Empty);
        }
Exemple #5
0
        public AdslDialer(ADSLItem adslItem, LogManagerBase logManager)
        {
            this.LogManager = logManager;
            if (null == adslItem)
            {
                LogManager.Error("ADSL dialer parameters can't be null!");
            }

            this.ADSLItem = adslItem;
            this.Timeout  = 5 * 60 * 1000;

            this.rasDialer.StateChanged  += rasDialer_StateChanged;
            this.rasDialer.DialCompleted += rasDialer_DialCompleted;
        }
Exemple #6
0
        public bool Reconnect(DetectionParamsItem detectionItem)
        {
            lock (lockObj)
            {
                if ((null == detectionItem) || (null == detectionItem.ADSL))
                {
                    LogManager.Error("ADSL parameters can't be empty");
                    return(false);
                }

                for (int i = 0; i < 3; i++)
                {
                    using (AdslDialer dialer = new AdslDialer(detectionItem.ADSL, this.LogManager))
                    {
                        if (dialer.Dial())
                        {
                            break;
                        }
                    }
                    Thread.Sleep(3 * 1000);
                }

                //this.Reconnect(detectionItem.ADSL);
                //ReconnectManager.Sleep();
                Thread.Sleep(2 * 1000);
                int t = 0;
                while (t++ < ReconnectManager.TRYCOUNT)
                {
                    if (CmdHelper.PingBaidu() || CmdHelper.Ping163())
                    {
                        return(true);
                    }
                    Thread.Sleep(2 * 1000);
                }
                return(false);
            }
        }
Exemple #7
0
        public static PwdResetItem GetPwdResetItem(string rawString, DataFormat dataFormat, LogManagerBase logManager)
        {
            if (string.IsNullOrEmpty(rawString))
            {
                return(null);
            }

            string[] values = rawString.Split(TextToItemHelper.AccountSplitChars, StringSplitOptions.RemoveEmptyEntries);
            if (values.Length >= 3)
            {
                // user name may contains space
                int emailIndex = GetEmailIndex(values, logManager);
                if (emailIndex != 0)
                {
                    logManager.Error(string.Format("GetAccountInfo({0}): Email address can't be the first item", rawString));
                    return(null);
                }
                else
                {
                    PwdResetItem item = new PwdResetItem();
                    item.EMail = values[0];
                    if (dataFormat == DataFormat.MailFstNSecN)
                    {
                        item.FirstName  = values[1];
                        item.SecondName = values[2];
                    }
                    else if (dataFormat == DataFormat.MailSecNFstN)
                    {
                        item.SecondName = values[1];
                        item.FirstName  = values[2];
                    }
                    return(item);
                }
            }

            return(null);
        }
Exemple #8
0
        public virtual T GetNextItem()
        {
            try
            {
                Interlocked.Increment(ref ipAccessCount);
                if (IsIPLimit)
                {
                    //ipAccessCount = -1;
                    LogManager.InfoWithCallback(string.Format("当前每IP只允许访问 {0} 个帐号,准备重新连接网络!", IPLimitCount));
                    return(null);
                }

                lock (this.readLockObject)
                {
                    // if process by custom range ,check it ,if out of range then  stop process
                    if ((this.HttperParamsItem.IsSupportedCustomRange))
                    {
                        if (this.CurrentIndex < this.HttperParamsItem.RangeLower)
                        {
                            this.CurrentIndex = this.HttperParamsItem.RangeLower;
                            if (this.CurrentIndex < 0)
                            {
                                this.CurrentIndex = 0;
                            }
                        }
                        if (this.CurrentIndex > this.HttperParamsItem.RangeUpper)
                        {
                            return(null);
                        }
                    }

                    if (this.CurrentIndex == 0)
                    {
                        queriedCount = 0;
                    }

                    if ((this.accountList.Count > 0) && (this.CurrentIndex >= 0) && (this.CurrentIndex < this.accountList.Count))
                    {
                        T item = this.accountList[this.CurrentIndex++];
                        while ((null != item) && queriedIndexList.Contains(item.Index))
                        {
                            if (this.CurrentIndex < this.accountList.Count)
                            {
                                if (queriedCount++ == 0)
                                {
                                    sb.Append(string.Format("Below accounts has been queried:\n"));
                                }

                                sb.Append(string.Format("{0}->:{1}; ", item.Index, item.EMail));
                                if (queriedCount % 100 == 0)
                                {
                                    LogManager.Info(sb.ToString());
                                    sb           = new StringBuilder();
                                    queriedCount = 0;
                                }
                                item = this.accountList[this.CurrentIndex++];
                            }
                            else
                            {
                                return(null);
                            }
                        }
                        return(item);
                    }
                    return(null);
                }
            }
            catch (System.Exception ex)
            {
                LogManager.Error(string.Format("HttperManager.GetNextItem() failed:{0}", ex.Message));
            }
            return(null);
        }
Exemple #9
0
 void SystemEvents_PowerModeChanged(object sender, PowerModeChangedEventArgs e)
 {
     LogManager.Error(string.Format("SystemEvents_PowerModeChanged() called,e.Mode={0}", e.Mode));
 }
Exemple #10
0
        public static bool GetLoginAccountItem(string rawString, ref string account, ref string pwd, ref string email,
                                               DataFormat dataFormat, LogManagerBase logManager)
        {
            if (string.IsNullOrEmpty(rawString))
            {
                return(false);
            }

            account = string.Empty;
            pwd     = string.Empty;
            email   = string.Empty;

            string[] values = rawString.Split(TextToItemHelper.SplitChars, StringSplitOptions.RemoveEmptyEntries);
            for (int i = 0; i < values.Length; i++)
            {
                values[i] = values[i].Trim();
            }
            if (values.Length == 2)
            {
                if (dataFormat == DataFormat.MailPassword)
                {
                    email   = values[0];
                    account = email;
                    pwd     = values[1];
                    return(true);
                }
                else if (dataFormat == DataFormat.AccountPassword)
                {
                    account = values[0];
                    email   = account;
                    pwd     = values[1];
                    return(true);
                }
            }
            else if (values.Length >= 3)
            {
                // user name may contains space
                int emailIndex = GetEmailIndex(values, logManager);
                if (emailIndex < 0)
                {
                    logManager.Error(string.Format("GetAccountInfo({0}): Email address can't be the first item", rawString));
                }
                //Trace.Assert(emailIndex >= 0, "GetAccountInfo(): Email address can't be the first item");
                if (emailIndex >= 0)
                {
                    if (dataFormat == DataFormat.AccountMailPassword)
                    {
                        email   = values[emailIndex];
                        account = GetUser(rawString, email, logManager);
                        if (emailIndex + 1 != (values.Length - 1))
                        {
                            logManager.Error("GetAccountInfo(): Email address can't be the last item. it's miss password item");
                        }
                        //Trace.Assert(emailIndex + 1 == (values.Length - 1), "GetAccountInfo(): Email address can't be the last item. it's miss password item");
                        pwd = values[emailIndex + 1];
                        return(true);
                    }

                    if (dataFormat == DataFormat.AccountPasswordMail)
                    {
                        email = values[emailIndex];
                        if (emailIndex - 1 < 0)
                        {
                            logManager.Error(string.Format("GetAccountInfo({0}):  Email address can't be the first item. it's miss password item", rawString));
                        }
                        //Trace.Assert(emailIndex - 1 >= 0, "GetAccountInfo(): Email address can't be the first item. it's miss password item");
                        pwd     = values[emailIndex - 1];
                        account = GetUser(rawString, pwd, logManager);
                        return(true);
                    }
                }
            }

            return(false);
        }