public static Airline LoadAirline(string path) { var doc = new XmlDocument(); doc.Load(path); XmlElement root = doc.DocumentElement; var profileElement = (XmlElement) root?.SelectSingleNode("profile"); if (profileElement != null) { 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; var countries = sCountries.Split(';').Select(Countries.GetCountry).ToList(); //Country country = Countries.GetCountry(profileElement.Attributes["country"].Value); string ceo = profileElement.Attributes["CEO"].Value; var mentality = (Airline.AirlineMentality) Enum.Parse(typeof (Airline.AirlineMentality), profileElement.Attributes["mentality"].Value); var market = (AirlineFocus) Enum.Parse(typeof (AirlineFocus), profileElement.Attributes["market"].Value); var routeFocus = Route.RouteType.Passenger; if (profileElement.HasAttribute("routefocus")) { routeFocus = (Route.RouteType) Enum.Parse(typeof (Route.RouteType), profileElement.Attributes["routefocus"].Value); } var narrativeElement = (XmlElement) profileElement.SelectSingleNode("narrative"); string narrative = ""; if (narrativeElement != null) { narrative = narrativeElement.Attributes["narrative"].Value; } bool isReal = true; int founded = 1950; int folded = 2199; var 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); } var license = Airline.AirlineLicense.Domestic; if (market == AirlineFocus.Global) { license = mentality == Airline.AirlineMentality.Aggressive ? Airline.AirlineLicense.LongHaul : Airline.AirlineLicense.ShortHaul; } if (market == AirlineFocus.Regional) { license = Airline.AirlineLicense.Regional; } var airline = new Airline( new AirlineProfile(name, iata, color, ceo, isReal, founded, folded), mentality, market, license, routeFocus) {Profile = {Countries = countries}}; airline.Profile.Country = airline.Profile.Countries[0]; airline.Profile.LogoName = logoImage; var 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")) { var primarypurchasing = (AirlineProfile.PreferedPurchasing) Enum.Parse( typeof (AirlineProfile.PreferedPurchasing), preferedsElement.Attributes["primarypurchasing"].Value); airline.Profile.PrimaryPurchasing = primarypurchasing; } } XmlNodeList logosList = profileElement.SelectNodes("logos/logo"); if (logosList != null) 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); var subMentality = (Airline.AirlineMentality) Enum.Parse( typeof (Airline.AirlineMentality), subsidiaryElement.Attributes["mentality"].Value); var subMarket = (AirlineFocus) Enum.Parse(typeof (AirlineFocus), subsidiaryElement.Attributes["market"].Value); string subLogo = AppSettings.GetDataPath() + "\\graphics\\airlinelogos\\" + subsidiaryElement.Attributes["logo"].Value + ".png"; var 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)); } } var startDataElement = (XmlElement) root.SelectSingleNode("startdata"); if (startDataElement != null) { var startData = new AirlineStartData(airline); XmlNodeList routesList = startDataElement.SelectNodes("routes/route"); if (routesList != null) 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); } var 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); var 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); } var 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; } return null; }
//adds a route to the list public void AddRoute(StartDataRoute route) { Routes.Add(route); }