Example #1
0
        public void DispatchBaggage(Flight flight)
        {
            flight.DispatchedBaggageCount++;
            var baggage = new Baggage()
            {
                Flight = flight,
            };

            var index   = FindMostSuitableCheckInIndex();
            var checkIn = _checkIns[index];
            var queue   = _checkInQueues[index];

            baggage.TransportationStartTime = TimerService.GetTicksSinceSimulationStart();
            baggage.TransporterId           = "Queue CheckIn";
            if (checkIn.Status == NodeState.Free)
            {
                checkIn.PassBaggage(baggage);
            }
            else
            {
                if (checkIn.OnStatusChangedToFree == null)
                {
                    checkIn.OnStatusChangedToFree += () => { PassQueuedBaggage(index); };
                }
                queue.Enqueue(baggage);
            }
        }
        private void DistributeBaggage(string destination)
        {
            var nextNode = _listOfNextNode[destination];

            nextNode.OnNodeStatusChangedToFree += () =>
            {
                if (_transporterQueues[destination].Count > 0)
                {
                    if (nextNode.NodeStatus == NodeStatus.Free)
                    {
                        IBaggage tempBag = null;

                        if (_transporterQueues.Count != 0)
                        {
                            tempBag = _transporterQueues[destination].Dequeue();

                            if (tempBag == null)
                            {
                                return;
                            }
                        }

                        tempBag.TransportationStartTime = TimerService.GetTicksSinceSimulationStart();
                        nextNode.PassBaggage(tempBag);
                    }
                }
            };
        }
        private void DispatchBaggage(IFlight flight)
        {
            var baggage = new Baggage()
            {
                Flight = flight
            };


            int chosen  = FindMostSuitableCheckin(baggage);
            var checkIn = checkins[chosen];
            var queue   = checkinQueues[chosen];

            baggage.TransportationStartTime = TimerService.GetTicksSinceSimulationStart();
            baggage.TransporterId           = "Queue CheckIn";

            if (checkIn.NodeStatus == NodeStatus.Free)
            {
                checkIn.PassBaggage(baggage);
                checkIn.OnNodeStatusChangedToFree -= () => PassQueuedBaggage(chosen);
            }
            else
            {
                queue.Enqueue(baggage);
                if (checkIn.OnNodeStatusChangedToFree == null)
                {
                    checkIn.OnNodeStatusChangedToFree += () => PassQueuedBaggage(chosen);
                }
            }

            flight.DispatchedBaggageCount++;
        }
Example #4
0
 private void AddTransportationLog(IBaggage baggage)
 {
     if (baggage.TransportationStartTime != null)
     {
         var transportationStart     = baggage.TransportationStartTime ?? 0;
         var transportingTimeElapsed = TimerService.GetTicksSinceSimulationStart() - transportationStart;
         baggage.AddEventLog(TimerService.GetTimeSinceSimulationStart(),
                             new TimeSpan(transportingTimeElapsed),
                             string.Format(LoggingConstants.BagReceivedInTemplate, Destination, baggage.TransporterId));
         baggage.TransportationStartTime = null;
     }
 }
Example #5
0
 private void ProcessInternal(IBaggage b)
 {
     Process(b);
     if (currentBag == null)
     {
         NodeStatus = NodeStatus.Free;
         return;
     }
     NextNode = nextNodes.FirstOrDefault(n => n.Destination == currentBag.Destination);
     currentBag.TransportationStartTime = TimerService.GetTicksSinceSimulationStart();
     Move();
 }
        private void ProcessInternal(IBaggage baggage)
        {
            Process(baggage);

            NextLink = _allSuccessors
                       .FirstOrDefault(x => x.Destination == baggage.Destination);

            //Condition
            //    .Requires(NextLink)
            //    .IsNotNull();

            _currentBaggage.TransportationStartTime = TimerService.GetTicksSinceSimulationStart();

            Move();
        }
        public override void PassBaggage(IBaggage baggage)
        {
            Status          = NodeState.Busy;
            _currentBaggage = baggage;
            if (baggage.TransportationStartTime != null)
            {
                var transportationStart     = baggage.TransportationStartTime ?? 0;
                var transportingTimeElapsed = TimerService.GetTicksSinceSimulationStart() - transportationStart;
                baggage.AddEventLog(TimerService.GetTimeSinceSimulationStart(),
                                    new TimeSpan(transportingTimeElapsed),
                                    string.Format(LoggingConstants.BagReceivedInTemplate, Destination, baggage.TransporterId));
                baggage.TransportationStartTime = null;
            }

            ProcessInternal(baggage);
        }
Example #8
0
        public void TimerService_ShouldShouldReturnSameTimeSinceStart_FromBothMethods()
        {
            var timerService = new TimerService();
            var settingsMock = new Mock <ISimulationSettings>();

            settingsMock.Setup(s => s.IncomingFlights).Returns(new Mock <List <Flight> >().Object);
            settingsMock.Setup(s => s.OutgoingFlights).Returns(new Mock <List <Flight> >().Object);
            settingsMock.Setup(s => s.Multiplier).Returns(1);

            timerService.SetSettings(settingsMock.Object);

            timerService.Start();
            Thread.Sleep(2000);
            timerService.Stop();

            timerService.GetTicksSinceSimulationStart().ShouldBeInRange(timerService.GetTimeSinceSimulationStart().Ticks - 5, timerService.GetTimeSinceSimulationStart().Ticks + 5);
        }
 private void PassOrEnqueueBaggage(IChainLink gate, IBaggage bag)
 {
     bag.TransportationStartTime = TimerService.GetTicksSinceSimulationStart();
     bag.TransporterId           = "Queue AA";
     if (gate.Status == NodeState.Free)
     {
         gate.PassBaggage(bag);
     }
     else
     {
         if (gate.OnStatusChangedToFree == null)
         {
             gate.OnStatusChangedToFree += () => { PassQueuedBaggage(gate); }
         }
         ;
         _gateQueues[gate].Enqueue(bag);
     }
 }
Example #10
0
 public override void PassBaggage(IBaggage b)
 {
     NodeStatus = NodeStatus.Busy;
     currentBag = b;
     if (b == null)
     {
         NodeStatus = NodeStatus.Free;
         return;
     }
     if (b.TransportationStartTime != null)
     {
         var transportationStart     = b.TransportationStartTime ?? 0;
         var transportingTimeElapsed = TimerService.GetTicksSinceSimulationStart() - transportationStart;
         b.AddLog(TimerService.GetTimeSinceSimulationStart(),
                  new TimeSpan(transportingTimeElapsed),
                  string.Format(LoggingConstants.BagReceivedInTemplate, Destination, b.TransporterId));
         b.TransportationStartTime = null;
     }
     ProcessInternal(currentBag);
 }
Example #11
0
        private void DistributeBaggage(string destination)
        {
            var nextNode = _allSuccessors[destination];

            nextNode.OnStatusChangedToFree += () =>
            {
                if (_baggageDistributors[destination].Count > 0)
                {
                    if (nextNode.Status == NodeState.Free)
                    {
                        var tempBaggage = _baggageDistributors[destination].Dequeue();

                        if (tempBaggage == null)
                        {
                            return;
                        }

                        tempBaggage.TransportationStartTime = TimerService.GetTicksSinceSimulationStart();

                        nextNode.PassBaggage(tempBaggage);
                    }
                }
            };
        }