Beispiel #1
0
        private static bool TryAllocateLockerToOrder(Order order)
        {
            OrderProcessor.TryAllocatingForPendingOrders();

            var allocationStatus = false;

            foreach (var pod in OrderProcessor.pods)
            {
                if (!pod.IsPodFull())
                {
                    allocationStatus = pod.AssignOrderToPod(order.GetOrderId, order.GetLockerSize);
                }
                if (allocationStatus == true)
                {
                    OrderProcessor.PrintPodStatusOnAllocation(pod.GetPodId);
                    return(allocationStatus);
                }
            }

            if (order.GetLockerSize == LockerSizeEnum.small)
            {
                bool largeSizeOrderPendingInQueue = false;

                foreach (var o in OrderProcessor.ordersQueue)
                {
                    if (o.GetLockerSize == LockerSizeEnum.large || o.GetLockerSize == LockerSizeEnum.small)
                    {
                        largeSizeOrderPendingInQueue = true;
                        break;
                    }
                }

                if (!largeSizeOrderPendingInQueue)
                {
                    foreach (var pod in OrderProcessor.pods)
                    {
                        if (!pod.IsPodFull())
                        {
                            allocationStatus = pod.AssignOrderToPod(order.GetOrderId, LockerSizeEnum.large);
                        }
                        if (allocationStatus == true)
                        {
                            OrderProcessor.PrintPodStatusOnAllocation(pod.GetPodId);
                            return(allocationStatus);
                        }
                    }
                }
            }

            return(allocationStatus);
        }
Beispiel #2
0
        private static void TryAllocatingForPendingOrders()
        {
            if (OrderProcessor.ordersQueue.Count == 0)
            {
                return;
            }

            if (OrderProcessor.ordersQueue.Count > 20) // If more than 20 pending orders create new pod;
            {
                var pod = new Pods(OrderProcessor.pods.Count);
                OrderProcessor.pods.Add(pod);
            }

            List <Order> orderList1 = OrderProcessor.ordersQueue.ToList();
            List <Order> orderList2 = new List <Order>();

            foreach (var order in orderList1)
            {
                var allocationStatus = false;
                foreach (var pod in OrderProcessor.pods)
                {
                    if (!pod.IsPodFull())
                    {
                        allocationStatus = pod.AssignOrderToPod(order.GetOrderId, order.GetLockerSize);
                    }
                    if (allocationStatus == true)
                    {
                        OrderProcessor.PrintPodStatusOnAllocation(pod.GetPodId);
                        OrderProcessor.orderStatus[order] = true;
                        orderList2.Add(order);
                        break;
                    }
                }
            }

            OrderProcessor.ordersQueue.Clear();


            foreach (var order in orderList2)
            {
                orderList1.Remove(order);
            }

            foreach (var order in orderList1)
            {
                OrderProcessor.ordersQueue.Enqueue(order);
            }
        }