コード例 #1
0
ファイル: RssDataSource.cs プロジェクト: m0rg0t/MoscowMuseums
        public static async Task <bool> AddGroupForFeedAsync(string feedUrl)
        {
            string clearedContent = String.Empty;

            if (RssDataSource.GetGroup(feedUrl) != null)
            {
                return(false);
            }

            var feed = await new SyndicationClient().RetrieveFeedAsync(new Uri(feedUrl));

            var feedGroup = new RssDataGroup(
                uniqueId: feedUrl,
                title: feed.Title != null ? feed.Title.Text : null,
                subtitle: feed.Subtitle != null ? feed.Subtitle.Text : null,
                imagePath: feed.ImageUri != null ? feed.ImageUri.ToString() : null,
                description: null);

            foreach (var i in feed.Items)
            {
                string imagePath = null;
                try
                {
                    imagePath = GetImageFromPostContents(i);;
                }
                catch { };

                if (i.Summary != null)
                {
                    clearedContent = Windows.Data.Html.HtmlUtilities.ConvertToText(i.Summary.Text);
                }
                else
                if (i.Content != null)
                {
                    clearedContent = Windows.Data.Html.HtmlUtilities.ConvertToText(i.Content.Text);
                }

                if (imagePath != null && feedGroup.Image == null)
                {
                    feedGroup.SetImage(imagePath);
                }

                if (imagePath == null)
                {
                    imagePath = "ms-appx:///Assets/DarkGray.png";
                }

                try
                {
                    feedGroup.Items.Add(new RssDataItem(
                                            uniqueId: i.Id, title: i.Title.Text, subtitle: null, imagePath: imagePath,
                                            description: null, content: clearedContent, @group: feedGroup));
                }
                catch { };
            }

            switch (feedGroup.UniqueId)
            {
            case "http://rybinsk.ru/news-2013?format=feed&type=atom":
                feedGroup.Order = 20;

                try
                {
                    var group1 = new RssDataGroup("MainNews", "Главная новость", "", "", "");
                    group1.Order = 30;
                    var tempitem = new RssDataItem(feedGroup.Items.First().UniqueId + "main",
                                                   feedGroup.Items.First().Title, null,
                                                   feedGroup.Items.First().ImagePath,
                                                   "",
                                                   feedGroup.Items.First().Content,
                                                   group1);

                    group1.Items.Add(tempitem);
                    group1.Items.Add(tempitem);
                    group1.Items.Add(tempitem);
                    group1.Items.Add(tempitem);
                    group1.Items.Add(tempitem);
                    group1.Items.Add(tempitem);

                    _sampleDataSource.AllGroups.Add(group1);
                    _sampleDataSource.RaisePropertyChanged("AllGroups");
                }
                catch { };
                break;
            }
            ;

            _sampleDataSource.AllGroups.Add(feedGroup);
            _sampleDataSource.RaisePropertyChanged("AllGroups");
            return(true);
        }
コード例 #2
0
ファイル: RssDataSource.cs プロジェクト: m0rg0t/MoscowMuseums
 public RssDataItem(String uniqueId, String title, String subtitle, String imagePath, String description, String content, RssDataGroup group)
     : base(uniqueId, title, subtitle, imagePath, description)
 {
     this._content = content;
     this._group   = group;
 }