Beispiel #1
0
 /// <summary>
 /// Find unit with backlog identified by id in subtree
 /// </summary>
 /// <param name="username">username</param>
 /// <returns></returns>
 public OrganizationUnit FindWithBacklog(Guid id)
 {
     if (Backlogs.Any(x => x.Id == id))
     {
         return(this);
     }
     return(Children
            .Select(childUnit => childUnit.FindWithBacklog(id))
            .FirstOrDefault(result => result != null));
 }
Beispiel #2
0
        public void ProcessOrders()
        {
            Order shipment = new Order("order shipment", 0);

            BacklogCalculation();
            BacklogCostTotal = CurBacklog;

            // backlogs
            if (Backlogs.Count > 0)
            {
                bool endBacklogProcessing = false;

                do
                {
                    Order backlogOrder = null;
                    if (Backlogs.TryPeek(out backlogOrder))
                    {
                        if (Inventory >= backlogOrder.Amount)
                        {
                            // add to shipment
                            shipment.Amount += backlogOrder.Amount;
                            Inventory       -= backlogOrder.Amount;

                            // dequeue backlog
                            Backlogs.TryDequeue(out backlogOrder);
                        }
                        else if (Inventory > 0)
                        {
                            // add all inventory to shipment
                            shipment.Amount += Inventory;
                            Inventory       -= backlogOrder.Amount;

                            // update backlog amount
                            backlogOrder.Amount = -Inventory;

                            endBacklogProcessing = true;
                        }
                        else
                        {
                            endBacklogProcessing = true;
                        }
                    }
                    else
                    {
                        endBacklogProcessing = true;
                    }
                } while (!endBacklogProcessing);
            }

            // current orders
            Order currentOrder = null;

            if (Orders.TryPeek(out currentOrder))
            {
                if (currentOrder.ProcessOn == simulator.CurrentDay)
                {
                    // dequeue
                    Orders.TryDequeue(out currentOrder);

                    Ordered = currentOrder.Amount;

                    if (Inventory >= currentOrder.Amount)
                    {
                        // add to shipment
                        shipment.Amount += currentOrder.Amount;
                        Inventory       -= currentOrder.Amount;
                    }
                    else if (Inventory > 0)
                    {
                        // add all inventory to shipment
                        shipment.Amount += Inventory;

                        // update backlog amount
                        currentOrder.Amount -= Inventory;

                        // transfer remaining order amount as backlog
                        Backlogs.Enqueue(currentOrder);
                    }
                    else
                    {
                        // transfer order to backlog
                        Backlogs.Enqueue(currentOrder);
                    }
                }
                else
                {
                    Ordered = 0;
                }
            }

            // send shipment
            if (shipment.Amount > 0)
            {
                Send(shipment);
            }
            else
            {
                CurSend = 0;
            }
        }