コード例 #1
0
 private void ProducerCycle()
 {
     while (!_shutdown && _testBookRequests.Count > 0)
     {
         BookTitleRequest bookTitleRequest = _testBookRequests.Dequeue();
         _addBookTitleRequestUseCase.Execute(bookTitleRequest);
         Thread.Sleep(5000);
     }
 }
コード例 #2
0
        public IHttpActionResult CreateBookRequest([FromBody] BookTitleOrderRequest bookTitleOrderRequest)
        {
            if (bookTitleOrderRequest == null)
            {
                return(BadRequest());
            }

            Guid bookOrderId = _addBookTitleRequestUseCase.Execute(new BookTitleRequest(
                                                                       bookTitleOrderRequest.Title,
                                                                       bookTitleOrderRequest.Supplier,
                                                                       bookTitleOrderRequest.Price,
                                                                       bookTitleOrderRequest.Quantity));

            return(Created <string>($"bookOrders/{bookOrderId}", null));
        }
コード例 #3
0
        private void OnReceive(BasicDeliverEventArgs args)
        {
            var message = Encoding.UTF8.GetString(args.Body);

            Logger.Debug("Received {RabbitMqMessage}", message);

            try
            {
                var bookRequest = JsonConvert.DeserializeObject <BookTitleRequest>(message);
                _addBookTitleRequestUseCase.Execute(bookRequest);
                _channel.BasicAck(args.DeliveryTag, false);
            }
            catch (Exception ex)
            {
                Console.WriteLine($"EXCEPTION: {ex.StackTrace}");
            }
        }
コード例 #4
0
        protected void CheckAndProcessCsvFiles()
        {
            IEnumerable <string> filePaths = GetFilesMatchingBookOrderFileMask();

            foreach (string filePath in filePaths)
            {
                if (FileExists(filePath))
                {
                    List <BookTitleRequest> bookTitleRequests = new List <BookTitleRequest>();

                    using (Stream stream = GetFileStream(filePath))
                    {
                        var reader = new StreamReader(stream);
                        var engine = new DelimitedFileEngine <BookTitleOrderModel>();
                        BookTitleOrderModel[] records = engine.ReadStream(reader);

                        foreach (var record in records)
                        {
                            bookTitleRequests.Add(new BookTitleRequest(
                                                      record.Title, record.Supplier, record.Price, record.Quantity));
                        }
                    }

                    // NOTE: Don't do this in production. There is no attempt here do even do this
                    // in a transactional manner, and you should mark the file as processed once all
                    // orders are placed correctly rather than delete it, and have some kind of support
                    // for resuming at the last processed line if a fault occurs
                    DeleteFile(filePath);

                    foreach (BookTitleRequest bookTitleRequest in bookTitleRequests)
                    {
                        // Invoke the use case from the domain for each book order
                        _addBookTitleRequestUseCase.Execute(bookTitleRequest);
                    }
                }
            }
        }
コード例 #5
0
        private void ProducerCycle()
        {
            Random rand = new Random();

            while (!_shutdown)
            {
                string supplier = $"Supplier{rand.Next(1, 5)}";
                int    numberOfRequestsForSupplier = rand.Next(1, 5);

                for (int i = 0; i < numberOfRequestsForSupplier; i++)
                {
                    Decimal price    = rand.Next(1, 100);
                    int     quantity = rand.Next(1, 10);

                    BookTitleRequest bookTitleRequest = new BookTitleRequest(
                        $"Title{Guid.NewGuid().ToString()}",
                        supplier,
                        price, quantity);
                    _addBookTitleRequestUseCase.Execute(bookTitleRequest);
                }

                Thread.Sleep(5000);
            }
        }