diff --git a/Application/App.xaml.cs b/Application/App.xaml.cs index e17ff0c..8f8f384 100644 --- a/Application/App.xaml.cs +++ b/Application/App.xaml.cs @@ -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() diff --git a/Application/FeedCenter.csproj b/Application/FeedCenter.csproj index 3baa99b..98e4097 100644 --- a/Application/FeedCenter.csproj +++ b/Application/FeedCenter.csproj @@ -125,7 +125,7 @@ - + diff --git a/Application/FeedErrorWindow.xaml.cs b/Application/FeedErrorWindow.xaml.cs index a0e919b..38e30f3 100644 --- a/Application/FeedErrorWindow.xaml.cs +++ b/Application/FeedErrorWindow.xaml.cs @@ -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; diff --git a/Application/FeedParsers/FeedParserBase.cs b/Application/FeedParsers/FeedParserBase.cs index 4bfc8fd..9c0be67 100644 --- a/Application/FeedParsers/FeedParserBase.cs +++ b/Application/FeedParsers/FeedParserBase.cs @@ -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) diff --git a/Application/Feeds/Feed.cs b/Application/Feeds/Feed.cs index 15a482f..79a8e61 100644 --- a/Application/Feeds/Feed.cs +++ b/Application/Feeds/Feed.cs @@ -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(" ", " "); // 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, "&"); 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 } } \ No newline at end of file diff --git a/Application/Feeds/FeedItem.cs b/Application/Feeds/FeedItem.cs index 7f4c5d3..50cc404 100644 --- a/Application/Feeds/FeedItem.cs +++ b/Application/Feeds/FeedItem.cs @@ -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 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(); } -} +} \ No newline at end of file diff --git a/Application/MainWindow/CommandLine.cs b/Application/MainWindow/CommandLine.cs index c4e28ee..374e469 100644 --- a/Application/MainWindow/CommandLine.cs +++ b/Application/MainWindow/CommandLine.cs @@ -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; diff --git a/Application/MainWindow/FeedCreation.cs b/Application/MainWindow/FeedCreation.cs index 9c59b86..044e3b6 100644 --- a/Application/MainWindow/FeedCreation.cs +++ b/Application/MainWindow/FeedCreation.cs @@ -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) diff --git a/Application/MainWindow/FeedReading.cs b/Application/MainWindow/FeedReading.cs index 5ae2c4f..40f50dc 100644 --- a/Application/MainWindow/FeedReading.cs +++ b/Application/MainWindow/FeedReading.cs @@ -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; diff --git a/Application/MainWindow/MainWindow.xaml.cs b/Application/MainWindow/MainWindow.xaml.cs index 1a8577b..9dd6ff5 100644 --- a/Application/MainWindow/MainWindow.xaml.cs +++ b/Application/MainWindow/MainWindow.xaml.cs @@ -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(); diff --git a/Application/Options/CheckedListItem.cs b/Application/Options/CheckedListItem.cs index 594bd90..0863f8e 100644 --- a/Application/Options/CheckedListItem.cs +++ b/Application/Options/CheckedListItem.cs @@ -24,7 +24,7 @@ public class CheckedListItem : INotifyPropertyChanged { _item = value; - PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Item")); + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Item))); } } @@ -35,7 +35,7 @@ public class CheckedListItem : INotifyPropertyChanged { _isChecked = value; - PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("IsChecked")); + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(IsChecked))); } } } \ No newline at end of file diff --git a/Application/SettingsStore.cs b/Application/SettingsStore.cs index 56e75c7..a76c54b 100644 --- a/Application/SettingsStore.cs +++ b/Application/SettingsStore.cs @@ -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 GetVersionList(object dataStore) => null; - - public static void DeleteSettingsForVersion(object dataStore, Version version) - { - } } -} +} \ No newline at end of file diff --git a/Application/SplashWindow.xaml.cs b/Application/SplashWindow.xaml.cs index 88d4deb..f03fe44 100644 --- a/Application/SplashWindow.xaml.cs +++ b/Application/SplashWindow.xaml.cs @@ -193,5 +193,7 @@ public partial class SplashWindow : IDisposable public void Dispose() { _backgroundWorker?.Dispose(); + + GC.SuppressFinalize(this); } } \ No newline at end of file diff --git a/Application/Xml/XmlSanitizingStream.cs b/Application/Xml/XmlSanitizingStream.cs index 56b2255..1fb3671 100644 --- a/Application/Xml/XmlSanitizingStream.cs +++ b/Application/Xml/XmlSanitizingStream.cs @@ -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(); }