Some cleanup

This commit is contained in:
2023-04-07 22:10:03 -04:00
parent 49842a1663
commit 96d327270f
14 changed files with 64 additions and 97 deletions

View File

@@ -62,12 +62,8 @@ namespace FeedCenter
// Set the callbacks into the provider
genericProvider.OpenDataStore = SettingsStore.OpenDataStore;
genericProvider.CloseDataStore = SettingsStore.CloseDataStore;
genericProvider.GetSettingValue = SettingsStore.GetSettingValue;
genericProvider.SetSettingValue = SettingsStore.SetSettingValue;
genericProvider.DeleteSettingsForVersion = SettingsStore.DeleteSettingsForVersion;
genericProvider.GetVersionList = SettingsStore.GetVersionList;
genericProvider.DeleteOldVersionsOnUpgrade = !IsDebugBuild;
Log.Logger = new LoggerConfiguration()
.Enrich.WithThreadId()

View File

@@ -125,7 +125,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="ChrisKaczor.ApplicationUpdate" Version="1.0.2" />
<PackageReference Include="ChrisKaczor.GenericSettingsProvider" Version="1.0.2" />
<PackageReference Include="ChrisKaczor.GenericSettingsProvider" Version="1.0.3" />
<PackageReference Include="ChrisKaczor.InstalledBrowsers" Version="1.0.2" />
<PackageReference Include="ChrisKaczor.Wpf.Application.SingleInstance" Version="1.0.4" />
<PackageReference Include="ChrisKaczor.Wpf.Application.StartWithWindows" Version="1.0.2" />

View File

@@ -115,7 +115,7 @@ namespace FeedCenter
var feed = (Feed) FeedDataGrid.SelectedItem;
_database.SaveChanges(() => feed.Read(_database, true));
_database.SaveChanges(() => feed.Read(true));
var selectedIndex = FeedDataGrid.SelectedIndex;

View File

@@ -104,19 +104,13 @@ namespace FeedCenter.FeedParsers
{
var feedType = DetectFeedType(feedText);
switch (feedType)
return feedType switch
{
case FeedType.Rss:
return new RssParser(feed);
case FeedType.Rdf:
return new RdfParser(feed);
case FeedType.Atom:
return new AtomParser(feed);
}
throw new ArgumentException($"Feed type {feedType} is not supported");
FeedType.Rss => new RssParser(feed),
FeedType.Rdf => new RdfParser(feed),
FeedType.Atom => new AtomParser(feed),
_ => throw new ArgumentException($"Feed type {feedType} is not supported")
};
}
public static FeedType DetectFeedType(string feedText)

View File

@@ -60,7 +60,7 @@ namespace FeedCenter
#endregion
public class Feed : RealmObject
public partial class Feed : RealmObject
{
[PrimaryKey]
[MapTo("ID")]
@@ -140,11 +140,11 @@ namespace FeedCenter
#region Reading
public FeedReadResult Read(FeedCenterEntities database, bool forceRead = false)
public FeedReadResult Read(bool forceRead = false)
{
Log.Logger.Information("Reading feed: {0}", Source);
var result = ReadFeed(database, forceRead);
var result = ReadFeed(forceRead);
// Handle the result
switch (result)
@@ -224,7 +224,7 @@ namespace FeedCenter
feedText = feedText.Replace("&nbsp;", "&#160;");
// 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]+);)");
var r = UnescapedAmpersandRegex();
feedText = r.Replace(feedText, "&amp;");
return Tuple.Create(FeedReadResult.Success, feedText);
@@ -291,7 +291,7 @@ namespace FeedCenter
}
}
private FeedReadResult ReadFeed(FeedCenterEntities database, bool forceRead)
private FeedReadResult ReadFeed(bool forceRead)
{
try
{
@@ -364,6 +364,9 @@ namespace FeedCenter
}
}
[GeneratedRegex("&(?!(?:[a-z]+|#[0-9]+|#x[0-9a-f]+);)")]
private static partial Regex UnescapedAmpersandRegex();
#endregion
}
}

View File

@@ -1,11 +1,11 @@
using System;
using System.Text.RegularExpressions;
using FeedCenter.Options;
using FeedCenter.Options;
using Realms;
using System;
using System.Text.RegularExpressions;
namespace FeedCenter
{
public class FeedItem : RealmObject
public partial class FeedItem : RealmObject
{
[PrimaryKey]
[MapTo("ID")]
@@ -30,22 +30,20 @@ namespace FeedCenter
return new FeedItem { Id = System.Guid.NewGuid() };
}
#region Methods
public override string ToString()
{
var title = Title;
switch (Properties.Settings.Default.MultipleLineDisplay)
{
case Options.MultipleLineDisplay.SingleLine:
case MultipleLineDisplay.SingleLine:
// Strip any newlines from the title
title = Regex.Replace(title, @"\n", " ");
title = NewlineRegex().Replace(title, " ");
break;
case Options.MultipleLineDisplay.FirstLine:
case MultipleLineDisplay.FirstLine:
// Find the first newline
var newlineIndex = title.IndexOf("\n", StringComparison.Ordinal);
@@ -62,10 +60,10 @@ namespace FeedCenter
}
// Condense multiple spaces to one space
title = Regex.Replace(title, @"[ ]{2,}", " ");
title = MultipleSpaceRegex().Replace(title, " ");
// Condense tabs to one space
title = Regex.Replace(title, @"\t", " ");
title = TabRegex().Replace(title, " ");
// If the title is blank then put in the "no title" title
if (title.Length == 0)
@@ -74,20 +72,13 @@ namespace FeedCenter
return title;
}
//public void ProcessActions(IEnumerable<FeedAction> feedActions)
//{
// foreach (FeedAction feedAction in feedActions)
// {
// switch (feedAction.Field)
// {
// case 1:
[GeneratedRegex("\\n")]
private static partial Regex NewlineRegex();
// Title = Regex.Replace(Title, feedAction.Search, feedAction.Replace);
// break;
// }
// }
//}
[GeneratedRegex("[ ]{2,}")]
private static partial Regex MultipleSpaceRegex();
#endregion
[GeneratedRegex("\\t")]
private static partial Regex TabRegex();
}
}
}

View File

@@ -26,7 +26,7 @@ namespace FeedCenter
var endPosition = commandLine.IndexOf(" ", startPosition, StringComparison.Ordinal);
// Extract the feed URL
var feedUrl = commandLine.Substring(startPosition, endPosition - startPosition);
var feedUrl = commandLine[startPosition..endPosition];
// Add the HTTP protocol by default
feedUrl = "http://" + feedUrl;

View File

@@ -63,7 +63,7 @@ namespace FeedCenter
}
// Read the feed for the first time
var feedReadResult = feed.Read(_database);
var feedReadResult = feed.Read();
// See if we read the feed okay
if (feedReadResult == FeedReadResult.Success)

View File

@@ -159,7 +159,7 @@ namespace FeedCenter
foreach (var feed in feedsToRead)
{
// Read the feed
database.SaveChanges(() => feed.Read(database, workerInput.ForceRead));
database.SaveChanges(() => feed.Read(workerInput.ForceRead));
// Increment progress
currentProgress += 1;

View File

@@ -131,9 +131,8 @@ namespace FeedCenter
break;
case Dock.Left:
case Dock.Right:
throw new NotSupportedException();
default:
throw new ArgumentOutOfRangeException(nameof(Settings.Default.ToolbarLocation));
throw new NotSupportedException();
}
break;
@@ -153,8 +152,8 @@ namespace FeedCenter
_database.Refresh();
_feedList = _currentCategory == null
? _database.Feeds
: _database.Feeds.Where(feed => feed.Category.Id == _currentCategory.Id);
? _database.Feeds.ToList()
: _database.Feeds.Where(feed => feed.Category.Id == _currentCategory.Id).ToList();
UpdateToolbarButtonState();

View File

@@ -24,7 +24,7 @@ public class CheckedListItem<T> : INotifyPropertyChanged
{
_item = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Item"));
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Item)));
}
}
@@ -35,7 +35,7 @@ public class CheckedListItem<T> : INotifyPropertyChanged
{
_isChecked = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("IsChecked"));
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(IsChecked)));
}
}
}

View File

@@ -1,7 +1,6 @@
using FeedCenter.Data;
using FeedCenter.Options;
using System;
using System.Collections.Generic;
using System.Linq;
namespace FeedCenter
@@ -18,11 +17,7 @@ namespace FeedCenter
return Database.Entities;
}
public static void CloseDataStore(object dataStore)
{
}
public static string GetSettingValue(object dataStore, string name, Version version)
public static string GetSettingValue(object dataStore, string name, Version _)
{
var entities = (FeedCenterEntities) dataStore;
@@ -31,7 +26,7 @@ namespace FeedCenter
return setting?.Value;
}
public static void SetSettingValue(object dataStore, string name, Version version, string value)
public static void SetSettingValue(object dataStore, string name, Version _, string value)
{
var entities = (FeedCenterEntities) dataStore;
@@ -57,11 +52,5 @@ namespace FeedCenter
setting.Value = value;
});
}
public static List<Version> GetVersionList(object dataStore) => null;
public static void DeleteSettingsForVersion(object dataStore, Version version)
{
}
}
}
}

View File

@@ -193,5 +193,7 @@ public partial class SplashWindow : IDisposable
public void Dispose()
{
_backgroundWorker?.Dispose();
GC.SuppressFinalize(this);
}
}

View File

@@ -48,28 +48,26 @@ public class XmlSanitizingStream : StreamReader
character <= 0x8 ||
character == 0xB ||
character == 0xC ||
(character >= 0xE && character <= 0x1F) ||
(character >= 0x7F && character <= 0x84) ||
(character >= 0x86 && character <= 0x9F) ||
character is >= 0xE and <= 0x1F ||
character is >= 0x7F and <= 0x84 ||
character is >= 0x86 and <= 0x9F ||
character > 0x10FFFF
);
}
case "1.0": // http://www.w3.org/TR/REC-xml/#charsets
{
return
(
character == 0x9 /* == '\t' == 9 */ ||
character == 0xA /* == '\n' == 10 */ ||
character == 0xD /* == '\r' == 13 */ ||
(character >= 0x20 && character <= 0xD7FF) ||
(character >= 0xE000 && character <= 0xFFFD) ||
(character >= 0x10000 && character <= 0x10FFFF)
);
character == 0x9 /* == '\t' == 9 */ ||
character == 0xA /* == '\n' == 10 */ ||
character == 0xD /* == '\r' == 13 */ ||
character is >= 0x20 and <= 0xD7FF ||
character is >= 0xE000 and <= 0xFFFD ||
character is >= 0x10000 and <= 0x10FFFF;
}
default:
{
throw new ArgumentOutOfRangeException
("xmlVersion", string.Format("'{0}' is not a valid XML version.", xmlVersion));
(nameof(xmlVersion), @$"'{xmlVersion}' is not a valid XML version.");
}
}
}
@@ -133,28 +131,28 @@ public class XmlSanitizingStream : StreamReader
#region Read*() method overrides
// The following methods are exact copies of the methods in TextReader,
// extracting by disassembling it in Refelctor
// extracting by disassembling it in Reflector
public override int Read(char[] buffer, int index, int count)
{
if (buffer == null)
{
throw new ArgumentNullException("buffer");
throw new ArgumentNullException(nameof(buffer));
}
if (index < 0)
{
throw new ArgumentOutOfRangeException("index");
throw new ArgumentOutOfRangeException(nameof(index));
}
if (count < 0)
{
throw new ArgumentOutOfRangeException("count");
throw new ArgumentOutOfRangeException(nameof(count));
}
if ((buffer.Length - index) < count)
if (buffer.Length - index < count)
{
throw new ArgumentException();
throw new ArgumentOutOfRangeException(nameof(buffer));
}
var num = 0;
@@ -179,7 +177,7 @@ public class XmlSanitizingStream : StreamReader
do
{
num2 += num = Read(buffer, index + num2, count - num2);
} while ((num > 0) && (num2 < count));
} while (num > 0 && num2 < count);
return num2;
}
@@ -193,16 +191,11 @@ public class XmlSanitizingStream : StreamReader
switch (num)
{
case -1:
if (builder.Length > 0)
{
return builder.ToString();
}
return null;
return builder.Length > 0 ? builder.ToString() : null;
case 13:
case 10:
if ((num == 13) && (Peek() == 10))
if (num == 13 && Peek() == 10)
{
Read();
}