Example #1
0
        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);
            }
        }
Example #2
0
        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);
            }
        }