private async Task loadChildrenAsync(IContentItem item, bool silent) { if (item == null) { return; } if (item.Children != null) { item.Children = new ObservableCollection <IContentItem>(); } if (item.IsChannel && (((item as ChannelEx).CredentialsType == ChannelCredentialsType.UsernamePassword) || ((item as ChannelEx).CredentialsType == ChannelCredentialsType.UsernamePasswordServiceProvider) || ((item as ChannelEx).CredentialsType == ChannelCredentialsType.UsernamePasswordPin)) && (!(item as ChannelEx).LoginInfo.HasCredentials)) { SelectedChannel = item; return; } try { IsLoading = true; IEnumerable <IContentItem> children = null; if (item.IsRoot) { LoggerService.Instance.Log("INFO: Loading channels list"); } if (item.IsChannel) { SelectedChannel = item; await ImageToolsService.Instance.PreloadUrl((item as ChannelEx).MastheadUrl); } if (item.Expired && !item.IsChannel) { await renewItemID(item); } try { children = await getItemChildren(item, silent); } catch (UpgradeException) { canRefresh = false; } catch (MaintenanceException) { canRefresh = false; } catch (SessionExpiredException) { if (await renewItemID(item)) { markAllExpired(); children = await getItemChildren(item, silent); item.Expired = false; } } if (children != null) { if (children.Any() && !item.IsRoot) { var firstChildImage = await ContentClient.GetSmallImage(children.First().ID, SizingMode.Auto); if ((firstChildImage == null) || (firstChildImage.Length == 0)) { firstChildImage = await ContentClient.GetSmallImage(item.ID, 192, 128); } if ((firstChildImage != null) && (firstChildImage.Length > 0)) { int width = 0; int height = 0; ImageToolsService.Instance.GetImageSize(firstChildImage, out width, out height); if ((width > 0) && (height > 0)) { double ratio = width / (double)height; foreach (var child in children) { (child as ContentItemEx).ImageRatio = ratio; } } } } item.Children = new ObservableCollection <IContentItem>(children); } if (item.IsRoot && (children != null)) { foreach (var channel in children) { loadStoredChannelLoginInfo(channel as ChannelEx); } accountViewModel.Channels = new ObservableCollection <IContentItem>(children); if (item.IsRoot) { LoggerService.Instance.Log("INFO: Channels list loaded"); } } } catch (Exception ex) { //XXX : Handle error LoggerService.Instance.Log("ERROR: MediaContent.loadChildrenAsync: " + ex); } finally { if (IsLoading) { IsLoading = false; } } }