AddAirlinerType() 공개 메소드

public AddAirlinerType ( AirlinerType type ) : void
type AirlinerType
리턴 void
예제 #1
0
        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);
                                }
                            }
                        }
                    }
                }
        }