Esempio n. 1
0
        /*!loads the countries.
         */
        /*! loads the temporary countries
         */
        private static void LoadTemporaryCountries()
        {
            var doc = new XmlDocument();
            doc.Load(AppSettings.GetDataPath() + "\\temporary countries.xml");
            XmlElement root = doc.DocumentElement;

            XmlNodeList countriesList = root?.SelectNodes("//country");
            if (countriesList != null)
                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;
                    var tempType =
                        (TemporaryCountry.TemporaryType)
                            Enum.Parse(typeof (TemporaryCountry.TemporaryType), element.Attributes["type"].Value);

                    var periodElement = (XmlElement) element.SelectSingleNode("period");
                    if (periodElement != null)
                    {
                        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));

                        var 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"));
                        }

                        var historyElement = (XmlElement) element.SelectSingleNode("history");

                        var tCountry = new TemporaryCountry(tempType, country, startDate, endDate);

                        if (tempType == TemporaryCountry.TemporaryType.ManyToOne)
                        {
                            if (historyElement != null)
                            {
                                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");

                            if (tempCountriesList != null)
                                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);
                    }
                }
        }
 public static void AddCountry(TemporaryCountry country)
 {
     Countries.Add(country);
 }