예제 #1
0
 private void InsertLogDownloadImageProduct(long productId, History_DownloadImageProductTableAdapter historyProductAdapter)
 {
     while (_isRunning)
     {
         try
         {
             if (historyProductAdapter.Connection.State == ConnectionState.Closed)
             {
                 historyProductAdapter.Connection.Open();
             }
             _historyProductAdapter.Insert(productId, DateTime.Now, true, false, "");
             break;
         }
         catch (Exception exception)
         {
             Log.Error(string.Format("ProductId {0} : Insert log error.", productId), exception);
             Thread.Sleep(60000);
         }
     }
 }
예제 #2
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;
     }
 }
예제 #3
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);
         }
     }
 }