Beispiel #1
0
 public void SendErrorDownloadImageToService(ImageProductInfo imageProductInfo)
 {
     lock (_keyLock)
     {
         int index = 0;
         var job   = new Job {
             Data = ImageProductInfo.GetMessage(imageProductInfo)
         };
         while (_isRunning)
         {
             try
             {
                 _checkErrorJobClient.PublishJob(job);
                 //Log.Info(string.Format("Push message to services checkerror = {0}", imageProductInfo.Id));
                 break;
             }
             catch (Exception exception)
             {
                 Thread.Sleep(60000);
                 Log.Error(
                     string.Format("Product: ID = {0} Send message to service check error download image.",
                                   imageProductInfo.Id), exception);
                 if (index == 5)
                 {
                     break;
                 }
                 else
                 {
                     index++;
                 }
             }
         }
     }
 }
Beispiel #2
0
        private void UploadImageButton_Click(object sender, EventArgs e)
        {
            long productid = CommonUtilities.Object2Long(iDTextBox.Text, 0);

            if (productid != 0)
            {
                if (string.IsNullOrEmpty(imageUrlsTextEdit.Text))
                {
                    MessageBox.Show("Kiểm tra Image url!!!");
                }
                else
                {
                    if (_rabbitMqServer == null)
                    {
                        _rabbitMqServer = RabbitMQManager.GetRabbitMQServer(ConfigImages.RabbitMqServerName);
                    }
                    if (_downloadImageProductJobClient == null)
                    {
                        _downloadImageProductJobClient = new JobClient(ConfigImages.ImboExchangeImages, GroupType.Topic, ConfigImages.ImboRoutingKeyDownloadImageRootProduct, true, _rabbitMqServer);
                    }
                    ImageProductInfo product = new ImageProductInfo();
                    product.Id        = productid;
                    product.ImageUrls = imageUrlsTextEdit.Text;
                    try
                    {
                        _downloadImageProductJobClient.PublishJob(new Job()
                        {
                            Data = ImageProductInfo.GetMessage(product)
                        });
                        UploadImageButton.Visible = false;
                        MessageBox.Show("Push message thành công");
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Error: " + ex.Message);
                    }
                }
            }
            else
            {
                MessageBox.Show("ERROR : ID product = 0.");
            }
        }
Beispiel #3
0
        public bool DownloadImageProduct(ImageProductInfo imageProductInfo, ProducerBasic producerUpdateImageIdSql)
        {
            bool result = false;

            try
            {
                if (!string.IsNullOrEmpty(imageProductInfo.ImageUrls))
                {
                    var idImbo = Common.DownloadImageProductWithImboServer(imageProductInfo.ImageUrls, ConfigImbo.PublicKey, ConfigImbo.PrivateKey, "wss", ConfigImbo.Host, ConfigImbo.Port);
                    //var idImbo = Common.DownloadImageProductWithImboServer(imageProductInfo.ImageUrls, ConfigImbo.PublicKey, ConfigImbo.PrivateKey, "wss", ConfigImbo.Host, ConfigImbo.Port);
                    if (!string.IsNullOrEmpty(idImbo))
                    {
                        UpdateImageIdSqlService(imageProductInfo.Id, idImbo, producerUpdateImageIdSql);
                        Log.Info(string.Format("Product: ID = {0} download image success!", imageProductInfo.Id));

                        producerCountDownloaded.Publish(ImageProductInfo.GetMessage(imageProductInfo));
                        result = true;
                    }
                    else
                    {
                        //UpdateImageIdSqlService(imageProductInfo.Id, "", producerUpdateImageIdSql);
                        imageProductInfo.ErrorMessage = "IDImbo = null";
                        SendErrorDownloadImageToService(imageProductInfo);
                        producerCountDownloadError.Publish(ImageProductInfo.GetMessage(imageProductInfo));
                    }
                }
                else
                {
                    imageProductInfo.ErrorMessage = "ImageUrls = null";
                    producerCountDownloadError.Publish(ImageProductInfo.GetMessage(imageProductInfo));
                    UpdateImageIdNullToSql(imageProductInfo);
                }
            }
            catch (Exception exception)
            {
                Log.Error(string.Format("Product: ID = {0}. ImageUrl: {1} . DetailUrl: {2}", imageProductInfo.Id, imageProductInfo.ImageUrls, imageProductInfo.DetailUrl), exception);
                imageProductInfo.ErrorMessage = exception.ToString();
                SendErrorDownloadImageToService(imageProductInfo);
                UpdateImageIdNullToSql(imageProductInfo);
                producerCountDownloadError.Publish(ImageProductInfo.GetMessage(imageProductInfo));
            }
            return(result);
        }
Beispiel #4
0
 public void PushQueueChangeChangeImage(ImageProductInfo mss)
 {
     while (true)
     {
         try
         {
             _jobClient.PublishJob(new Websosanh.Core.JobServer.Job()
             {
                 Data = ImageProductInfo.GetMessage(mss)
             });
             return;
         }
         catch (Exception ex01)
         {
             _log.Error(string.Format("Error push job ChangeMainInfo to MQ:{0}.{1}", ex01.Message, ex01.StackTrace));
             Thread.Sleep(10000);
         }
     }
 }
Beispiel #5
0
        private bool DownloadImageProduct(Product productInfo, JobClient updateImagePathProductJobClient, JobClient checkErrorJobClient)
        {
            var result   = false;
            var fileName = productInfo.Name;

            if (fileName.Length > 100)
            {
                fileName = fileName.Substring(0, 99);
            }
            fileName += "_" + productInfo.ID;
            try
            {
                var folder = Common.GetFolderSaveImageProduct(fileName, productInfo.DetailUrl);
                Common.SaveImageProduct(productInfo.ImageUrls, _pathImageProduct + folder, fileName + ".jpg");
                var job = new Job
                {
                    Data = ImageProductInfo.GetMessage(new ImageProductInfo()
                    {
                        Id        = productInfo.ID,
                        ImagePath = Common.GetImagePath(folder, fileName)
                    })
                };
                updateImagePathProductJobClient.PublishJob(job);
                result = true;
            }
            catch (Exception exception)
            {
                Log.Error(string.Format("Product: ID = {0}. ImageUrl: {1} . DetailUrl: {2}", productInfo.ID, productInfo.ImageUrls, productInfo.DetailUrl), exception);
                SendErrorDownloadImageToService(
                    new ImageProductInfo()
                {
                    Id           = productInfo.ID,
                    DetailUrl    = productInfo.DetailUrl,
                    ImageUrls    = productInfo.ImageUrls,
                    Name         = productInfo.Name,
                    ErrorMessage = exception.ToString(),
                    Type         = 2
                }, checkErrorJobClient);
            }
            return(result);
        }
Beispiel #6
0
        private void ResendToServiceDownloadImageProduct(ImageProductInfo imageProductInfo, JobClient downloadImageProductJobClient)
        {
            var job = new Job {
                Data = ImageProductInfo.GetMessage(imageProductInfo)
            };

            while (_isRunning)
            {
                try
                {
                    downloadImageProductJobClient.PublishJob(job);
                    Log.Info(string.Format("Resend to services download image productid {0}", imageProductInfo.Id));
                    break;
                }
                catch (Exception ex)
                {
                    Log.Error(string.Format("ProductId = {0} resend message to service downloadimageproduct.", imageProductInfo.Id), ex);
                    Thread.Sleep(120000);
                }
            }
        }
Beispiel #7
0
        public void SendErrorDownloadImageToService(ImageProductInfo imageProductInfo, JobClient errorJobClient)
        {
            var job = new Job {
                Data = ImageProductInfo.GetMessage(imageProductInfo)
            };

            while (!_checkStop)
            {
                try
                {
                    errorJobClient.PublishJob(job);
                    break;
                }
                catch (Exception ex)
                {
                    Thread.Sleep(30000);
                    Log.Error(string.Format("ProductId = {0} Send message check error download image fail.",
                                            imageProductInfo.Id), ex);
                }
            }
        }
Beispiel #8
0
        private void SendMessageDownloadImageProduct(Product product, JobClient downloadImageProductJobClient, bool isNews)
        {
            var imageProductInfo = new ImageProductInfo(product.ID, product.Name, product.DetailUrl, product.ImageUrl, isNews);
            var job = new Job {
                Data = ImageProductInfo.GetMessage(imageProductInfo)
            };

            while (_isRunning)
            {
                try
                {
                    downloadImageProductJobClient.PublishJob(job);
                    Log.Info(string.Format("Resend to services download image productid {0}", imageProductInfo.Id));
                    break;
                }
                catch (Exception ex)
                {
                    Log.Error(string.Format("ProductId = {0} resend message to service downloadimageproduct.", imageProductInfo.Id), ex);
                    Thread.Sleep(120000);
                }
            }
        }
Beispiel #9
0
        private void SendMessageToServiceUpdateImagePath(ImageProductInfo imageProductInfo, JobClient updateImagePathProductJobClient)
        {
            var job = new Job {
                Data = ImageProductInfo.GetMessage(imageProductInfo)
            };

            while (_isRunning)
            {
                try
                {
                    updateImagePathProductJobClient.PublishJob(job);
                    //Log.Info(string.Format("Push message to services update imagepath = {0}", imageProductInfo.Id));
                    break;
                }
                catch (Exception exception)
                {
                    Thread.Sleep(60000);
                    Log.Error(
                        string.Format("Product: ID = {0} Send message to service update imagepath error.",
                                      imageProductInfo.Id), exception);
                }
            }
        }
Beispiel #10
0
        public override void ProcessMessage(BasicDeliverEventArgs message)
        {
            try
            {
                var pt = ProductEntity.GetFromJson(message.Body);
                if (pt.StatusChange.IsDelete)
                {
                    string    sql = string.Format(@"select top 1 p.DetailUrl, p.Name, p.Price, p.CategoryID, p.LastUpdate, p.ImagePath, p.ImageUrls, p.ImageId, p.ID
	from Product p
	where p.ID = {0} "    , pt.ID);
                    DataTable tbl = _productAdapter.GetSqlDb().GetTblData(sql, CommandType.Text, null);
                    if (tbl.Rows.Count > 0 && _productAdapter.DeleteProduct(pt.ID))
                    {
                        _log.Info("Deleted Success product: " + pt.ID + pt.DetailUrl);
                        var    row1      = tbl.Rows[0];
                        string imgId     = Common.Obj2String(row1["ImageId"]);
                        var    objBackUp = new JobBackupProductToDel()
                        {
                            Id         = Common.Obj2Int64(row1["ID"]),
                            Price      = Common.Obj2Int64(row1["Price"]),
                            ImageId    = imgId,
                            ImageUrl   = Common.Obj2String(row1["ImageUrls"]),
                            Name       = Common.Obj2String(row1["Name"]),
                            ProductUrl = Common.Obj2String("DetailUrl")
                        };
                        RabbitMQAdapter.Instance.PushProductToQueueChangeMainInfo(new List <long>()
                        {
                            pt.ID
                        });
                        if (!string.IsNullOrEmpty(imgId))
                        {
                            _producerDelImgImbo.PublishString(imgId);
                        }
                        _producerLogDelProduct.PublishString(objBackUp.ToJson());
                    }
                }
                else if (pt.StatusChange.IsDuplicate)
                {
                    if (_productAdapter.DeleteProduct(pt.ID))
                    {
                        _log.Info("Deleted  duplicate: " + pt.ID + pt.DetailUrl);
                        RabbitMQAdapter.Instance.PushProductToQueueChangeMainInfo(new List <long>()
                        {
                            pt.ID
                        });
                    }
                }
                else if (pt.StatusChange.IsNew)
                {
                    if (_productAdapter.InsertProduct(pt))
                    {
                        _jobClient.PublishJob(new Websosanh.Core.JobServer.Job()
                        {
                            Data = ImageProductInfo.GetMessage(new ImageProductInfo(pt.ID, pt.Name, pt.DetailUrl, pt.ImageUrl, true))
                        });
                        _producerLogAddProduct.PublishString(Newtonsoft.Json.JsonConvert.SerializeObject(new JobRabbitAddProduct()
                        {
                            DateAdd   = DateTime.Now,
                            DetailUrl = pt.DetailUrl,
                            IDCompnay = pt.CompanyId,
                            Name      = pt.Name,
                            ProductID = pt.ID
                        }));
                        _log.Info(string.Format("Company: {0} Inserted product: {1}", pt.CompanyId, pt.ID));
                    }
                }
                else
                {
                    if (_productAdapter.UpdateProduct(pt))
                    {
                        _log.Info(string.Format("Company: {0} Updated product: {1}", pt.CompanyId, pt.ID));

                        if (pt.StatusChange.IsChangeImage)
                        {
                            _jobClient.PublishJob(new Websosanh.Core.JobServer.Job()
                            {
                                Data = ImageProductInfo.GetMessage(new ImageProductInfo(pt.ID, pt.Name, pt.DetailUrl, pt.ImageUrl, false))
                            });
                        }
                        RabbitMQAdapter.Instance.PushProductToQueueChangeMainInfo(new List <long>()
                        {
                            pt.ID
                        });
                    }
                }
            }

            catch (Exception ex)
            {
                _log.Error(ex.Message);
            }

            GetChannel().BasicAck(message.DeliveryTag, true);
        }