/// <summary> /// Posts the sorted journy. /// This API should call the bussines logic that is JourneySorterAssemblye.dll /// </summary> /// <param name="tripCards">The trip cards.</param> /// <returns></returns> public string PostSortedJourny(List <TripCard> tripCards) { string journeyInfo = string.Empty; IBoardingJourneyCard airplaneBoardingJourneyCardFactory = new AirplaneBoardingJourneyCardExtension(); IBoardingJourneyCard trainBoardingJourneyCardFactory = new TrainBoardingJourneyCardExtension(); IBoardingJourneyCard busBoardingJourneyCardFactory = new BusBoardingJourneyCardExtension(); List <BoardingJourneyCard> unorderedBCards = new List <BoardingJourneyCard>(); #region boarding passes Journey Cards Data for (int i = 0; i < tripCards.Count; i++) { var trip = tripCards[i]; if (trip.Transport.ToLower() == "airplane") { unorderedBCards.Add(airplaneBoardingJourneyCardFactory.CreateBoardingJourneyCard()); var bJourneyAir = (AirplaneBoardingJourneyCard)unorderedBCards[i]; bJourneyAir .SetFlightNumber(trip.FlightNumber) .SetGate(trip.Gate) .SetBaggageTicketCounter(trip.BaggageTicketCounter) .SetId(trip.Id) .SetTransport(new Airplane()) .SetSeat(trip.Seat) .SetDeparture(new JourneySorterAssembly.Locator .Location(trip.Departure.City + "-" + trip.Departure.Country, trip.Departure.City, trip.Departure.Country)) .SetDestination(new JourneySorterAssembly.Locator .Location(trip.Destination.City + "-" + trip.Destination.Country, trip.Destination.City, trip.Destination.Country)); } else if (trip.Transport.ToLower() == "bus") { unorderedBCards.Add(busBoardingJourneyCardFactory.CreateBoardingJourneyCard()); var bJourneyBus = (BusBoardingJourneyCard)unorderedBCards[i]; bJourneyBus .SetId(trip.Id) .SetSeat(null) .SetDeparture(new JourneySorterAssembly.Locator .Location(trip.Departure.City + "-" + trip.Departure.Country, trip.Departure.City, trip.Departure.Country)) .SetDestination(new JourneySorterAssembly.Locator .Location(trip.Destination.City + "-" + trip.Destination.Country, trip.Destination.City, trip.Destination.Country)); } else if (trip.Transport.ToLower() == "train") { unorderedBCards.Add(trainBoardingJourneyCardFactory.CreateBoardingJourneyCard()); var bJourneyTrain = (TrainBoardingJourneyCard)unorderedBCards[i]; bJourneyTrain .SetId(trip.Id) .SetTransport(new Train(trip.TrainNumber)) .SetSeat(trip.Seat) .SetDeparture(new JourneySorterAssembly.Locator .Location(trip.Departure.City + "-" + trip.Departure.Country, trip.Departure.City, trip.Departure.Country)) .SetDestination(new JourneySorterAssembly.Locator .Location(trip.Destination.City + "-" + trip.Destination.Country, trip.Destination.City, trip.Destination.Country)); } } #endregion // Establish the ordering Technique following the Technique pattern Journey Journey = new Journey(unorderedBCards); Journey.SetOrderingTravelTechnique(new TechniqueNoStartNoEnd()); // Order travel cards Journey.SortJourney(unorderedBCards); // Show the Journey information journeyInfo = Journey.GetMoreInformationFroTravel(); Console.WriteLine(journeyInfo); return(journeyInfo); }
/// <summary> /// Defines the entry point of the application. /// </summary> /// <param name="args">The arguments.</param> static void Main(string[] args) { // Manufacture 4 boarding passes using the Factory pattern to create different factories // according to the type of boarding card we want to create IBoardingJourneyCard airplaneBoardingJourneyCardFactory = new AirplaneBoardingJourneyCardExtension(); IBoardingJourneyCard trainBoardingJourneyCardFactory = new TrainBoardingJourneyCardExtension(); IBoardingJourneyCard busBoardingJourneyCardFactory = new BusBoardingJourneyCardExtension(); List <BoardingJourneyCard> unorderedBoardingJourneyCards = new List <BoardingJourneyCard>() { airplaneBoardingJourneyCardFactory.CreateBoardingJourneyCard(), trainBoardingJourneyCardFactory.CreateBoardingJourneyCard(), airplaneBoardingJourneyCardFactory.CreateBoardingJourneyCard(), busBoardingJourneyCardFactory.CreateBoardingJourneyCard() }; #region 4 boarding passes Journey Cards Data var bJourneyCard1 = (AirplaneBoardingJourneyCard)unorderedBoardingJourneyCards[0]; var bJourneyCard2 = (TrainBoardingJourneyCard)unorderedBoardingJourneyCards[1]; var bJourneyCard3 = (AirplaneBoardingJourneyCard)unorderedBoardingJourneyCards[2]; var bJourneyCard4 = (BusBoardingJourneyCard)unorderedBoardingJourneyCards[3]; bJourneyCard1.SetFlightNumber("SK22") .SetGate("22") .SetBaggageTicketCounter(null) .SetId("004") .SetTransport(new Airplane()) .SetSeat("7B") .SetDeparture(new Location("stockolm-sweeden", "Stockolm", "Sweeden")) .SetDestination(new Location("ny-usa", "New York", "USA")); bJourneyCard2 .SetId("001") .SetTransport(new Train("78A")) .SetSeat("45B") .SetDeparture(new Location("madrid-spain", "Madrid", "Spain")) .SetDestination(new Location("barcelona-spain", "Barcelona", "Spain")); bJourneyCard3 .SetFlightNumber("SK455") .SetGate("45B") .SetBaggageTicketCounter("344") .SetId("003") .SetSeat("3A") .SetDeparture(new Location("geronaairport-spain", "Gerona", "Spain")) .SetDestination(new Location("stockolm-sweeden", "Stockolm", "Sweeden")); bJourneyCard4 .SetId("002") .SetSeat(null) .SetDeparture(new Location("barcelona-spain", "Barcelona", "Spain")) .SetDestination(new Location("geronaairport-spain", "Gerona", "Spain")); #endregion // Establish the ordering Technique following the Technique pattern Journey Journey = new Journey(unorderedBoardingJourneyCards); Journey.SetOrderingTravelTechnique(new TechniqueNoStartNoEnd()); // Order travel cards Journey.SortJourney(unorderedBoardingJourneyCards); // Show the Journey information Console.WriteLine(Journey.GetMoreInformationFroTravel()); //Stop program until the user inter any keword Console.ReadKey(); }