private void EditSelectedFeed() { if (FeedDataGrid.SelectedItem == null) { return; } var feed = (Feed)FeedDataGrid.SelectedItem; var feedWindow = new FeedWindow(); feedWindow.Display(_database, feed, GetWindow(this)); }
private void HandleEditCurrentFeedMenuItemClick(object sender, RoutedEventArgs e) { // Create a new feed window var feedWindow = new FeedWindow(); // Display the feed window and get the result var result = feedWindow.Display(_database, _currentFeed, this); // If OK was clicked... if (result.HasValue && result.Value) { // Save _database.SaveChanges(); // Update feed DisplayFeed(); } }
private void HandleNewFeed(string feedUrl) { // Create and configure the new feed var feed = Feed.Create(_database); feed.Source = feedUrl; feed.Category = _database.DefaultCategory; // Try to detect the feed type var feedTypeResult = feed.DetectFeedType(); // If we can't figure it out it could be an HTML page if (feedTypeResult.Item1 == FeedType.Unknown) { // Only check if the feed was able to be read - otherwise fall through and show the dialog if (feedTypeResult.Item2.Length > 0) { // Create and load an HTML document with the text var htmlDocument = new HtmlAgilityPack.HtmlDocument(); htmlDocument.LoadHtml(feedTypeResult.Item2); // Look for all RSS or atom links in the document var rssLinks = htmlDocument.DocumentNode.Descendants("link") .Where(n => n.Attributes["type"] != null && (n.Attributes["type"].Value == "application/rss+xml" || n.Attributes["type"].Value == "application/atom+xml")) .Select(n => new Tuple <string, string>(UrlHelper.GetAbsoluteUrlString(feed.Source, n.Attributes["href"].Value), WebUtility.HtmlDecode(n.Attributes["title"]?.Value ?? feedUrl))) .Distinct() .ToList(); // If there was only one link found then switch to feed to it if (rssLinks.Count == 1) { feed.Source = rssLinks[0].Item1; } else { var feedChooserWindow = new FeedChooserWindow(); var feedLink = feedChooserWindow.Display(this, rssLinks); if (string.IsNullOrEmpty(feedLink)) { return; } feed.Source = feedLink; } } } // Read the feed for the first time var feedReadResult = feed.Read(_database); // See if we read the feed okay if (feedReadResult == FeedReadResult.Success) { // Update the feed name to be the title feed.Name = feed.Title; // Add the feed to the feed table _database.Feeds.Add(feed); // Save the changes _database.SaveChanges(); // Show a tip NotificationIcon.ShowBalloonTip(string.Format(Properties.Resources.FeedAddedNotification, feed.Name), System.Windows.Forms.ToolTipIcon.Info); // Re-initialize the feed display DisplayFeed(); } else { // Feed read failed - ceate a new feed window var feedForm = new FeedWindow(); var dialogResult = feedForm.Display(_database, feed, this); // Display the new feed form if (dialogResult.HasValue && dialogResult.Value) { // Add the feed to the feed table _database.Feeds.Add(feed); // Save the changes _database.SaveChanges(); // Re-initialize the feed display DisplayFeed(); } } }