예제 #1
0
 public void SetDevice(Enigma device)
 {
     this.device = device;
 }
예제 #2
0
파일: Factory.cs 프로젝트: Groutcho/Enigma
        private IEnumerable<Enigma> GetEnigmaPresets(XDocument doc)
        {
            IEnumerable<XElement> enigmaCollection;

            try
            {
                enigmaCollection = doc.Root.Element("presets").Elements("device");
            }

            catch (Exception)
            {
                throw;
            }

            var enigmaDescriptors = from enigma in enigmaCollection
                                   select new EnigmaDescriptor
                                   {
                                       Id = (string)enigma.Element("id"),
                                       Name = (string)enigma.Attribute("name"),
                                       Description = (string)enigma.Element("description"),
                                       Rotors = from  rotor in enigma.Element("rotors").Elements("rotor") select rotor.Value
                                   };

            List<Enigma> result = new List<Enigma>(enigmaDescriptors.Count());

            foreach (var descriptor in enigmaDescriptors)
            {
                var rotors = from rotor in descriptor.Rotors select rotorModels[rotor];

                Enigma device = new Enigma(rotors, descriptor);

                result.Add(device);
            }

            return result;
        }