Exemple #1
0
 private void EvictOrderBox(OrderBox orderBox)
 {
     // Remove orderBox from orderBoxes
     OrderBoxes.Remove(orderBox);
     // Invoke OnOrderBoxFinishedAtStation with orderBox
     OnOrderBoxFinishedAtStation?.Invoke(orderBox);
 }
Exemple #2
0
        public OrderBoxProgress(OrderBox order, int secondsToSpend)
        {
            OrderBox       = order ?? throw new ArgumentNullException(nameof(order));
            TimeOfArrival  = TimeKeeper.CurrentDateTime;
            SecondsToSpend = secondsToSpend;

            TimeKeeper.Tick += OneSecondSpent;
        }
Exemple #3
0
 private AreaCode ChooseNextArea(OrderBox orderBox)
 {
     // Find areaCode of first needed area which is not full
     if (orderBox.AreasVisited.Any(a => !a.Value && !Areas[a.Key].AreaIsFull))
     {
         return(orderBox.AreasVisited.First(a => !a.Value && !Areas[a.Key].AreaIsFull).Key);
     }
     // If all needed areas are full -> just choose a needed area and take a chill on the MainLoop
     return(orderBox.AreasVisited.First(a => !a.Value).Key);
 }
Exemple #4
0
 private void SendToArea(OrderBox orderBox, AreaCode areaCode)
 {
     // If orderBox has been in areaCode already - throw exception
     if (orderBox.AreasVisited[areaCode])
     {
         throw new ArgumentException("Area has already been visited.");
     }
     // Send orderBox to area
     Areas[areaCode].ReceiveOrderBox(orderBox);
 }
Exemple #5
0
        //Listening on stations for orders that are done
        public void ReceiveOrderBox(OrderBox orderBox)
        {
            if (this.AreaCode == AreaCode.Area25)
            {
                var a = 2;
            }

            OnOrderBoxReceivedAtAreaEvent?.Invoke(orderBox, AreaCode);
            //call DistributeOrder with input as parameter
            DistributeOrder(orderBox);
        }
Exemple #6
0
        private OrderBoxProgress PackToOrderboxProgress(OrderBox orderBox, AreaCode area)
        {
            // Estimate time based on Loop Flow and areas
            int timeToSpend = EstimateTimeInSeconds(area);

            // Create new OrderBoxProgress based on orderbox and time.
            var orderBoxProgress =
                new OrderBoxProgress(orderBox, EstimateTimeInSeconds(area));

            // Return the new OrderBoxProgress.
            return(orderBoxProgress);
        }
Exemple #7
0
 private void ReceiveOrderBoxFromMainLoop(OrderBox orderBox, AreaCode areaTo)
 {
     // If Area is full, then choose new area and give it another turn in MainLoop
     if (Areas[areaTo].AreaIsFull)
     {
         var newArea = ChooseNextArea(orderBox);
         SendToMainLoop(orderBox, newArea);
     }
     else
     {
         // Else send to the area
         SendToArea(orderBox, areaTo);
     }
 }
Exemple #8
0
        public void ReceiveOrder(Order order)
        {
            if (HandlerIsFull)
            {
                throw new AccessViolationException("Handler received order when it is full!");
            }
            // Convert Order to OrderBox
            OrderBox orderBox = new OrderBox(order);
            // Choose area to send to
            var nextArea = ChooseNextArea(orderBox);

            // Send to Main Loop
            SendToMainLoop(orderBox, nextArea);
        }
Exemple #9
0
        //method for distributing orders to stations
        private void DistributeOrder(OrderBox receivedOrderBox)
        {
            // Make a list of all non-full stations in a random order
            var nonFullStationsInRandomOrder = Stations
                                               .Where(s => !s.StationIsFull)
                                               .OrderBy(a => Rand.Next()).ToList();

            // Choose one station and send the receivedOrderBox to it
            if (!nonFullStationsInRandomOrder.Any())
            {
                throw new AccessViolationException($"{this} should not have received an orderBox because area is full.");
            }

            nonFullStationsInRandomOrder.First().ReceiveOrderBox(receivedOrderBox);
        }
Exemple #10
0
        private void OrderBoxLineFinishedPacking(OrderBox orderBox)
        {
            // Check if any shelfBoxes can be evicted
            MaybeEvictShelfBoxes();

            // Set orderBoxLineBeingPicked to null
            _orderBoxBeingPacked = null;

            // If orderBox is fully packed then
            if (!orderBox.LinesNotPickedIn(_areaCode).Any())
            {
                // Evict orderBox
                EvictOrderBox(orderBox);
            }
        }
Exemple #11
0
        public OrderBoxPickingContainer(OrderBox orderBox, Line lineBeingPicked)
        {
            _orderBox        = orderBox ?? throw new ArgumentNullException(nameof(orderBox));
            _lineBeingPicked = lineBeingPicked ?? throw new ArgumentNullException(nameof(lineBeingPicked));

            // Check if lineBeingPicked is in orderBox. Should ALWAYS be the case
            if (!orderBox.LineIsPickedStatuses.ContainsKey(lineBeingPicked))
            {
                throw new ArgumentException($"{nameof(lineBeingPicked)} is not in {nameof(orderBox)}");
            }
            // Calculate the time it needs to actually this line. At least one.
            _timeLeftOfPicking = Math.Max(1, (int)(lineBeingPicked.Quantity * GlobalConstants.TimePerArticlePick));

            TimeKeeper.Tick += DecrementAndMaybeInvoke;
        }
Exemple #12
0
        public void ReceiveOrderBox(OrderBox orderBox)
        {
            // If the station is full but still received an orderBox -> throw error
            if (OrderBoxes.Count >= MaxOrderBoxes)
            {
                throw new AccessViolationException($"Station {this} in should not have received an orderBox.");
            }
            // Add orderBox to orderBoxes
            OrderBoxes.Add(orderBox);

            // Maybe request more shelfboxes - depends on if there is more space left for shelfBoxes
            MaybeRequestShelfBoxes();

            // Invoke event stating this happened
            OnOrderBoxReceivedAtStation?.Invoke(orderBox);
        }
Exemple #13
0
        private void ReceiverOrderBoxFromArea(OrderBox orderBox, AreaCode areaFrom)
        {
            // Update AreaVisited in orderBox
            orderBox.AreasVisited[areaFrom] = true;
            // Check if all areas has been visited
            if (orderBox.AreasVisited.All(a => a.Value))
            {
                OnOrderBoxFinished?.Invoke(orderBox);
                return;
            }
            // Choose Next Area
            var nextArea = ChooseNextArea(orderBox);

            // Send to MainLoop with area
            SendToMainLoop(orderBox, nextArea);
        }
Exemple #14
0
 public void StationOrderCompleted(OrderBox orderBox)
 {
     OnOrderBoxInAreaFinished?.Invoke(orderBox, AreaCode);
 }
Exemple #15
0
        public void ReceiveOrderBoxAndArea(OrderBox orderBox, AreaCode areaCode)
        {
            var orderBoxProgress = PackToOrderboxProgress(orderBox, areaCode);

            areaQueues[areaCode].AddOrderBoxProgress(orderBoxProgress);
        }
Exemple #16
0
 private void SendToMainLoop(OrderBox orderBox, AreaCode areaCode)
 {
     // Call MainLoops ReceiveOrderBox with this input
     MainLoop.ReceiveOrderBoxAndArea(orderBox, areaCode);
 }
Exemple #17
0
 public OrderBoxEventArgs(OrderBox orderBox)
 {
     OrderBox = orderBox;
 }