示例#1
0
 private static Task FindUnactive()
 {
     return(Task.Run(() => {
         while (!_Service.exit)
         {
             var startWiatDT = DateTime.Now;
             while ((DateTime.Now - startWiatDT).TotalMinutes < 3)
             {
                 Task.Delay(100);
             }
             Sql sql = new Sql();
             using (DataTable DT = sql.GetTable("select proxy, dtcreate from [xxxImport].[proxy].Proxys"))
             {
                 var dt = DT.AsEnumerable().OrderBy(m => m.Field <DateTime>("dtcreate")).Select(m => m.Field <string>("proxy").Trim()).Distinct();
                 foreach (string proxy in dt)
                 {
                     if (!WebR.Check(proxy))
                     {
                         int n = sql.Exec("delete from [xxxImport].[proxy].Proxys where proxy = '" + proxy + "'");
                         Console.WriteLine(proxy + " : removed from base : " + n);
                     }
                     else
                     {
                         Console.WriteLine(proxy + " : still alive");
                     }
                 }
             }
             sql.Dispose();
         }
     }));
 }
示例#2
0
        /// <summary>
        /// Добавляет запись в базу,
        /// если прокси прошел проверку и не имеет дублей в базе.
        /// Возвращает кол-во затронутых строк
        /// </summary>
        /// <param name="prx_"></param>
        /// <returns></returns>
        public static int Add(string prx_, ref Sql sql)
        {
            prx_ = prx_.Trim();

            try
            {
                if (sql.Exec("select count (proxy) from [xxxImport].[proxy].Proxys where proxy = '" + prx_ + "'") > 0)
                {
                    throw new Exception();
                }
                if (!WebR.Check(prx_))
                {
                    throw new Exception();
                }

                lock (_Service.addingSync)
                {
                    int n = sql.Exec(@"insert into [xxxImport].[proxy].Proxys (id, proxy, dtcreate) values 
((select isnull(max(id), 0) from [CursorImport].[proxy].Proxys) + 1, '" + prx_ + "', getdate())");
                    Console.WriteLine(prx_ + " : added to base : " + n);
                    return(n);
                }
            }
            catch { return(0); }
        }