private ObservableCollection <IServerListItem> GetMatchedServers(ServersByCountryViewModel country, string searchQuery) { ObservableCollection <IServerListItem> servers = new ObservableCollection <IServerListItem>(); foreach (IServerListItem server in country.Servers) { if (server.MatchesQuery(searchQuery)) { servers.Add(server); } } return(servers); }
private IEnumerable <IServerListItem> CreateServersByCountryViewModels(User user, IList <string> countryCodes, string searchQuery) { foreach (string countryCode in countryCodes) { ServersByCountryViewModel country = new ServersByCountryViewModel(countryCode, user.MaxTier, _serverManager, _vpnState); if (string.IsNullOrEmpty(searchQuery) || country.MatchesQuery(searchQuery)) { country.LoadServers(); yield return(country); } else if (!string.IsNullOrEmpty(searchQuery)) { ObservableCollection <IServerListItem> servers = GetMatchedServers(country, searchQuery); if (servers.Count > 0) { yield return(new ServersByCountryViewModel(country.CountryCode, _userStorage.User().MaxTier, _serverManager, _vpnState) { Servers = servers, Expanded = true, }); } } } }