Esempio n. 1
0
 public BookOrdersController(AddBookTitleRequestUseCase addBookTitleRequestUseCase,
                             ApproveBookOrderUseCase approveBookOrderUseCase,
                             SendBookOrderUseCase sendBookOrderUseCase,
                             GetAllBookOrdersUseCase getAllBookOrdersUseCase,
                             DeleteBookOrdersUseCase deleteBookOrdersUseCase)
 {
     if (addBookTitleRequestUseCase == null)
     {
         throw new ArgumentNullException(nameof(addBookTitleRequestUseCase));
     }
     if (approveBookOrderUseCase == null)
     {
         throw new ArgumentNullException(nameof(approveBookOrderUseCase));
     }
     if (sendBookOrderUseCase == null)
     {
         throw new ArgumentNullException(nameof(sendBookOrderUseCase));
     }
     if (getAllBookOrdersUseCase == null)
     {
         throw new ArgumentNullException(nameof(getAllBookOrdersUseCase));
     }
     if (deleteBookOrdersUseCase == null)
     {
         throw new ArgumentNullException(nameof(deleteBookOrdersUseCase));
     }
     _addBookTitleRequestUseCase = addBookTitleRequestUseCase;
     _approveBookOrderUseCase    = approveBookOrderUseCase;
     _sendBookOrderUseCase       = sendBookOrderUseCase;
     _getAllBookOrdersUseCase    = getAllBookOrdersUseCase;
     _deleteBookOrdersUseCase    = deleteBookOrdersUseCase;
 }
        private void SendBookOrders()
        {
            IBookOrderRepository bookOrderRepository  = Container.GetInstance <IBookOrderRepository>();
            SendBookOrderUseCase sendBookOrderUseCase = Container.GetInstance <SendBookOrderUseCase>();
            Random rand = new Random();

            while (!_shutdown)
            {
                var bookOrderToSend = bookOrderRepository.GetByState(BookOrderState.Approved).FirstOrDefault();

                if (bookOrderToSend != null)
                {
                    sendBookOrderUseCase.Execute(bookOrderToSend.Id);
                }

                Thread.Sleep(rand.Next(1000, 10000));
            }
        }