예제 #1
0
 private void DownloadImageCompany(long idCompany, ProducerBasic producerUpdateImageIdSql, bool redownloadAll)
 {
     try
     {
         var start = DateTime.Now;
         var productTableAdapter = new ProductTableAdapter();
         productTableAdapter.Connection.ConnectionString = _connectionString;
         var productTable = new DBImage.ProductDataTable();
         if (idCompany == 6619858476258121218)
         {
             productTableAdapter.FillBy_RootProduct(productTable);
         }
         else if (idCompany == 1)
         {
             productTableAdapter.FillAllImageIdNull(productTable);
         }
         else if (redownloadAll)
         {
             productTableAdapter.FillAllBy_Company(productTable, idCompany);
         }
         else
         {
             productTableAdapter.FillBy_CompanyAndImageIdNull(productTable, idCompany);
         }
         if (productTable.Rows.Count > 0)
         {
             List <long> listIdFail = new List <long>();
             int         success    = 0;
             int         fail       = 0;
             for (int i = 0; i < productTable.Rows.Count; i++)
             {
                 ImageProductInfo product = new ImageProductInfo();
                 product.Id        = Common.Obj2Int64(productTable.Rows[i]["ID"]);
                 product.ImageUrls = productTable.Rows[i]["ImageUrls"].ToString();
                 if (idCompany == 6619858476258121218)
                 {
                     if (DownloadImageRootProduct(product, producerUpdateImageIdSql))
                     {
                         success++;
                     }
                     else
                     {
                         fail++;
                         listIdFail.Add(product.Id);
                     }
                 }
                 else
                 {
                     if (DownloadImageProduct(product, producerUpdateImageIdSql))
                     {
                         success++;
                     }
                     else
                     {
                         fail++;
                         listIdFail.Add(product.Id);
                     }
                 }
             }
             Log.Info(string.Format("CompanyId = {0} downloaded {1}/{2} image", idCompany, success, productTable.Count));
             var end = DateTime.Now;
             #region Insert History donwloadimage Company
             try
             {
                 History_DownloadImageCompanyTableAdapter historyCompanyAdapter = new History_DownloadImageCompanyTableAdapter();
                 historyCompanyAdapter.Connection.ConnectionString = _connectionString;
                 historyCompanyAdapter.Insert(idCompany, productTable.Count, success, fail, start, end, string.Join(",", listIdFail));
             }
             catch (Exception ex)
             {
                 Log.Error(string.Format("Insert log error companyId = {1}", idCompany), ex);
             }
             #endregion
         }
         else
         {
             Log.Info(string.Format("CompanyId {0} 0 product download image", idCompany));
         }
     }
     catch (Exception exception)
     {
         Log.Error(string.Format("CompanyId: ID = {0} ERROR: ", idCompany), exception);
     }
 }