mirror of
https://github.com/ckaczor/FeedCenter.git
synced 2026-02-16 10:58:31 -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">
|
<Reference Include="EntityFramework.SqlServerCompact">
|
||||||
<HintPath>..\packages\EntityFramework.SqlServerCompact.6.1.1\lib\net45\EntityFramework.SqlServerCompact.dll</HintPath>
|
<HintPath>..\packages\EntityFramework.SqlServerCompact.6.1.1\lib\net45\EntityFramework.SqlServerCompact.dll</HintPath>
|
||||||
</Reference>
|
</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" />
|
||||||
<Reference Include="System.ComponentModel.DataAnnotations" />
|
<Reference Include="System.ComponentModel.DataAnnotations" />
|
||||||
<Reference Include="System.configuration" />
|
<Reference Include="System.configuration" />
|
||||||
|
|||||||
@@ -119,7 +119,7 @@ namespace FeedCenter.FeedParsers
|
|||||||
throw new ArgumentException($"Feed type {feedType} is not supported");
|
throw new ArgumentException($"Feed type {feedType} is not supported");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static FeedType DetectFeedType(string feedText)
|
public static FeedType DetectFeedType(string feedText)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -150,7 +150,9 @@ namespace FeedCenter.FeedParsers
|
|||||||
}
|
}
|
||||||
catch (Exception exception)
|
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));
|
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()
|
private Tuple<FeedReadResult, string> RetrieveFeed()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ using System.Collections.Generic;
|
|||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Net;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Web.UI;
|
using System.Web.UI;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
@@ -17,11 +18,14 @@ using System.Windows.Controls;
|
|||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
using System.Windows.Interop;
|
using System.Windows.Interop;
|
||||||
using System.Windows.Media;
|
using System.Windows.Media;
|
||||||
|
using Common.Internet;
|
||||||
|
|
||||||
namespace FeedCenter
|
namespace FeedCenter
|
||||||
{
|
{
|
||||||
public partial class MainWindow
|
public partial class MainWindow
|
||||||
{
|
{
|
||||||
|
private readonly string[] _chromeExtensions = { "chrome-extension://ehojfdcmnajoklleckniaifaijfnkpbi/subscribe.html?", "chrome-extension://nlbjncdgjeocebhnmkbbbdekmmmcbfjd/subscribe.html?" };
|
||||||
|
|
||||||
#region Member variables
|
#region Member variables
|
||||||
|
|
||||||
private int _feedIndex;
|
private int _feedIndex;
|
||||||
@@ -354,7 +358,7 @@ namespace FeedCenter
|
|||||||
OpenAllToolbarButton.IsEnabled = (feedCount > 0);
|
OpenAllToolbarButton.IsEnabled = (feedCount > 0);
|
||||||
MarkReadToolbarButton.IsEnabled = (feedCount > 0);
|
MarkReadToolbarButton.IsEnabled = (feedCount > 0);
|
||||||
FeedLabel.Visibility = (feedCount == 0 ? Visibility.Hidden : Visibility.Visible);
|
FeedLabel.Visibility = (feedCount == 0 ? Visibility.Hidden : Visibility.Visible);
|
||||||
FeedButton.Visibility = (feedCount > 1 ? Visibility.Hidden : Visibility.Visible);
|
FeedButton.Visibility = (feedCount > 1 ? Visibility.Hidden : Visibility.Visible);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void InitializeFeed()
|
private void InitializeFeed()
|
||||||
@@ -788,6 +792,37 @@ namespace FeedCenter
|
|||||||
feed.Source = feedUrl;
|
feed.Source = feedUrl;
|
||||||
feed.Category = _database.DefaultCategory;
|
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
|
// Read the feed for the first time
|
||||||
var feedReadResult = feed.Read(_database);
|
var feedReadResult = feed.Read(_database);
|
||||||
|
|
||||||
@@ -899,6 +934,16 @@ namespace FeedCenter
|
|||||||
// Get the data as a string
|
// Get the data as a string
|
||||||
var data = (string) e.Data.GetData(DataFormats.Text);
|
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
|
// Handle the new feed but allow the drag/drop to complete
|
||||||
Dispatcher.BeginInvoke(new NewFeedDelegate(HandleNewFeed), data);
|
Dispatcher.BeginInvoke(new NewFeedDelegate(HandleNewFeed), data);
|
||||||
}
|
}
|
||||||
@@ -981,13 +1026,13 @@ namespace FeedCenter
|
|||||||
|
|
||||||
// Create a menu item
|
// Create a menu item
|
||||||
var menuItem = new MenuItem
|
var menuItem = new MenuItem
|
||||||
{
|
{
|
||||||
Header = display,
|
Header = display,
|
||||||
Tag = feed,
|
Tag = feed,
|
||||||
|
|
||||||
// Set the current item to bold
|
// Set the current item to bold
|
||||||
FontWeight = feed == _currentFeed ? FontWeights.Bold : FontWeights.Normal
|
FontWeight = feed == _currentFeed ? FontWeights.Bold : FontWeights.Normal
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// Handle the click
|
// Handle the click
|
||||||
@@ -1046,12 +1091,12 @@ namespace FeedCenter
|
|||||||
var screen = System.Windows.Forms.Screen.FromHandle(windowInteropHelper.Handle);
|
var screen = System.Windows.Forms.Screen.FromHandle(windowInteropHelper.Handle);
|
||||||
|
|
||||||
var rectangle = new System.Drawing.Rectangle
|
var rectangle = new System.Drawing.Rectangle
|
||||||
{
|
{
|
||||||
X = (int) Left,
|
X = (int) Left,
|
||||||
Y = (int) Top,
|
Y = (int) Top,
|
||||||
Width = (int) Width,
|
Width = (int) Width,
|
||||||
Height = (int) Height
|
Height = (int) Height
|
||||||
};
|
};
|
||||||
|
|
||||||
var borderThickness = new Thickness();
|
var borderThickness = new Thickness();
|
||||||
|
|
||||||
|
|||||||
@@ -2,5 +2,6 @@
|
|||||||
<packages>
|
<packages>
|
||||||
<package id="EntityFramework" version="6.1.1" targetFramework="net45" />
|
<package id="EntityFramework" version="6.1.1" targetFramework="net45" />
|
||||||
<package id="EntityFramework.SqlServerCompact" 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" />
|
<package id="Microsoft.SqlServer.Compact" version="4.0.8854.1" targetFramework="net45" />
|
||||||
</packages>
|
</packages>
|
||||||
@@ -175,6 +175,8 @@
|
|||||||
|
|
||||||
<File Source="$(var.FeedCenter.TargetDir)\Common.Wpf.MarkupExtensions.dll" />
|
<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.dll" />
|
||||||
<File Source="$(var.FeedCenter.TargetDir)\EntityFramework.SqlServer.dll" />
|
<File Source="$(var.FeedCenter.TargetDir)\EntityFramework.SqlServer.dll" />
|
||||||
<File Source="$(var.FeedCenter.TargetDir)\EntityFramework.SqlServerCompact.dll" />
|
<File Source="$(var.FeedCenter.TargetDir)\EntityFramework.SqlServerCompact.dll" />
|
||||||
|
|||||||
Reference in New Issue
Block a user