Exemplo n.º 1
0
        public bool Handle(Order order)
        {
            IOrderHandler handler = _handlers.Dequeue();

            handler.Handle(order);
            _handlers.Enqueue(handler);

            return(true);
        }
        public void Handle(T message)
        {
            if (DateTime.Now > message.TimeToLive)
            {
                Console.WriteLine($"Dropping order {message.Id} due to staleness");
                TotalOrdersDropped++;
                return;
            }

            _handler.Handle(message);
        }
        public void Handle(T message)
        {
            while (true)
            {
                IOrderHandler <T> nextValidHander =
                    GetNextAvailableHandler();

                if (nextValidHander != null)
                {
                    nextValidHander.Handle(message);
                    break;
                }

                Thread.Sleep(1);
            }
        }
Exemplo n.º 4
0
        public ActionResult Buy(Product product, ProductShipmentDetailsViewModel details)
        {
            details.Product = _productRepository.Products
                              .FirstOrDefault(p => p.Id == product.Id);
            if (!ModelState.IsValid)
            {
                return(View(details));
            }

            string message = String.Empty;

            if (ModelState.IsValid)
            {
                message = _orderHandler.Handle(details.Product, details.ShippingCredentials);
            }
            return(View("Success", (object)message));
        }
Exemplo n.º 5
0
 public void Start()
 {
     _thread = new Thread(() =>
     {
         while (true)
         {
             T order;
             _orderQueue.TryDequeue(out order);
             if (order != null)
             {
                 Console.WriteLine($"Handling order {order.Id}");
                 _orderHandler.Handle(order);
             }
         }
     });
     _thread.Name = $"Thread_{_thread.ManagedThreadId}";
     _thread.Start();
 }
        public bool Handle(Order order)
        {
            Task.Factory.StartNew(() => _handler.Handle(order));

            return(true);
        }