private async Task LoadAllGroups() { var existing = await LoadCachedGroups(); var live = await LoadLiveGroups(); foreach (BlogGroup liveGroup in live .Where(liveGroup => !existing.Contains(liveGroup, new BaseItemComparer()))) { existing.Add(liveGroup); await StorageUtility.SaveItem(GROUP_FOLDER, liveGroup); } foreach (var group in existing.OrderBy(e => e.Title)) { GroupList.Add(group); } }
private static async Task <IList <BlogGroup> > LoadCachedGroups() { var retVal = new List <BlogGroup>(); foreach (var item in await StorageUtility.ListItems(GROUP_FOLDER)) { try { var group = await StorageUtility.RestoreItem <BlogGroup>(GROUP_FOLDER, item); retVal.Add(group); } catch (Exception ex) { Debug.WriteLine(ex.ToString()); } } return(retVal); }
public async Task LoadAllItems(BlogGroup group) { var cachedItems = await LoadCachedItems(group); group.ItemCount = cachedItems.Count; group.NewItemCount = 0; var newItems = await LoadLiveItems(group); foreach (var item in newItems.Where(i => !cachedItems.Contains(i, new BaseItemComparer()))) { MessageDialog dialog = null; try { var client = GetClient(); var page = await client.GetStringAsync(item.PageUri); item.ImageUriList = new ObservableCollection <Uri>(BlogUtility.ExtractImagesFromPage(page)); foreach (var image in item.ImageUriList) { ImageUriManager.AddImage(item.Id, image); } } catch (Exception ex) { dialog = new MessageDialog(ex.Message); } if (dialog != null) { await dialog.ShowAsync(); } cachedItems.Add(item); group.NewItemCount++; await StorageUtility.SaveItem(group.Id.GetHashCode().ToString(), item); } foreach (var item in cachedItems.OrderByDescending(i => i.PostDate)) { group.Items.Add(item); } }
private static async Task <IList <BlogItem> > LoadCachedItems(BlogGroup group) { var retVal = new List <BlogItem>(); var groupFolder = group.Id.GetHashCode().ToString(); foreach (var item in await StorageUtility.ListItems(groupFolder)) { try { var post = await StorageUtility.RestoreItem <BlogItem>(groupFolder, item); post.Group = group; retVal.Add(post); } catch (Exception ex) { Debug.WriteLine(ex.ToString()); } } return(retVal); }