protected override async void LoadItemsAsync() { IsBusy = true; //var groupId = GroupId > 0 ? GroupId : (uint?)null; try { Items = await Executer.Execute( () => _hostProxyServer.GetHostsAsync(GroupId, new[] { HostSortField.ByName })); } catch (Exception ex) { ErrorHandler.Handle(ex); } finally { IsBusy = false; } }
private async Task <IEnumerable <DataItemViewModel> > ResolveHosts(IEnumerable <Item> items) { if (items == null) { return(null); } var cachedIds = _cachedHosts.Select(i => i.Id).ToList(); var hostIds = items .Where(i => !cachedIds.Contains(i.HostId)) .Select(i => i.HostId) .Distinct(); // try to find out all new hosts in our cache if (hostIds.Any()) { var hosts = await _hostProxyServer.GetHostsAsync(null, null, hostIds.ToArray()); foreach (var host in hosts) { _cachedHosts.Add(host); } } var result = new List <DataItemViewModel>(); foreach (var item in items) { var itemViewModel = new DataItemViewModel(item); itemViewModel.HostName = _cachedHosts .Where(i => i.Id == item.HostId) .Select(i => i.Name) .SingleOrDefault(); result.Add(itemViewModel); } return(result); }