From 64d0f770ca74d414d18c236b4005fbf810dfb29e Mon Sep 17 00:00:00 2001 From: Chris Kaczor Date: Fri, 7 Apr 2023 22:24:52 -0400 Subject: [PATCH] Code cleanup --- Application/App.xaml.cs | 10 ++-- Application/Data/LegacyDatabase.cs | 4 +- Application/FeedParsers/RdfParser.cs | 5 +- Application/FeedParsers/RssParser.cs | 4 +- Application/Feeds/Category.cs | 4 +- Application/Feeds/Feed.cs | 24 +++------ Application/MainWindow/MainWindow.xaml | 1 - Application/MainWindow/MainWindow.xaml.cs | 12 ++--- .../Options/GeneralOptionsPanel.xaml.cs | 8 +-- Application/Options/OptionsWindow.xaml.cs | 4 +- Application/SystemConfiguration.cs | 4 +- Application/Xml/XmlSanitizingStream.cs | 50 +++++++++---------- 12 files changed, 58 insertions(+), 72 deletions(-) diff --git a/Application/App.xaml.cs b/Application/App.xaml.cs index 8f8f384..99f6a6b 100644 --- a/Application/App.xaml.cs +++ b/Application/App.xaml.cs @@ -1,12 +1,12 @@ -using System; -using System.IO; -using System.Linq; -using System.Windows.Threading; +using ChrisKaczor.GenericSettingsProvider; using ChrisKaczor.Wpf.Application; -using ChrisKaczor.GenericSettingsProvider; using FeedCenter.Data; using FeedCenter.Properties; using Serilog; +using System; +using System.IO; +using System.Linq; +using System.Windows.Threading; namespace FeedCenter { diff --git a/Application/Data/LegacyDatabase.cs b/Application/Data/LegacyDatabase.cs index e19d9c8..768d5d3 100644 --- a/Application/Data/LegacyDatabase.cs +++ b/Application/Data/LegacyDatabase.cs @@ -169,9 +169,9 @@ public static class LegacyDatabase var realm = Realm.GetInstance(realmConfiguration); - if (!File.Exists(DatabaseFile)) + if (!File.Exists(DatabaseFile)) return; - + using var connection = new SqlCeConnection($"Data Source={DatabaseFile}"); connection.Open(); diff --git a/Application/FeedParsers/RdfParser.cs b/Application/FeedParsers/RdfParser.cs index 1a1f155..58923bd 100644 --- a/Application/FeedParsers/RdfParser.cs +++ b/Application/FeedParsers/RdfParser.cs @@ -1,7 +1,6 @@ -using Serilog; -using System; +using FeedCenter.Xml; +using Serilog; using System.Xml; -using FeedCenter.Xml; namespace FeedCenter.FeedParsers { diff --git a/Application/FeedParsers/RssParser.cs b/Application/FeedParsers/RssParser.cs index 4f34174..2f4beda 100644 --- a/Application/FeedParsers/RssParser.cs +++ b/Application/FeedParsers/RssParser.cs @@ -1,7 +1,7 @@ -using Serilog; +using FeedCenter.Xml; +using Serilog; using System; using System.Xml; -using FeedCenter.Xml; namespace FeedCenter.FeedParsers { diff --git a/Application/Feeds/Category.cs b/Application/Feeds/Category.cs index 50e8b5d..1789bea 100644 --- a/Application/Feeds/Category.cs +++ b/Application/Feeds/Category.cs @@ -1,6 +1,6 @@ -using System; +using Realms; +using System; using System.Collections.Generic; -using Realms; namespace FeedCenter { diff --git a/Application/Feeds/Feed.cs b/Application/Feeds/Feed.cs index 79a8e61..c232cb4 100644 --- a/Application/Feeds/Feed.cs +++ b/Application/Feeds/Feed.cs @@ -1,7 +1,8 @@ using ChrisKaczor.ApplicationUpdate; -using FeedCenter.Data; using FeedCenter.FeedParsers; using FeedCenter.Properties; +using FeedCenter.Xml; +using JetBrains.Annotations; using Realms; using Serilog; using System; @@ -14,8 +15,6 @@ using System.Net.Http; using System.Net.Http.Headers; using System.Text; using System.Text.RegularExpressions; -using System.Threading.Tasks; -using FeedCenter.Xml; using Resources = FeedCenter.Properties.Resources; namespace FeedCenter @@ -36,12 +35,6 @@ namespace FeedCenter Atom } - public enum FeedItemComparison : byte - { - Default, - Title - } - public enum FeedReadResult { Success, @@ -77,7 +70,6 @@ namespace FeedCenter public bool Authenticate { get; set; } public string Username { get; set; } public string Password { get; set; } - public string Domain { get; set; } private string LastReadResultRaw { get; set; } @@ -89,14 +81,6 @@ namespace FeedCenter public DateTimeOffset LastUpdated { get; set; } - private string ItemComparisonRaw { get; set; } - - public FeedItemComparison ItemComparison - { - get => Enum.TryParse(ItemComparisonRaw, out FeedItemComparison result) ? result : FeedItemComparison.Default; - set => ItemComparisonRaw = value.ToString(); - } - [MapTo("CategoryID")] public Guid CategoryId { get; set; } @@ -110,6 +94,7 @@ namespace FeedCenter public Category Category { get; set; } + [UsedImplicitly] public IList Items { get; } // ReSharper disable once UnusedMember.Global @@ -217,6 +202,9 @@ namespace FeedCenter // Get the feed text var feedText = textReader.ReadToEnd(); + if (string.IsNullOrEmpty(feedText)) + return Tuple.Create(FeedReadResult.NoResponse, string.Empty); + // Get rid of any leading and trailing whitespace feedText = feedText.Trim(); diff --git a/Application/MainWindow/MainWindow.xaml b/Application/MainWindow/MainWindow.xaml index 00f3b9f..5f79d4c 100644 --- a/Application/MainWindow/MainWindow.xaml +++ b/Application/MainWindow/MainWindow.xaml @@ -153,7 +153,6 @@ Foreground="White" nameBasedGrid:NameBasedGrid.Row="FeedListRow" ScrollViewer.HorizontalScrollBarVisibility="Disabled"> - = 0xE and <= 0x1F || - character is >= 0x7F and <= 0x84 || - character is >= 0x86 and <= 0x9F || - character > 0x10FFFF - ); - } + { + return + !( + character <= 0x8 || + character == 0xB || + character == 0xC || + 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 is >= 0x20 and <= 0xD7FF || - character is >= 0xE000 and <= 0xFFFD || - character is >= 0x10000 and <= 0x10FFFF; - } + { + return + 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 - (nameof(xmlVersion), @$"'{xmlVersion}' is not a valid XML version."); - } + { + throw new ArgumentOutOfRangeException + (nameof(xmlVersion), @$"'{xmlVersion}' is not a valid XML version."); + } } }