/// <summary> /// Restore a page /// </summary> /// <param name="pageId">The page identifier</param> /// <returns>The restored page</returns> private static async Task <SkrapedPage> RestorePage(int pageId) { var restoredPage = new SkrapedPage { Id = pageId }; var loaded = LocalSettings.Values.ContainsKey("Page" + pageId) && (bool)LocalSettings.Values["Page" + pageId]; var container = Roaming.CreateContainer( PageKey, ApplicationDataCreateDisposition.Always); var compositeValue = container.Values[pageId.ToString()] as ApplicationDataCompositeValue; if (compositeValue != null) { restoredPage.Url = new Uri(compositeValue[UrlProperty].ToString()); restoredPage.Title = compositeValue[TitleProperty].ToString(); restoredPage.ThumbnailPath = loaded ? new Uri(compositeValue[ThumbnailProperty].ToString()) : new Uri("ms-appx:///Assets/ie.png"); restoredPage.Loaded = loaded; var imageCount = (int)compositeValue[ImageCountProperty]; for (var idx = 0; idx < imageCount; idx++) { restoredPage.Images.Add(new Uri(compositeValue[ImageIndex + idx].ToString())); } } await RestorePageData(restoredPage); return(restoredPage); }
/// <summary> /// The restore groups. /// </summary> /// <returns> /// The <see cref="Task"/> for asynchronous operation. /// </returns> public async Task <IEnumerable <SkrapeGroup> > RestoreGroups() { var groups = new List <SkrapeGroup>(); var groupsContainer = Roaming.CreateContainer(GroupKey, ApplicationDataCreateDisposition.Always); foreach (var group in groupsContainer.Values) { var restoredGroup = new SkrapeGroup { Id = int.Parse(@group.Key) }; var compositeValue = group.Value as ApplicationDataCompositeValue; if (compositeValue != null) { restoredGroup.Title = compositeValue[TitleProperty].ToString(); restoredGroup.Description = compositeValue[DescriptionProperty].ToString(); var pageCount = (int)compositeValue[PageCountProperty]; for (var idx = 0; idx < pageCount; idx++) { var pageId = (int)compositeValue[PageIndex + idx]; restoredGroup.Pages.Add(await RestorePage(pageId)); } } groups.Add(restoredGroup); } return(groups); }
/// <summary> /// The save group. /// </summary> /// <param name="group"> /// The group. /// </param> /// <returns> /// The <see cref="Task"/> to run asynchronously. /// </returns> public Task SaveGroup(SkrapeGroup group) { return(Task.Run( () => { var compositeValue = new ApplicationDataCompositeValue { { IdProperty, @group.Id }, { TitleProperty, @group.Title }, { DescriptionProperty, @group.Description }, { PageCountProperty, @group.Pages.Count() } }; for (var idx = 0; idx < group.Pages.Count(); idx++) { compositeValue.Add(PageIndex + idx, group.Pages[idx].Id); } var container = Roaming.CreateContainer(GroupKey, ApplicationDataCreateDisposition.Always); container.Values[group.Id.ToString()] = compositeValue; })); }
/// <summary> /// The save page. /// </summary> /// <param name="page"> /// The page. /// </param> /// <returns> /// The <see cref="Task"/> for asynchronous saving. /// </returns> public async Task SavePage(SkrapedPage page) { // save loaded status locally, so remote machines will load on first use LocalSettings.Values["Page" + page.Id] = page.Loaded; var compositeValue = new ApplicationDataCompositeValue { { IdProperty, page.Id }, { TitleProperty, page.Title }, { ThumbnailProperty, page.ThumbnailPath.ToString() }, { UrlProperty, page.Url.ToString() }, { ImageCountProperty, page.Images.Count() } }; for (var idx = 0; idx < page.Images.Count(); idx++) { compositeValue.Add(ImageIndex + idx, page.Images[idx].ToString()); } var container = Roaming.CreateContainer( PageKey, ApplicationDataCreateDisposition.Always); container.Values[page.Id.ToString()] = compositeValue; await SavePageData(page); }
/// <summary> /// The delete page method. /// </summary> /// <param name="page"> /// The page. /// </param> public void DeletePage(SkrapedPage page) { var container = Roaming.CreateContainer( PageKey, ApplicationDataCreateDisposition.Always); if (container.Values.ContainsKey(page.Id.ToString())) { container.Values.Remove(page.Id.ToString()); } }
/// <summary> /// The delete group method. /// </summary> /// <param name="group"> /// The group. /// </param> public void DeleteGroup(SkrapeGroup group) { foreach (var page in group.Pages) { DeletePage(page); } var container = Roaming.CreateContainer(GroupKey, ApplicationDataCreateDisposition.Always); if (container.Values.ContainsKey(group.Id.ToString())) { container.Values.Remove(group.Id.ToString()); } }