/// <summary>
        /// Resolve the <see cref="ContainerList{T}"/> from a <see cref="IEnumerable{Guid}"/> that represent the ids of the contained <see cref="Thing"/>s
        /// </summary>
        /// <typeparam name="T">The type of <see cref="Thing"/></typeparam>
        /// <param name="list">The <see cref="ContainerList{T}"/> to resolve</param>
        /// <param name="guidList">The source <see cref="IEnumerable{Guid}"/></param>
        /// <param name="iterationId">The potential <see cref="Iteration"/> container id of the contained <see cref="Thing"/>s</param>
        /// <param name="cache">The cache that stores the <see cref="Thing"/>s</param>
        internal static void ResolveList <T>(this ContainerList <T> list, IEnumerable <Guid> guidList, Guid?iterationId, ConcurrentDictionary <CacheKey, Lazy <CommonData.Thing> > cache) where T : Thing
        {
            list.Clear();

            foreach (var guid in guidList)
            {
                if (cache.TryGet(guid, iterationId, out T thing))
                {
                    thing.ChangeKind = ChangeKind.None;
                    list.Add(thing);
                }
            }
        }
 /// <inheritdoc/>
 public virtual void Clear()
 {
     ContainerList.Clear();
 }
Example #3
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);
            });
        }