public void Strart() { try { isActive = true; Task t = WorkerAsync(); t.Wait(); } catch (Exception ex) { EmailNotifier.CreateMessage($"Ошибка при парсинге! Текст: {ex.InnerException.Message}. Trace:{ex.InnerException.StackTrace}", "Error"); throw; } }
/// <summary> /// Инициирует создание контрольной точки и слепок цен на товары от сегодняшней даты /// </summary> /// <returns></returns> public async Task MakePriceSnapshotAsync() { Statistic statistic = new Statistic() { CreationDate = DateTime.Now.Date }; statisticRepository.SaveStatistic(statistic); try { int startFrom = 0; int blockSize = 1000; IQueryable <Product> total = productRepository.Products.OrderBy(x => x.Code); //.Where(x => x.UpdateDate.Date == DateTime.Now.Date); for (int i = startFrom; i < total.Count() + blockSize; i += blockSize) { if (total == null) { break; } List <Price> prices = (await total.Skip(startFrom).Take(blockSize).ToListAsync()).ProductListToPriceList(statistic); startFrom += blockSize; await priceRepository.SavePriceRangeAsync(prices); } } catch (Exception) { statistic.Status = -1; statisticRepository.SaveStatistic(statistic); Status = "Falled during Price snapshot"; } finally { EmailNotifier.CreateMessage(Status, "Error"); } }