diff --git a/Application/App.xaml.cs b/Application/App.xaml.cs index 72e5216..92b491d 100644 --- a/Application/App.xaml.cs +++ b/Application/App.xaml.cs @@ -12,7 +12,8 @@ namespace FeedCenter { public partial class App { - public static bool IsDebugBuild + // ReSharper disable ConvertPropertyToExpressionBody + private static bool IsDebugBuild { get { @@ -23,6 +24,7 @@ namespace FeedCenter #endif } } + // ReSharper restore ConvertPropertyToExpressionBody [STAThread] public static void Main() diff --git a/Application/BrowserCommon.cs b/Application/BrowserCommon.cs index 0a85b66..dd4f1ab 100644 --- a/Application/BrowserCommon.cs +++ b/Application/BrowserCommon.cs @@ -43,7 +43,7 @@ namespace FeedCenter return true; // Add quotes around the URL for safety - url = string.Format("\"{0}\"", url); + url = $"\"{url}\""; // Start the browser if (browser == null) diff --git a/Application/Data/Database.cs b/Application/Data/Database.cs index 470798a..03f7e21 100644 --- a/Application/Data/Database.cs +++ b/Application/Data/Database.cs @@ -69,17 +69,14 @@ namespace FeedCenter.Data #endregion - public static bool DatabaseExists - { - get { return File.Exists(DatabasePath); } - } + public static bool DatabaseExists => File.Exists(DatabasePath); public static void CreateDatabase() { Tracer.WriteLine("Creating database engine"); // Create the database engine - using (var engine = new SqlCeEngine(string.Format("Data Source={0}", DatabasePath))) + using (var engine = new SqlCeEngine($"Data Source={DatabasePath}")) { Tracer.WriteLine("Creating database"); @@ -133,7 +130,7 @@ namespace FeedCenter.Data Tracer.WriteLine("Creating database engine"); // Create the database engine - using (var engine = new SqlCeEngine(string.Format("Data Source={0}", DatabasePath))) + using (var engine = new SqlCeEngine($"Data Source={DatabasePath}")) { Tracer.WriteLine("Upgrading database"); @@ -145,7 +142,7 @@ namespace FeedCenter.Data Tracer.WriteLine("Getting database version"); // Create a database connection - using (var connection = new SqlCeConnection(string.Format("Data Source={0}", DatabasePath))) + using (var connection = new SqlCeConnection($"Data Source={DatabasePath}")) { // Open the connection connection.Open(); @@ -190,7 +187,7 @@ namespace FeedCenter.Data Tracer.WriteLine("Creating database engine"); // Create the database engine - using (var engine = new SqlCeEngine(string.Format("Data Source={0}", DatabasePath))) + using (var engine = new SqlCeEngine($"Data Source={DatabasePath}")) { Tracer.WriteLine("Shrinking database"); @@ -202,7 +199,7 @@ namespace FeedCenter.Data private static void ExecuteScript(string scriptText) { // Create a database connection - using (var connection = new SqlCeConnection(string.Format("Data Source={0}", DatabasePath))) + using (var connection = new SqlCeConnection($"Data Source={DatabasePath}")) { // Open the connection connection.Open(); diff --git a/Application/Data/Extensions.cs b/Application/Data/Extensions.cs index 3c1a021..5ad949f 100644 --- a/Application/Data/Extensions.cs +++ b/Application/Data/Extensions.cs @@ -1,7 +1,4 @@ -using System; -using System.Data; -using System.Data.SqlServerCe; -using System.Data.SqlTypes; +using System.Data.SqlTypes; namespace FeedCenter.Data { @@ -12,144 +9,5 @@ namespace FeedCenter.Data public static SqlDateTime SqlDateTimeZero = new SqlDateTime(0, 0); #endregion - - #region DataSet - - public static DataRow GetFirstDataRow(this DataSet dataSet) - { - // If we get no data set then return nothing - if (dataSet == null) - return null; - - // If there were no tables returns then return nothing - if (dataSet.Tables.Count == 0) - return null; - - // Get the first table - var firstTable = dataSet.Tables[0]; - - // If the table has no rows then return nothing - if (firstTable.Rows.Count == 0) - return null; - - // Return the first row - return firstTable.Rows[0]; - } - - #endregion - - #region SqlCeCommand - - public static void SetStatement(this SqlCeCommand command, string statement, params object[] parameters) - { - // Create a new array to hold the updated parameters - var formattedParameters = new object[parameters.Length]; - - // Initialize our position - var position = 0; - - // Loop over each parameter - foreach (var parameter in parameters) - { - // If the parameter is a DateTime then we need to reformat - if (parameter == null) - { - // Use a explicit null value - formattedParameters[position++] = "NULL"; - } - else if (parameter is DateTime) - { - // Cast the parameter back to a DateTime - var dateTime = (DateTime) parameter; - - // Convert the DateTime to sortable format - var formatted = dateTime.ToString("s"); - - // Set into the formatted array - formattedParameters[position++] = formatted; - } - else if (parameter is bool) - { - // Convert the boolean to a number - formattedParameters[position++] = Convert.ToInt32(parameter); - } - else if (parameter.GetType().IsEnum) - { - // Convert the enum to a number - formattedParameters[position++] = Convert.ToInt32(parameter); - } - else if (parameter is string) - { - // Escape single quotes - formattedParameters[position++] = (parameter as string).Replace("'", "''"); - } - else - { - // Just put the original value in - formattedParameters[position++] = parameter; - } - } - - // Build the full statement - command.CommandText = string.Format(statement, formattedParameters); - } - - #endregion - - #region SqlCeConnection - - public static void ExecuteNonQuery(this SqlCeConnection connection, string query, params object[] parameters) - { - // Create the command object - var command = connection.CreateCommand(); - - // Set the statement based on the query and parameters - command.SetStatement(query, parameters); - - //Tracer.WriteLine("Executing SQL statement: {0}", command.CommandText); - - // Execute the command - command.ExecuteNonQuery(); - } - - public static DataSet ExecuteDataSet(this SqlCeConnection connection, string query, params object[] parameters) - { - // Create the command object - var command = connection.CreateCommand(); - - // Set the statement based on the query and parameters - command.SetStatement(query, parameters); - - // Create a new data adapter - using (var adapter = new SqlCeDataAdapter(command)) - { - // Create the new data set - using (var dataSet = new DataSet()) - { - //Tracer.WriteLine("Executing SQL query: {0}", command.CommandText); - - // Fill the data set - adapter.Fill(dataSet); - - return dataSet; - } - } - } - - public static object ExecuteScalar(this SqlCeConnection connection, string query, params object[] parameters) - { - // Create the command object - var command = connection.CreateCommand(); - - // Set the statement based on the query and parameters - command.SetStatement(query, parameters); - - //Tracer.WriteLine("Executing SQL statement: {0}", command.CommandText); - - // Execute the command - return command.ExecuteScalar(); - } - - #endregion } } diff --git a/Application/Entities.cs b/Application/Entities.cs index d28e236..ad7ebca 100644 --- a/Application/Entities.cs +++ b/Application/Entities.cs @@ -86,12 +86,14 @@ namespace FeedCenter void HandleObjectStateManagerObjectStateManagerChanged(object sender, CollectionChangeEventArgs e) { - if (e.Element is Category) + var element = e.Element as Category; + + if (element != null) { if (_allCategories == null) return; - var category = e.Element as Category; + var category = element; switch (e.Action) { @@ -113,7 +115,7 @@ namespace FeedCenter if (_allFeeds == null) return; - var feed = e.Element as Feed; + var feed = (Feed) e.Element; switch (e.Action) { diff --git a/Application/FeedParsers/AtomParser.cs b/Application/FeedParsers/AtomParser.cs index 220fb30..6171024 100644 --- a/Application/FeedParsers/AtomParser.cs +++ b/Application/FeedParsers/AtomParser.cs @@ -1,5 +1,4 @@ using Common.Debug; -using Common.Xml; using System.Xml; namespace FeedCenter.FeedParsers @@ -18,9 +17,6 @@ namespace FeedCenter.FeedParsers // Load the XML document from the text document.LoadXml(feedText); - // Create the namespace manager - var namespaceManager = document.GetAllNamespaces(); - // Get the root node XmlNode rootNode = document.DocumentElement; @@ -62,7 +58,7 @@ namespace FeedCenter.FeedParsers break; case "entry": - HandleFeedItem(namespaceManager, node, ref sequence); + HandleFeedItem(node, ref sequence); break; } } @@ -77,7 +73,7 @@ namespace FeedCenter.FeedParsers } } - protected override FeedItem ParseFeedItem(XmlNamespaceManager namespaceManager, XmlNode node) + protected override FeedItem ParseFeedItem(XmlNode node) { // Create a new feed item var feedItem = FeedItem.Create(); diff --git a/Application/FeedParsers/FeedParserBase.cs b/Application/FeedParsers/FeedParserBase.cs index 0fe9eaf..b95e7f4 100644 --- a/Application/FeedParsers/FeedParserBase.cs +++ b/Application/FeedParsers/FeedParserBase.cs @@ -35,12 +35,12 @@ namespace FeedCenter.FeedParsers public abstract FeedReadResult ParseFeed(string feedText); - protected abstract FeedItem ParseFeedItem(XmlNamespaceManager namespaceManager, XmlNode node); + protected abstract FeedItem ParseFeedItem(XmlNode node); - protected void HandleFeedItem(XmlNamespaceManager namespaceManager, XmlNode node, ref int sequence) + protected void HandleFeedItem(XmlNode node, ref int sequence) { // Build a feed item from the node - FeedItem newFeedItem = ParseFeedItem(namespaceManager, node); + FeedItem newFeedItem = ParseFeedItem(node); if (newFeedItem == null) return; @@ -116,10 +116,10 @@ namespace FeedCenter.FeedParsers return new AtomParser(feed); } - throw new ArgumentException(string.Format("Feed type {0} is not supported", feedType)); + throw new ArgumentException($"Feed type {feedType} is not supported"); } - public static FeedType DetectFeedType(string feedText) + private static FeedType DetectFeedType(string feedText) { try { diff --git a/Application/FeedParsers/RdfParser.cs b/Application/FeedParsers/RdfParser.cs index f119852..ba01901 100644 --- a/Application/FeedParsers/RdfParser.cs +++ b/Application/FeedParsers/RdfParser.cs @@ -64,7 +64,7 @@ namespace FeedCenter.FeedParsers switch (node.Name) { case "item": - HandleFeedItem(namespaceManager, node, ref sequence); + HandleFeedItem(node, ref sequence); break; } } @@ -79,7 +79,7 @@ namespace FeedCenter.FeedParsers } } - protected override FeedItem ParseFeedItem(XmlNamespaceManager namespaceManager, XmlNode node) + protected override FeedItem ParseFeedItem(XmlNode node) { // Create a new feed item FeedItem feedItem = FeedItem.Create(); diff --git a/Application/FeedParsers/RssParser.cs b/Application/FeedParsers/RssParser.cs index 8ade570..7be3da1 100644 --- a/Application/FeedParsers/RssParser.cs +++ b/Application/FeedParsers/RssParser.cs @@ -57,7 +57,7 @@ namespace FeedCenter.FeedParsers break; case "item": - HandleFeedItem(namespaceManager, node, ref sequence); + HandleFeedItem(node, ref sequence); break; } } @@ -72,7 +72,7 @@ namespace FeedCenter.FeedParsers } } - protected override FeedItem ParseFeedItem(XmlNamespaceManager namespaceManager, XmlNode node) + protected override FeedItem ParseFeedItem(XmlNode node) { // Create a new feed item FeedItem feedItem = FeedItem.Create(); diff --git a/Application/Feeds/Category.cs b/Application/Feeds/Category.cs index ff2f03b..90f0cfc 100644 --- a/Application/Feeds/Category.cs +++ b/Application/Feeds/Category.cs @@ -9,14 +9,9 @@ namespace FeedCenter return new Category { ID = Guid.NewGuid() }; } - public bool IsDefault - { - get { return Name == "< default >"; } - } + public bool IsDefault => Name == "< default >"; - public int SortKey - { - get { return IsDefault ? 0 : 1; } - } + // ReSharper disable once UnusedMember.Global + public int SortKey => IsDefault ? 0 : 1; } } diff --git a/Application/Feeds/Feed.cs b/Application/Feeds/Feed.cs index 7e0b735..89c989b 100644 --- a/Application/Feeds/Feed.cs +++ b/Application/Feeds/Feed.cs @@ -58,12 +58,6 @@ namespace FeedCenter return new Feed { ID = Guid.NewGuid(), CategoryID = database.DefaultCategory.ID }; } - #region Event delegates - - public delegate void ErrorEventHandler(WebException webException); - - #endregion - #region Reading public FeedReadResult Read(FeedCenterEntities database, bool forceRead = false) @@ -317,6 +311,7 @@ namespace FeedCenter #endregion + // ReSharper disable once UnusedMember.Global public string LastReadResultDescription { get @@ -325,7 +320,7 @@ namespace FeedCenter var lastReadResult = LastReadResult; // Build the name of the resource using the enum name and the value - var resourceName = string.Format("{0}_{1}", typeof(FeedReadResult).Name, lastReadResult); + var resourceName = $"{typeof (FeedReadResult).Name}_{lastReadResult}"; // Try to get the value from the resources var resourceValue = Properties.Resources.ResourceManager.GetString(resourceName); diff --git a/Application/MainWindow.xaml.cs b/Application/MainWindow.xaml.cs index 49b1259..e45396d 100644 --- a/Application/MainWindow.xaml.cs +++ b/Application/MainWindow.xaml.cs @@ -838,7 +838,7 @@ namespace FeedCenter private void ResetDatabase() { // Get the ID of the current feed - var currentId = _currentFeed == null ? Guid.Empty : _currentFeed.ID; + var currentId = _currentFeed?.ID ?? Guid.Empty; // Create a new database object _database = new FeedCenterEntities(); @@ -977,7 +977,7 @@ namespace FeedCenter foreach (var feed in _database.Feeds.OrderBy(feed => feed.Name)) { // Build a string to display the feed name and the unread count - var display = string.Format("{0} ({1:d})", feed.Name, feed.Items.Count(item => !item.BeenRead)); + var display = $"{feed.Name} ({feed.Items.Count(item => !item.BeenRead):d})"; // Create a menu item var menuItem = new MenuItem diff --git a/Application/NotificationIcon.cs b/Application/NotificationIcon.cs index 1e26970..e345e1b 100644 --- a/Application/NotificationIcon.cs +++ b/Application/NotificationIcon.cs @@ -73,7 +73,7 @@ namespace FeedCenter ShowBalloonTip(text, icon, Settings.Default.BalloonTipTimeout); } - public static void ShowBalloonTip(string text, ToolTipIcon icon, int timeout) + private static void ShowBalloonTip(string text, ToolTipIcon icon, int timeout) { _notificationIcon.ShowBalloonTip(timeout, Resources.ApplicationDisplayName, text, icon); } diff --git a/Application/SettingsStore.cs b/Application/SettingsStore.cs index e9ed70b..9a9cefa 100644 --- a/Application/SettingsStore.cs +++ b/Application/SettingsStore.cs @@ -36,7 +36,7 @@ namespace FeedCenter var setting = entities.Settings.FirstOrDefault(s => s.Name == name && s.Version == versionString); - return setting == null ? null : setting.Value; + return setting?.Value; } public static void SetSettingValue(object dataStore, string name, Version version, string value) @@ -69,14 +69,11 @@ namespace FeedCenter { var entities = (FeedCenterEntities) dataStore; - if (entities == null) - return null; - // Get a distinct list of version strings - var versions = entities.Settings.Select(s => s.Version).Distinct().ToList(); + var versions = entities?.Settings.Select(s => s.Version).Distinct().ToList(); // Create a version object for each string and return the list - return versions.Select(s => new Version(s)).ToList(); + return versions?.Select(s => new Version(s)).ToList(); } public static void DeleteSettingsForVersion(object dataStore, Version version) diff --git a/Application/SystemConfiguration.cs b/Application/SystemConfiguration.cs index 1292a56..8b0509c 100644 --- a/Application/SystemConfiguration.cs +++ b/Application/SystemConfiguration.cs @@ -1,9 +1,7 @@ -using Common.Wpf.Extensions; -using Microsoft.Win32; +using Microsoft.Win32; using System; using System.IO; using System.Reflection; -using System.Windows; using FeedCenter.Properties; namespace FeedCenter @@ -44,7 +42,7 @@ namespace FeedCenter if (subKey != null) { // Write the assembly location and parameter - subKey.SetValue(string.Empty, string.Format("\"{0}\" %1", assemblyLocation)); + subKey.SetValue(string.Empty, $"\"{assemblyLocation}\" %1"); // Close the subkey subKey.Close(); @@ -56,21 +54,9 @@ namespace FeedCenter } } - public static bool UseDebugPath - { - get - { - return Environment.CommandLine.IndexOf("/debugPath", StringComparison.InvariantCultureIgnoreCase) != -1; - } - } + private static bool UseDebugPath => Environment.CommandLine.IndexOf("/debugPath", StringComparison.InvariantCultureIgnoreCase) != -1; - public static string DataDirectory - { - get - { - return UseDebugPath ? Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) : UserSettingsPath; - } - } + public static string DataDirectory => UseDebugPath ? Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) : UserSettingsPath; public static string UserSettingsPath { @@ -83,7 +69,7 @@ namespace FeedCenter // Get the path to the local application data directory var path = Path.Combine( Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), - Properties.Resources.ApplicationName); + Resources.ApplicationName); // Make sure it exists - create it if needed if (!Directory.Exists(path))