Ejemplo n.º 1
0
        /*loads an airline and returns the object
         */
        public static Airline LoadAirline(string path)
        {
            XmlDocument doc = new XmlDocument();
            doc.Load(path);
            XmlElement root = doc.DocumentElement;

            XmlElement profileElement = (XmlElement)root.SelectSingleNode("profile");

            string name = profileElement.Attributes["name"].Value;
            string iata = profileElement.Attributes["iata"].Value;
            string color = profileElement.Attributes["color"].Value;

            string logoImage = profileElement.HasAttribute("logo") ? profileElement.Attributes["logo"].Value : "";

            string sCountries = profileElement.Attributes["country"].Value;

            List<Country> countries = new List<Country>();

            foreach (string sCountry in sCountries.Split(';'))
                countries.Add(Countries.GetCountry(sCountry));

            //Country country = Countries.GetCountry(profileElement.Attributes["country"].Value);
            string ceo = profileElement.Attributes["CEO"].Value;
            Airline.AirlineMentality mentality = (Airline.AirlineMentality)Enum.Parse(typeof(Airline.AirlineMentality), profileElement.Attributes["mentality"].Value);
            Airline.AirlineFocus market = (Airline.AirlineFocus)Enum.Parse(typeof(Airline.AirlineFocus), profileElement.Attributes["market"].Value);

            Route.RouteType routeFocus = Route.RouteType.Passenger;

            if (profileElement.HasAttribute("routefocus"))
                routeFocus = (Route.RouteType)Enum.Parse(typeof(Route.RouteType), profileElement.Attributes["routefocus"].Value);

            XmlElement narrativeElement = (XmlElement)profileElement.SelectSingleNode("narrative");

            string narrative = "";
            if (narrativeElement != null)
                narrative = narrativeElement.Attributes["narrative"].Value;

            Boolean isReal = true;
            int founded = 1950;
            int folded = 2199;

            XmlElement infoElement = (XmlElement)root.SelectSingleNode("info");
            if (infoElement != null)
            {
                isReal = Convert.ToBoolean(infoElement.Attributes["real"].Value);
                founded = Convert.ToInt16(infoElement.Attributes["from"].Value);
                folded = Convert.ToInt16(infoElement.Attributes["to"].Value);

            }

            Airline.AirlineLicense license = Airline.AirlineLicense.Domestic;

            if (market == Airline.AirlineFocus.Global)
                if (mentality == Airline.AirlineMentality.Aggressive)
                    license = Airline.AirlineLicense.Long_Haul;
                else
                    license = Airline.AirlineLicense.Short_Haul;

            if (market == Airline.AirlineFocus.Regional)
                license = Airline.AirlineLicense.Regional;

            Airline airline = new Airline(new AirlineProfile(name, iata, color, ceo, isReal, founded, folded), mentality, market, license, routeFocus);
            airline.Profile.Countries = countries;
            airline.Profile.Country = airline.Profile.Countries[0];
            airline.Profile.LogoName = logoImage;

            XmlElement preferedsElement = (XmlElement)root.SelectSingleNode("prefereds");

            if (preferedsElement != null)
            {
                if (preferedsElement.HasAttribute("aircrafts"))
                {
                    string[] preferedAircrafts = preferedsElement.Attributes["aircrafts"].Value.Split(',');

                    foreach (string preferedAircraft in preferedAircrafts)
                    {
                        AirlinerType pAircraft = AirlinerTypes.GetType(preferedAircraft);
                        airline.Profile.addPreferedAircraft(pAircraft);
                    }
                }
                if (preferedsElement.HasAttribute("primarypurchasing"))
                {
                    AirlineProfile.PreferedPurchasing primarypurchasing = (AirlineProfile.PreferedPurchasing)Enum.Parse(typeof(AirlineProfile.PreferedPurchasing), preferedsElement.Attributes["primarypurchasing"].Value);
                    airline.Profile.PrimaryPurchasing = primarypurchasing;
                }
            }

            XmlNodeList logosList = profileElement.SelectNodes("logos/logo");

            foreach (XmlElement logoElement in logosList)
            {
                int logoFromYear = Convert.ToInt16(logoElement.Attributes["from"].Value);
                int logoToYear = Convert.ToInt16(logoElement.Attributes["to"].Value);
                string logoPath = AppSettings.getDataPath() + "\\graphics\\airlinelogos\\multilogos\\" + logoElement.Attributes["path"].Value + ".png";

                airline.Profile.addLogo(new AirlineLogo(logoFromYear, logoToYear, logoPath));
            }

            if (profileElement.HasAttribute("preferedairport"))
            {
                Airport preferedAirport = Airports.GetAirport(profileElement.Attributes["preferedairport"].Value);
                airline.Profile.PreferedAirport = preferedAirport;
            }

            XmlNodeList subsidiariesList = root.SelectNodes("subsidiaries/subsidiary");
            if (subsidiariesList != null)
            {
                foreach (XmlElement subsidiaryElement in subsidiariesList)
                {
                    string subName = subsidiaryElement.Attributes["name"].Value;
                    string subIATA = subsidiaryElement.Attributes["IATA"].Value;
                    Airport subAirport = Airports.GetAirport(subsidiaryElement.Attributes["homebase"].Value);
                    Airline.AirlineMentality subMentality = (Airline.AirlineMentality)Enum.Parse(typeof(Airline.AirlineMentality), subsidiaryElement.Attributes["mentality"].Value);
                    Airline.AirlineFocus subMarket = (Airline.AirlineFocus)Enum.Parse(typeof(Airline.AirlineFocus), subsidiaryElement.Attributes["market"].Value);
                    string subLogo = AppSettings.getDataPath() + "\\graphics\\airlinelogos\\" + subsidiaryElement.Attributes["logo"].Value + ".png";

                    Route.RouteType airlineRouteFocus = Route.RouteType.Passenger;

                    if (subsidiaryElement.HasAttribute("routefocus"))
                        airlineRouteFocus = (Route.RouteType)Enum.Parse(typeof(Route.RouteType), subsidiaryElement.Attributes["routefocus"].Value);

                    airline.FutureAirlines.Add(new FutureSubsidiaryAirline(subName, subIATA, subAirport, subMentality, subMarket, airlineRouteFocus, subLogo));
                }
            }

            XmlElement startDataElement = (XmlElement)root.SelectSingleNode("startdata");
            if (startDataElement != null)
            {
                AirlineStartData startData = new AirlineStartData(airline);

                XmlNodeList routesList = startDataElement.SelectNodes("routes/route");
                foreach (XmlElement routeElement in routesList)
                {
                    string dest1 = routeElement.Attributes["destination1"].Value;
                    string dest2 = routeElement.Attributes["destination2"].Value;
                    int opened = Convert.ToInt16(routeElement.Attributes["opened"].Value);
                    int closed = Convert.ToInt16(routeElement.Attributes["closed"].Value);

                    Route.RouteType routetype = airline.AirlineRouteFocus;

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

                    StartDataRoute sdr = new StartDataRoute(dest1, dest2, opened, closed, routetype);
                    startData.addRoute(sdr);

                    if (routeElement.HasAttribute("airliner"))
                    {
                        AirlinerType airlinerType = AirlinerTypes.GetType(routeElement.Attributes["airliner"].Value);
                        sdr.Type = airlinerType;
                    }

                }

                XmlNodeList airlinersList = startDataElement.SelectNodes("airliners/airliner");

                foreach (XmlElement airlinerElement in airlinersList)
                {
                    string type = airlinerElement.Attributes["type"].Value;
                    int early = Convert.ToInt16(airlinerElement.Attributes["early"].Value);
                    int late = Convert.ToInt16(airlinerElement.Attributes["late"].Value);

                    startData.addAirliners(new StartDataAirliners(type, early, late));
                }

                XmlNodeList randomRoutesList = startDataElement.SelectNodes("random_routes/routes");

                foreach (XmlElement routeElement in randomRoutesList)
                {
                    string origin = routeElement.Attributes["origin"].Value;
                    int destinations = Convert.ToInt16(routeElement.Attributes["destinations"].Value);
                    GeneralHelpers.Size minimumsize = (GeneralHelpers.Size)Enum.Parse(typeof(GeneralHelpers.Size), routeElement.Attributes["minimumsize"].Value);

                    Route.RouteType routetype = airline.AirlineRouteFocus;

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

                    StartDataRoutes routes = new StartDataRoutes(origin, destinations, minimumsize, routetype);

                    XmlNodeList countriesList = routeElement.SelectNodes("countries/country");

                    foreach (XmlElement countryElement in countriesList)
                    {
                        Country routesCountry = Countries.GetCountry(countryElement.Attributes["value"].Value);
                        routes.addCountry(routesCountry);
                    }
                    startData.addOriginRoutes(routes);
                }

                AirlineStartDatas.AddStartData(startData);
            }

            airline.Profile.Narrative = narrative;

            Airlines.AddAirline(airline);

            return airline;
        }
 //adds a route to the list
 public void addRoute(StartDataRoute route)
 {
     this.Routes.Add(route);
 }
Ejemplo n.º 3
0
 //adds a route to the list
 public void addRoute(StartDataRoute route)
 {
     this.Routes.Add(route);
 }