Пример #1
0
        //creates the stop over route based on the main route
        public static StopoverRoute CreateStopoverRoute(Airport dest1, Airport stopover, Airport dest2, Route mainroute, Boolean oneLegged,Route.RouteType type)
        {
            StopoverRoute stopoverRoute = new StopoverRoute(stopover);

            Guid id = Guid.NewGuid();

            if (!oneLegged)
            {
                if (mainroute.Type == Route.RouteType.Passenger || mainroute.Type == Route.RouteType.Mixed)
                {
                    PassengerRoute routeLegTwo = new PassengerRoute(id.ToString(), dest1, stopover, 0);

                    foreach (RouteAirlinerClass aClass in ((PassengerRoute)mainroute).Classes)
                    {
                        //routeLegTwo.getRouteAirlinerClass(aClass.Type).FarePrice = aClass.FarePrice;
                        routeLegTwo.getRouteAirlinerClass(aClass.Type).FarePrice = PassengerHelpers.GetPassengerPrice(dest1, stopover) * GeneralHelpers.ClassToPriceFactor(aClass.Type);

                        foreach (RouteFacility facility in aClass.getFacilities())
                            routeLegTwo.getRouteAirlinerClass(aClass.Type).addFacility(facility);

                        routeLegTwo.getRouteAirlinerClass(aClass.Type).Seating = aClass.Seating;

                    }


                    stopoverRoute.addLeg(routeLegTwo);
                }
                if (mainroute.Type == Route.RouteType.Cargo || mainroute.Type == Route.RouteType.Mixed)
                {
                    CargoRoute routeLegTwo = new CargoRoute(id.ToString(), dest1, stopover, ((CargoRoute)mainroute).PricePerUnit);

                    stopoverRoute.addLeg(routeLegTwo);
                }

            }

            if (mainroute.Type == Route.RouteType.Mixed || mainroute.Type == Route.RouteType.Passenger)
            {
                id = Guid.NewGuid();

                PassengerRoute routeLegOne = new PassengerRoute(id.ToString(), stopover, dest2, 0);

                foreach (RouteAirlinerClass aClass in ((PassengerRoute)mainroute).Classes)
                {
                    //routeLegOne.getRouteAirlinerClass(aClass.Type).FarePrice = aClass.FarePrice;

                    routeLegOne.getRouteAirlinerClass(aClass.Type).FarePrice = PassengerHelpers.GetPassengerPrice(stopover, dest2) * GeneralHelpers.ClassToPriceFactor(aClass.Type);


                    foreach (RouteFacility facility in aClass.getFacilities())
                        routeLegOne.getRouteAirlinerClass(aClass.Type).addFacility(facility);

                    routeLegOne.getRouteAirlinerClass(aClass.Type).Seating = aClass.Seating;

                }

                stopoverRoute.addLeg(routeLegOne);
            }
            if (mainroute.Type == Route.RouteType.Cargo || mainroute.Type == Route.RouteType.Mixed)
            {
                CargoRoute routeLegOne = new CargoRoute(id.ToString(), stopover, dest2, ((CargoRoute)mainroute).PricePerUnit);

                stopoverRoute.addLeg(routeLegOne);
              
            }
           

            return stopoverRoute;
        }
Пример #2
0
        //loads a route
        private static Route LoadRoute(XmlElement routeNode, Airline airline, Route.RouteType routetype = Route.RouteType.Passenger)
        {
            string id = routeNode.Attributes["id"].Value;
            Airport dest1 = Airports.GetAirport(routeNode.Attributes["destination1"].Value);
            Airport dest2 = Airports.GetAirport(routeNode.Attributes["destination2"].Value);
            Boolean isBanned = Convert.ToBoolean(routeNode.Attributes["isbanned"].Value);

            if (routeNode.HasAttribute("type"))
                routetype = (Route.RouteType)Enum.Parse(typeof(Route.RouteType), routeNode.Attributes["type"].Value);

            Route route;

            if (routetype == Route.RouteType.Passenger || routetype == Route.RouteType.Mixed)
                route = new PassengerRoute(id, dest1, dest2, DateTime.Now,0);
            else
                route = new CargoRoute(id, dest1, dest2, DateTime.Now,0);

            route.Banned = isBanned;

            /* foreach (StopoverRoute stopover in route.Stopovers)
            {
                XmlElement routeStopoverNode = xmlDoc.CreateElement("stopover");
                routeStopoverNode.SetAttribute("airport", stopover.Stopover.Profile.ID);

                XmlElement stopoverLegsNode = xmlDoc.CreateElement("legs");
                foreach (Route leg in stopover.Legs)
                {
                    XmlElement stopoverLegNode = xmlDoc.CreateElement("leg");

                    stopoverLegNode.AppendChild(SaveRoute(xmlDoc, leg));

                    stopoverLegsNode.AppendChild(stopoverLegNode);
                }
                routeStopoverNode.AppendChild(stopoverLegsNode);
                routeStopoversNode.AppendChild(routeStopoverNode);*/

            XmlNodeList routeStopoverList = routeNode.SelectNodes("stopovers/stopover");

            foreach (XmlElement routeStopoverNode in routeStopoverList)
            {
                Airport stopoverAirport = Airports.GetAirportFromID(routeStopoverNode.Attributes["airport"].Value);

                StopoverRoute stopoverRoute = new StopoverRoute(stopoverAirport);

                XmlNodeList legsList = routeStopoverNode.SelectNodes("legs/leg");

                foreach (XmlElement legNode in legsList)
                {

                    stopoverRoute.addLeg(LoadRoute((XmlElement)legNode.SelectSingleNode("route"), airline, routetype));
                }

                route.addStopover(stopoverRoute);

            }

            if (routetype == Route.RouteType.Passenger || routetype == Route.RouteType.Mixed)
            {
                ((PassengerRoute)route).Classes.Clear();

                XmlNodeList routeClassList = routeNode.SelectNodes("routeclasses/routeclass");

                foreach (XmlElement routeClassNode in routeClassList)
                {
                    AirlinerClass.ClassType airlinerClassType = (AirlinerClass.ClassType)Enum.Parse(typeof(AirlinerClass.ClassType), routeClassNode.Attributes["type"].Value);
                    double fareprice = Convert.ToDouble(routeClassNode.Attributes["fareprice"].Value,new CultureInfo("de-DE", false));
                    RouteAirlinerClass.SeatingType seatingType = (RouteAirlinerClass.SeatingType)Enum.Parse(typeof(RouteAirlinerClass.SeatingType), routeClassNode.Attributes["seating"].Value);

                    RouteAirlinerClass rClass = new RouteAirlinerClass(airlinerClassType, RouteAirlinerClass.SeatingType.Reserved_Seating, fareprice);
                    rClass.Seating = seatingType;

                    foreach (RouteFacility.FacilityType ftype in Enum.GetValues(typeof(RouteFacility.FacilityType)))
                    {
                        if (routeClassNode.HasAttribute(ftype.ToString()))
                        {
                            RouteFacility facility = RouteFacilities.GetFacility(routeClassNode.Attributes[ftype.ToString()].Value);
                            rClass.addFacility(facility);
                        }
                    }

                    ((PassengerRoute)route).addRouteAirlinerClass(rClass);

                }
            }
            if (routetype == Route.RouteType.Mixed || routetype == Route.RouteType.Cargo)
            {
                XmlElement routeCargoNode = (XmlElement)routeNode.SelectSingleNode("cargo");
                double unitPrice = Convert.ToDouble(routeCargoNode.Attributes["priceperunit"].Value,new CultureInfo("de-DE", false));

                ((CargoRoute)route).PricePerUnit = unitPrice;

            }

            RouteTimeTable timeTable = new RouteTimeTable(route);

            XmlNodeList timetableList = routeNode.SelectNodes("timetable/timetableentry");

            foreach (XmlElement entryNode in timetableList)
            {
                Airport entryDest = Airports.GetAirport(entryNode.Attributes["destination"].Value);
                string flightCode = entryNode.Attributes["flightcode"].Value;
                DayOfWeek day = (DayOfWeek)Enum.Parse(typeof(DayOfWeek), entryNode.Attributes["day"].Value);
                TimeSpan time = TimeSpan.Parse(entryNode.Attributes["time"].Value);
                FleetAirliner airliner = entryNode.Attributes["airliner"].Value == "-" ? null : airline.Fleet.Find(a => a.Airliner.ID == entryNode.Attributes["airliner"].Value); ;

                RouteTimeTableEntry entry = new RouteTimeTableEntry(timeTable, day, time, new RouteEntryDestination(entryDest, flightCode,null),null);

                if (entryNode.HasAttribute("id"))
                    entry.ID = entryNode.Attributes["id"].Value;

                if (entryNode.HasAttribute("mainentry")) entry.MainEntry = airline.Routes.SelectMany(r => r.TimeTable.Entries).ToList().Find(e => e.ID == entryNode.Attributes["mainentry"].Value);

                entry.Airliner = airliner;

                if (airliner != null && !airliner.Routes.Contains(route))
                    airliner.Routes.Add(route);

                timeTable.addEntry(entry);
            }
            route.TimeTable = timeTable;

            XmlNodeList routeInvoiceList = routeNode.SelectNodes("invoices/invoice");

            foreach (XmlElement routeInvoiceNode in routeInvoiceList)
            {
                Invoice.InvoiceType type = (Invoice.InvoiceType)Enum.Parse(typeof(Invoice.InvoiceType), routeInvoiceNode.Attributes["type"].Value);
                int invoiceYear = Convert.ToInt16(routeInvoiceNode.Attributes["year"].Value);
                int invoiceMonth = Convert.ToInt16(routeInvoiceNode.Attributes["month"].Value);
                double invoiceAmount = Convert.ToDouble(routeInvoiceNode.Attributes["amount"].Value, new CultureInfo("de-DE", false));

                route.setRouteInvoice(type, invoiceYear, invoiceMonth, invoiceAmount);
            }

            return route;
        }