예제 #1
0
        private bool DownloadImageRootProduct(ImageProductInfo imageProductInfo, ProducerBasic producerUpdateImageIdSql)
        {
            bool result = false;

            try
            {
                var idImbo = Common.DownloadImageProductWithImboServer(imageProductInfo.ImageUrls, ConfigImbo.PublicKey, ConfigImbo.PrivateKey, "root_product", ConfigImbo.Host, ConfigImbo.Port);
                if (!string.IsNullOrEmpty(idImbo))
                {
                    UpdateImageIdSqlService(imageProductInfo.Id, idImbo, producerUpdateImageIdSql);
                    //ThumbImageService(imageProductInfo.Id, idImbo, producerThumbImage);
                    Log.Info(string.Format("RootProduct: ID = {0} download image success!", imageProductInfo.Id));
                    //InsertLogDownloadImageProduct(imageProductInfo.Id);
                    result = true;
                }
                else
                {
                    imageProductInfo.ErrorMessage = "IDImbo = null";
                    SendErrorDownloadImageToService(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);
            }
            return(result);
        }
예제 #2
0
        public static bool DownloadImageRootProduct(ImageProductInfo imageProductInfo, ProducerBasic producerUpdateImageIdSql, ref string messageError)
        {
            bool result = false;

            try
            {
                var idImbo = Common.DownloadImageProductWithImboServer(imageProductInfo.ImageUrls, ConfigImbo.PublicKey, ConfigImbo.PrivateKey, "root_product", 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));
                    messageError = "";
                    result       = true;
                }
                else
                {
                    messageError = "IDImbo null";
                    result       = false;
                }
            }
            catch (Exception exception)
            {
                Log.Error(string.Format("Product: ID = {0}. ImageUrl: {1} . DetailUrl: {2}", imageProductInfo.Id, imageProductInfo.ImageUrls, imageProductInfo.DetailUrl), exception);
                messageError = exception.ToString();
            }
            return(result);
        }
예제 #3
0
        private void SendMessageToServiceInsertHistoryDownload(ImageProductInfo imageProductInfo, JobClient historyJobClient)
        {
            var job = new Job
            {
                Data = LogHistoryImageProduct.GetMessage(new LogHistoryImageProduct()
                {
                    ProductId    = imageProductInfo.Id,
                    DateLog      = DateTime.Now,
                    ErrorName    = imageProductInfo.ErrorMessage,
                    IsDownloaded = false,
                    NewsToValid  = false
                })
            };

            while (_isRunning)
            {
                try
                {
                    historyJobClient.PublishJob(job);
                    Log.Info(string.Format("Push message to services insert history download image productid = {0}",
                                           imageProductInfo.Id));
                    break;
                }
                catch (Exception ex)
                {
                    Log.Error(string.Format("ProductId = {0} Push message to services insert history download image.", imageProductInfo.Id), ex);
                    Thread.Sleep(60000);
                }
            }
        }
예제 #4
0
 public void Download()
 {
     _workers             = new Worker[_workerProduct + _workerCompany + 1];
     _rabbitMqServer      = RabbitMQManager.GetRabbitMQServer(ConfigImages.RabbitMqServerName);
     _checkErrorJobClient = new JobClient(ConfigImages.ImboExchangeImages, GroupType.Topic, ConfigImages.ImboRoutingKeyCheckErrorDownload, true, _rabbitMqServer);
     for (var i = 0; i < _workerProduct; i++)
     {
         var worker = new Worker(ConfigImages.ImboQueueDownloadImageProduct, false, _rabbitMqServer);
         _workers[i] = worker;
         var workerTask = new Task(() =>
         {
             //JobClient send message to service upload sql & thumb của tráng
             var producerUpdateImageIdSql = new ProducerBasic(_rabbitMqServer, ConfigImages.ImboExchangeImages, ConfigImages.ImboRoutingKeyUploadImageIdSql);
             //var producerDelImage = new ProducerBasic(_rabbitMqServer, ConfigImages.ImboExchangeImages, ConfigImages.ImboRoutingKeyThumbImage);
             worker.JobHandler = (downloadImageJob) =>
             {
                 try
                 {
                     DownloadImageProduct(ImageProductInfo.GetDataFromMessage(downloadImageJob.Data), producerUpdateImageIdSql);
                 }
                 catch (Exception exception)
                 {
                     Log.Error("Execute Job Error.", exception);
                 }
                 return(true);
             };
             worker.Start();
         });
         workerTask.Start();
         Log.InfoFormat("Worker {0} started", i);
     }
 }
예제 #5
0
 private void UpdateImageIdNullToSql(ImageProductInfo imageProductInfo)
 {
     using (IDbConnection db = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]))
     {
         db.Execute("Update Product set ImageId = null where Id = @Id", new { Id = imageProductInfo.Id });
     }
 }
예제 #6
0
 public void AddItem(ImageProductInfo productInfo)
 {
     lock (this.objLockRun)
     {
         _imageProductInfos.Add(productInfo);
     }
 }
예제 #7
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++;
                 }
             }
         }
     }
 }
예제 #8
0
        protected override void OnStart(string[] args)
        {
            try
            {
                _workers        = new Worker[_workerCount];
                _rabbitMqServer = RabbitMQManager.GetRabbitMQServer(ConfigImages.RabbitMqServerName);
                //JobClient send message to service update redis (a hoàng)
                _updateSolrAndRedisJobClient = new JobClient(ConfigRabbitMqCacheSolrAndRedis.ExchangeProduct, GroupType.Topic, ConfigRabbitMqCacheSolrAndRedis.RoutingKeyUpdateSolrAndRedis,
                                                             true, _rabbitMqServer);
                for (var i = 0; i < _workerCount; i++)
                {
                    var worker = new Worker(ConfigImages.QueueUpdateImagePath, false, _rabbitMqServer);
                    _workers[i] = worker;

                    var workerTask = new Task(() =>
                    {
                        //JobClient send message to service update redis (a hoàng)
                        var updateRedisJobClient = new JobClient(ConfigRabbitMqCacheSolrAndRedis.ExchangeProductRedis, GroupType.Direct, ConfigRabbitMqCacheSolrAndRedis.RoutingKeyUpdateRedis,
                                                                 true, _rabbitMqServer);
                        //Jobclient send message to service insert log download image
                        var historyJobClient = new JobClient(ConfigImages.ExchangeImages, GroupType.Topic, ConfigImages.RoutingKeyHistoryDownloadImage, true, _rabbitMqServer);
                        worker.JobHandler    = (downloadImageJob) =>
                        {
                            try
                            {
                                var productAdapter = new DBProductTableAdapters.ProductTableAdapter();
                                productAdapter.Connection.ConnectionString = _connectionString;
                                UpdateImagePathProduct(ImageProductInfo.GetDataFromMessage(downloadImageJob.Data), productAdapter, historyJobClient, updateRedisJobClient);
                            }
                            catch (Exception exception)
                            {
                                Log.Error("Execute Job Error.", exception);
                            }
                            return(true);
                        };
                        worker.Start();
                    });
                    workerTask.Start();
                    Log.InfoFormat("Worker {0} started", i);
                }
            }
            catch (Exception exception)
            {
                Log.Error("Start error", exception);
                throw;
            }
        }
예제 #9
0
        private void CheckErrorDownloadImageProduct(ImageProductInfo imageProductInfo, JobClient downloadImageProductJobClient, JobClient historyJobClient)
        {
            //Check số lần download error trên Redis
            var errordownload = RedisErrorDownloadImageProductAdapter.GetErrorDownloadImage(imageProductInfo.Id);

            //errordownload < 5  resend message to service downloadimageproduct
            if (errordownload <= 5)
            {
                errordownload++;
                RedisErrorDownloadImageProductAdapter.SetErrorDownloadImage(imageProductInfo.Id, errordownload);
                ResendToServiceDownloadImageProduct(imageProductInfo, downloadImageProductJobClient);
            }
            else // send to service insert log history download image
            {
                SendMessageToServiceInsertHistoryDownload(imageProductInfo, historyJobClient);
            }
        }
예제 #10
0
 private void btnDownloadByLink_Click(object sender, EventArgs e)
 {
     if (!string.IsNullOrEmpty(iDTextEdit.Text))
     {
         ImageProductInfo product = new ImageProductInfo();
         product.Id        = Common.Obj2Int64(iDTextEdit.Text);
         product.ImageUrls = imageUrlsTextEdit.Text;
         string message = string.Empty;
         if (CommonDownloadImage.DownloadImageProduct(product, _producerUpdateImageIdSql, ref message))
         {
             rbMessage.AppendText(string.Format("ProductId {0} success", product.Id) + System.Environment.NewLine);
         }
         else
         {
             rbMessage.AppendText(string.Format("ProductId {0} success fails: {1}", product.Id, message) + System.Environment.NewLine);
         }
     }
 }
예제 #11
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.");
            }
        }
예제 #12
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);
        }
예제 #13
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);
         }
     }
 }
예제 #14
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);
        }
예제 #15
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);
                }
            }
        }
예제 #16
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);
                }
            }
        }
예제 #17
0
 protected override void OnStart(string[] args)
 {
     try
     {
         _workers        = new Worker[_workerCount];
         _rabbitMqServer = RabbitMQManager.GetRabbitMQServer(ConfigImages.RabbitMqServerName);
         for (var i = 0; i < _workerCount; i++)
         {
             var worker = new Worker(ConfigImages.QueueCheckErrorDownload, false, _rabbitMqServer);
             _workers[i] = worker;
             var workerTask = new Task(() =>
             {
                 //Jobclient resend message to service download image
                 var downloadImageProductJobClient = new JobClient(ConfigImages.ExchangeImages, GroupType.Topic, ConfigImages.RoutingKeyChangeImageProduct, true, _rabbitMqServer);
                 //Jobclient send message to service insert log download image (check image fail 5 rep -> insert to History_DownloadImageProduct)
                 var historyJobClient = new JobClient(ConfigImages.ExchangeImages, GroupType.Topic, ConfigImages.RoutingKeyHistoryDownloadImage, true, _rabbitMqServer);
                 worker.JobHandler    = (downloadImageJob) =>
                 {
                     try
                     {
                         CheckErrorDownloadImageProduct(ImageProductInfo.GetDataFromMessage(downloadImageJob.Data), downloadImageProductJobClient, historyJobClient);
                     }
                     catch (Exception exception)
                     {
                         Log.Error("Execute Job Error.", exception);
                     }
                     return(true);
                 };
                 worker.Start();
             });
             workerTask.Start();
             Log.InfoFormat("Worker {0} started", i);
         }
     }
     catch (Exception exception)
     {
         Log.Error("Start error", exception);
         throw;
     }
 }
예제 #18
0
        public override void ProcessMessage(RabbitMQ.Client.Events.BasicDeliverEventArgs message)
        {
            _rabbitMqServer = RabbitMQManager.GetRabbitMQServer(ConfigImages.RabbitMqServerName);
            //_rabbitMqServerDownload = RabbitMQManager.GetRabbitMQServer("rabbitMqCrlProperties");
            _checkErrorJobClient = new JobClient(ConfigImages.ImboExchangeImages, GroupType.Topic, ConfigImages.ImboRoutingKeyCheckErrorDownload, true, _rabbitMqServer);

            //Tam thoi tat
            //var producerUpdateImageIdSql = new ProducerBasic(_rabbitMqServer, ConfigImages.ImboExchangeImages, ConfigImages.ImboRoutingKeyUploadImageIdSql);

            //tam thoi bat
            var producerUpdateImageIdSql = new ProducerBasic(_rabbitMqServer, "ImboImageBatchTemp", "ImboImage.UpdateImageIdSql.Temp.#");

            try
            {
                DownloadImageProduct(ImageProductInfo.FromJson(Encoding.UTF8.GetString(message.Body)), producerUpdateImageIdSql);
            }
            catch (Exception exception)
            {
                Log.Error("Execute Job Error.", exception);
            }
            this.GetChannel().BasicAck(message.DeliveryTag, true);
        }
예제 #19
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);
                }
            }
        }
예제 #20
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);
                }
            }
        }
예제 #21
0
 private void UpdateImagePathProduct(ImageProductInfo imageProductInfo, ProductTableAdapter productAdapter, JobClient historyJobClient, JobClient updateRedisJobClient)
 {
     while (_isRunning)
     {
         try
         {
             if (productAdapter.Connection.State == ConnectionState.Closed)
             {
                 productAdapter.Connection.Open();
             }
             productAdapter.UpdateImagePathAndValidAndIsNews(imageProductInfo.ImagePath, imageProductInfo.Id);
             Log.Info(string.Format("ProductId {0} : Update ImagePath And Valid success.", imageProductInfo.Id));
             break;
         }
         catch (Exception exception)
         {
             Log.Error(string.Format("ProductId {0} : Update ImagePath And Valid error.", imageProductInfo.Id), exception);
             Thread.Sleep(60000);
         }
     }
     SendMessageToServiceInsertHistoryDownload(new LogHistoryImageProduct
     {
         DateLog      = imageProductInfo.DownloadedTime,
         IsDownloaded = true,
         ErrorName    = string.Empty,
         ProductId    = imageProductInfo.Id,
         NewsToValid  = imageProductInfo.IsNew
     }, historyJobClient);
     if (imageProductInfo.IsNew)
     {
         SendMessageToServiceUpdateSolrAndRedis(imageProductInfo.Id);
     }
     else
     {
         SendMessageToServiceUpdateRedis(imageProductInfo.Id, updateRedisJobClient);
     }
 }
예제 #22
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);
            }
        }
예제 #23
0
        private void btnChooseFile_Click(object sender, EventArgs e)
        {
            DialogResult result = openFileDialog1.ShowDialog();

            if (result == DialogResult.OK)
            {
                lblPath.Text = openFileDialog1.FileName;
                string path = openFileDialog1.FileName;
                if (!string.IsNullOrEmpty(path))
                {
                    ImageProductInfo product = new ImageProductInfo();
                    product.Id = Common.Obj2Int64(iDTextEdit.Text);
                    string message = string.Empty;
                    if (CommonDownloadImage.UploadImageProductByHand(path, product, _producerUpdateImageIdSql, ref message))
                    {
                        rbMessage.AppendText(string.Format("ProductId {0} success", product.Id) + System.Environment.NewLine);
                    }
                    else
                    {
                        rbMessage.AppendText(string.Format("ProductId {0} success fails: {1}", product.Id, message) + System.Environment.NewLine);
                    }
                }
            }
        }
예제 #24
0
        private void DownloadImageWithCompany(long idCompany)
        {
            this.Invoke(new Action(() =>
            {
                rbSuccess.AppendText(string.Format("Start get from Database with CompanyId = {0}", idCompany) + System.Environment.NewLine);
            }));
            try
            {
                if (idCompany == 6619858476258121218)
                {
                    this.Invoke(new Action(() =>
                    {
                        rbSuccess.AppendText("STOP download with ID = 6619858476258121218");
                    }));
                    return;
                    //productTableAdapter.FillBy_CompanyRootProductNotImageId(dBWss.Product);
                }
                else if (checkEditReloadAll.Checked)
                {
                    productTableAdapter.FillAllBy_CompanyAndValid(dBWss.Product, idCompany, true);
                }
                else
                {
                    productTableAdapter.FillBy_CompanyAndValidAndImageId(dBWss.Product, idCompany, true);
                }
            }
            catch (Exception ex)
            {
                this.Invoke(new Action(() =>
                {
                    rbFail.AppendText("Get data product from SQL error:" + System.Environment.NewLine +
                                      ex.ToString() + System.Environment.NewLine);
                }));
            }
            if (dBWss.Product.Rows.Count > 0)
            {
                this.Invoke(new Action(() =>
                {
                    lbCount.Text = dBWss.Product.Rows.Count.ToString();
                    rbSuccess.AppendText(string.Format("Get {1} product need download from Database with CompanyId = {0}", idCompany, dBWss.Product.Rows.Count) + System.Environment.NewLine);
                }));
                var producerUpdateImageIdSql = new ProducerBasic(_rabbitMqServer, ConfigImages.ImboExchangeImages, ConfigImages.ImboRoutingKeyUploadImageIdSql);
                int success = 0;
                int fail    = 0;
                for (int i = 0; i < dBWss.Product.Rows.Count; i++)
                {
                    ImageProductInfo product = new ImageProductInfo();
                    product.Id        = Common.Obj2Int64(dBWss.Product.Rows[i]["ID"]);
                    product.ImageUrls = dBWss.Product.Rows[i]["ImageUrls"].ToString();
                    string message = string.Empty;
                    if (CommonDownloadImage.DownloadImageProduct(product, producerUpdateImageIdSql, ref message))
                    {
                        success++;
                        this.Invoke(new Action(() =>
                        {
                            lbSuccess.Text = success.ToString();
                            rbSuccess.AppendText(string.Format("CompanyId = {0}: {1}/{2} success", idCompany, i, dBWss.Product.Count) + System.Environment.NewLine);
                        }));
                    }
                    else
                    {
                        this.Invoke(new Action(() =>
                        {
                            rbSuccess.AppendText(string.Format("CompanyId = {0}: {1}/{2} fails", idCompany, i, dBWss.Product.Count) + System.Environment.NewLine);
                        }));

                        fail++;
                        this.Invoke(new Action(() =>
                        {
                            if (rbFail.TextLength > 1000000)
                            {
                                rbFail.Clear();
                            }
                            lbFails.Text = fail.ToString();
                            rbFail.AppendText(string.Format("CompanyId = {0}: {1}/{2} {4} fails: {3}", idCompany, i, dBWss.Product.Count, message, product.ImageUrls) + System.Environment.NewLine);
                            rbListIdFails.AppendText(product.Id + System.Environment.NewLine);
                        }));
                    }
                }
                this.Invoke(new Action(() =>
                {
                    rbSuccess.AppendText(string.Format("CompanyId = {0} downloaded {1}/{2} image", idCompany, success, dBWss.Product.Count) + System.Environment.NewLine);
                }));
            }
            else
            {
                this.Invoke(new Action(() =>
                {
                    rbSuccess.AppendText(string.Format("CompanyId {0} 0 product download image", idCompany) + System.Environment.NewLine);
                }));
            }
        }
예제 #25
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);
        }
예제 #26
0
 protected sealed override void OnStart(string[] args)
 {
     try
     {
         _workers             = new Worker[_workerCount + 1];
         _rabbitMqServer      = RabbitMQManager.GetRabbitMQServer(ConfigImages.RabbitMqServerName);
         _checkErrorJobClient = new JobClient(ConfigImages.ExchangeImages, GroupType.Topic, ConfigImages.RoutingKeyCheckErrorDownload, true, _rabbitMqServer);
         for (var i = 0; i < _workerCount; i++)
         {
             var worker = new Worker(ConfigImages.QueueChangeImageProduct, false, _rabbitMqServer);
             _workers[i] = worker;
             var workerTask = new Task(() =>
             {
                 //JobClient send message to service thumbimage (viết kiểu ProducerBasic để gửi cho a quang)
                 var thumbImageJobClient = new ProducerBasic(_rabbitMqServer, ConfigImages.ExchangeImages, ConfigImages.RoutingKeyThumbImage);
                 //Jobclient send message to service update imagepath to sql
                 var updateImagePathProductJobClient = new JobClient(ConfigImages.ExchangeImages, GroupType.Topic,
                                                                     ConfigImages.RoutingKeyUpdateImagePath, true, _rabbitMqServer);
                 worker.JobHandler = (downloadImageJob) =>
                 {
                     try
                     {
                         DownloadImageProduct(ImageProductInfo.GetDataFromMessage(downloadImageJob.Data), updateImagePathProductJobClient, thumbImageJobClient);
                     }
                     catch (Exception exception)
                     {
                         Log.Error("Execute Job Error.", exception);
                     }
                     return(true);
                 };
                 worker.Start();
             });
             workerTask.Start();
             Log.InfoFormat("Worker {0} started", i);
         }
         #region Tách 1 consumer ra để download ảnh sp gốc
         var workerSpGoc = new Worker(ConfigImages.QueueChangeImageRootProduct, false, _rabbitMqServer);
         _workers[_workerCount] = workerSpGoc;
         var workerSpGocTask = new Task(() =>
         {
             //JobClient send message to service thumbimage (viết kiểu ProducerBasic để gửi cho a quang)
             var thumbImageJobClient = new ProducerBasic(_rabbitMqServer, ConfigImages.ExchangeImages, ConfigImages.RoutingKeyThumbImage);
             //Jobclient send message to service update imagepath to sql
             var updateImagePathProductJobClient = new JobClient(ConfigImages.ExchangeImages, GroupType.Topic, ConfigImages.RoutingKeyUpdateImagePath, true, _rabbitMqServer);
             workerSpGoc.JobHandler = (downloadImageJob) =>
             {
                 try
                 {
                     DownloadImageRootProduct(ImageProductInfo.GetDataFromMessage(downloadImageJob.Data), updateImagePathProductJobClient, thumbImageJobClient);
                 }
                 catch (Exception exception)
                 {
                     Log.Error("Execute Job Error.", exception);
                 }
                 return(true);
             };
             workerSpGoc.Start();
         });
         workerSpGocTask.Start();
         Log.InfoFormat("Worker(SpGoc) {0} started", _workerCount);
         #endregion
     }
     catch (Exception exception)
     {
         Log.Error("Start error", exception);
         throw;
     }
 }
예제 #27
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);
     }
 }
예제 #28
0
        protected sealed override void OnStart(string[] args)
        {
            try
            {
                _historyProductAdapter.Connection.ConnectionString = _connectionString;
                _workers             = new Worker[_workerProduct + _workerCompany + 1];
                _rabbitMqServer      = RabbitMQManager.GetRabbitMQServer(ConfigImages.RabbitMqServerName);
                _checkErrorJobClient = new JobClient(ConfigImages.ImboExchangeImages, GroupType.Topic, ConfigImages.ImboRoutingKeyCheckErrorDownload, true, _rabbitMqServer);
                #region Worker Product
                for (var i = 0; i < _workerProduct; i++)
                {
                    var worker = new Worker(ConfigImages.ImboQueueDownloadImageProduct, false, _rabbitMqServer);
                    _workers[i] = worker;
                    var workerTask = new Task(() =>
                    {
                        //JobClient send message to service upload sql & thumb của tráng
                        var producerUpdateImageIdSql = new ProducerBasic(_rabbitMqServer, ConfigImages.ImboExchangeImages, ConfigImages.ImboRoutingKeyUploadImageIdSql);
                        //var producerDelImage = new ProducerBasic(_rabbitMqServer, ConfigImages.ImboExchangeImages, ConfigImages.ImboRoutingKeyThumbImage);
                        worker.JobHandler = (downloadImageJob) =>
                        {
                            try
                            {
                                DownloadImageProduct(ImageProductInfo.GetDataFromMessage(downloadImageJob.Data), producerUpdateImageIdSql);
                            }
                            catch (Exception exception)
                            {
                                Log.Error("Execute Job Error.", exception);
                            }
                            return(true);
                        };
                        worker.Start();
                    });
                    workerTask.Start();
                    Log.InfoFormat("Worker {0} started", i);
                }
                #endregion

                #region Worker RootProduct
                var workerSpGoc = new Worker(ConfigImages.ImboQueueDownloadImageRootProduct, false, _rabbitMqServer);
                _workers[_workerProduct] = workerSpGoc;
                var workerSpGocTask = new Task(() =>
                {
                    //JobClient send message to service upload sql & thumb của tráng
                    var producerUpdateImageIdSql = new ProducerBasic(_rabbitMqServer, ConfigImages.ImboExchangeImages, ConfigImages.ImboRoutingKeyUploadImageIdSql);
                    //var producerThumbImage = new ProducerBasic(_rabbitMqServer, ConfigImages.ImboExchangeImages, ConfigImages.ImboRoutingKeyThumbImage);
                    workerSpGoc.JobHandler = (downloadImageJob) =>
                    {
                        try
                        {
                            DownloadImageRootProduct(ImageProductInfo.GetDataFromMessage(downloadImageJob.Data), producerUpdateImageIdSql);
                        }
                        catch (Exception exception)
                        {
                            Log.Error("Execute Job Error.", exception);
                        }
                        return(true);
                    };
                    workerSpGoc.Start();
                });
                workerSpGocTask.Start();
                Log.InfoFormat("Worker(SpGoc) {0} started", _workerProduct);
                #endregion

                #region Worker Company
                for (var i = _workerProduct + 1; i <= _workerProduct + _workerCompany; i++)
                {
                    var worker = new Worker(ConfigImages.ImboQueueDownloadImageCompany, false, _rabbitMqServer);
                    _workers[i] = worker;
                    var workerTask = new Task(() =>
                    {
                        //JobClient send message to service upload sql & thumb của tráng
                        var producerUpdateImageIdSql = new ProducerBasic(_rabbitMqServer, ConfigImages.ImboExchangeImages, ConfigImages.ImboRoutingKeyUploadImageIdSql);
                        //var producerThumbImage = new ProducerBasic(_rabbitMqServer, ConfigImages.ImboExchangeImages, ConfigImages.ImboRoutingKeyThumbImage);
                        worker.JobHandler = (downloadImageJob) =>
                        {
                            long idCompany;
                            try
                            {
                                idCompany = BitConverter.ToInt64(downloadImageJob.Data, 0);
                                if (downloadImageJob.Type == (int)TypeJobWithRabbitMQ.ReloadAll)
                                {
                                    DownloadImageCompany(idCompany, producerUpdateImageIdSql, true);
                                }
                                else
                                {
                                    DownloadImageCompany(idCompany, producerUpdateImageIdSql, false);
                                }
                            }
                            catch (Exception exception)
                            {
                                Log.Error("Execute Job Error.", exception);
                            }
                            return(true);
                        };
                        worker.Start();
                    });
                    workerTask.Start();
                    Log.InfoFormat("Worker(Company) {0} started", i);
                }
                #endregion
            }
            catch (Exception exception)
            {
                Log.Error("Start error", exception);
                throw;
            }
        }