//returns a temporary country which a country is a part of public static TemporaryCountry GetTemporaryCountry(Country country, DateTime date) { if (country == null) { return(null); } TemporaryCountry tCountry = tCountries.Find(c => c.StartDate <date && c.EndDate> date && (c.CountryBefore == country || c.CountryAfter == country || c.Countries.Find(tc => tc.Country.Uid == country.Uid) != null)); return(tCountry); }
/*! loads the temporary countries */ private static void LoadTemporaryCountries() { XmlDocument doc = new XmlDocument(); doc.Load(AppSettings.getDataPath() + "\\temporary countries.xml"); XmlElement root = doc.DocumentElement; XmlNodeList countriesList = root.SelectNodes("//country"); foreach (XmlElement element in countriesList) { string section = root.Name; string uid = element.Attributes["uid"].Value; string shortname = element.Attributes["shortname"].Value; string flag = element.Attributes["flag"].Value; Region region = Regions.GetRegion(element.Attributes["region"].Value); string tailformat = element.Attributes["tailformat"].Value; TemporaryCountry.TemporaryType tempType = (TemporaryCountry.TemporaryType)Enum.Parse(typeof(TemporaryCountry.TemporaryType), element.Attributes["type"].Value); XmlElement periodElement = (XmlElement)element.SelectSingleNode("period"); DateTime startDate = Convert.ToDateTime(periodElement.Attributes["start"].Value, new CultureInfo("en-US", false)); DateTime endDate = Convert.ToDateTime(periodElement.Attributes["end"].Value, new CultureInfo("en-US", false)); Country country = new Country(section, uid, shortname, region, tailformat); if (element.SelectSingleNode("translations") != null) Translator.GetInstance().addTranslation(root.Name, element.Attributes["uid"].Value, element.SelectSingleNode("translations")); XmlElement historyElement = (XmlElement)element.SelectSingleNode("history"); TemporaryCountry tCountry = new TemporaryCountry(tempType, country, startDate, endDate); if (tempType == TemporaryCountry.TemporaryType.ManyToOne) { Country before = Countries.GetCountry(historyElement.Attributes["before"].Value); Country after = Countries.GetCountry(historyElement.Attributes["after"].Value); tCountry.CountryBefore = before; tCountry.CountryAfter = after; } if (tempType == TemporaryCountry.TemporaryType.OneToMany) { XmlNodeList tempCountriesList = historyElement.SelectNodes("tempcountries/tempcountry"); foreach (XmlElement tempCountryElement in tempCountriesList) { Country tempCountry = Countries.GetCountry(tempCountryElement.Attributes["id"].Value); DateTime cStartDate = Convert.ToDateTime(tempCountryElement.Attributes["start"].Value, new CultureInfo("en-US", false)); DateTime cEndDate = Convert.ToDateTime(tempCountryElement.Attributes["end"].Value, new CultureInfo("en-US", false)); tCountry.Countries.Add(new OneToManyCountry(tempCountry, cStartDate, cEndDate)); } } tCountry.Flag = AppSettings.getDataPath() + "\\graphics\\flags\\" + flag + ".png"; TemporaryCountries.AddCountry(tCountry); } }
//adds a country to the list public static void AddCountry(TemporaryCountry country) { tCountries.Add(country); }
//returns a country public static Country GetCountry(string uid) { TemporaryCountry country = tCountries.Find(t => t.Uid == uid); return(country); }
//adds a country to the list public static void AddCountry(TemporaryCountry country) { tCountries.Add(country); }