Esempio n. 1
0
        public void LoadContainersStructureFromXML(string filename)
        {
            BaysList.Clear();
            ContainerList.Clear();
            XDocument xml = XDocument.Load(filename);

            xml.Descendants("Bay").Select(x => new
            {
                Name              = x.Attribute("Name").Value.ToString(),
                LcgDeck           = Convert.ToDouble(x.Attribute("LcgDeck").Value),
                LcgHold           = Convert.ToDouble(x.Attribute("LcgHold").Value),
                NearLivingQuarter = Convert.ToBoolean(x.Attribute("NearLivingQuarter").Value),
                Stack             = x.Descendants("Stack").Where(s => Convert.ToInt16(s.Attribute("StartTier").Value) >= 80).Select(s => new
                {
                    Row       = Convert.ToInt16(s.Attribute("Row").Value),
                    StartTier = Convert.ToInt16(s.Attribute("StartTier").Value),
                    LastTier  = Convert.ToInt16(s.Attribute("LastTier").Value),
                    Container = s.Descendants("ContainerType").Where(c => Convert.ToDouble(c.Attribute("Length").Value) < 13).Where(c => Convert.ToInt16(c.Attribute("StartTier").Value) >= 80).Select(c => new
                    {
                        Length = Convert.ToDouble(c.Attribute("Length").Value),
                        Width  = Convert.ToDouble(c.Attribute("Width").Value),
                    }).ToList()
                }).ToList(),
            }).ToList().ForEach(x =>
            {
                // Create Bay object.
                BayObject Bay = new BayObject(x.Name, x.LcgDeck, x.LcgHold, x.NearLivingQuarter);

                int currentBayNumber = Convert.ToInt16(x.Name);

                // Get the bays number.
                if (IsOdd(currentBayNumber) && currentBayNumber > this.LastBayNumber)
                {
                    LastBayNumber = currentBayNumber;
                }

                // Loop through all the bay stacks (floor).
                foreach (var tier in x.Stack)
                {
                    // Get the width and the length of the container type.
                    double width  = tier.Container[0].Width;
                    double length = tier.Container[0].Length;
                    if (LastTierNumber < tier.LastTier)
                    {
                        LastTierNumber = tier.LastTier;
                    }
                    // Loop through all the possible tiers.
                    for (var t = tier.StartTier; t <= tier.LastTier; t += 2)
                    {
                        if (Bay.MaxRow < tier.Row)
                        {
                            // Get the rows number.
                            Bay.MaxRow = tier.Row;
                        }
                        // Save the top tier number.
                        if (Bay.MaxTier < tier.LastTier)
                        {
                            Bay.MaxTier = tier.LastTier;
                        }
                        // Create the container as a unit object.
                        ContainerObject Container = new ContainerObject(Bay, tier.Row, t, width, length);
                        // Attach container object to the bay object.
                        Bay.AddContainerToList(Container);
                        // Add the container to the container list of the vessel.
                        this.AddContainerToList(Container);

                        if (LastRowNumber < Bay.MaxRow)
                        {
                            LastRowNumber = Bay.MaxRow;
                        }
                    }
                }
                // Add bay to the vessel.
                this.AddBaysToList(Bay);
            });
        }