Exemplo n.º 1
0
        public async void AddElement(Uri blogUri, string categoryName)
        {
            _i_GetBlogs++;
            System.Threading.Tasks.Task task = new System.Threading.Tasks.Task( async() =>{            
                if (categoryName == "" || categoryName == null)
                    categoryName = strCommon;
                else
                    AddCategoryList(categoryName);
                FB_Category fb_cate = CategoryFind(categoryName);

                SyndicationClient client = new SyndicationClient();
                Uri feedUri = blogUri;

                SyndicationFeed feed;// = await client.RetrieveFeedAsync(feedUri);
                try
                {   // 비정상 적으로 받았을 경우
                    feed = await client.RetrieveFeedAsync(feedUri);
                }
                catch (Exception)
                {
                    _b_Error = true;
                    _i_GetBlogs--;
                    return;
                }

                // This code is executed after RetrieveFeedAsync returns the SyndicationFeed.
                // Process it and copy the data we want into our FeedData and FeedItem classes.
                FB_Blog feedData = new FB_Blog();

                feedData.Title = feed.Title.Text;
                feedData.BlogUri = feedUri;
                feedData.ImageUri = feed.ImageUri;
                if (feed.Subtitle != null && feed.Subtitle.Text != null)
                {
                    feedData.Description = feed.Subtitle.Text;
                }
                // Use the date of the latest post as the last updated date.
                feedData.PubDate = feed.Items[0].PublishedDate.DateTime;
                feedData.ReadLastDate = DateTime.Now;
                feedData.CategoryName = fb_cate;

                fb_cate.FB_Blogs.Add(feedData);
                Ori_Blogs.Add(feedData);
                await FeedPost(feedData);
                _i_GetBlogs--;
            });
            task.Start();

            // 동기화 시켜주기 위해서 기다리는 명령줄
            while (_i_GetBlogs != 0)
            {
                new System.Threading.ManualResetEvent(false).WaitOne(10);
            }
        }
Exemplo n.º 2
0
 public async void InitSet_Posts(FB_Blog blog)
 {
     Posts = new ObservableCollection<FB_Post>();
     //await FeedPost(blog);
     foreach (FB_Post post in blog.FB_Posts)
     {
         Posts.Add(post);
     }
 }
Exemplo n.º 3
0
 public async Task<ObservableCollection<FB_Post>> GetPosts(FB_Blog blog)
 {
     InitSet_Posts(blog);
     return Posts;
 }
Exemplo n.º 4
0
        private async Task FeedPost(FB_Blog blog)
        {
            // using Windows.Web.Syndication;
            SyndicationClient client = new SyndicationClient();
            Uri feedUri = blog.BlogUri;            
            try
            {
                SyndicationFeed feed = await client.RetrieveFeedAsync(feedUri);

                blog.Title = feed.Title.Text;
                if (feed.Subtitle != null && feed.Subtitle.Text != null)
                {
                    blog.Description = feed.Subtitle.Text;
                }
                // Use the date of the latest post as the last updated date.
                blog.PubDate = feed.Items[0].PublishedDate.DateTime;
                blog.ImageUri = Search_ImageUri(feed);

                foreach (SyndicationItem item in feed.Items)
                {
                    FB_Post feedItem = new FB_Post();
                    feedItem.Title = item.Title.Text;
                    feedItem.PubDate = item.PublishedDate.DateTime;
                    //feedItem.Author = item.Authors[0].Name.ToString();
                    // Handle the differences between RSS and Atom feeds.
                    if (feed.SourceFormat == SyndicationFormat.Atom10)
                    {
                        feedItem.Content = item.Content.Text;
                        // 주소를 읽어들인다.
                        try
                        {
                            feedItem.Link = new Uri(feed.Links[0].Uri.AbsoluteUri + item.Id);
                        }
                        catch (Exception)
                        {
                            try
                            {
                                feedItem.Link = item.Links[1].Uri;
                            }
                            catch (Exception)
                            {
                            }
                        }
                    }
                    else if (feed.SourceFormat == SyndicationFormat.Rss20)
                    {
                        //feedItem.Content = item.Summary.Text;
                        try
                        {   // 이미지를 추가한다.
                            feedItem.Img = blog.ImageUri;
                        }
                        catch (Exception)
                        {
                            feedItem.Img = null;
                        }
                        feedItem.Link = item.Links[1].Uri;
                    }
                    blog.FB_Posts.Add(feedItem);
                }
            }
            catch (Exception)
            {
                int a;
            }            
        }