Ejemplo n.º 1
0
        private void LoadTestGroups()
        {
            var jeremyGroup = new BlogGroup
            {
                Id      = JEREMY_BLOG,
                PageUri = new Uri(JEREMY_BLOG, UriKind.Absolute),
                Title   = "Jeremy Likness' Blog",
                RssUri  =
                    new Uri("http://www.wintellect.com/CS/blogs/jlikness/rss.aspx",
                            UriKind.Absolute),
            };

            GroupList.Add(jeremyGroup);

            var item = new BlogItem
            {
                Id =
                    SAMPLE_BLOG,
                PageUri     = new Uri(SAMPLE_BLOG, UriKind.Absolute),
                Title       = "Windows 8: The Facts about ARM, Metro, and the Blue Stack",
                Description =
                    "Many eyes will be focused on Barcelona on February 29, 2012 when Microsoft releases the Windows 8 Consumer Preview or what many are calling the beta version of the new platform. You’ve probably heard quite a bit about the Metro interface. It has design...",
                PostDate     = DateTime.Now,
                ImageUriList = new ObservableCollection <Uri>(new[]
                {
                    new Uri(
                        "http://lh6.ggpht.com/-qhW3FfZ7vXI/TzScQ_3eEEI/AAAAAAAAAds/3en8ijjglEg/stacks_thumb%25255B1%25255D.jpg?imgmax=800",
                        UriKind.Absolute),
                    new Uri(
                        "http://lh5.ggpht.com/-mUJv5DN5sOQ/TzScRSjHfJI/AAAAAAAAAd8/XErEJslVnKI/stackclr_thumb%25255B1%25255D.png?imgmax=800",
                        UriKind.Absolute),
                    new Uri(
                        "http://lh3.ggpht.com/-yCXImOFtSrc/TzScR2uTZ-I/AAAAAAAAAeM/43a7SGj5Uwo/stacklanguage_thumb%25255B1%25255D.png?imgmax=800",
                        UriKind.Absolute)
                }),
                Group = jeremyGroup
            };

            jeremyGroup.Items.Add(item);
        }
Ejemplo n.º 2
0
        private static async Task <List <BlogItem> > LoadLiveItems(BlogGroup group)
        {
            var info = NetworkInformation.GetInternetConnectionProfile();

            if (info == null || info.GetNetworkConnectivityLevel() != NetworkConnectivityLevel.InternetAccess)
            {
                return(new List <BlogItem>());
            }

            MessageDialog dialog = null;
            var           retVal = new List <BlogItem>();

            try
            {
                var client = GetSyndicationClient();
                var feed   = await client.RetrieveFeedAsync(group.RssUri);

                foreach (var item in feed.Items.OrderBy(i => i.PublishedDate))
                {
                    MessageDialog innerDialog = null;
                    try
                    {
                        var blogItem = new BlogItem {
                            Group = @group
                        };
                        var uri = string.Empty;

                        if (item.Links.Count > 0)
                        {
                            var link =
                                item.Links.FirstOrDefault(
                                    l => l.Relationship.Equals("alternate", StringComparison.OrdinalIgnoreCase)) ??
                                item.Links[0];
                            uri = link.Uri.AbsoluteUri;
                        }

                        blogItem.Id = uri;

                        blogItem.PageUri = new Uri(uri, UriKind.Absolute);
                        blogItem.Title   = item.Title != null ? item.Title.Text : "(no title)";

                        blogItem.PostDate = item.PublishedDate.LocalDateTime;

                        var content = "(no content)";

                        if (item.Content != null)
                        {
                            content = BlogUtility.ParseHtml(item.Content.Text);
                        }
                        else if (item.Summary != null)
                        {
                            content = BlogUtility.ParseHtml(item.Summary.Text);
                        }

                        blogItem.Description = content;

                        retVal.Add(blogItem);
                    }
                    catch (Exception ex)
                    {
                        innerDialog = new MessageDialog(ex.Message);
                    }

                    if (innerDialog != null)
                    {
                        await innerDialog.ShowAsync();
                    }
                }
            }
            catch (Exception ex)
            {
                dialog = new MessageDialog(ex.Message);
            }

            if (dialog != null)
            {
                await dialog.ShowAsync();
            }
            return(retVal);
        }