mirror of
https://github.com/ckaczor/FeedCenter.git
synced 2026-01-14 01:25:38 -05:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| a0214b98f1 | |||
| 59bb8ae3cd | |||
| 840bd1acd0 | |||
| ed1d5566f2 | |||
| be1bd39974 | |||
| 92469c15aa |
@@ -44,13 +44,13 @@ namespace FeedCenter.FeedParsers
|
||||
if (node.Attributes == null)
|
||||
break;
|
||||
|
||||
XmlNode relNode = node.Attributes["rel"];
|
||||
XmlNode relNode = GetAttribute(node, "rel");
|
||||
|
||||
if (relNode != null)
|
||||
rel = relNode.InnerText;
|
||||
|
||||
if (string.IsNullOrEmpty(rel) || rel == "alternate")
|
||||
Feed.Link = node.Attributes["href"].InnerText.Trim();
|
||||
Feed.Link = GetAttribute(node, "href").InnerText.Trim();
|
||||
|
||||
break;
|
||||
|
||||
@@ -103,14 +103,14 @@ namespace FeedCenter.FeedParsers
|
||||
if (childNode.Attributes == null)
|
||||
break;
|
||||
|
||||
XmlNode relNode = childNode.Attributes["rel"];
|
||||
XmlNode relNode = GetAttribute(childNode, "rel");
|
||||
|
||||
if (relNode != null)
|
||||
rel = relNode.InnerText.Trim();
|
||||
|
||||
if (string.IsNullOrEmpty(rel) || rel == "alternate")
|
||||
{
|
||||
var link = childNode.Attributes["href"].InnerText;
|
||||
var link = GetAttribute(childNode, "href").InnerText;
|
||||
|
||||
if (link.StartsWith("/"))
|
||||
{
|
||||
@@ -131,5 +131,13 @@ namespace FeedCenter.FeedParsers
|
||||
|
||||
return feedItem;
|
||||
}
|
||||
|
||||
private static XmlAttribute GetAttribute(XmlNode node, string attributeName)
|
||||
{
|
||||
if (node?.Attributes == null)
|
||||
return null;
|
||||
|
||||
return node.Attributes[attributeName, node.NamespaceURI] ?? node.Attributes[attributeName];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
using Common.Debug;
|
||||
using Common.Xml;
|
||||
using FeedCenter.FeedParsers;
|
||||
using System;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
@@ -9,7 +6,12 @@ using System.Net;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
using Common.Debug;
|
||||
using Common.Update;
|
||||
using Common.Xml;
|
||||
using FeedCenter.Data;
|
||||
using FeedCenter.FeedParsers;
|
||||
using FeedCenter.Properties;
|
||||
|
||||
namespace FeedCenter
|
||||
{
|
||||
@@ -55,6 +57,25 @@ namespace FeedCenter
|
||||
|
||||
public partial class Feed
|
||||
{
|
||||
// ReSharper disable once UnusedMember.Global
|
||||
public string LastReadResultDescription
|
||||
{
|
||||
get
|
||||
{
|
||||
// Cast the last read result to the proper enum
|
||||
var lastReadResult = LastReadResult;
|
||||
|
||||
// Build the name of the resource using the enum name and the value
|
||||
var resourceName = $"{typeof(FeedReadResult).Name}_{lastReadResult}";
|
||||
|
||||
// Try to get the value from the resources
|
||||
var resourceValue = Resources.ResourceManager.GetString(resourceName);
|
||||
|
||||
// Return the value or just the enum value if not found
|
||||
return resourceValue ?? lastReadResult.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
public static Feed Create(FeedCenterEntities database)
|
||||
{
|
||||
return new Feed { ID = Guid.NewGuid(), CategoryID = database.DefaultCategory.ID };
|
||||
@@ -75,6 +96,7 @@ namespace FeedCenter
|
||||
case FeedReadResult.NotDue:
|
||||
case FeedReadResult.NotEnabled:
|
||||
case FeedReadResult.NotModified:
|
||||
|
||||
// Ignore
|
||||
break;
|
||||
|
||||
@@ -86,7 +108,7 @@ namespace FeedCenter
|
||||
}
|
||||
|
||||
// If the feed was successfully read and we have no last update timestamp - set the last update timestamp to now
|
||||
if (result == FeedReadResult.Success && LastUpdated == Data.Extensions.SqlDateTimeZero.Value)
|
||||
if (result == FeedReadResult.Success && LastUpdated == Extensions.SqlDateTimeZero.Value)
|
||||
LastUpdated = DateTime.Now;
|
||||
|
||||
Tracer.DecrementIndentLevel();
|
||||
@@ -120,13 +142,10 @@ namespace FeedCenter
|
||||
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
|
||||
|
||||
// Create the web request
|
||||
var oRequest = WebRequest.Create(new Uri(Source));
|
||||
|
||||
// Attempt to cast to a web request
|
||||
var webRequest = oRequest as HttpWebRequest;
|
||||
var request = WebRequest.Create(new Uri(Source));
|
||||
|
||||
// If this is an http request set some special properties
|
||||
if (webRequest != null)
|
||||
if (request is HttpWebRequest webRequest)
|
||||
{
|
||||
// Make sure to use HTTP version 1.1
|
||||
webRequest.ProtocolVersion = HttpVersion.Version11;
|
||||
@@ -137,50 +156,56 @@ namespace FeedCenter
|
||||
// Set a timeout
|
||||
webRequest.Timeout = 10000;
|
||||
|
||||
// Make sure the service point closes the connection right away
|
||||
webRequest.ServicePoint.ConnectionLeaseTimeout = 0;
|
||||
|
||||
// If we need to authenticate then set the credentials
|
||||
if (Authenticate)
|
||||
webRequest.Credentials = new NetworkCredential(Username, Password, Domain);
|
||||
|
||||
// Set a user agent string
|
||||
if (string.IsNullOrWhiteSpace(Properties.Settings.Default.DefaultUserAgent))
|
||||
if (string.IsNullOrWhiteSpace(Settings.Default.DefaultUserAgent))
|
||||
webRequest.UserAgent = "FeedCenter/" + UpdateCheck.LocalVersion;
|
||||
else
|
||||
webRequest.UserAgent = Properties.Settings.Default.DefaultUserAgent;
|
||||
webRequest.UserAgent = Settings.Default.DefaultUserAgent;
|
||||
}
|
||||
|
||||
// Set the default encoding
|
||||
var encoding = Encoding.UTF8;
|
||||
|
||||
// Attempt to get the response
|
||||
var response = (HttpWebResponse) oRequest.GetResponse();
|
||||
using (var response = (HttpWebResponse) request.GetResponse())
|
||||
{
|
||||
// If the response included an encoding then change the encoding
|
||||
if (response.ContentEncoding.Length > 0)
|
||||
encoding = Encoding.GetEncoding(response.ContentEncoding);
|
||||
|
||||
// If the response included an encoding then change the encoding
|
||||
if (response.ContentEncoding.Length > 0)
|
||||
encoding = Encoding.GetEncoding(response.ContentEncoding);
|
||||
// Get the response stream
|
||||
using (var responseStream = response.GetResponseStream())
|
||||
{
|
||||
if (responseStream == null)
|
||||
return Tuple.Create(FeedReadResult.NoResponse, string.Empty);
|
||||
|
||||
// Get the response stream
|
||||
var responseStream = response.GetResponseStream();
|
||||
// Create the text reader
|
||||
using (StreamReader textReader = new XmlSanitizingStream(responseStream, encoding))
|
||||
{
|
||||
// Get the feed text
|
||||
var feedText = textReader.ReadToEnd();
|
||||
|
||||
if (responseStream == null)
|
||||
return Tuple.Create(FeedReadResult.NoResponse, string.Empty);
|
||||
// Get rid of any leading and trailing whitespace
|
||||
feedText = feedText.Trim();
|
||||
|
||||
// Create the text reader
|
||||
StreamReader textReader = new XmlSanitizingStream(responseStream, encoding);
|
||||
// Clean up common invalid XML characters
|
||||
feedText = feedText.Replace(" ", " ");
|
||||
|
||||
// Get the feed text
|
||||
var feedText = textReader.ReadToEnd();
|
||||
// Find ampersands that aren't properly escaped and replace them with escaped versions
|
||||
var r = new Regex("&(?!(?:[a-z]+|#[0-9]+|#x[0-9a-f]+);)");
|
||||
feedText = r.Replace(feedText, "&");
|
||||
|
||||
// Get rid of any leading and trailing whitespace
|
||||
feedText = feedText.Trim();
|
||||
|
||||
// Clean up common invalid XML characters
|
||||
feedText = feedText.Replace(" ", " ");
|
||||
|
||||
// Find ampersands that aren't properly escaped and replace them with escaped versions
|
||||
var r = new Regex("&(?!(?:[a-z]+|#[0-9]+|#x[0-9a-f]+);)");
|
||||
feedText = r.Replace(feedText, "&");
|
||||
|
||||
return Tuple.Create(FeedReadResult.Success, feedText);
|
||||
return Tuple.Create(FeedReadResult.Success, feedText);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (IOException ioException)
|
||||
{
|
||||
@@ -192,23 +217,25 @@ namespace FeedCenter
|
||||
{
|
||||
var result = FeedReadResult.UnknownError;
|
||||
|
||||
var errorResponse = webException.Response as HttpWebResponse;
|
||||
|
||||
if (errorResponse != null)
|
||||
if (webException.Response is HttpWebResponse errorResponse)
|
||||
{
|
||||
switch (errorResponse.StatusCode)
|
||||
{
|
||||
case HttpStatusCode.InternalServerError:
|
||||
|
||||
return Tuple.Create(FeedReadResult.ServerError, string.Empty);
|
||||
|
||||
case HttpStatusCode.NotModified:
|
||||
|
||||
return Tuple.Create(FeedReadResult.NotModified, string.Empty);
|
||||
|
||||
case HttpStatusCode.NotFound:
|
||||
|
||||
return Tuple.Create(FeedReadResult.NotFound, string.Empty);
|
||||
|
||||
case HttpStatusCode.Unauthorized:
|
||||
case HttpStatusCode.Forbidden:
|
||||
|
||||
return Tuple.Create(FeedReadResult.Unauthorized, string.Empty);
|
||||
}
|
||||
}
|
||||
@@ -218,10 +245,12 @@ namespace FeedCenter
|
||||
case WebExceptionStatus.ConnectFailure:
|
||||
case WebExceptionStatus.NameResolutionFailure:
|
||||
result = FeedReadResult.ConnectionFailed;
|
||||
|
||||
break;
|
||||
|
||||
case WebExceptionStatus.Timeout:
|
||||
result = FeedReadResult.Timeout;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -321,7 +350,7 @@ namespace FeedCenter
|
||||
|
||||
private void ProcessActions()
|
||||
{
|
||||
var sortedActions = from action in Actions orderby action.Sequence ascending select action;
|
||||
var sortedActions = from action in Actions orderby action.Sequence select action;
|
||||
|
||||
foreach (var feedAction in sortedActions)
|
||||
{
|
||||
@@ -329,30 +358,12 @@ namespace FeedCenter
|
||||
{
|
||||
case 0:
|
||||
Title = Title.Replace(feedAction.Search, feedAction.Replace);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
// ReSharper disable once UnusedMember.Global
|
||||
public string LastReadResultDescription
|
||||
{
|
||||
get
|
||||
{
|
||||
// Cast the last read result to the proper enum
|
||||
var lastReadResult = LastReadResult;
|
||||
|
||||
// Build the name of the resource using the enum name and the value
|
||||
var resourceName = $"{typeof(FeedReadResult).Name}_{lastReadResult}";
|
||||
|
||||
// Try to get the value from the resources
|
||||
var resourceValue = Properties.Resources.ResourceManager.GetString(resourceName);
|
||||
|
||||
// Return the value or just the enum value if not found
|
||||
return resourceValue ?? lastReadResult.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,8 +9,8 @@ namespace FeedCenter
|
||||
private static void InitializeUpdate()
|
||||
{
|
||||
UpdateCheck.ApplicationName = Properties.Resources.ApplicationDisplayName;
|
||||
UpdateCheck.UpdateServerType = ServerType.GitHub;
|
||||
UpdateCheck.UpdateServer = Settings.Default.VersionLocation;
|
||||
UpdateCheck.UpdateFile = Settings.Default.VersionFile;
|
||||
UpdateCheck.ApplicationShutdown = ApplicationShutdown;
|
||||
UpdateCheck.ApplicationCurrentMessage = ApplicationCurrentMessage;
|
||||
UpdateCheck.ApplicationUpdateMessage = ApplicationUpdateMessage;
|
||||
|
||||
13
Application/Properties/Settings.Designer.cs
generated
13
Application/Properties/Settings.Designer.cs
generated
@@ -12,7 +12,7 @@ namespace FeedCenter.Properties {
|
||||
|
||||
|
||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.1.0.0")]
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.6.0.0")]
|
||||
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
|
||||
|
||||
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
|
||||
@@ -262,16 +262,7 @@ namespace FeedCenter.Properties {
|
||||
|
||||
[global::System.Configuration.ApplicationScopedSettingAttribute()]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[global::System.Configuration.DefaultSettingValueAttribute("FeedCenterSetup.xml")]
|
||||
public string VersionFile {
|
||||
get {
|
||||
return ((string)(this["VersionFile"]));
|
||||
}
|
||||
}
|
||||
|
||||
[global::System.Configuration.ApplicationScopedSettingAttribute()]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[global::System.Configuration.DefaultSettingValueAttribute("http://server/FeedCenter/")]
|
||||
[global::System.Configuration.DefaultSettingValueAttribute("https://api.github.com/repos/ckaczor/FeedCenter/releases/latest")]
|
||||
public string VersionLocation {
|
||||
get {
|
||||
return ((string)(this["VersionLocation"]));
|
||||
|
||||
@@ -62,11 +62,8 @@
|
||||
<Setting Name="MultipleLineDisplay" Provider="Common.Settings.GenericSettingsProvider" Type="FeedCenter.Options.MultipleLineDisplay" Scope="User">
|
||||
<Value Profile="(Default)">Normal</Value>
|
||||
</Setting>
|
||||
<Setting Name="VersionFile" Type="System.String" Scope="Application">
|
||||
<Value Profile="(Default)">FeedCenterSetup.xml</Value>
|
||||
</Setting>
|
||||
<Setting Name="VersionLocation" Type="System.String" Scope="Application">
|
||||
<Value Profile="(Default)">http://server/FeedCenter/</Value>
|
||||
<Value Profile="(Default)">https://api.github.com/repos/ckaczor/FeedCenter/releases/latest</Value>
|
||||
</Setting>
|
||||
<Setting Name="LastCategoryID" Type="System.String" Scope="User">
|
||||
<Value Profile="(Default)" />
|
||||
|
||||
@@ -82,11 +82,8 @@
|
||||
<setting name="VersionCheckInterval" serializeAs="String">
|
||||
<value>01:00:00</value>
|
||||
</setting>
|
||||
<setting name="VersionFile" serializeAs="String">
|
||||
<value>FeedCenterSetup.xml</value>
|
||||
</setting>
|
||||
<setting name="VersionLocation" serializeAs="String">
|
||||
<value>http://server/FeedCenter/</value>
|
||||
<value>https://api.github.com/repos/ckaczor/FeedCenter/releases/latest</value>
|
||||
</setting>
|
||||
</FeedCenter.Properties.Settings>
|
||||
</applicationSettings>
|
||||
|
||||
@@ -61,9 +61,7 @@
|
||||
</ItemGroup>
|
||||
<Import Project="$(WixTargetsPath)" />
|
||||
<PropertyGroup>
|
||||
<PostBuildEvent>rem D:\Code\Personal\CreateInstallDescriptor\bin\Debug\CreateInstallDescriptor.exe !(TargetPath) $(TargetDir)\$(TargetName).xml
|
||||
rem copy $(TargetDir)\$(TargetName).xml \\server\d\FeedCenter
|
||||
rem copy $(TargetDir)\$(TargetName).exe \\server\d\FeedCenter</PostBuildEvent>
|
||||
<PostBuildEvent />
|
||||
</PropertyGroup>
|
||||
<!--
|
||||
To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
|
||||
2
Common
2
Common
Submodule Common updated: 81ef8f451c...686f33982d
@@ -176,6 +176,8 @@
|
||||
<File Source="$(var.FeedCenter.TargetDir)\NameBasedGrid.dll" />
|
||||
|
||||
<File Source="$(var.FeedCenter.TargetDir)\HtmlAgilityPack.dll" />
|
||||
|
||||
<File Source="$(var.FeedCenter.TargetDir)\Newtonsoft.Json.dll" />
|
||||
|
||||
<File Source="$(var.FeedCenter.TargetDir)\EntityFramework.dll" />
|
||||
<File Source="$(var.FeedCenter.TargetDir)\EntityFramework.SqlServer.dll" />
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
version: 1.0.{build}
|
||||
version: 1.0.0.{build}
|
||||
pull_requests:
|
||||
do_not_increment_build_number: true
|
||||
skip_tags: true
|
||||
|
||||
Reference in New Issue
Block a user