Example #1
0
        public static void Main()
        {
            ILog log            = log4net.LogManager.GetLogger(typeof(Program));
            var  rabbitMQServer = RabbitMQManager.GetRabbitMQServer("rabbitMQ177");
            var  worker         = new Worker("ChangePriceQueue.LogToRedis", false, rabbitMQServer);
            Task workerTask     = new Task(() =>
            {
                log.Info("Start consumer!");
                worker.JobHandler = (downloadImageJob) =>
                {
                    log.Info("Get job from MQ");
                    try
                    {
                        Encoding enc             = new UTF8Encoding(true, true);
                        string strData           = enc.GetString(downloadImageJob.Data);
                        JobRabbitChangePrice job = JsonConvert.DeserializeObject <JobRabbitChangePrice>(strData);
                        RedisPriceLogAdapter.PushMerchantProductPrice(job.ProductID, job.NewPrice, DateTime.Now);
                        log.Info(string.Format("Saved for job:{0}", strData));
                        return(true);
                    }
                    catch (Exception ex01)
                    {
                        log.Error("Exception:", ex01);
                        return(true);
                    }
                };
                worker.Start();
            });

            workerTask.Start();
            Console.ReadLine();
        }
Example #2
0
        private void RefreshData()
        {
            this.chartControl1.Series.Clear();
            this.chartControl1.RefreshData();
            List <KeyValuePair <DateTime, long> > LogPrice = RedisPriceLogAdapter.GetMerchantProductPriceLog(Convert.ToInt64(textBox1.Text));

            DevExpress.XtraCharts.Series seriesPrice = new DevExpress.XtraCharts.Series("LogPrice", DevExpress.XtraCharts.ViewType.Line);
            foreach (KeyValuePair <DateTime, long> item in LogPrice)
            {
                seriesPrice.Points.Add(new DevExpress.XtraCharts.SeriesPoint(item.Key, item.Value));
            }
            this.chartControl1.Series.Add(seriesPrice);
            this.chartControl1.RefreshData();
        }
Example #3
0
        public static bool InsertRootProductMappingCache(long productID, string searchEnginesServiceUrl, TimeSpan?expiry = null)
        {
            var client   = new ProtoBufServiceStackClient(searchEnginesServiceUrl);
            var response = client.Send <GetRootProductMappingResponse>(new GetRootProductMappingRequest {
                ProductID = productID, RegionID = 0, IncludeBlackList = false, GetFacet = true, SortType = RootProductMappingSortType.PriceWithVAT
            });

            if (response.RootProductMapping != null)
            {
                if (response.RootProductMapping.NumMerchant > 0)
                {
                    RedisPriceLogAdapter.PushRootProductPrice(productID, response.RootProductMapping.MinPrice, response.RootProductMapping.MaxPrice, response.RootProductMapping.MeanPrice, DateTime.Now.Date);
                }
                RootProductMappingBAL.InsertRootProductMappingIntoCache(response.RootProductMapping, 0, RootProductMappingSortType.PriceWithVAT, false, expiry);
                return(true);
            }
            else
            {
                Log.ErrorFormat("InsertRootProductMappingIntoCache failed - ProductID {0}", productID);
                return(false);
            }
        }
Example #4
0
 private void SetMethod()
 {
     base.JobHandler = (downloadImageJob) =>
     {
         if (_token.IsCancellationRequested)
         {
             return(false);
         }
         try
         {
             Encoding enc = new UTF8Encoding(true, true);
             var      job = JsonConvert.DeserializeObject <JobRabbitChangePrice>(enc.GetString(downloadImageJob.Data));
             RedisPriceLogAdapter.PushMerchantProductPrice(job.ProductID, job.NewPrice, DateTime.Now);
             _log.Info(string.Format("Saved for job:{0}", enc.GetString(downloadImageJob.Data)));
             return(true);
         }
         catch (Exception ex)
         {
             _log.Error(ex);
             return(false);
         }
     };
 }