Inheritance: BaseModel
 public static void AddEngineType(EngineType type)
 {
     _types.Add(type);
 }
        public static object ShowPopUp(AirlinerType type, List<AirlinerClass> classes, EngineType engine)
        {
            PopUpWindow window = new PopUpAirlinerSeatsConfiguration(type, classes, engine);
            window.ShowDialog();

            return window.Selected;
        }
        private static void LoadEngineTypes(string file)
        {
            var doc = new XmlDocument();
            doc.Load(file);

            XmlElement root = doc.DocumentElement;

            XmlNodeList enginesList = root?.SelectNodes("//engine");

            if (enginesList != null)
                foreach (XmlElement engineElement in enginesList)
                {
                    string manufacturerName = engineElement.Attributes["manufacturer"].Value;
                    Manufacturer manufacturer = Manufacturers.GetManufacturer(manufacturerName);

                    string name = engineElement.Attributes["model"].Value;

                    var specsElement = (XmlElement) engineElement.SelectSingleNode("specs");
                    if (specsElement != null)
                    {
                        var engineType =
                            (EngineType.TypeOfEngine)
                                Enum.Parse(typeof (EngineType.TypeOfEngine), specsElement.Attributes["type"].Value);
                        var noiseLevel =
                            (EngineType.NoiseLevel)
                                Enum.Parse(typeof (EngineType.NoiseLevel), specsElement.Attributes["noise"].Value);
                        double consumption = Convert.ToDouble(
                            specsElement.Attributes["consumptionModifier"].Value,
                            CultureInfo.GetCultureInfo("en-US").NumberFormat);
                        long price = Convert.ToInt64(specsElement.Attributes["price"].Value);

                        var perfElement = (XmlElement) engineElement.SelectSingleNode("performance");
                        if (perfElement != null)
                        {
                            int speed = Convert.ToInt32(perfElement.Attributes["maxspeed"].Value);
                            int ceiling = Convert.ToInt32(perfElement.Attributes["ceiling"].Value);
                            double runway = Convert.ToDouble(
                                perfElement.Attributes["runwaylengthrequiredModifier"].Value,
                                CultureInfo.GetCultureInfo("en-US").NumberFormat);
                            double range = Convert.ToDouble(
                                perfElement.Attributes["rangeModifier"].Value,
                                CultureInfo.GetCultureInfo("en-US").NumberFormat);

                            var producedElement = (XmlElement) engineElement.SelectSingleNode("produced");
                            if (producedElement != null)
                            {
                                int from = Convert.ToInt16(producedElement.Attributes["from"].Value);
                                int to = Convert.ToInt16(producedElement.Attributes["to"].Value);

                                var aircraftElement = (XmlElement) engineElement.SelectSingleNode("aircraft");
                                if (aircraftElement != null)
                                {
                                    string modelsElement = aircraftElement.Attributes["models"].Value;

                                    var engine = new EngineType(
                                        name,
                                        manufacturer,
                                        engineType,
                                        noiseLevel,
                                        consumption,
                                        price,
                                        speed,
                                        ceiling,
                                        runway,
                                        range,
                                        new Period<int>(@from, to));

                                    string[] models = modelsElement.Split(',');

                                    foreach (string model in models)
                                    {
                                        AirlinerType airlinerType = AirlinerTypes.GetAllTypes().FirstOrDefault(a => a.Name == model.Trim());

                                        if (airlinerType != null)
                                        {
                                            engine.AddAirlinerType(airlinerType);
                                        }
                                        else
                                            Console.WriteLine(@"Missing airliner type for engine: " + model);
                                    }

                                    EngineTypes.AddEngineType(engine);
                                }
                            }
                        }
                    }
                }
        }
        public PopUpAirlinerSeatsConfiguration(AirlinerType type, List<AirlinerClass> classes, EngineType engine)
        {
            this.FreeClassTypes = new ObservableCollection<AirlinerClass.ClassType>();
            this.Classes = new ObservableCollection<AirlinerClassMVVM>();
            this.Type = type;
            this.Engines = new List<EngineType>();

            foreach (EngineType e in EngineTypes.GetEngineTypes(type, GameObject.GetInstance().GameTime.Year).OrderBy(t => t.Price))
                this.Engines.Add(e);

            if (this.Engines.Count > 0)
                this.SelectedEngine = engine;

            AirlinerClass economyClass = classes.Find(c => c.Type == AirlinerClass.ClassType.EconomyClass);

            foreach (AirlinerClass aClass in classes)
            {

                int maxseats = aClass.Type == AirlinerClass.ClassType.EconomyClass ? aClass.SeatingCapacity : economyClass.RegularSeatingCapacity - 1;
                AirlinerClassMVVM nClass = new AirlinerClassMVVM(aClass.Type, aClass.SeatingCapacity, maxseats, aClass.Type != AirlinerClass.ClassType.EconomyClass);
                this.Classes.Add(nClass);

                foreach (AirlinerFacility facility in aClass.GetFacilities())
                    nClass.Facilities.Where(f => f.Type == facility.Type).First().SelectedFacility = facility;

            }

            this.CanAddNewClass = this.Classes.Count < ((AirlinerPassengerType)this.Type).MaxAirlinerClasses;

            if (this.Classes.Count < 3)
            {
                this.FreeClassTypes.Clear();
                this.FreeClassTypes.Add(AirlinerClass.ClassType.BusinessClass);
                this.FreeClassTypes.Add(AirlinerClass.ClassType.FirstClass);

            }

            this.Loaded += PopUpAirlinerSeatsConfiguration_Loaded;

            InitializeComponent();
        }