Пример #1
0
 private void CopyGalaxiesCollectionToOrbsCollection()
 {
     _orbsCollection = new OrbsCollection();
     foreach (Galaxy galaxy in GalaxiesCollection[0].Galaxies.Values)
     {
         _orbsCollection.GalaxiesCollection.Add(new SimpleGalaxy(galaxy));
         if (galaxy.HasStars)
         {
             foreach (Star star in galaxy.Stars.Values)
             {
                 _orbsCollection.StarsCollection.Add(new SimpleStar(star));
                 if (star.HasPlanets)
                 {
                     foreach (Planet planet in star.Planets.Values)
                     {
                         _orbsCollection.PlanetsCollection.
                         Add(new SimplePlanet(planet));
                         if (planet.HasSecondaryPlanets)
                         {
                             foreach (Planet secondaryPlanet in
                                      planet.SecondaryPlanets.Values)
                             {
                                 _orbsCollection.SecondaryPlanetsCollection.
                                 Add(new SimplePlanet(secondaryPlanet));
                             }
                         }
                     }
                 }
             }
         }
     }
 }
Пример #2
0
        public void ReadFromFile()
        {
            var dcs = new DataContractSerializer(typeof(OrbsCollection));

            var fi = new FileInfo(ConnectionString);

            _orbsCollection = new OrbsCollection();

            using (Stream fs = fi.Open(FileMode.OpenOrCreate, FileAccess.Read,
                                       FileShare.None))
            {
                _orbsCollection = (OrbsCollection)dcs.ReadObject(fs);
            }
            CopyOrbsCollectionToGalaxiesCollection();
        }