Esempio n. 1
0
 private void SendMessageToServiceThumbImage(ThumbImageProductInfo thumbImageInfo, ProducerBasic thumbImageJobClient)
 {
     while (_isRunning)
     {
         try
         {
             thumbImageJobClient.Publish(ThumbImageProductInfo.GetMessage(thumbImageInfo));
             //Log.Info(string.Format("Push message to services thumb image = {0}", thumbImageInfo.ProductId));
             break;
         }
         catch (Exception exception)
         {
             Log.Error(string.Format("Push message to services thumb image = {0} error.", thumbImageInfo.ProductId), exception);
             Thread.Sleep(60000);
         }
     }
 }
Esempio n. 2
0
        private void DownloadImageRootProduct(ImageProductInfo imageProductInfo, JobClient updateImagePathProductJobClient, ProducerBasic thumbImageJobClient)
        {
            var fileName = Common.UnicodeToKoDauAndGach(imageProductInfo.Name);

            if (fileName.Length > 100)
            {
                fileName = fileName.Substring(0, 99);
            }
            fileName += ".jpg";
            try
            {
                var folder = Common.GetFolderSaveImageRootProduct(fileName);
                Common.SaveImageProduct(imageProductInfo.ImageUrls, _pathImageRootProduct + folder, fileName);
                imageProductInfo.ImagePath      = Common.GetImagePathRootProduct(folder, fileName);
                imageProductInfo.DownloadedTime = DateTime.Now;
                SendMessageToServiceUpdateImagePath(imageProductInfo, updateImagePathProductJobClient);
                var fulldirectory  = _pathImageProduct.Replace("\\", @"\") + folder.Replace("\\", @"\") + fileName;
                var thumbImageInfo = new ThumbImageProductInfo()
                {
                    ProductId          = imageProductInfo.Id,
                    FileNameImage      = fileName,
                    FolderImage        = folder.Replace("\\", @"\"),
                    FullDirectoryImage = fulldirectory,
                    SizeImage          = widthHeightImages,
                    TypeProduct        = 2
                };
                SendMessageToServiceThumbImage(thumbImageInfo, thumbImageJobClient);
                Log.Info(string.Format("RootProduct: ID = {0} download image success!", imageProductInfo.Id));
            }
            catch (Exception exception)
            {
                Log.Error(string.Format("RootProduct: ID = {0}. ImageUrl: {1} . DetailUrl: {2}", imageProductInfo.Id, imageProductInfo.ImageUrls, imageProductInfo.DetailUrl), exception);
                imageProductInfo.ErrorMessage = exception.ToString();
                SendErrorDownloadImageToService(imageProductInfo);
            }
        }