public override void ProcessMessage(BasicDeliverEventArgs message) { try { var pt = ProductEntity.GetFromJson(message.Body); if (!string.IsNullOrEmpty(pt.Session)) { _noSqlHistoryCrawler.InsertProduct(pt); _producerHistoryProduct.PublishString( Newtonsoft.Json.JsonConvert.SerializeObject(new HistoryProductSorl() { DateUpdate = Convert.ToInt32(pt.LastUpdate.ToString("yyyyMMdd")), CompanyId = pt.CompanyId, Id = pt.ID + ":" + pt.Session, ProductId = pt.ID, LastUpdate = pt.LastUpdate.Ticks, Session = pt.Session, DetailUrl = pt.DetailUrl, TypeRun = 1, })); } } catch (Exception ex) { _log.Error(ex); } this.GetChannel().BasicAck(message.DeliveryTag, true); }
public override void ProcessMessage(RabbitMQ.Client.Events.BasicDeliverEventArgs message) { var pt = ProductEntity.GetFromJson(message.Body); if (!hID.Contains(Common.GetIDClassification(pt.GetCategoryString()))) { bool bOK = _sqlDb.RunQuery( "insert into Classification (Id, Name, IdCompany) values (@Id, @Name, @IdCompany)", CommandType.Text, new SqlParameter[] { SqlDb.CreateParamteterSQL("@Id", pt.IdCategories, SqlDbType.BigInt), SqlDb.CreateParamteterSQL("@Name", pt.IdCategories, SqlDbType.NVarChar), SqlDb.CreateParamteterSQL("@IdCompany", pt.CompanyId, SqlDbType.BigInt), }); if (bOK) { hID.Add(pt.IdCategories); } _log.InfoFormat("Saved for categor: {0}", Common.ConvertToString(pt.Categories, "->")); } this.GetChannel().BasicAck(message.DeliveryTag, true); }
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); }
public override void ProcessMessage(BasicDeliverEventArgs message) { try { var pt = ProductEntity.GetFromJson(message.Body); _producerClassification.Publish(new Classification() { CompanyId = pt.CompanyId, Id = pt.ID, Category = pt.GetCategoryString() }.GetArbyteJson()); if (pt.StatusChange.IsNew) { _chLastProduct.UpdateBathLastUpdateProduct(pt.CompanyId, new List <long> { pt.ID }, DateTime.Now); _chProductHash.SetCacheProductHash(pt.CompanyId, new ProductHash() { url = pt.DetailUrl, Id = pt.ID, Price = pt.Price, HashImage = pt.GetHashImage(), HashChange = pt.GetHashChange(), HashDuplicate = pt.GetHashDuplicate() }); } else if (pt.StatusChange.IsDelete) { _chLastProduct.RemoveProduct(pt.CompanyId, pt.ID); _chProductHash.RemoveProduct(pt.CompanyId, pt.ID); } else if (pt.StatusChange.IsDuplicate) { _chLastProduct.RemoveProduct(pt.CompanyId, pt.ID); _chProductHash.RemoveProduct(pt.CompanyId, pt.CompanyId); } else if (pt.StatusChange.IsChangeBasic) { _chLastProduct.UpdateBathLastUpdateProduct(pt.CompanyId, new List <long> { pt.ID }, DateTime.Now); _chProductHash.SetCacheProductHash(pt.CompanyId, new ProductHash() { url = pt.DetailUrl, Id = pt.ID, Price = pt.Price, HashImage = pt.GetHashImage(), HashChange = pt.GetHashChange(), HashDuplicate = pt.GetHashDuplicate() }); } if (pt.StatusChange.IsChangeDesc) { var jobDescription = new JobMqChangeDesc() { Id = pt.ID, FullDesc = pt.FullDescHtml, ShortDesc = pt.ShortDescHtml, SpecDesc = pt.SpecsDescHtml, VideoDesc = pt.VideoDescHtml }; _producerDescriptionQuang.Publish(UtilZipFile.Zip(jobDescription.GetJSON())); _producerChangeDesc.Publish(UtilZipFile.Zip(jobDescription.GetJSON())); _chProductDesciptioHash.SetHashDesc(pt.CompanyId, new Tuple <long, long>(pt.ID, pt.GetHashDesc())); } if (pt.StatusChange.IsChangePrice) { _jobPushChangePrice.PushQueueChangePriceLog(new JobRabbitChangePrice() { Name = pt.Name, ProductID = pt.ID, CompanyID = pt.CompanyId, NewPrice = pt.Price, OldPrice = pt.OldPrice }); } _log.Info(string.Format("Saved for pt: {0}", pt.ID)); } catch (Exception ex01) { _log.Error(ex01); } this.GetChannel().BasicAck(message.DeliveryTag, true); }