mirror of
https://github.com/ckaczor/FeedCenter.git
synced 2026-01-13 17:22:48 -05:00
Add a few new ways to drag/drop a URL - from a few Chrome extensions or the page URL itself - page URL only supports single links right now
This commit is contained in:
@@ -157,6 +157,10 @@
|
||||
<Reference Include="EntityFramework.SqlServerCompact">
|
||||
<HintPath>..\packages\EntityFramework.SqlServerCompact.6.1.1\lib\net45\EntityFramework.SqlServerCompact.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="HtmlAgilityPack, Version=1.4.9.0, Culture=neutral, PublicKeyToken=bd319b19eaf3b43a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\HtmlAgilityPack.1.4.9\lib\Net45\HtmlAgilityPack.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.ComponentModel.DataAnnotations" />
|
||||
<Reference Include="System.configuration" />
|
||||
|
||||
@@ -119,7 +119,7 @@ namespace FeedCenter.FeedParsers
|
||||
throw new ArgumentException($"Feed type {feedType} is not supported");
|
||||
}
|
||||
|
||||
private static FeedType DetectFeedType(string feedText)
|
||||
public static FeedType DetectFeedType(string feedText)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -150,7 +150,9 @@ namespace FeedCenter.FeedParsers
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
throw new InvalidFeedFormatException(exception);
|
||||
Tracer.WriteException(exception);
|
||||
|
||||
return FeedType.Unknown;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -99,6 +99,18 @@ namespace FeedCenter
|
||||
return await Task.Run(() => Read(database, forceRead));
|
||||
}
|
||||
|
||||
public Tuple<FeedType, string> DetectFeedType()
|
||||
{
|
||||
var retrieveResult = RetrieveFeed();
|
||||
|
||||
if (retrieveResult.Item1 != FeedReadResult.Success)
|
||||
{
|
||||
return new Tuple<FeedType, string>(FeedType.Unknown, string.Empty);
|
||||
}
|
||||
|
||||
return new Tuple<FeedType, string>(FeedParserBase.DetectFeedType(retrieveResult.Item2), retrieveResult.Item2);
|
||||
}
|
||||
|
||||
private Tuple<FeedReadResult, string> RetrieveFeed()
|
||||
{
|
||||
try
|
||||
|
||||
@@ -10,6 +10,7 @@ using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Threading;
|
||||
using System.Web.UI;
|
||||
using System.Windows;
|
||||
@@ -17,11 +18,14 @@ using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Interop;
|
||||
using System.Windows.Media;
|
||||
using Common.Internet;
|
||||
|
||||
namespace FeedCenter
|
||||
{
|
||||
public partial class MainWindow
|
||||
{
|
||||
private readonly string[] _chromeExtensions = { "chrome-extension://ehojfdcmnajoklleckniaifaijfnkpbi/subscribe.html?", "chrome-extension://nlbjncdgjeocebhnmkbbbdekmmmcbfjd/subscribe.html?" };
|
||||
|
||||
#region Member variables
|
||||
|
||||
private int _feedIndex;
|
||||
@@ -788,6 +792,37 @@ namespace FeedCenter
|
||||
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 => UrlHelper.GetAbsoluteUrlString(feed.Source, n.Attributes["href"].Value))
|
||||
.ToArray();
|
||||
|
||||
// If there was only one link found then switch to feed to it
|
||||
if (rssLinks.Length == 1)
|
||||
{
|
||||
feed.Source = rssLinks[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO - show dialog to choose feed
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Read the feed for the first time
|
||||
var feedReadResult = feed.Read(_database);
|
||||
|
||||
@@ -899,6 +934,16 @@ namespace FeedCenter
|
||||
// Get the data as a string
|
||||
var data = (string) e.Data.GetData(DataFormats.Text);
|
||||
|
||||
// Check to see if the data starts with any known Chrome extension
|
||||
var chromeExtension = _chromeExtensions.FirstOrDefault(c => data.StartsWith(c));
|
||||
|
||||
// Remove the Chrome extension URL and decode the URL
|
||||
if (chromeExtension != null)
|
||||
{
|
||||
data = data.Substring(chromeExtension.Length);
|
||||
data = WebUtility.UrlDecode(data);
|
||||
}
|
||||
|
||||
// Handle the new feed but allow the drag/drop to complete
|
||||
Dispatcher.BeginInvoke(new NewFeedDelegate(HandleNewFeed), data);
|
||||
}
|
||||
|
||||
@@ -2,5 +2,6 @@
|
||||
<packages>
|
||||
<package id="EntityFramework" version="6.1.1" targetFramework="net45" />
|
||||
<package id="EntityFramework.SqlServerCompact" version="6.1.1" targetFramework="net45" />
|
||||
<package id="HtmlAgilityPack" version="1.4.9" targetFramework="net451" />
|
||||
<package id="Microsoft.SqlServer.Compact" version="4.0.8854.1" targetFramework="net45" />
|
||||
</packages>
|
||||
@@ -175,6 +175,8 @@
|
||||
|
||||
<File Source="$(var.FeedCenter.TargetDir)\Common.Wpf.MarkupExtensions.dll" />
|
||||
|
||||
<File Source="$(var.FeedCenter.TargetDir)\HtmlAgilityPack.dll" />
|
||||
|
||||
<File Source="$(var.FeedCenter.TargetDir)\EntityFramework.dll" />
|
||||
<File Source="$(var.FeedCenter.TargetDir)\EntityFramework.SqlServer.dll" />
|
||||
<File Source="$(var.FeedCenter.TargetDir)\EntityFramework.SqlServerCompact.dll" />
|
||||
|
||||
Reference in New Issue
Block a user