Exemplo n.º 1
0
        /*		private List<string> getMapaRadio(string prov, string dpto, string frac, string radio, string extent)
         *              {
         *                      List<string> radios = new List<string>();
         *                      var args = new NameValueCollection() {
         *                                              { "la", ""}, {
         *                                      "qProvincias", prov},{
         *                                      "qDepartamentos", dpto},{
         *                                      "qFracciones", frac},{
         *                                      "qRadios", radio},{
         *                                      "extent", extent},{
         *                                      "old_mapa_x", ""},{
         *                                      "old_mapa_y", ""},{
         *                                      "mode", "9"},{
         *                                      "layer_g_Provincias", "on"},					{
         *                                      "togglecapa", "i_consultas"},{
         *                                      "zsize", "1"},{
         *                                      "zoomdir", "eco"},{
         *                                      "ver_escala", "1"},{
         *                                      "escala", "26000"} };
         *                      //extent:1688948 3601619.5 5996706 7909377.5
         *                      // 4026334.96104 6061347.65263 4031832.35085 6066845.04243
         *
         *                      var response = Post(url, args);
         *                      string name = "prov" + prov + "-" + dpto + "-" + frac + "-" + radio;
         *                      string htmlRoot = Saver(response, name, prov);
         *                      int i = htmlRoot.IndexOf("/temp/image");
         *                      int iEnd = htmlRoot.IndexOf(".gif", i);
         *                      string gif = url2 + htmlRoot.Substring(i, iEnd - i + 4);
         *                      var argument = gif;
         *
         *                      byte[] response2 = null;
         *                      using (WebDownload client = new WebDownload())
         *                      {
         *                              int tries = 0;
         *                      retry2:
         *                              try
         *                              {
         *                                      response2 = client.DownloadData(gif);
         *                              }
         *                              catch
         *                              {
         *                                      tries++;
         *                                      if (tries == 4)
         *                                              throw;
         *                                      Thread.Sleep(20 * 1000);
         *                                      goto retry2;
         *                              }
         *                      }
         *                      Saver(response2, name + ".gif", prov);
         *                      //Process.Start("iexplore.exe", argument);
         *                      //MessageBox.Show("Traje " + radios.Count.ToString() + " radios");
         *                      Thread.Sleep(5 * 1000);
         *                      return radios;
         *              }
         *
         */
        private void getMapaRadio(string prov, string dpto, string frac, string radio, string extent)
        {
            string name = "prov" + prov + "-" + dpto + "-" + frac + "-" + radio;

            mapCount++;
            Console.WriteLine("Getting MAP " + name + " (" + mapCount.ToString() + ")...");
            if (isDone(name + ".gif", prov))
            {
                return;
            }
            //return;
            List <string> radios = new List <string>();
            var           args   = new NameValueCollection()
            {
                { "la", "" }, {
                    "qProvincias", prov
                }, {
                    "qDepartamentos", dpto
                }, {
                    "qFracciones", frac
                }, {
                    "qRadios", radio
                }, {
                    "extent", extent
                }, {
                    "old_mapa_x", ""
                }, {
                    "old_mapa_y", ""
                }, {
                    "mode", "14"
                }, {
                    "togglecapa", "i_selectores"
                }, {
                    "zsize", "1"
                }, {
                    "zoomdir", "pan"
                }, {
                    "ver_escala", "2"
                }, {
                    "escala", "26000"
                }
            };

            //extent:1688948 3601619.5 5996706 7909377.5
            // 4026334.96104 6061347.65263 4031832.35085 6066845.04243
retry3:
            var response = Post(url, args);

            if (response == null)
            {
                string file = resolveFilename("timeouts", "");
                Console.WriteLine("Timeout");
                File.AppendAllText(file, name + Environment.NewLine);
                return;
            }
            string htmlRoot = Saver(response, name, prov);
            var    notFound = htmlRoot.IndexOf("No encontr&eacute; cobertura para");

            if (notFound > 0)
            {
                Console.WriteLine("Error");
                string file = resolveFilename("errors", "");
                File.AppendAllText(file, htmlRoot.Substring(notFound) + Environment.NewLine);
                return;
            }
            Console.WriteLine("Gotfile!");
            int    i        = htmlRoot.IndexOf("/temp/image");
            int    iEnd     = htmlRoot.IndexOf(".gif", i);
            string gif      = url2 + htmlRoot.Substring(i, iEnd - i + 4);
            var    argument = gif;

            byte[] response2 = null;
            using (WebDownload client = new WebDownload())
            {
                int tries = 0;
retry2:
                try
                {
                    response2 = client.DownloadData(gif);
                }
                catch
                {
                    tries++;
                    if (tries == 8)
                    {
                        throw;
                    }
                    Thread.Sleep(30 * 1000);
                    goto retry3;
                }
            }
            Saver(response2, name + ".gif", prov);
            //Process.Start("iexplore.exe", argument);
            //MessageBox.Show("Traje " + radios.Count.ToString() + " radios");
            Thread.Sleep(1 * 1000);
        }
Exemplo n.º 2
0
        public void getMapaRadio(RadioInfo radio, string extent, bool useHiResNames = false)
        {
            mapCount++;
            if (radio.isDone(useHiResNames))
            {
                if (mapCount % 50 == 0)
                {
                    Console.Write(".");
                }
                return;
            }
            Console.WriteLine("Getting MAP " + radio.makeName() + " (" + mapCount.ToString() + ")...");
            //return;
            List <string> radios = new List <string>();
            var           args   = new NameValueCollection()
            {
                { "la", "" }, {
                    "qProvincias", radio.Prov
                }, {
                    "qDepartamentos", radio.Dpto
                }, {
                    "qFracciones", radio.Fraccion
                }, {
                    "qRadios", radio.Radio
                }, {
                    "extent", extent
                }, {
                    "old_mapa_x", ""
                }, {
                    "old_mapa_y", ""
                }, {
                    "mode", "14"
                }, {
                    "togglecapa", "i_selectores"
                }, {
                    "zsize", "1"
                }, {
                    "zoomdir", "pan"
                }, {
                    "ver_escala", "2"
                }, {
                    "escala", "26000"
                }
            };

            //extent:1688948 3601619.5 5996706 7909377.5
            // 4026334.96104 6061347.65263 4031832.35085 6066845.04243
retry3:
            var response = Post(Context.url, args);

            if (response == null)
            {
                Context.Log("timeouts", radio);
                return;
            }
            string htmlRoot = Saver(response, radio, useHiResNames);
            var    notFound = htmlRoot.IndexOf("No encontr&eacute; cobertura para");

            if (notFound > 0)
            {
                Context.Log("no_covered", radio.makeKey());
                return;
            }
            Console.WriteLine("Gotfile!");
            int i = htmlRoot.IndexOf("/temp/image");

            if (i == -1)
            {
                Context.Log("errors", "No map for radio " + radio.makeName());
                return;
            }

            int    iEnd     = htmlRoot.IndexOf(".gif", i);
            string gif      = Context.url2 + htmlRoot.Substring(i, iEnd - i + 4);
            var    argument = gif;

            byte[] response2 = null;
            using (WebDownload client = new WebDownload())
            {
                int tries = 0;
retry2:
                try
                {
                    response2 = client.DownloadData(gif);
                    Thread.Sleep(1 * 1000);
                }
                catch
                {
                    tries++;
                    if (tries == 8)
                    {
                        throw;
                    }
                    Thread.Sleep(30 * 1000);
                    goto retry3;
                }
            }
            GifSaver(response2, radio, useHiResNames);
            //Process.Start("iexplore.exe", argument);
            //MessageBox.Show("Traje " + radios.Count.ToString() + " radios");
        }
        /// <summary>
        /// Seller Portal处理新产品图片
        /// </summary>
        public static void SellerPortalProductRequestForNewProduct()
        {
            WriteLog("\r\n" + DateTime.Now + "------------------- Begin-------------------------");
            WriteLog("\r\n" + DateTime.Now + "对Seller新建商品导入job开始运行......");

            #region 处理商品描述外链(新品创建)

            WriteLog("\r\n" + DateTime.Now + "正在处理商品详细信息描述Start......");
            List <ItemVendorProductRequestEntity> productRequestDescLongList = SellerPortalProductDescAndImageDA.GetSellerPortalProductRequestDescLongList();

            //获取ExInfoStatus为P的,详细信息描述列表
            //insert into ProductRequest_ProcessLog,记录原来的详细描述值
            //update ProductRequest_Ex表
            //update ipp3.dbo.Product
            //update OverseaContentManagement.dbo.ProductCommonInfo_Ex
            foreach (ItemVendorProductRequestEntity item in productRequestDescLongList)
            {
                string mailbody = string.Empty;
                using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(0, 5, 0)))
                {
                    WriteLog("\r\n" + DateTime.Now + "正在处理商品详细信息:" + item.SysNo.ToString() + " Start......");
                    if (string.IsNullOrEmpty(item.ProductDescLong))
                    {
                        //如果详细信息描述无img Src处理,则把ExInfoStatus修改为"F"
                        SellerPortalProductDescAndImageDA.UpdateSellerPortalProductRequestExInfoStatus(item.SysNo);
                    }
                    else
                    {
                        //string productDescLong = GetProductDescLong(item.ProductDescLong, item.SysNo);
                        string        productDescLong = item.ProductDescLong;
                        bool          isError         = false;
                        List <string> imageSrcList    = new List <string>();
                        List <string> imageUrlList    = new List <string>();
                        if (item.ProcessCount == 0)//处理新商品的描述信息
                        {
                            //过滤html,js,css代码
                            productDescLong = RemoveHtmlStr(item.ProductDescLong);

                            //读取Img标签的SRC
                            imageSrcList = GetImageSrc(productDescLong);
                            //读取URL标签中的图片地址
                            imageUrlList = GetImageUrl(productDescLong);

                            imageSrcList.AddRange(imageUrlList);
                            imageSrcList = imageSrcList.Distinct().ToList();
                        }
                        else
                        {
                            //获取处理成功的图片信息
                            SellerPortalProductDescAndImageDA.GetProductRequestImageListLog(item.SysNo, "F").ForEach(p =>
                            {
                                productDescLong.Replace(p.ImageUrl, Path.Combine(ProductDescLongImageUrl, p.ImageName));
                            });
                            //获取处理失败的图片信息
                            imageSrcList = SellerPortalProductDescAndImageDA.GetProductRequestImageListLog(item.SysNo, "E").Select(p =>
                            {
                                return(p.ImageUrl);
                            }).ToList();

                            //获取未处理的图片信息
                            List <string> notBeginList = SellerPortalProductDescAndImageDA.GetProductRequestImageListLog(item.SysNo, "O").Select(p =>
                            {
                                return(p.ImageUrl);
                            }).ToList();
                            imageSrcList.AddRange(notBeginList);
                        }
                        //有需要处理的img图片链接
                        if (imageSrcList.Count > 0)
                        {
                            #region Process Each ImageScr
                            foreach (string imageSrc in imageSrcList)
                            {
                                if (imageSrc.Equals(""))
                                {
                                    continue;
                                }
                                string status   = "O";
                                string memo     = "未下载";
                                string fileName = string.Empty;
                                if (!isError)
                                {
                                    WriteLog("\r\n" + DateTime.Now + "正在处理商品详细信息图片:" + imageSrc + "Start......");

                                    if (WhiteList_Check_IsExists(imageSrc))
                                    {
                                        int delay = 100;
                                        if (!int.TryParse(FriendlyDelay, out delay))
                                        {
                                            delay = 100;
                                        }
                                        Thread.Sleep(delay);
                                    }
                                    else
                                    {
                                        int delay = 500;
                                        if (!int.TryParse(DefaultDelay, out delay))
                                        {
                                            delay = 500;
                                        }
                                        Thread.Sleep(delay);
                                    }

                                    try
                                    {
                                        WriteLog("\r\n" + DateTime.Now + "正在验证图片请求地址的可访问性......");
                                        HttpWebRequest req = HttpWebRequest.Create(imageSrc) as HttpWebRequest;
                                        req.Method  = "HEAD";
                                        req.Timeout = 5000;
                                        //--------------------发布要取消代理-----------------------
                                        if (ByProxy == "Y")
                                        {
                                            proxy             = new WebProxy(ByProxyHost, string.IsNullOrEmpty(ByProxyPort) ? 8080 : int.Parse(ByProxyPort));
                                            proxy.Credentials = new NetworkCredential(ByProxyUser, ByProxyPassword);
                                            req.Proxy         = proxy;
                                        }
                                        WriteLog("\r\n\t\t" + "请求超时时间:" + req.Timeout.ToString() + "ms");
                                        //--------------------发布要取消代理-----------------------
                                        HttpWebResponse res        = req.GetResponse() as HttpWebResponse;
                                        int             statuscode = (int)res.StatusCode;
                                        WriteLog("\r\n\t\t" + "请求响应状态:" + statuscode.ToString() + "\t" + "详细描述:" + res.StatusDescription);
                                        if (res.StatusCode == HttpStatusCode.OK)
                                        {
                                            string fileType = "";
                                            switch (res.ContentType)
                                            {
                                            case "image/jpeg":
                                                fileType = ".jpg";
                                                break;

                                            case "image/bmp":
                                                fileType = ".bmp";
                                                break;

                                            case "image/gif":
                                                fileType = ".gif";
                                                break;

                                            case "image/png":
                                                fileType = ".png";
                                                break;
                                            }
                                            //新文件名
                                            fileName = Guid.NewGuid().ToString() + fileType;
                                            WebDownload myWebClient = new WebDownload();
                                            myWebClient.Timeout = req.Timeout;

                                            //本地测试需要设置代理
                                            if (ByProxy == "Y")
                                            {
                                                myWebClient.Proxy = proxy;
                                            }
                                            Image  uploadImage = Image.FromStream(new MemoryStream(myWebClient.DownloadData(imageSrc)));
                                            string dFilePath   = ImageServicePath;
                                            if (!Directory.Exists(dFilePath))
                                            {
                                                Directory.CreateDirectory(dFilePath);
                                            }
                                            uploadImage.Save(dFilePath + fileName);

                                            //替换原始文件名称
                                            productDescLong = productDescLong.Replace(imageSrc, ProductDescLongImageUrl + fileName);
                                        }
                                        else
                                        {
                                            isError = true;
                                            memo    = res.StatusDescription;
                                        }
                                        res.Close();
                                    }
                                    catch (Exception ex)
                                    {
                                        isError = true;
                                        WriteLog("\r\n" + DateTime.Now + " 商品详细描述图片获取失败!" + imageSrc + ex.Message + ex.StackTrace);
                                        memo = ex.Message;
                                    }

                                    if (isError)
                                    {
                                        //ProductRequest_Ex count + 1
                                        SellerPortalProductDescAndImageDA.SetProductRequestExCount(item.SysNo);

                                        status = "E";
                                        if (item.ProcessCount >= 5)
                                        {
                                            mailbody = string.Format(mailbodyTemplate, item.C3Name, item.ProductID, item.ProductName, memo, item.PMName);
                                        }
                                        fileName = string.Empty;
                                    }
                                    else
                                    {
                                        status = "F";
                                        memo   = "";
                                    }

                                    WriteLog("\r\n" + DateTime.Now + "正在处理商品详细信息图片:" + imageSrc + ".End.....");
                                }
                                SellerPortalProductDescAndImageDA.InsertProductRequestImageProcessLog(imageSrc, fileName, item.SysNo, status, memo);
                            }
                            #endregion Process Each ImageScr
                        }
                        if (!isError)
                        {
                            SellerPortalProductDescAndImageDA.ApproveProductRequest_Ex(item.SysNo, productDescLong);
                        }
                        else if (item.ProcessCount >= 5)
                        {
                            SellerPortalProductDescAndImageDA.SendMailIMGProcFail("(Info)商家商品详细描述信息处理失败[JOB]", mailbody);
                        }
                    }
                    scope.Complete();
                    WriteLog("\r\n" + DateTime.Now + "正在处理商品详细信息:" + item.SysNo.ToString() + "End......");
                }
            }


            WriteLog("\r\n" + DateTime.Now + "正在处理商品详细信息描述End......");
            #endregion

            #region 存在未处理的新品图片
            List <ItemVendorProductRequestFileEntity> requestImageList = SellerPortalProductDescAndImageDA.GetSellerPortalProductRequestImageList();
            if (requestImageList.Count > 0)
            {
                foreach (ItemVendorProductRequestFileEntity item in requestImageList)
                {
                    try
                    {
                        WriteLog("\r\n" + DateTime.Now + "正在处理品商:" + item.CommonSKUNumber.ToString() + "......");
                        DefaultDataContract rtn     = new DefaultDataContract();
                        ProductDFISImage    service = new ProductDFISImage();

                        EntityHeader header = new EntityHeader();
                        header.CompanyCode                      = CompanyCode;
                        header.Language                         = LanguageCode;
                        header.OriginalGUID                     = Guid.NewGuid().ToString();
                        header.OperationUser                    = new OperationUserEntity();
                        header.OperationUser.FullName           = InUser;
                        header.OperationUser.CompanyCode        = "8601";
                        header.OperationUser.LogUserName        = "******";
                        header.OperationUser.SourceDirectoryKey = "bitkoo";
                        header.OperationUser.SourceUserName     = InUser;
                        header.OperationUser.UniqueUserName     = "******";
                        rtn = service.UploadSendorPortalImageList(item.SysNo, item.GroupSysNo, item.comskuSysNo, item.CommonSKUNumber, header);

                        if (rtn.Faults != null && rtn.Faults.Count > 0)
                        {
                            WriteLog("\r\n" + DateTime.Now + "商品:" + item.CommonSKUNumber.ToString() + " 处理失败......");
                            WriteLog("\r\n" + rtn.Faults[0].ErrorDescription);
                        }
                        else
                        {
                            WriteLog("\r\n" + DateTime.Now + "商品:" + item.CommonSKUNumber.ToString() + " 处理成功......");
                        }
                    }
                    catch (Exception ex)
                    {
                        WriteLog("\r\n" + DateTime.Now + "商品:" + item.CommonSKUNumber.ToString() + " 处理失败......");
                        WriteLog("\r\n" + ex.Message);
                    }
                }
            }
            else
            {
                WriteLog("\r\n" + DateTime.Now + " 无商品图片处理......");
            }
            #endregion

            using (TransactionScope scope = new TransactionScope())
            {
                #region count>5,删除ProductRequest_Files表记录,同时在表ProductRequest_ProcessLog增加log日志
                List <ItemVendorProductRequestFileEntity> exceedFiveCountList = SellerPortalProductDescAndImageDA.GetExceedFiveCountList();
                if (exceedFiveCountList.Count > 0)
                {
                    foreach (ItemVendorProductRequestFileEntity li in exceedFiveCountList)
                    {
                        WriteLog("\r\n" + DateTime.Now + "正在处理失败>5的商品:" + li.SysNo.ToString() + "开始......");
                        SellerPortalProductDescAndImageDA.DeleteSellerPortalProductRequestImageFiles(li.SysNo);
                        ItemVendorProductRequestEntity item = SellerPortalProductDescAndImageDA.GetSellerPortalProductRequestBySysNo(li.ProductRequestSysno);
                        string mailbody = string.Format(mailbodyTemplate, item.C3Name, item.ProductID, item.ProductName, "", item.PMName);
                        SellerPortalProductDescAndImageDA.SendMailIMGProcFail("(Info)商家商品图片信息处理失败[JOB]", mailbody);
                        WriteLog("\r\n" + DateTime.Now + "处理失败>5的商品:" + li.SysNo.ToString() + "成功!......");
                    }
                }
                #endregion

                #region 查询详细描述图片每个ProductRequestSysno都为"F"的list,然后处理其ExInfoStatus为F
                List <ProductRequestImage> longDescFStatusList = SellerPortalProductDescAndImageDA.GetSellerPortalProductLongDescFStatusList();
                if (longDescFStatusList.Count > 0)
                {
                    foreach (ProductRequestImage li in longDescFStatusList)
                    {
                        //WriteLog("\r\n" + DateTime.Now + "正在处理商品:" + li.ProductRequestSysno.ToString() + "的FileStatus状态为F......");
                        SellerPortalProductDescAndImageDA.UpdateSellerPortalProductRequestExInfoStatus(li.ProductRequestSysNo);
                        SellerPortalProductDescAndImageDA.InsertProductDescProductRequest_ProcessLog(li.ProductRequestSysNo);
                        //WriteLog("\r\n" + DateTime.Now + "商品:" + li.ProductRequestSysno.ToString() + "的FileStatus状态成功修改为F......");
                    }
                }
                #endregion

                #region 查询图片每个ProductRequestSysno都为"F"的list,然后处理其FileStatus为F
                List <ItemVendorProductRequestFileEntity> imageFilesFStatusList = SellerPortalProductDescAndImageDA.GetSellerPortalImageFFilesFStatusList();
                if (imageFilesFStatusList.Count > 0)
                {
                    foreach (ItemVendorProductRequestFileEntity li in imageFilesFStatusList)
                    {
                        //WriteLog("\r\n" + DateTime.Now + "正在处理商品:" + li.ProductRequestSysno.ToString() + "的FileStatus状态为F......");
                        SellerPortalProductDescAndImageDA.UpdateSellerPortalProductRequestFileStatus(li.ProductRequestSysno);
                        //WriteLog("\r\n" + DateTime.Now + "商品:" + li.ProductRequestSysno.ToString() + "的FileStatus状态成功修改为F......");
                    }
                }
                #endregion

                #region 处理三个状态都 BasicInfoStatus = "F",FileStatus = "F",ExInfoStatus = "F",则Status = "F"
                List <ItemVendorProductRequestFileEntity> threeFStatusList = SellerPortalProductDescAndImageDA.GetSellerPortalThreeFStatusList();
                if (threeFStatusList.Count > 0)
                {
                    foreach (ItemVendorProductRequestFileEntity li in threeFStatusList)
                    {
                        WriteLog("\r\n" + DateTime.Now + "正在处理商品:" + li.ProductRequestSysno.ToString() + "的Status状态为F......");
                        SellerPortalProductDescAndImageDA.UpdateSellerPortalProductRequestStatus(li.ProductRequestSysno, "F");

                        //同步SellPortal表状态
                        SellerPortalProductDescAndImageDA.CallExternalSP(li.ProductRequestSysno);

                        WriteLog("\r\n" + DateTime.Now + "商品:" + li.ProductRequestSysno.ToString() + "的Status状态成功修改为F......");
                    }
                }
                #endregion


                scope.Complete();
            }

            WriteLog("\r\n" + DateTime.Now + "Job.......END......");
        }