Esempio n. 1
0
        /// <summary>
        /// Method used to save Planet's Data
        /// </summary>
        /// <param name="line"></param>
        internal void AddPlanet(string line)
        {
            string[] values      = line.Split(',');
            int      planetIndex = DataStructure.FindHeaderIndex(Constants.PlanetNameHeader);
            int      starIndex   = DataStructure.FindHeaderIndex(Constants.HostNameHeader);
            string   planetName  = values[planetIndex].Trim();
            string   starName    = values[starIndex].Trim();


            //Checks if the List alreay has the current planet...
            if (Planets.GetAstroByName(planetName) != null)
            {
                //...and throws a Repeated Planet Exception
                throw new Exception("Repeated planet.");
            }


            Star thisPlanetStar = Stars.GetAstroByName(starName);

            //Checks if the planet's star doensn't exist....
            if (thisPlanetStar == null)
            {
                //...and adds it if it doesn't
                thisPlanetStar = new Star(starName);

                Stars.AddLast(thisPlanetStar);
            }

            //Creates a new planet
            Planet newPlanet = new Planet(thisPlanetStar, planetName);

            //Adds it to the Star host
            thisPlanetStar.AddPlanet(newPlanet);

            //Adds the new planet to the list
            Planets.AddLast(newPlanet);

            //Sets the new planet's data
            HandleDataFields(newPlanet, values);
        }