示例#1
0
 public virtual void Execute()
 {
     log.Info("Start extracting");
     int count;
     int pageSize = Global.Instance.config.PageSize;
     try
     {
         PgSqlConnection connection1 = getConnection();
         string countCommandSql = "SELECT count(*) " + GetSqlBodyCommand();
         string selectCommandSql = "SELECT model.id, model.urldocument " + GetSqlBodyCommand() + " order by model.id asc";
         PgSqlCommand command = new PgSqlCommand(countCommandSql, connection1);
         command.Parameters.AddWithValue("startDate", Global.Instance.config.StartDate);
         command.Parameters.AddWithValue("endDate", Global.Instance.config.EndDate);
         command.Parameters.AddWithValue("model", Global.Instance.config.PacketPatterns[0].Model);
         command.Parameters.AddWithValue("pattern", Global.Instance.config.PacketPatterns[0].Pattern);
         using (connection1)
         using (command)
         {
             connection1.Open();
             count = Convert.ToInt32(command.ExecuteScalar());
             log.Info("Total count:" + count.ToString());
             Console.WriteLine("Total count:" + command.ExecuteScalar().ToString());
         }
         int j = 0;
         //for (int i = 0; i < count; i += pageSize)
         int k = pageSize;
         int startFrom = 0;
         while (k == pageSize)
         {
             j++;
             log.Info("**start iteration: " + j);
             Console.WriteLine("start iteration: " + j);
             PgSqlConnection connection2 = getConnection();
             command.CommandText = selectCommandSql;
             command.Connection = connection2;
             log.Info("****start fetch ");
             List<packageInfo> fileList = new List<packageInfo>();
             k = 0;
             using (connection2)
             using (command)
             {
                 connection2.Open();
                 using (PgSqlDataReader reader = command.ExecutePageReader(System.Data.CommandBehavior.SingleResult, startFrom, pageSize))
                 {
                     while (reader.Read())
                     {
                         fileList.Add(new packageInfo(reader.GetValue(0).ToString(), reader.GetValue(1).ToString()));
                         k++;
                     }
                 }
             }
             startFrom += pageSize;
             log.Info("****end fetch ");
             log.Info("****start coping ");
             foreach (packageInfo p in fileList)
             {
                 extractPackages(p);
             }
             log.Info("****end coping ");
             log.Info("**end iteration: " + j);
             Console.WriteLine("end iteration: " + j);
         }
         log.Info("Finish extracting");
     }
     catch (Exception ex)
     {
         log.Error(ex);
         Console.WriteLine(ex);
     }
 }