Example #1
0
        AgentIPModel getAgentIPInner(SQLiteDataReader sr)
        {
            bool         acknowledge;
            AgentIPModel model = new AgentIPModel();

            if (sr.GetValue(0) != DBNull.Value)
            {
                model.ip = sr.GetString(0);
            }
            if (sr.GetValue(1) != DBNull.Value)
            {
                model.port = sr.GetString(1);
            }

            try
            {
                if (sr.GetString(2) != "")
                {
                    model.LastCheckData = Convert.ToDateTime(sr.GetString(2));
                }
            }
            catch (Exception e)
            { }
            if (sr.GetValue(3) != DBNull.Value)
            {
                model.Active = Convert.ToBoolean(sr.GetString(3));
            }

            if (sr.GetValue(4) != DBNull.Value)
            {
                model.LastSuccess = Convert.ToBoolean(sr.GetString(4));
            }

            return(model);
        }
Example #2
0
        public List <AgentIPModel> GetAgentIP(AgentIPModel condition, int pageSize, int pageIndex)
        {
            try
            {
                StringBuilder sbCondition = GetConditionString(condition);
                int           startindex  = (pageIndex - 1) * pageSize;
                string        searchSql   = string.Format(Select_AgentIPByConditionPage, sbCondition.ToString(), pageSize, startindex);



                sr = Sqlite.ExecuteReader(searchSql);
                List <AgentIPModel> AgentIPList = new List <AgentIPModel>();
                while (sr.Read())
                {
                    AgentIPList.Add(getAgentIPInner(sr));
                }
                return(AgentIPList);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                sr.Close();
            }
        }
Example #3
0
        public void SetAgent(AgentIPModel ObjModel, bool active)
        {
            List <AgentIPModel> aList = dal.GetAgentIP(ObjModel);

            if (aList.Count <= 0)
            {
                ObjModel.Active        = active;
                ObjModel.LastCheckData = DateTime.Now;
                dal.InsertAgentIPModel(ObjModel);
            }
        }
Example #4
0
        public void InsertAgentIPModel(AgentIPModel data)
        {
            try
            {
                string executeInsert = string.Format(Insert_AgentIP, data.ip, data.port, data.LastCheckData, data.Active, data.LastSuccess);

                int retCount = Sqlite.ExecuteNonQuery(executeInsert);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
            }
        }
Example #5
0
        /// <summary>
        /// get total rows count
        /// </summary>
        /// <returns></returns>
        public int GetTotalCount(AgentIPModel condition)
        {
            try
            {
                StringBuilder sbCondition = GetConditionString(condition);
                string        searchSql   = string.Format(Select_TotalCount, sbCondition.ToString());

                object count;
                count = Sqlite.ExecuteScalar(searchSql);
                int intcount = 0;
                int.TryParse(count + "", out intcount);

                return(intcount);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
            }
        }
Example #6
0
        /// <summary>
        /// http://www.goodips.com/?ip=&port=&dengji=&adr=&checktime=&sleep=&cunhuo=&px=&pageid=2;
        /// </summary>
        /// <param name="url"></param>
        /// <returns></returns>
        List <AgentIPModel> GetAgentIPs(string url)
        {
            List <AgentIPModel> mList = new List <AgentIPModel>();
            string html = Agent.GetHTMLCode(url, Encoding.UTF8);

            #region 解析

            Regex           re = new Regex(@"class\=\""ctable_head\""\>(.*?)\<\/table\>", RegexOptions.Multiline);
            MatchCollection mc = re.Matches(html.Replace("\r", "").Replace("\n", ""));
            try
            {
                string          tds   = mc[0].Groups[1].Value.Replace("\t", "");
                Regex           retds = new Regex(@"\<tr\>(.*?)\<td\>(.*?)\<\/td\>(.*?)\<td\>(.*?)\<\/td\>(.*?)\<\/tr\>", RegexOptions.Multiline);
                MatchCollection tdmc  = retds.Matches(tds);
                foreach (Match mt in tdmc)
                {
                    AgentIPModel ipModel = new AgentIPModel();
                    ipModel.LastCheckData = DateTime.Now;
                    ipModel.ip            = mt.Groups[2].Value;
                    ipModel.port          = mt.Groups[4].Value;
                    string newip_temp = string.Format("{0}:{1}", ipModel.ip, ipModel.port);
                    if (promaxy1.Pro2.checkProxyIP(newip_temp, 10000))
                    {
                        //数据库保存ip
                        ipBLL.SetAgent(ipModel, true);
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
            }


            #endregion

            return(mList);
        }
Example #7
0
        /// <summary>
        /// return success
        /// </summary>
        /// <param name="agent"></param>
        /// <returns></returns>
        bool singleAgent(AgentIPModel agent)
        {
            newip = string.Format("{0}:{1}", agent.ip, agent.port);
            promaxy1.IEProxy.SetProxy(newip);
            webBrowserOK = false;
            webBrowser1.Navigate(url);

            for (int i = 10; i > 0; i--)
            {
                Thread.Sleep(800);
                if (webBrowserOK)
                {
                    break;
                }
            }
            if (webBrowserOK)
            {
                LabelRecord(label3, "当前IP" + agent.ip);
                return(true);
                //addClick();
            }
            return(false);
        }
Example #8
0
        StringBuilder GetConditionString(AgentIPModel condition)
        {
            StringBuilder sbCondition = new StringBuilder(" 1=1 ");

            if (!string.IsNullOrEmpty(condition.ip))
            {
                sbCondition.AppendFormat(" and [ip] = '{0}' ", condition.ip);
            }
            if (!string.IsNullOrEmpty(condition.port))
            {
                sbCondition.AppendFormat(" and [port] = '{0}' ", condition.port);
            }
            if (condition.LastCheckData != null && condition.LastCheckData != DateTime.MinValue)
            {
                sbCondition.AppendFormat(" and [LastCheckData] = '{0}' ", condition.LastCheckData);
            }
            if (condition.LastSuccess != null)
            {
                sbCondition.AppendFormat(" and [LastSuccess] = '{0}' ", condition.LastSuccess);
            }

            return(sbCondition);
        }
Example #9
0
 public void Update(AgentIPModel ObjModel)
 {
     dal.Update(ObjModel);
 }
Example #10
0
 public int GetTotalCount(AgentIPModel condition)
 {
     return(dal.GetTotalCount(condition));
 }
Example #11
0
 public List <AgentIPModel> GetAgentIP(AgentIPModel condition, int pageSize, int pageIndex)
 {
     return(dal.GetAgentIP(condition, pageSize, pageIndex));
 }
Example #12
0
 /// <summary>
 /// get AgentIP list by condition
 /// </summary>
 /// <param name="condition"></param>
 /// <returns></returns>
 public List <AgentIPModel> GetAgentIP(AgentIPModel condition)
 {
     return(dal.GetAgentIP(condition));
 }
Example #13
0
 /// <summary>
 /// 新增
 /// </summary>
 /// <param name="ObjModel">模型对象</param>
 /// <returns>产生主键值</returns>
 public void Insert(AgentIPModel ObjModel)
 {
     dal.InsertAgentIPModel(ObjModel);
 }
Example #14
0
        /// <summary>
        /// Update
        /// </summary>
        /// <param name="mObj"></param>
        /// <returns></returns>
        public void Update(AgentIPModel mObj)
        {
            try
            {
                StringBuilder strSql = new StringBuilder();
                strSql.Append("update AgentIP set ");
                StringBuilder sbCondition = new StringBuilder();

                if (mObj.ip != null)
                {
                    if (sbCondition.Length > 0)
                    {
                        sbCondition.Append(",");
                    }
                    sbCondition.AppendFormat(" ip = '{0}' ", mObj.ip);
                }
                if (mObj.port != null)
                {
                    if (sbCondition.Length > 0)
                    {
                        sbCondition.Append(",");
                    }
                    sbCondition.AppendFormat(" port = '{0}' ", mObj.port);
                }
                if (mObj.LastCheckData != null)
                {
                    if (sbCondition.Length > 0)
                    {
                        sbCondition.Append(",");
                    }
                    sbCondition.AppendFormat(" LastCheckData = '{0}' ", mObj.LastCheckData);
                }
                if (mObj.Active != null)
                {
                    if (sbCondition.Length > 0)
                    {
                        sbCondition.Append(",");
                    }
                    sbCondition.AppendFormat(" Active = '{0}' ", mObj.Active);
                }
                if (mObj.LastSuccess != null)
                {
                    if (sbCondition.Length > 0)
                    {
                        sbCondition.Append(",");
                    }
                    sbCondition.AppendFormat(" LastSuccess = '{0}' ", mObj.LastSuccess);
                }

                strSql.Append(sbCondition.ToString());
                strSql.AppendFormat(" where [ip]='{0}'", mObj.ip);

                object ret = Sqlite.ExecuteNonQuery(strSql.ToString());
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
            }
        }