/// <summary> /// 按照国家或地区的名称筛选服务器,同时更新程序中按国家或地区筛选的菜单 /// </summary> /// <param name="serverInfoCollection"></param> /// <returns></returns> private ServerInfo[] FilterByCountryAndUpdateCountryList(ServerInfo[] servers) { MenuItemCollection menuItems = FilterByCountryMenuItems.MenuItems; menuItems.Clear(); IEnumerable <string> countries = servers.Select(server => server.Country); IEnumerable <string> candidates = countries.Concat(new[] { "", Settings.Default.ChosenServerCountry }); CountryIpTable countryIpTable = CountryIpTable.Instance(); foreach (string country in candidates.OrderBy(x => x).Distinct()) { string countryName = country == "" ? Resources.AnyCountry : countryIpTable.GetCountryName(country); menuItems.Add(new MenuItem(countryName, delegate { if (Settings.Default.ChosenServerCountry == country) { return; } Settings.Default.ChosenServerCountry = country; DoUpdate(true); }) { Checked = country == Settings.Default.ChosenServerCountry, RadioCheck = true, }); } if ((Settings.Default.ChosenServerCountry ?? "") == "") { return(servers); } return(servers.Where(server => server.Country == Settings.Default.ChosenServerCountry).ToArray()); }
public static CountryIpTable Instance() { if (CurrentInstance == null) { CurrentInstance = new CountryIpTable(); } return(CurrentInstance); }