Exemplo n.º 1
0
        /// <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);
        }
Exemplo n.º 2
0
        /// <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;
            }));
        }
Exemplo n.º 3
0
        /// <summary>
        /// The generate test data method.
        /// </summary>
        private void GenerateTestData()
        {
            var baseuri    = new Uri("http://csharperimage.jeremylikness.com/", UriKind.Absolute);
            var groupNames = new[] { "Alpha", "Beta", "Omega " };

            foreach (var groupName in groupNames)
            {
                var pages = new[]
                {
                    "/2013/02/review-of-lenovo-ideapad-yoga-13-for.html",
                    "/2010/04/model-view-viewmodel-mvvm-explained.html",
                    "/2010/10/so-whats-fuss-about-silverlight.html",
                    "/2013/01/traveling-with-microsoft-and-asus.html"
                };
                var images = new[]
                {
                    new Uri(
                        "http://1.bp.blogspot.com/-R7LqKNm9BBk/Tl4oD5P9JdI/AAAAAAAAAZ8/pZ8J8gz_e5E/s1600/BlogHeader4.png"),
                    new Uri(
                        "http://lh6.ggpht.com/-YPUxFruIDFA/USFp0raqHAI/AAAAAAAAA6E/bHy3vg05Ed4/picture005_thumb2.jpg?imgmax=800"),
                    new Uri(
                        "http://lh6.ggpht.com/-WYkLA5K30mw/UObJc7Ls6bI/AAAAAAAAA3A/2gng-TfN6aE/WP_000232_thumb%25255B1%25255D.jpg?imgmax=800")
                };

                var group = new SkrapeGroup();
                group.Id          = groupIdProvider.GetId();
                group.Title       = groupName;
                group.Description =
                    string.Format(
                        "The {0} group for holding a set of test pages for the sample data of the application.",
                        groupName);
                for (var x = 0; x < 50; x++)
                {
                    var pageName = pages[x % pages.Length];
                    var pageUri  = new Uri(baseuri, pageName);
                    var page     = new SkrapedPage
                    {
                        Id            = pageIdProvider.GetId(),
                        Url           = pageUri,
                        Title         = pageName.Replace("/", " "),
                        ThumbnailPath = new Uri("ms-appx:///Assets/Logo.png")
                    };
                    foreach (var image in images)
                    {
                        page.Images.Add(image);
                    }

                    group.Pages.Add(page);
                }

                groups.Add(group);
            }
        }
Exemplo n.º 4
0
        /// <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());
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// The add url.
        /// </summary>
        /// <param name="url">
        /// The url.
        /// </param>
        /// <returns>
        /// The <see cref="Task"/> to run asynchronously.
        /// </returns>
        public async Task AddUrl(Uri url)
        {
            var existingPage = groups.SelectMany(g => g.Pages, (g, p) => new { g, p })
                               .Where(@t => [email protected] && @t.p.Url == url)
                               .Select(@t => @t.p).Any();

            if (existingPage)
            {
                return;
            }

            var page = new SkrapedPage
            {
                Id            = pageIdProvider.GetId(),
                Url           = url,
                Title         = "New Skrape - Tap to Load",
                ThumbnailPath = new Uri("ms-appx:///Assets/ie.png")
            };

            var domain = url.Host.ToLower();
            var group  = groups.FirstOrDefault(g => g.Title == domain);

            if (group != null)
            {
                group.Pages.Add(page);
                await Manager.SaveGroup(group);
            }
            else
            {
                var newGroup = new SkrapeGroup
                {
                    Id          = groupIdProvider.GetId(),
                    Title       = domain,
                    Description =
                        string.Format("Collection of Skrapes for the {0} domain.", domain)
                };
                newGroup.Pages.Add(page);
                Groups.Add(newGroup);
                await Manager.SaveGroup(newGroup);
            }

            await Manager.SavePage(page);

            Manager.AddUri(page.Url);
        }