private async Task <IList <NewsItem> > LoadMoreItemsAsync() { BusyCount++; IsError = false; var items = new List <NewsItem>(); var lastItem = FeedItems.LastOrDefault(); var dateTime = lastItem == null ? DateTimeOffset.Now : DateTimeOffset.Parse(lastItem.DatePublish); try { var response = await _feedNewsProvider.LoadNewsAsync(dateTime, Category.Code); items.AddRange(response); } catch (Exception ex) { //var response = await _feedNewsProvider.LoadFeedNewsAsync(FeedItems.LastOrDefault(), Category.Code, DataAccess.RequestAccessMode.Cache); //if (response != null) //{ // items.AddRange(response); //} //IsError = true; } //foreach (var item in items) //{ // item.IsReaded = DataProviders.DataBaseProvider.IsItemExists<FeedItem>(item.Id); //} BusyCount--; return(items); }
public async Task TestQueryFeedItemsWithTransactionTimesBetween() { // Parameters for the API call var accountUid = GetAccountId(); var categoryUid = Guid.Parse("aaaaaaaa-aaaa-4aaa-aaaa-aaaaaaaaaaaa"); var minTransactionTimestamp = DateTime.ParseExact("2020-06-01T12:34:56.000Z", "yyyy'-'MM'-'dd'T'HH':'mm':'ss.FFFFFFFK", CultureInfo.InvariantCulture, DateTimeStyles.RoundtripKind); var maxTransactionTimestamp = DateTime.ParseExact("2020-07-01T12:34:56.000Z", "yyyy'-'MM'-'dd'T'HH':'mm':'ss.FFFFFFFK", CultureInfo.InvariantCulture, DateTimeStyles.RoundtripKind); // Perform API call FeedItems result = null; try { result = await _controller.GetQueryFeedItemsWithTransactionTimesBetweenAsync(accountUid, categoryUid, minTransactionTimestamp, maxTransactionTimestamp); } catch (APIException) {}; // Test response code Assert.AreEqual(200, HTTPCallBackHandler.Response.StatusCode, "Status should be 200"); // Test headers var headers = new Dictionary <string, string>(); headers.Add("Content-Type", "application/json"); Assert.IsTrue(TestHelper.AreHeadersProperSubsetOf( headers, HTTPCallBackHandler.Response.Headers), "Headers should match"); }
public async Task ExecuteLoadItemsCommand() { if (IsBusy) { return; } IsBusy = true; var httpClient = new HttpClient(); try { var feed = "https://www.lebensmittelwarnung.de/bvl-lmw-de/opensaga/feed/alle/alle_bundeslaender.rss"; var responseString = await httpClient.GetStringAsync(feed); FeedItems.Clear(); var items = await ParseFeed(responseString); foreach (var item in items) { item.Image = item.ImageURL; FeedItems.Add(item); } } catch (Exception e) { } IsBusy = false; }
/// <summary> /// Removes feedItems for a given feed from the list of feedItems. /// </summary> /// <param name="feed">The feed for which the articles should be removed</param> private void RemoveFeedItems(Feed feed) { var counter = 0; foreach (var article in feed.Items) { while (counter < FeedItems.Count && FeedItems[counter].Link != article.Link) { counter++; } if (counter == FeedItems.Count) { break; } else { FeedItems.RemoveAt(counter); if (counter > 0) { counter--; } } } // ReSharper Disable All OnPropertyChanged("HasFeedItems"); // ReSharper Restore All }
public async Task ExecuteLoadItemsCommand() { if (IsBusy) { return; } IsBusy = true; var httpClient = new HttpClient(); var feed = "http://planet.xamarin.com/feed/"; var responseString = await httpClient.GetStringAsync(feed); FeedItems.Clear(); var items = await ParseFeed(responseString); foreach (var item in items) { item.Image = Gravatar.GetUrl(item.Author); FeedItems.Add(item); } IsBusy = false; }
private async Task <IList <FeedItem> > LoadMoreItemsAsync() { BusyCount++; var items = new List <FeedItem>(); IsError = false; try { var response = await _authorsProvider.LoadAuthorsFeedAsync(FeedItems.LastOrDefault(), this.Category.Code); items.AddRange(response); } catch (Exception) { //IsError = true; var response = await _authorsProvider.LoadAuthorsFeedAsync(FeedItems.LastOrDefault(), this.Category.Code); if (response != null) { items.AddRange(response); } } //foreach (var item in items) //{ // item.IsReaded = DataProviders.DataBaseProvider.IsItemExists<FeedItem>(item.Id); //} base.BusyCount--; return(items); }
/// <summary> /// Adds an item to the feed /// </summary> /// <param name="color"></param> /// <param name="text"></param> public void AddItem(Color color, string text) { var item = new MultiplayerFeedItem(color, text) { Parent = this, Alignment = Alignment.BotLeft, X = 10 }; FeedItems.Add(item); if (FeedItems.Count == 6) { var first = FeedItems.First(); first.Destroy(); FeedItems.Remove(first); } for (var i = FeedItems.Count - 1; i >= 0; i--) { var feedItem = FeedItems[i]; feedItem.ClearAnimations(); feedItem.MoveToY(-22 * (FeedItems.Count - i - 1) - 11, Easing.OutQuint, 200); } }
private async Task ExecuteLoadFilteredItemsCommand(string filter) { if (IsBusy) { return; } IsBusy = true; try { FeedItems.Clear(); var items = await _feedRepository.GetFilteredFeed(StaticData.RssFeed, filter); foreach (var item in items) { FeedItems.Add(item); } } catch (Exception ex) { var page = new ContentPage(); var result = page.DisplayAlert("Error", "Unable to load filtered podcast feed. " + ex.Message, "OK"); Insights.Report(ex, new Dictionary <string, string> { { "Error", "Unable to load filtered podcast feed." }, { "Message", ex.Message }, { "Result", result.ToString() } }); } IsBusy = false; }
private async Task ExecuteLoadItemsCommand() { if (IsBusy) { return; } IsBusy = true; try{ var httpClient = new HttpClient(); var feed = "http://feeds.hanselman.com/ScottHanselman"; var responseString = await httpClient.GetStringAsync(feed); FeedItems.Clear(); var items = await ParseFeed(responseString); foreach (var item in items) { FeedItems.Add(item); } } catch (Exception ex) { var page = new ContentPage(); var result = page.DisplayAlert("Error", "Unable to load blog.", "OK", null); } IsBusy = false; }
public async void ReloadItemsAsync() { BusyCount++; FeedItems.HasMoreItems = false; FeedItems.Clear(); //FeedItems.CanMoreItems(); await FeedItems.LoadMoreItemsAsync(0); FeedItems.HasMoreItems = FeedItems.Count > 0; BusyCount--; }
private async Task ExecuteLoadItemsCommandAsync() { if (IsBusy) { return; } IsBusy = true; bool error = false; try { HttpClient httpClient = new HttpClient(); string feed = string.Empty; switch (item) { case MenuType.Playlist: feed = @"https://software-enginnering-daily-api.herokuapp.com/api/posts"; break; case MenuType.Podcast: feed = @"https://software-enginnering-daily-api.herokuapp.com/api/posts"; break; case MenuType.Twitter: feed = @"https://feeds.podtrac.com/9dPm65vdpLL1"; break; } string responseString = await httpClient.GetStringAsync(feed); FeedItems.Clear(); var items = await ParseFeed(responseString); foreach (var feedItem in items) { FeedItems.Add(feedItem); } } catch (Exception e) { error = true; Debug.WriteLine(e.Message); } if (error) { ContentPage page = new ContentPage(); Task result = page.DisplayAlert("Error", $"Unable to load podcast feed.", "OK"); } IsBusy = false; }
private async Task ExecuteLoadItemsCommand() { if (IsBusy) { return; } IsBusy = true; var error = false; try { var httpClient = new HttpClient(); var feed = string.Empty; switch (item.MenuType) { case MenuType.Hanselminutes: feed = "http://feeds.podtrac.com/9dPm65vdpLL1"; break; case MenuType.Ratchet: feed = "http://feeds.feedburner.com/RatchetAndTheGeek?format=xml"; break; case MenuType.DeveloperLife: feed = "http://feeds.feedburner.com/ThisDevelopersLife?format=xml"; break; } var responseString = await httpClient.GetStringAsync(feed); FeedItems.Clear(); var items = await ParseFeed(responseString); foreach (var feedItem in items) { FeedItems.Add(feedItem); } } catch { error = true; } if (error) { var page = new ContentPage(); var result = page.DisplayAlert("Error", "Unable to load podcast feed.", "OK"); } IsBusy = false; }
/// <summary> /// RSSフィード取得コマンドを実行する /// </summary> private void GetRssExecute() { // RSSフィード取得中のフラグをオンにします。 IsProgress = true; if (FeedItems != null) { // 現在のフィード情報をクリアする FeedItems.Clear(); } // RSSフィードを非同期で取得します。 Task result = GetRSSAsync(FeedUrl); }
private async Task ExecuteLoadItemsCommand() { if (IsBusy) { return; } IsBusy = true; IsNotBusy = false; try { FeedItems.Clear(); var items = await _feedRepository.GetAll(StaticData.RssFeed); foreach (var item in items) { FeedItems.Add(item); } LastFeedItem = FeedItems[0]; PodcastTitle = LastFeedItem.Title; PodcastDate = LastFeedItem.PublishDate; if (LastFeedItem.FileImage != null) { FileImage = LastFeedItem.FileImage; } else { FileImage = "empty_image.png"; } } catch (Exception ex) { var page = new ContentPage(); var result = page.DisplayAlert("Error", "Unable to load podcast feed. " + ex.Message, "OK"); Insights.Report(ex, new Dictionary <string, string> { { "Error", "Unable to load podcast feed." }, { "Message", ex.Message }, { "Result", result.ToString() } }); } IsBusy = false; IsNotBusy = true; }
private void LoadAction() { FeedItems?.Clear(); SelectedFeedItem = null; using (XmlReader reader = XmlReader.Create(FeedURL)) { SyndicationFeed feed = SyndicationFeed.Load(reader); //Next step, getting Images from Comic feeds/etc. foreach (SyndicationItem item in feed.Items) { FeedItems.Add(FeedItemModel.FromSyndicationItem(item)); } } OnPropertyChanged(nameof(FeedItems)); }
/// <summary> /// The GetFeed /// </summary> /// <param name="refresh">The <see cref="bool"/></param> private void GetFeed(bool refresh) { IsProcessing = true; FeedItems.Clear(); LoadFeedFromStore(); //if refresh is on, get feed from web if (refresh && FeedUrl != null) { LoadFeedFromWeb(); } if (timer != null) { timer.Change(this.ReloadInterval * 1000, this.ReloadInterval * 1000); } IsProcessing = false; }
private async Task ExecuteLoadItemsCommand() { if (IsBusy) { return; } IsBusy = true; var error = false; try { var responseString = string.Empty; //TODO: get feed and //using (var httpClient = new HttpClient()) //{ // var feed = "http://feeds.hanselman.com/ScottHanselman"; // responseString = await httpClient.GetStringAsync(feed); //} FeedItems.Clear(); var items = await ParseFeed(responseString); foreach (var item in items) { FeedItems.Add(item); } } catch { error = true; } if (error) { var page = new ContentPage(); await page.DisplayAlert("Error", "Unable to load blog.", "OK"); } IsBusy = false; }
private async Task ExecuteLoadItemsCommand() { if (IsBusy) { return; } IsBusy = true; var error = false; try { var responseString = string.Empty; using (var httpClient = new HttpClient()) { var feed = "http://lawebdelprogramador.cl/bloglawebdelprogramador/feed/"; responseString = await httpClient.GetStringAsync(feed); } FeedItems.Clear(); var items = await ParseFeed(responseString); foreach (var item in items) { FeedItems.Add(item); } } catch { error = true; } if (error) { var page = new ContentPage(); await page.DisplayAlert("Error", "No es posible cargar el blog en este momento", "OK"); } IsBusy = false; }
private async Task ExecuteLoadItemsCommand() { if (IsBusy) { return; } IsBusy = true; var error = false; try { var responseString = string.Empty; using (var httpClient = new HttpClient()) { var feed = "https://bwired.ca/blog/feed"; responseString = await httpClient.GetStringAsync(feed); } FeedItems.Clear(); var items = await ParseFeed(responseString); foreach (var item in items) { FeedItems.Add(item); } } catch { error = true; } if (error) { var page = new ContentPage(); await page.DisplayAlert("Error", "Unable to load blog.", "OK"); } IsBusy = false; }
/// <summary> /// Adds feedItems to the list of feedItems. /// All feedItems are inserted at the correct date (since the list is sorted by date) /// </summary> /// <param name="feedItems">List of feedItems to be added</param> private void AddFeedItems(List <EasyNewsFeedItem> feedItems) { var counter = 0; foreach (var article in feedItems) { // New Article is older than the oldest article in the list, append article to end if (counter >= FeedItems.Count) { FeedItems.Add(article); } // Insert new Article somewhere in the middle of the array, we don't know where it is else { // Iterate through Articles until we found the right date to insert our new article while (counter < FeedItems.Count && FeedItems[counter].PublishingDate > article.PublishingDate) { counter++; } // All articles we searched were newer than our article => Append the article if (counter == FeedItems.Count) { FeedItems.Add(article); } else { // Found the right date, insert the article, redo with the next one FeedItems.Insert(counter, article); } } } // ReSharper Disable All OnPropertyChanged("HasFeedItems"); // ReSharper Restore All }
private static void CreateRSS() { FeedItems feeds = new FeedItems(); foreach (var feed in feeds) { try { XDocument rssFeed = XDocument.Load(feed.FeedUrl.ToString()); var posts = from item in rssFeed.Descendants("item") select new RssItem { Title = item.Element("title").Value, PublishDate = ParseDate(item.Element("pubDate")), Url = item.Element("link").Value, Id = item.Element("guid").Value, Description = item.Element("description").Value, SourceFeed = feed.FeedUrl.ToString() }; feed.RssItems.AddRange(posts.ToList()); } catch (Exception e) { Console.WriteLine("Feed:{0} failed with error message: {1}", feed.FeedUrl.ToString(), e.Message); } } StreamReader sr = new StreamReader(FILE_LOCATION); string sLine = ""; ArrayList arrText = new ArrayList(); while (sLine != null) { sLine = sr.ReadLine(); if (sLine != null) arrText.Add(sLine); } sr.Close(); int alreadyAdded = 0; int processCount = 0; FileStream fs = new FileStream(FILE_LOCATION,FileMode.Append, FileAccess.Write,FileShare.None); using(StreamWriter sw = new StreamWriter(fs)) { foreach (var feed in feeds) { feed.RssItems.ForEach(delegate(RssItem ri) { if (!arrText.Contains(ri.Id)) { CreatePost(ri, feed.SpecificTags); sw.WriteLine(ri.Id); } else { alreadyAdded++; } processCount++; } ); } } Console.WriteLine(processCount.ToString() + " items processed," + alreadyAdded.ToString() + " already processed."); }
/// <summary> /// Gets a specific feed item for an Id /// </summary> /// <param name="id"></param> /// <returns></returns> public FeedItem GetFeedItem(int id) { return(FeedItems.FirstOrDefault(i => i.Id == id)); }
public int GetUnreadItemCount() { return FeedItems.Count(x => x.IsUnread); }
private async Task _Refresh() { if (!IsNeedRefresh) { return; } Debug.WriteLine($"{Label} starting update feed."); var updateTime = DateTime.Now; var latestItems = new List<FeedItem>(); foreach (var feedSource in _FeedSourceList) { var items = await feedSource.GetLatestItems(HohoemaApp); foreach (var item in items) { latestItems.Add(item); } } var latestOrderedItems = latestItems .OrderByDescending(x => x.SubmitDate) .Take(MaxFeedItemsCount) .ToList(); foreach (var item in latestOrderedItems) { item.CheckedTime = updateTime; } var exceptItems = latestOrderedItems.Except(FeedItems, FeedItemComparer.Default).ToList(); var addedItems = exceptItems.Where(x => x.CheckedTime == updateTime); var removedItems = FeedItems .Except(latestOrderedItems, FeedItemComparer.Default) .Where(x => x.CheckedTime != updateTime) .ToList(); foreach (var addItem in addedItems) { addItem.IsUnread = true; // 投稿日時が初期化されていない場合はThumbnailInfoから拾ってくる // ユーザー動画取得の場合に投稿時刻が取れないことが原因 // 追加されたアイテムだけのThumbnailを取得することで無駄な処理を減らす if (addItem.SubmitDate == default(DateTime)) { try { var nicoVideo = await HohoemaApp.MediaManager.GetNicoVideoAsync(addItem.VideoId); addItem.SubmitDate = nicoVideo.PostedAt; } catch (Exception ex) { Debug.Fail("UserFeedItem 更新中、NicoVideoオブジェクトの取得に失敗しました。", ex.Message); } } FeedItems.Add(addItem); } foreach (var removedItem in removedItems) { var item = FeedItems.SingleOrDefault(x => x.VideoId == removedItem.VideoId); if (item != null) { item.IsDeleted = true; FeedItems.Remove(item); } } FeedItems.Sort(FeedItemComparer.Default); UpdateTime = updateTime; await FeedManager.SaveOne(this); Completed?.Invoke(this); IsNeedRefresh = false; Debug.WriteLine($"{Label} update feed done."); }
public async void ReloadItemsAsync() { FeedItems.Clear(); FeedItems.CanMoreItems(); await FeedItems.LoadMoreItemsAsync(0); }
// RSSフィードを取得します。(非同期メソッド) private async Task GetRSSAsync(String i_feedUrl) { Boolean result = false; try { var client = new HttpClient(); RssFeed latest; using (var reader = new StringReader(await client.GetStringAsync(i_feedUrl))) { var desirializer = new XmlSerializer(typeof(RssFeed)); latest = desirializer.Deserialize(reader) as RssFeed; } IsProgress = false; if (latest == null) { throw new Exception("取得したフィードがnull"); } // RSSフィードの配信元情報を取得します。 this.FeedTitle = latest.Channel.Title; this.FeedDescription = Regex.Replace(latest.Channel.Description, Define.PATTERN_STR, String.Empty, RegexOptions.Singleline); this.FeedLastUpdatedTime = latest.Channel.LastBuildDate; // RSSフィードのコンテンツを取得します。 foreach (var item in latest.Channel.Items) { // コンテンツ取得 RSSContent content = new RSSContent(); content.Title = item.Title; content.Description = Regex.Replace(item.Description, Define.PATTERN_STR, String.Empty, RegexOptions.Singleline); content.PubDate = item.PubDate; content.Link = item.Link; // サムネイル画像取得 var imgMatch = Regex.Match(item.Description, Define.PATTERN_IMGTAG, RegexOptions.Singleline); if (imgMatch.Success) { content.Thumbnail = ImageSource.FromUri(new Uri(imgMatch.Groups["uri"].Value)); } Device.BeginInvokeOnMainThread(() => FeedItems.Add(content)); //FeedItems.Add(new RSSContent //{ // Title = item.Title, // Description = Regex.Replace(item.Description, Define.PATTERN_STR, String.Empty, RegexOptions.Singleline), // PubDate = item.PubDate, // Link = item.Link //}); } // RSSフィードの取得が完了したことをView側に通知します。 // ※通知の引数にRSSフィード取得の結果を渡す GetRSSCompleted?.Invoke(this, new TaskResultEventArgs(result)); } catch (Exception ex) { // RSSフィードの取得中に例外が発生したら、失敗フラグを立てます。 result = false; } }
public void addFeedItem(FeedItem newItem) { FeedItems.Add(newItem); }
/// <summary> /// Unread /// </summary> /// <param name="subscribe_id">subscribe_id</param> private async void Unread(string subscribe_id) { FeedListResult.ItemsSource = null; FeedListResult.Visibility = Visibility.Collapsed; NoItemLabel.Visibility = Visibility.Collapsed; ProgressIndicator.IsActive = true; try { HttpClient httpClient = new HttpClient(); Dictionary<string, string> postData = new Dictionary<string, string>() { { "subscribe_id", subscribe_id }, { "ApiKey", apiKey } }; HttpResponseMessage response = await httpClient.PostAsync(new Uri(domainURL + "/api/pin/unread"), new HttpFormUrlEncodedContent(postData)); string res = await response.Content.ReadAsStringAsync(); // refer to http://blogs.gine.jp/taka/archives/2106 var serializer = new DataContractJsonSerializer(typeof(FeedItems)); byte[] bytes = Encoding.UTF8.GetBytes(res); MemoryStream ms = new MemoryStream(bytes); feedItems = serializer.ReadObject(ms) as FeedItems; res = ""; // AD feed block (cannnot use "\s" ?) // from http://www.atmarkit.co.jp/fdotnet/dotnettips/815listremove/listremove.html var roamingSettings = ApplicationData.Current.RoamingSettings; object block = roamingSettings.Values["AdBlockEnableBool"]; if (block != null && (bool)block) // Default is no blocking feedItems.Items.RemoveAll(item => System.Text.RegularExpressions.Regex.IsMatch(item.Title, adBlockRegExp)); //Format item foreach (FeedItem item in feedItems.Items) { // trim (=remove \s or \n or zenkaku space from start and end) from title string item.Title = item.Title.Trim(' ', '\u3000', '\n'); item.Title = WebUtility.HtmlDecode(item.Title); item.Link = WebUtility.HtmlDecode(item.Link); } // Data binding FeedListResult.ItemsSource = feedItems.Items; if (feedItems.Items.Count > 0) FeedListResult.Visibility = Visibility.Visible; else NoItemLabel.Visibility = Visibility.Visible; ProgressIndicator.IsActive = false; } catch (Exception) { await new MessageDialog("This app could not send/receive data.", "Error @ Unread").ShowAsync(); NoItemLabel.Visibility = Visibility.Visible; ProgressIndicator.IsActive = false; } }