Пример #1
0
        public void TestMethod2()
        {
            FeedViewModel feed = new FeedViewModel();

            feed.Link = new Uri("http://www.shisujie.com/rss?containerid=31");
            feed.Name = "奇葩史";
            feed.RefreshAsync().Wait();

            List <FeedViewModel> feeds = new List <FeedViewModel>();

            feeds.Add(feed);
            var withoutwait = feeds.SaveAsync();

            feed.OfflineFeed();
        }
Пример #2
0
        private async void AddFeed_ButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
        {
            // Ensure the Feed or Site URL fields isn't empty. If a required field
            // is empty, set args.Cancel = true to keep the dialog open.
            if (string.IsNullOrEmpty(feedTextBox.Text))
            {
                args.Cancel         = true;
                errorTextBlock.Text = "Feed or Site URL is required.";
                return;
            }

            // 检查URI是否非法,是否重复
            try
            {
                Uri check_uri = new Uri(this.feedTextBox.Text);
                foreach (var item in MainPage.Current.ViewModel.Feeds)
                {
                    if (item.Source.Equals(check_uri))
                    {
                        args.Cancel         = true;
                        errorTextBlock.Text = "You already add this Feed!";
                        return;
                    }
                }
            }
            catch (UriFormatException)
            {
                args.Cancel         = true;
                errorTextBlock.Text = "FreeRSS could not find a feed at the specified location.";
                return;
            }

            // 开始尝试添加新的feed
            var newfeed = new FeedViewModel(new FeedInfo {
                Source = this.feedTextBox.Text,
            });

            // 在refresh里面内嵌了添加的逻辑,如果Id为空的话,就会往MainPage.Current.ViewModel.Feeds.里面加新的feed
            await newfeed.RefreshAsync();

            if (newfeed.ErrorMessage != null)
            {
                args.Cancel         = true;
                errorTextBlock.Text = newfeed.ErrorMessage;
            }
        }
Пример #3
0
        /// <summary>
        /// 获取已订阅的rss源——并从网络获取源数据
        /// </summary>
        public static List <FeedViewModel> GetFeedsAsync()
        {
            var feeds = new List <FeedViewModel>();

            if (!File.Exists(Path.Combine(RunTime.DataPath, "feeds.xml")))
            {
                return(new List <FeedViewModel>());
            }
            using (Stream fs = new FileStream(Path.Combine(RunTime.DataPath, "feeds.xml"), FileMode.Open))
            {
                DataContractSerializer dcs      = new DataContractSerializer(typeof(IEnumerable <FeedSketch>));
                FeedSketch[]           feeddata = (FeedSketch[])dcs.ReadObject(fs);

                foreach (var item in feeddata)
                {
                    if (item.Link == null)
                    {
                        continue;
                    }
                    if (item.Name != null && File.Exists(Path.Combine(RunTime.OfflineDetailPath, item.Name + ".xml")))
                    {
                        using (Stream fs1 = new FileStream(Path.Combine(RunTime.OfflineDetailPath, item.Name + ".xml"), FileMode.Open))
                        {
                            DataContractSerializer dcs1 = new DataContractSerializer(typeof(FeedViewModel));
                            var tempa = (FeedViewModel)dcs1.ReadObject(fs1);
                            feeds.Add(tempa);
                            continue;
                        }
                    }

                    var feedvm = new FeedViewModel {
                        Name = item.Name, Link = new Uri(item.Link)
                    };
                    feeds.Add(feedvm);
                    var withoutAwait = feedvm.RefreshAsync();
                }
                return(feeds);
            }
        }