예제 #1
0
        /// <summary>
        /// Initialize a new instance of the TerrestrialProvider class.
        /// </summary>
        /// <param name="name"></param>
        public TerrestrialProvider(string name)
            : base(name)
        {
            if (!name.Contains("."))
            {
                country = new Country(name, null);
                area = null;
                return;
            }

            string[] parts = name.Split(new char[] { '.' });
            country = new Country(parts[0], null);
            area = new Area(parts[1], 0);
        }
예제 #2
0
 internal void load(XmlReader reader)
 {
     switch (reader.Name)
     {
         case "TimeZone":
             AddTimeZone(new Region(reader.GetAttribute("name"), Int32.Parse(reader.GetAttribute("code"))), true);
             break;
         case "Area":
             lastArea = new Area(reader.GetAttribute("name"), Int32.Parse(reader.GetAttribute("code")));
             AddArea(lastArea, true);
             break;
         default:
             lastArea.Load(reader);
             break;
     }
 }
예제 #3
0
        /// <summary>
        /// Add an area to the country.
        /// </summary>
        /// <param name="newArea">The area to be added.</param>
        /// <param name="addUndefined">True if an undefined entry is to be added to the start of the list; false otherwise.</param>
        public void AddArea(Area newArea, bool addUndefined)
        {
            if (addUndefined && Areas.Count == 0)
            {
                Area undefinedArea = new Area("-- Undefined --", 0);
                undefinedArea.AddRegion(new Region("-- Undefined --", 0));
                Areas.Add(undefinedArea);
            }

            foreach (Area oldArea in Areas)
            {
                if (oldArea.Name == newArea.Name)
                    return;

                if (oldArea.Name.CompareTo(newArea.Name) > 0)
                {
                    areas.Insert(areas.IndexOf(oldArea), newArea);
                    return;
                }
            }

            areas.Add(newArea);
        }
예제 #4
0
        /// <summary>
        /// Add a country to a collection.
        /// </summary>
        /// <param name="newCountry">The country to be added.</param>
        /// <param name="countries">The collection of countries to be added to.</param>
        public static void addCountry(Country newCountry, Collection<Country> countries)
        {
            if (countries.Count == 0)
            {
                Country undefinedCountry = new Country("-- Undefined --", "");
                Area undefinedArea = new Area("-- Undefined --", 0);
                undefinedArea.Regions.Add(new Region("-- Undefined --", 0));
                undefinedCountry.Areas.Add(undefinedArea);
                countries.Add(undefinedCountry);
            }

            foreach (Country oldCountry in countries)
            {
                if (oldCountry.Code == newCountry.Code)
                    return;

                if (oldCountry.Code.CompareTo(newCountry.Code) > 0)
                {
                    countries.Insert(countries.IndexOf(oldCountry), newCountry);
                    return;
                }
            }

            countries.Add(newCountry);
        }