예제 #1
0
        public CrewConfigurationInfo Clone()
        {
            var clone = new CrewConfigurationInfo();

            foreach (var kvp in _crews)
            {
                clone._crews.Add(kvp.Key, kvp.Value.Clone());
            }

            return(clone);
        }
        internal CrewConfiguration(IRepository repository, TankEntity tank, ScriptHost scriptHost, CrewConfigurationInfo configInfo)
            : base(repository, tank, scriptHost)
        {
            if (configInfo == null)
            {
                _crewConfigurationInfo = new CrewConfigurationInfo();
            }

            _element = new XElement("crews");

            var crewDatum = tank.QueryMany("crews/crew");

            var redundancyCounters = new Dictionary <string, int>();
            var crewList           = new List <CrewInstance>();

            foreach (var data in crewDatum)
            {
                var primaryRole    = data["@role"];
                var secondaryRoles = data.QueryManyValues("secondaryRoles/secondaryRole").ToArray();
                int redundancyIndex;
                if (redundancyCounters.ContainsKey(primaryRole))
                {
                    redundancyIndex = redundancyCounters[primaryRole] = redundancyCounters[primaryRole] + 1;
                }
                else
                {
                    redundancyIndex = redundancyCounters[primaryRole] = 0;
                }

                var crew = new CrewInstance(this, primaryRole, secondaryRoles, redundancyIndex);
                crewList.Add(crew);
                this.Element.Add(crew.Element);

                if (configInfo == null)
                {
                    _crewConfigurationInfo[crew.PrimaryRole] = crew.CrewInstanceInfo;
                }
            }

            _crews = crewList.ToArray();

            if (configInfo != null)
            {
                _crewConfigurationInfo = configInfo;
            }
        }