diff --git a/Application/App.xaml.cs b/Application/App.xaml.cs index 2dcd0af..04c7201 100644 --- a/Application/App.xaml.cs +++ b/Application/App.xaml.cs @@ -50,7 +50,7 @@ namespace FeedCenter genericProvider.SetSettingValue = SettingsStore.SetSettingValue; genericProvider.DeleteSettingsForVersion = SettingsStore.DeleteSettingsForVersion; genericProvider.GetVersionList = SettingsStore.GetVersionList; - genericProvider.DeleteOldVersionsOnUpgrade = false; + genericProvider.DeleteOldVersionsOnUpgrade = true; // Initialize the tracer with the current process ID Tracer.Initialize(SystemConfiguration.UserSettingsPath, FeedCenter.Properties.Resources.ApplicationName, Process.GetCurrentProcess().Id.ToString(CultureInfo.InvariantCulture), false); diff --git a/Application/SettingsStore.cs b/Application/SettingsStore.cs index 0d815aa..e9ed70b 100644 --- a/Application/SettingsStore.cs +++ b/Application/SettingsStore.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Linq; namespace FeedCenter @@ -24,33 +25,37 @@ namespace FeedCenter entities.Dispose(); } - public static string GetSettingValue(object dataStore, string name, string version) + public static string GetSettingValue(object dataStore, string name, Version version) { var entities = (FeedCenterEntities) dataStore; if (entities == null) return null; - var setting = entities.Settings.FirstOrDefault(s => s.Name == name && s.Version == version); + var versionString = version.ToString(); + + var setting = entities.Settings.FirstOrDefault(s => s.Name == name && s.Version == versionString); return setting == null ? null : setting.Value; } - public static void SetSettingValue(object dataStore, string name, string version, string value) + public static void SetSettingValue(object dataStore, string name, Version version, string value) { var entities = (FeedCenterEntities) dataStore; if (entities == null) return; + var versionString = version.ToString(); + // Try to get the setting from the database that matches the name and version - var setting = entities.Settings.FirstOrDefault(s => s.Name == name && s.Version == version); + var setting = entities.Settings.FirstOrDefault(s => s.Name == name && s.Version == versionString); // If there was no setting we need to create it if (setting == null) { // Create the new setting - setting = new Setting { Name = name, Version = version }; + setting = new Setting { Name = name, Version = version.ToString() }; // Add the setting to the database entities.Settings.Add(setting); @@ -60,26 +65,31 @@ namespace FeedCenter setting.Value = value; } - public static List GetVersionList(object dataStore) + public static List GetVersionList(object dataStore) { var entities = (FeedCenterEntities) dataStore; if (entities == null) return null; - return (from setting in entities.Settings - select setting.Version).Distinct().ToList(); + // Get a distinct list of version strings + 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(); } - public static void DeleteSettingsForVersion(object dataStore, string version) + public static void DeleteSettingsForVersion(object dataStore, Version version) { var entities = (FeedCenterEntities) dataStore; if (entities == null) return; + var versionString = version.ToString(); + // Get all the settings for the current version number - var settings = entities.Settings.Where(setting => setting.Version == version); + var settings = entities.Settings.Where(setting => setting.Version == versionString); // Delete each setting foreach (var setting in settings)