diff --git a/Confectionery/ConfectioneryBusinessLogic/BusinessLogics/WorkModeling.cs b/Confectionery/ConfectioneryBusinessLogic/BusinessLogics/WorkModeling.cs index f721d7d..ea5fc82 100644 --- a/Confectionery/ConfectioneryBusinessLogic/BusinessLogics/WorkModeling.cs +++ b/Confectionery/ConfectioneryBusinessLogic/BusinessLogics/WorkModeling.cs @@ -16,27 +16,26 @@ namespace ConfectioneryBusinessLogic.BusinessLogics public class WorkModeling : IWorkProcess { private readonly ILogger _logger; - private readonly Random _rnd; - private IOrderLogic? _orderLogic; - public WorkModeling(ILogger logger) { _logger = logger; _rnd = new Random(1000); } - public void DoWork(IImplementerLogic implementerLogic, IOrderLogic orderLogic) { _orderLogic = orderLogic; var implementers = implementerLogic.ReadList(null); if (implementers == null) { - _logger.LogWarning("DoWork. Implementers is null"); + _logger.LogWarning("DoWork. Исполнитель равен null"); return; } - var orders = _orderLogic.ReadList(new OrderSearchModel { Status = OrderStatus.Принят }); + var orders = _orderLogic.ReadList(new OrderSearchModel + { + Status = OrderStatus.Принят + }); if (orders == null || orders.Count == 0) { _logger.LogWarning("DoWork. Orders is null or empty"); @@ -48,7 +47,6 @@ namespace ConfectioneryBusinessLogic.BusinessLogics Task.Run(() => WorkerWorkAsync(implementer, orders)); } } - /// /// Иммитация работы исполнителя /// @@ -61,14 +59,13 @@ namespace ConfectioneryBusinessLogic.BusinessLogics return; } await RunOrderInWork(implementer); - await Task.Run(() => { foreach (var order in orders) { try { - _logger.LogDebug("DoWork. Worker {Id} try get order {Order}", implementer.Id, order.Id); + _logger.LogDebug("DoWork. Worker {Id} try get order {Order} ", implementer.Id, order.Id); // пытаемся назначить заказ на исполнителя _orderLogic.TakeOrderInWork(new OrderBindingModel { @@ -77,10 +74,10 @@ namespace ConfectioneryBusinessLogic.BusinessLogics }); // делаем работу Thread.Sleep(implementer.WorkExperience * _rnd.Next(100, 1000) * order.Count); - _logger.LogDebug("DoWork. Worker {Id} finish order {Order}", implementer.Id, order.Id); + _logger.LogDebug("DoWork. Worker {Id} finish order {Order} ", implementer.Id, order.Id); _orderLogic.FinishOrder(new OrderBindingModel { - Id = order.Id + Id = order.Id, }); // отдыхаем Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100)); @@ -96,11 +93,9 @@ namespace ConfectioneryBusinessLogic.BusinessLogics _logger.LogError(ex, "Error while do work"); throw; } - } }); } - /// /// Ищем заказ, которые уже в работе (вдруг исполнителя прервали) /// @@ -123,7 +118,6 @@ namespace ConfectioneryBusinessLogic.BusinessLogics { return; } - _logger.LogDebug("DoWork. Worker {Id} back to order {Order}", implementer.Id, runOrder.Id); // доделываем работу Thread.Sleep(implementer.WorkExperience * _rnd.Next(100, 300) * runOrder.Count);