Inheritance: BaseUnit
示例#1
0
        /*! load the unions
         */
        private static void LoadUnions()
        {
            var doc = new XmlDocument();
            doc.Load(AppSettings.GetDataPath() + "\\unions.xml");
            XmlElement root = doc.DocumentElement;

            XmlNodeList unionsList = root?.SelectNodes("//union");
            if (unionsList != null)
                foreach (XmlElement element in unionsList)
                {
                    try
                    {
                        string section = root.Name;
                        string uid = element.Attributes["uid"].Value;
                        string shortname = element.Attributes["shortname"].Value;
                        string flag = element.Attributes["flag"].Value;

                        var periodElement = (XmlElement) element.SelectSingleNode("period");
                        if (periodElement != null)
                        {
                            DateTime creationDate = Convert.ToDateTime(
                                periodElement.Attributes["creation"].Value,
                                new CultureInfo("en-US", false));
                            DateTime obsoleteDate = Convert.ToDateTime(
                                periodElement.Attributes["obsolete"].Value,
                                new CultureInfo("en-US", false));

                            var union = new Union(section, uid, shortname, creationDate, obsoleteDate);
                            XmlNodeList membersList = element.SelectNodes("members/member");

                            if (membersList != null)
                                foreach (XmlElement memberNode in membersList)
                                {
                                    Country country = Countries.GetCountry(memberNode.Attributes["country"].Value);
                                    DateTime fromDate = Convert.ToDateTime(
                                        memberNode.Attributes["memberfrom"].Value,
                                        new CultureInfo("en-US", false));
                                    DateTime toDate = Convert.ToDateTime(
                                        memberNode.Attributes["memberto"].Value,
                                        new CultureInfo("en-US", false));

                                    if (country == null)
                                    {
                                        uid = "";
                                    }

                                    union.AddMember(new UnionMember(country, fromDate, toDate));
                                }

                            union.Flag = AppSettings.GetDataPath() + "\\graphics\\flags\\" + flag + ".png";
                            Unions.AddUnion(union);
                        }

                        if (element.SelectSingleNode("translations") != null)
                        {
                            Translator.GetInstance()
                                .AddTranslation(
                                    root.Name,
                                    element.Attributes["uid"].Value,
                                    element.SelectSingleNode("translations"));
                        }
                    }
                    catch (Exception e)
                    {
                        Logger.Error("Error loading unions", e);
                    }
                }
        }
示例#2
0
 public static void AddUnion(Union union)
 {
     unions.Add(union);
 }