Exemple #1
0
        public Ferry NextFerryAvailableFrom(int portId, TimeSpan time)
        {
            var ports1 = _ports.All().Select(x => new PortModel(x)).ToList();

            foreach (var ferry in _ferries.All())
            {
                var port = ports1.Single(x => x.Id == ferry.HomePortId);
                port.AddFerry(new TimeSpan(0, 0, 0), ferry);
            }
            var ports      = ports1;
            var allEntries = _timeTables.All().SelectMany(x => x.Entries).OrderBy(x => x.Time).ToList();

            foreach (var entry in allEntries)
            {
                var journey = new Journey
                {
                    Origin      = ports.Single(x => x.Id == entry.OriginId),
                    Destination = ports.Single(x => x.Id == entry.DestinationId)
                };

                journey.Ferry = journey.Origin.GetNextAvailable(entry.Time);

                var destination = journey.Destination;

                var arrivalTime = entry.Time.Add(entry.JourneyTime);
                int turnaroundTime;

                switch (destination.Id)
                {
                case 3:
                    turnaroundTime = 25;
                    break;

                case 2:
                    turnaroundTime = 20;
                    break;

                default:
                    turnaroundTime = 15;
                    break;
                }
                var timeReady = arrivalTime.Add(TimeSpan.FromMinutes(turnaroundTime));

                destination.AddFerry(timeReady, journey.Ferry);
                if (entry.OriginId == portId && entry.Time >= time)
                {
                    return(journey.Ferry);
                }
            }

            return(null);
        }
Exemple #2
0
 // Sets a ferry on a journey
 public void SetFerryJourney(Ferry ferry, Journey journey)
 {
     ferry.Journey = journey;
 }
 // Set a ferry on a journey
 public static void SetFerryJourney(Ferry ferry, Journey journey)
 {
     _ferryManager.SetFerryJourney(ferry, journey);
 }