示例#1
0
 private void InsertHistoryDownloadImage(LogHistoryImageProduct logHistoryImageProduct, History_DownloadImageProductTableAdapter historyAdapter)
 {
     while (_isRunning)
     {
         try
         {
             if (historyAdapter.Connection.State == ConnectionState.Closed)
             {
                 historyAdapter.Connection.Open();
             }
             if (logHistoryImageProduct.ErrorName.Length > 4000)
             {
                 logHistoryImageProduct.ErrorName = logHistoryImageProduct.ErrorName.Substring(0, 3999);
             }
             historyAdapter.Insert(logHistoryImageProduct.ProductId, logHistoryImageProduct.DateLog,
                                   logHistoryImageProduct.IsDownloaded, logHistoryImageProduct.ErrorName,
                                   logHistoryImageProduct.NewsToValid);
             Log.Info(string.Format("ProductId {0} : Insert history success.", logHistoryImageProduct.ProductId));
             break;
         }
         catch (Exception exception)
         {
             Log.Error(string.Format("ProductId {0} : Insert history error.", logHistoryImageProduct.ProductId), exception);
             Thread.Sleep(60000);
         }
     }
 }
示例#2
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);
                }
            }
        }
示例#3
0
 protected override void OnStart(string[] args)
 {
     try
     {
         _workers        = new Worker[_workerCount + 1];
         _rabbitMqServer = RabbitMQManager.GetRabbitMQServer(ConfigImages.RabbitMqServerName);
         for (var i = 0; i < _workerCount; i++)
         {
             var worker = new Worker(ConfigImages.QueueHistoryDownloadImage, false, _rabbitMqServer);
             _workers[i] = worker;
             var historyAdapter = new History_DownloadImageProductTableAdapter();
             historyAdapter.Connection.ConnectionString = _connectionString;
             var workerTask = new Task(() =>
             {
                 worker.JobHandler = (downloadImageJob) =>
                 {
                     try
                     {
                         InsertHistoryDownloadImage(
                             LogHistoryImageProduct.GetDataFromMessage(downloadImageJob.Data), historyAdapter);
                     }
                     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;
     }
 }
示例#4
0
        private void SendMessageToServiceInsertHistoryDownload(LogHistoryImageProduct historyImageProduct, JobClient historyJobClient)
        {
            var job = new Job
            {
                Data = LogHistoryImageProduct.GetMessage(historyImageProduct)
            };

            while (_isRunning)
            {
                try
                {
                    historyJobClient.PublishJob(job);
                    Log.Info(string.Format("Push message to services insert history download image productid = {0}",
                                           historyImageProduct.ProductId));
                    break;
                }
                catch (Exception ex)
                {
                    Log.Error(string.Format("ProductId = {0} Push message to services insert history download image error.", historyImageProduct.ProductId), ex);
                    Thread.Sleep(60000);
                }
            }
        }