Ejemplo n.º 1
0
 public Airport(AirportProfile profile)
 {
     this.Profile = profile;
     this.Income = 0;
     this.DestinationPassengers = new List<DestinationDemand>();
     this.DestinationCargo = new List<DestinationDemand>();
     this.Facilities = new List<AirlineAirportFacility>();
     this.Statistics = new AirportStatistics();
     this.Weather = new Weather[5];
     this.Terminals = new Terminals(this);
     this.Runways = new List<Runway>();
     this._Hubs = new List<Hub>();
     this.DestinationPassengerStatistics = new Dictionary<Airport, long>();
     this.DestinationCargoStatistics = new Dictionary<Airport, double>();
     this.LastExpansionDate = new DateTime(1900, 1, 1);
     this.Statics = new AirportStatics(this);
     this.AirlineContracts = new List<AirportContract>();
 }
Ejemplo n.º 2
0
 public Airport(AirportProfile profile)
 {
     this.Profile = profile;
     this.Income  = 0;
     this.DestinationPassengers = new List <DestinationDemand>();
     this.DestinationCargo      = new List <DestinationDemand>();
     this.Facilities            = new List <AirlineAirportFacility>();
     this.Statistics            = new AirportStatistics();
     this.Weather   = new Weather[5];
     this.Terminals = new Terminals(this);
     this.Runways   = new List <Runway>();
     this._Hubs     = new List <Hub>();
     this.DestinationPassengerStatistics = new Dictionary <Airport, long>();
     this.DestinationCargoStatistics     = new Dictionary <Airport, double>();
     this.LastExpansionDate = new DateTime(1900, 1, 1);
     this.Statics           = new AirportStatics(this);
     this.AirlineContracts  = new List <AirportContract>();
 }
Ejemplo n.º 3
0
        private static void LoadAirports(string filename)
        {
            string id = "";
            try
            {
                XmlDocument doc = new XmlDocument();
                doc.Load(filename);
                XmlElement root = doc.DocumentElement;

                XmlNodeList airportsList = root.SelectNodes("//airport");

                foreach (XmlElement airportElement in airportsList)
                {

                    string name = airportElement.Attributes["name"].Value;
                    string icao = airportElement.Attributes["icao"].Value;
                    string iata = airportElement.Attributes["iata"].Value;

                    id = name + " iata: " + iata;

                    AirportProfile.AirportType type = (AirportProfile.AirportType)Enum.Parse(typeof(AirportProfile.AirportType), airportElement.Attributes["type"].Value);
                    Weather.Season season = (Weather.Season)Enum.Parse(typeof(Weather.Season), airportElement.Attributes["season"].Value);

                    XmlElement periodElement = (XmlElement)airportElement.SelectSingleNode("period");

                    Period<DateTime> airportPeriod;
                    if (periodElement != null)
                    {
                        DateTime airportFrom = Convert.ToDateTime(periodElement.Attributes["from"].Value, new CultureInfo("en-US", false));
                        DateTime airportTo = Convert.ToDateTime(periodElement.Attributes["to"].Value, new CultureInfo("en-US", false));

                        airportPeriod = new Period<DateTime>(airportFrom, airportTo);
                    }
                    else
                        airportPeriod = new Period<DateTime>(new DateTime(1959, 12, 31), new DateTime(2199, 12, 31));

                    XmlElement townElement = (XmlElement)airportElement.SelectSingleNode("town");
                    string town = townElement.Attributes["town"].Value;
                    string country = townElement.Attributes["country"].Value;
                    TimeSpan gmt = TimeSpan.Parse(townElement.Attributes["GMT"].Value);
                    TimeSpan dst = TimeSpan.Parse(townElement.Attributes["DST"].Value);

                    XmlElement latitudeElement = (XmlElement)airportElement.SelectSingleNode("coordinates/latitude");
                    XmlElement longitudeElement = (XmlElement)airportElement.SelectSingleNode("coordinates/longitude");
                    string[] latitude = latitudeElement.Attributes["value"].Value.Split(new Char[] { '°', '\'' }, StringSplitOptions.RemoveEmptyEntries);
                    string[] longitude = longitude = longitudeElement.Attributes["value"].Value.Split(new Char[] { '°', '\'' }, StringSplitOptions.RemoveEmptyEntries);
                    int[] coords = new int[6];

                    //latitude
                    coords[0] = int.Parse(latitude[0]);
                    coords[1] = int.Parse(latitude[1]);
                    coords[2] = int.Parse(latitude[2]);

                    if (latitude[3] == "S")
                        coords[0] = -coords[0];

                    //longitude
                    coords[3] = int.Parse(longitude[0]);
                    coords[4] = int.Parse(longitude[1]);
                    coords[5] = int.Parse(longitude[2]);

                    if (longitude[3] == "W")
                        coords[3] = -coords[3];

                    /*
                    foreach(string l in latitude )
                    {
                        //int.TryParse(l, out coords[c]);
                        coords[c] = int.Parse(l);
                        c++;
                    }
                    c = 3;

                    foreach (string l in longitude)
                    {
                        //int.TryParse(l, out coords[c]);
                        coords[c] = int.Parse(l);

                        c++;
                    }*/

                    //cleaning up
                    latitude = null;
                    longitude = null;

                    //GeoCoordinate pos = new GeoCoordinate(MathHelpers.DMStoDeg(coords[0], coords[1], coords[2]),MathHelpers.DMStoDeg(coords[3],coords[4],coords[5]));
                    Coordinates pos = new Coordinates(new Coordinate(coords[0], coords[1], coords[2]), new Coordinate(coords[3], coords[4], coords[5]));

                    //double longitude = Coordinate.Parse(longitudeElement.Attributes["value"].Value);

                    XmlElement sizeElement = (XmlElement)airportElement.SelectSingleNode("size");

                    List<PaxValue> paxValues = new List<PaxValue>();

                    if (!sizeElement.HasChildNodes)
                    {
                        GeneralHelpers.Size size = (GeneralHelpers.Size)Enum.Parse(typeof(GeneralHelpers.Size), sizeElement.Attributes["value"].Value);
                        int pax = sizeElement.HasAttribute("pax") ? Convert.ToInt32(sizeElement.Attributes["pax"].Value) : 0;

                        paxValues.Add(new PaxValue(airportPeriod.From.Year, airportPeriod.To.Year, size, pax));
                    }
                    else
                    {
                        XmlNodeList yearsList = sizeElement.SelectNodes("yearvalues/yearvalue");

                        foreach (XmlElement yearElement in yearsList)
                        {
                            int fromYear = Convert.ToInt16(yearElement.Attributes["from"].Value);
                            int toYear = Convert.ToInt16(yearElement.Attributes["to"].Value);
                            GeneralHelpers.Size size = (GeneralHelpers.Size)Enum.Parse(typeof(GeneralHelpers.Size), yearElement.Attributes["value"].Value);
                            int pax = Convert.ToInt32(yearElement.Attributes["pax"].Value);

                            PaxValue paxValue = new PaxValue(fromYear, toYear, size, pax);

                            if (yearElement.HasAttribute("inflationafter"))
                                paxValue.InflationAfterYear = Convert.ToDouble(yearElement.Attributes["inflationafter"].Value, CultureInfo.GetCultureInfo("en-US").NumberFormat);
                            if (yearElement.HasAttribute("inflationbefore"))
                                paxValue.InflationBeforeYear = Convert.ToDouble(yearElement.Attributes["inflationbefore"].Value, CultureInfo.GetCultureInfo("en-US").NumberFormat);

                            paxValues.Add(paxValue);
                        }
                    }

                    GeneralHelpers.Size cargoSize = GeneralHelpers.Size.Very_small;
                    double cargovolume = sizeElement.HasAttribute("cargovolume") ? Convert.ToDouble(sizeElement.Attributes["cargovolume"].Value, CultureInfo.GetCultureInfo("en-US").NumberFormat) : 0;

                    if (sizeElement.HasAttribute("cargo"))
                        cargoSize = (GeneralHelpers.Size)Enum.Parse(typeof(GeneralHelpers.Size), sizeElement.Attributes["cargo"].Value);
                    else
                    {
                        //calculates the cargo size
                        GeneralHelpers.Size[] cargoSizes = (GeneralHelpers.Size[])Enum.GetValues(typeof(GeneralHelpers.Size));

                        int i=0;

                       Dictionary<GeneralHelpers.Size,int> list = new Dictionary<GeneralHelpers.Size,int>();

                        while (i<cargoSizes.Length && cargoSizes[i] <= paxValues.First().Size)
                        {
                            list.Add(cargoSizes[i], 10 - i);
                            i++;
                        }

                        cargoSize = AIHelpers.GetRandomItem(list);

                       }

                    Town eTown = null;
                    if (town.Contains(","))
                    {
                        State state = States.GetState(Countries.GetCountry(country), town.Split(',')[1].Trim());

                        if (state == null)
                            eTown = new Town(town.Split(',')[0], Countries.GetCountry(country));
                        else
                            eTown = new Town(town.Split(',')[0], Countries.GetCountry(country), state);
                    }
                    else
                        eTown = new Town(town, Countries.GetCountry(country));

                    AirportProfile profile = new AirportProfile(name, iata, icao, type, airportPeriod, eTown, gmt, dst, pos, cargoSize, cargovolume, season);
                    profile.PaxValues = paxValues;

                    Airport airport = new Airport(profile);

                    XmlElement destinationsElement = (XmlElement)airportElement.SelectSingleNode("destinations");

                    if (destinationsElement != null)
                    {
                        XmlNodeList majorDestinationsList = destinationsElement.SelectNodes("destination");

                        Dictionary<string, int> majorDestinations = new Dictionary<string, int>();

                        foreach (XmlElement majorDestinationNode in majorDestinationsList)
                        {
                            string majorDestination = majorDestinationNode.Attributes["airport"].Value;
                            int majorDestinationPax = Convert.ToInt32(majorDestinationNode.Attributes["pax"].Value);

                            majorDestinations.Add(majorDestination, majorDestinationPax);
                        }

                        airport.Profile.MajorDestionations = majorDestinations;

                    }

                    XmlNodeList terminalList = airportElement.SelectNodes("terminals/terminal");

                    foreach (XmlElement terminalNode in terminalList)
                    {
                        string terminalName = terminalNode.Attributes["name"].Value;
                        int terminalGates = XmlConvert.ToInt32(terminalNode.Attributes["gates"].Value);

                        airport.Terminals.addTerminal(new Terminal(airport, null, terminalName, terminalGates, new DateTime(1950, 1, 1)));
                    }

                    XmlNodeList runwaysList = airportElement.SelectNodes("runways/runway");

                    foreach (XmlElement runwayNode in runwaysList)
                    {
                        string runwayName = runwayNode.Attributes["name"].Value;
                        long runwayLength = XmlConvert.ToInt32(runwayNode.Attributes["length"].Value);
                        Runway.SurfaceType surface = (Runway.SurfaceType)Enum.Parse(typeof(Runway.SurfaceType), runwayNode.Attributes["surface"].Value);

                        airport.Runways.Add(new Runway(runwayName, runwayLength, surface, new DateTime(1900, 1, 1), true));

                    }

                    if (Airports.GetAirport(a => a.Profile.ID == airport.Profile.ID) == null)
                        Airports.AddAirport(airport);

                }
            }
            catch (Exception e)
            {
                /*
                System.IO.StreamWriter file = new System.IO.StreamWriter(AppSettings.getCommonApplicationDataPath() + "\\theairlinestartup.log", true);
                file.WriteLine("Airport failing: " + id);
                file.WriteLine(e.ToString());
                file.WriteLine(e.StackTrace);
                file.Close();
                 * */
                string i = id;
                string s = e.ToString();
            }
        }