rubberduck-vba / Rubberduck
Showing 62 of 107 files from the diff.
Other files ignored by Codecov
Rubberduck.sln has changed.

@@ -26,7 +26,7 @@
Loading
26 26
        private readonly IOperatingSystem _operatingSystem;
27 27
        private readonly IMessageBox _messageBox;
28 28
        private readonly IVbeSettings _vbeSettings;
29 -
        private readonly IFilePersistanceService<HotkeySettings> _hotkeyService;
29 +
        private readonly IFilePersistenceService<HotkeySettings> _hotkeyService;
30 30
31 31
        private bool _indenterPrompted;
32 32
        private readonly IReadOnlyList<Type> _experimentalFeatureTypes;
@@ -37,8 +37,8 @@
Loading
37 37
            IMessageBox messageBox,
38 38
            IVbeSettings vbeSettings,
39 39
            IExperimentalTypesProvider experimentalTypesProvider,
40 -
            IFilePersistanceService<Rubberduck.Settings.GeneralSettings> service,
41 -
            IFilePersistanceService<HotkeySettings> hotkeyService) 
40 +
            IFilePersistenceService<Rubberduck.Settings.GeneralSettings> service,
41 +
            IFilePersistenceService<HotkeySettings> hotkeyService) 
42 42
            : base(service)
43 43
        {
44 44
            _operatingSystem = operatingSystem;

@@ -0,0 +1,50 @@
Loading
1 +
using System.Collections.Generic;
2 +
using System.Linq;
3 +
using Rubberduck.CodeAnalysis.Inspections;
4 +
using Rubberduck.SettingsProvider;
5 +
using Rubberduck.Parsing.VBA;
6 +
using Rubberduck.Parsing.VBA.Extensions;
7 +
using Rubberduck.Settings;
8 +
9 +
namespace Rubberduck.CodeAnalysis.Settings
10 +
{
11 +
    public class CodeInspectionConfigProvider : ConfigurationServiceBase<CodeInspectionSettings>
12 +
    {
13 +
        private readonly HashSet<string> foundInspectionNames;
14 +
15 +
        public CodeInspectionConfigProvider(IPersistenceService<CodeInspectionSettings> persister, IInspectionProvider inspectionProvider)
16 +
            : base(persister, new DefaultSettings<CodeInspectionSettings, Properties.CodeInspectionDefaults>())
17 +
        {
18 +
            foundInspectionNames = inspectionProvider.Inspections.Select(inspection => inspection.Name).ToHashSet();
19 +
            // Ignore settings for unknown inspections, for example when using the Experimental attribute
20 +
            Defaults.Default.CodeInspections = Defaults.Default.CodeInspections.Where(setting => foundInspectionNames.Contains(setting.Name)).ToHashSet();
21 +
22 +
            var defaultNames = Defaults.Default.CodeInspections.Select(x => x.Name);
23 +
            var nonDefaultInspections = inspectionProvider.Inspections.Where(inspection => !defaultNames.Contains(inspection.Name));
24 +
25 +
            Defaults.Default.CodeInspections.UnionWith(nonDefaultInspections.Select(inspection => new CodeInspectionSetting(inspection)));
26 +
        }
27 +
28 +
        public override CodeInspectionSettings Read()
29 +
        {
30 +
            var loaded = LoadCacheValue();
31 +
            // Loaded settings don't contain defaults, so we need to combine user settings with defaults.
32 +
            var settings = new HashSet<CodeInspectionSetting>();
33 +
34 +
            foreach (var loadedSetting in loaded.CodeInspections.Where(inspection => foundInspectionNames.Contains(inspection.Name)))
35 +
            {
36 +
                var matchingDefaultSetting = Defaults.Default.CodeInspections.FirstOrDefault(inspection => inspection.Equals(loadedSetting));
37 +
                if (matchingDefaultSetting != null)
38 +
                {
39 +
                    loadedSetting.InspectionType = matchingDefaultSetting.InspectionType;
40 +
                }
41 +
42 +
                settings.Add(loadedSetting);
43 +
            }
44 +
            settings.UnionWith(Defaults.Default.CodeInspections.Where(inspection => !settings.Contains(inspection)));
45 +
46 +
            loaded.CodeInspections = settings;
47 +
            return loaded;
48 +
        }
49 +
    }
50 +
}
0 51
imilarity index 99%
1 52
ename from Rubberduck.Core/Settings/CodeInspectionSettings.cs
2 53
ename to Rubberduck.CodeAnalysis/Settings/CodeInspectionSettings.cs

@@ -2,15 +2,16 @@
Loading
2 2
using System.Globalization;
3 3
using System.Windows.Threading;
4 4
using Rubberduck.Settings;
5 +
using Rubberduck.SettingsProvider;
5 6
6 7
namespace Rubberduck.UI.Settings
7 8
{
8 9
    public class Settings : IDisposable
9 10
    {
10 -
        private static IGeneralConfigService _configService;
11 +
        private static IConfigurationService<Configuration> _configService;
11 12
        private static CultureInfo _cultureInfo = null;
12 13
13 -
        public Settings(IGeneralConfigService configService)
14 +
        public Settings(IConfigurationService<Configuration> configService)
14 15
        {
15 16
            _configService = configService;
16 17
            _configService.SettingsChanged += SettingsChanged;
@@ -48,7 +49,7 @@
Loading
48 49
49 50
            try
50 51
            {
51 -
                var config = _configService.LoadConfiguration();
52 +
                var config = _configService.Read();
52 53
                _cultureInfo = CultureInfo.GetCultureInfo(config.UserSettings.GeneralSettings.Language.Code);
53 54
                
54 55
                Dispatcher.CurrentDispatcher.Thread.CurrentUICulture = _cultureInfo;

@@ -0,0 +1,69 @@
Loading
1 +
using Rubberduck.Settings;
2 +
using System;
3 +
4 +
namespace Rubberduck.SettingsProvider
5 +
{
6 +
    public class ConfigurationServiceBase<T> : IConfigurationService<T>
7 +
        where T : class, new()
8 +
    {
9 +
        private readonly IPersistenceService<T> persister;
10 +
        protected readonly IDefaultSettings<T> Defaults;
11 +
12 +
        private readonly object valueLock = new object();
13 +
        protected T CurrentValue;
14 +
15 +
        public ConfigurationServiceBase(IPersistenceService<T> persister, IDefaultSettings<T> defaultSettings)
16 +
        {
17 +
            this.persister = persister;
18 +
            Defaults = defaultSettings;
19 +
        }
20 +
21 +
        protected void OnSettingsChanged()
22 +
        {
23 +
            var eventArgs = new ConfigurationChangedEventArgs(false, false, false, false);
24 +
            SettingsChanged?.Invoke(this, eventArgs);
25 +
        }
26 +
27 +
        public event EventHandler<ConfigurationChangedEventArgs> SettingsChanged;
28 +
29 +
        protected T LoadCacheValue()
30 +
        {
31 +
            lock(valueLock)
32 +
            {
33 +
                if (CurrentValue == null)
34 +
                {
35 +
                    T defaults = ReadDefaults();
36 +
                    T newValue = persister.Load(defaults) ?? defaults;
37 +
                    CurrentValue = newValue;
38 +
                }
39 +
                return CurrentValue;
40 +
            }
41 +
        }
42 +
43 +
        public virtual T Read()
44 +
        {
45 +
            return LoadCacheValue();
46 +
        }
47 +
48 +
        public virtual T ReadDefaults()
49 +
        {
50 +
            return Defaults.Default;
51 +
        }
52 +
53 +
        protected void PersistValue(T settings)
54 +
        {
55 +
            lock (valueLock)
56 +
            {
57 +
                // purge current value
58 +
                CurrentValue = null;
59 +
                persister.Save(settings);
60 +
            }
61 +
        }
62 +
63 +
        public virtual void Save(T settings)
64 +
        {
65 +
            PersistValue(settings);
66 +
            OnSettingsChanged();
67 +
        }
68 +
    }
69 +
}

@@ -27,12 +27,12 @@
Loading
27 27
        public static readonly List<string> TypeLibraryExtensions = new List<string> { ".olb", ".tlb", ".dll", ".ocx", ".exe" };
28 28
29 29
        private readonly IMessageBox _messageBox;
30 -
        private readonly IConfigProvider<ReferenceSettings> _settings;
30 +
        private readonly IConfigurationService<ReferenceSettings> _settings;
31 31
        private readonly IComLibraryProvider _libraryProvider;
32 32
33 33
        public ReferenceReconciler(
34 34
            IMessageBox messageBox, 
35 -
            IConfigProvider<ReferenceSettings> settings, 
35 +
            IConfigurationService<ReferenceSettings> settings, 
36 36
            IComLibraryProvider libraryProvider)
37 37
        {
38 38
            _messageBox = messageBox;

@@ -12,7 +12,7 @@
Loading
12 12
    {
13 13
        public readonly string DefaultSerializationPath;
14 14
15 -
        public XmlComProjectSerializer(IPersistancePathProvider pathProvider)
15 +
        public XmlComProjectSerializer(IPersistencePathProvider pathProvider)
16 16
        {
17 17
            DefaultSerializationPath = pathProvider.DataFolderPath("Declarations");
18 18
        }

@@ -2,30 +2,9 @@
Loading
2 2
3 3
namespace Rubberduck.Settings
4 4
{
5 -
    public class WindowConfigProvider : IConfigProvider<WindowSettings>
5 +
    public class WindowConfigProvider : ConfigurationServiceBase<WindowSettings>
6 6
    {
7 -
        private readonly IPersistanceService<WindowSettings> _persister;
8 -
        private readonly WindowSettings _defaultSettings;
9 -
10 -
        public WindowConfigProvider(IPersistanceService<WindowSettings> persister)
11 -
        {
12 -
            _persister = persister;
13 -
            _defaultSettings = new DefaultSettings<WindowSettings>().Default;
14 -
        }
15 -
16 -
        public WindowSettings Create()
17 -
        {
18 -
            return _persister.Load(_defaultSettings) ?? _defaultSettings;
19 -
        }
20 -
21 -
        public WindowSettings CreateDefaults()
22 -
        {
23 -
            return _defaultSettings;
24 -
        }
25 -
26 -
        public void Save(WindowSettings settings)
27 -
        {
28 -
            _persister.Save(settings);
29 -
        }
7 +
        public WindowConfigProvider(IPersistenceService<WindowSettings> persister)
8 +
            : base(persister, new DefaultSettings<WindowSettings, Properties.Settings>()) { }
30 9
    }
31 10
}

@@ -0,0 +1,30 @@
Loading
1 +
using System;
2 +
3 +
namespace Rubberduck.SettingsProvider
4 +
{
5 +
    public interface IConfigurationService<T>
6 +
    {
7 +
        T Read();
8 +
        T ReadDefaults();
9 +
10 +
        void Save(T settings);
11 +
12 +
        event EventHandler<ConfigurationChangedEventArgs> SettingsChanged;
13 +
    }
14 +
15 +
    public class ConfigurationChangedEventArgs : EventArgs
16 +
    {
17 +
        public bool LanguageChanged { get; }
18 +
        public bool InspectionSettingsChanged { get; }
19 +
        public bool RunInspectionsOnReparse { get; }
20 +
        public bool AutoCompleteSettingsChanged { get; }
21 +
22 +
        public ConfigurationChangedEventArgs(bool runInspections, bool languageChanged, bool inspectionSettingsChanged, bool autoCompleteSettingsChanged)
23 +
        {
24 +
            AutoCompleteSettingsChanged = autoCompleteSettingsChanged;
25 +
            RunInspectionsOnReparse = runInspections;
26 +
            LanguageChanged = languageChanged;
27 +
            InspectionSettingsChanged = inspectionSettingsChanged;
28 +
        }
29 +
    }
30 +
}
0 31
imilarity index 75%
1 32
ename from Rubberduck.SettingsProvider/IPersistancePathProvider.cs
2 33
ename to Rubberduck.SettingsProvider/Persistence/IPersistencePathProvider.cs

@@ -3,31 +3,19 @@
Loading
3 3
4 4
namespace Rubberduck.Settings
5 5
{
6 -
    public class ToDoListConfigProvider : IConfigProvider<ToDoListSettings>
6 +
    public class ToDoListConfigProvider : ConfigurationServiceBase<ToDoListSettings>
7 7
    {
8 -
        private readonly IPersistanceService<ToDoListSettings> _persister;
9 -
        private readonly IEnumerable<ToDoMarker> _defaultMarkers;
8 +
        private readonly IEnumerable<ToDoMarker> defaultMarkers;
10 9
11 -
        public ToDoListConfigProvider(IPersistanceService<ToDoListSettings> persister)
10 +
        public ToDoListConfigProvider(IPersistenceService<ToDoListSettings> persister)
11 +
            : base(persister, new DefaultSettings<ToDoListSettings, Properties.Settings>())
12 12
        {
13 -
            _persister = persister;
14 -
            _defaultMarkers = new DefaultSettings<ToDoMarker>().Defaults;
13 +
            defaultMarkers = new DefaultSettings<ToDoMarker, Properties.Settings>().Defaults;
15 14
        }
16 -
17 -
        public ToDoListSettings Create()
18 -
        {
19 -
            var prototype = new ToDoListSettings(_defaultMarkers);
20 -
            return _persister.Load(prototype) ?? prototype;
21 -
        }
22 -
23 -
        public ToDoListSettings CreateDefaults()
24 -
        {
25 -
            return new ToDoListSettings(_defaultMarkers);
26 -
        }
27 -
28 -
        public void Save(ToDoListSettings settings)
15 +
        
16 +
        public override ToDoListSettings ReadDefaults()
29 17
        {
30 -
            _persister.Save(settings);
18 +
            return new ToDoListSettings(defaultMarkers);
31 19
        }
32 20
    }
33 21
}

@@ -9,7 +9,7 @@
Loading
9 9
// ReSharper disable StaticMemberInGenericType
10 10
namespace Rubberduck.SettingsProvider
11 11
{
12 -
    public abstract class XmlPersistanceServiceBase<T> : IFilePersistanceService<T> where T : class, IEquatable<T>, new()
12 +
    internal abstract class XmlPersistenceServiceBase<T> : IFilePersistenceService<T> where T : class, IEquatable<T>, new()
13 13
    {
14 14
        private const string DefaultConfigFile = "rubberduck.config";
15 15
@@ -28,7 +28,7 @@
Loading
28 28
29 29
        protected T Cached { get; set; }
30 30
31 -
        protected XmlPersistanceServiceBase(IPersistancePathProvider pathProvider)
31 +
        protected XmlPersistenceServiceBase(IPersistencePathProvider pathProvider)
32 32
        {
33 33
            RootPath = pathProvider.DataRootPath;
34 34
        }

@@ -28,7 +28,7 @@
Loading
28 28
        private readonly IWindow _window;
29 29
        private readonly WindowSettings _settings;  //Storing this really doesn't matter - it's only checked on startup and never persisted.
30 30
31 -
        protected DockableToolwindowPresenter(IVBE vbe, IAddIn addin, IDockableUserControl view, IConfigProvider<WindowSettings> settingsProvider)
31 +
        protected DockableToolwindowPresenter(IVBE vbe, IAddIn addin, IDockableUserControl view, IConfigurationService<WindowSettings> settingsProvider)
32 32
        {
33 33
            _vbe = vbe;
34 34
            _addin = addin;
@@ -36,7 +36,7 @@
Loading
36 36
            UserControl = view as UserControl;
37 37
            if (settingsProvider != null)
38 38
            {
39 -
                _settings = settingsProvider.Create();
39 +
                _settings = settingsProvider.Read();
40 40
            }
41 41
            _window = CreateToolWindow(view);
42 42
        }

@@ -1,6 +1,7 @@
Loading
1 1
using System.Xml.Serialization;
2 2
using Rubberduck.SmartIndenter;
3 3
using Rubberduck.UnitTesting.Settings;
4 +
using Rubberduck.CodeAnalysis.Settings;
4 5
5 6
namespace Rubberduck.Settings
6 7
{

@@ -16,7 +16,7 @@
Loading
16 16
    {
17 17
        private readonly string _rootPath;
18 18
19 -
        public TemplateFileHandlerProvider(IPersistancePathProvider pathProvider)
19 +
        public TemplateFileHandlerProvider(IPersistencePathProvider pathProvider)
20 20
        {
21 21
            _rootPath = pathProvider.DataFolderPath("Templates");
22 22
        }

@@ -12,7 +12,7 @@
Loading
12 12
{
13 13
    public sealed class IndenterSettingsViewModel : SettingsViewModelBase<SmartIndenter.IndenterSettings>, ISettingsViewModel<SmartIndenter.IndenterSettings>
14 14
    {
15 -
        public IndenterSettingsViewModel(Configuration config, IFilePersistanceService<SmartIndenter.IndenterSettings> service)
15 +
        public IndenterSettingsViewModel(Configuration config, IFilePersistenceService<SmartIndenter.IndenterSettings> service)
16 16
            : base(service)
17 17
        {
18 18
            _alignCommentsWithCode = config.UserSettings.IndenterSettings.AlignCommentsWithCode;

@@ -6,7 +6,7 @@
Loading
6 6
{
7 7
    public class CodeMetricsDockablePresenter : DockableToolwindowPresenter
8 8
    {
9 -
        public CodeMetricsDockablePresenter(IVBE vbe, IAddIn addIn, CodeMetricsWindow view, IConfigProvider<WindowSettings> settings)
9 +
        public CodeMetricsDockablePresenter(IVBE vbe, IAddIn addIn, CodeMetricsWindow view, IConfigurationService<WindowSettings> settings)
10 10
            : base(vbe, addIn, view, settings)
11 11
        {
12 12
        }

@@ -5,7 +5,7 @@
Loading
5 5
6 6
namespace Rubberduck.SettingsProvider
7 7
{
8 -
    public class XmlContractPersistanceService<T> : XmlPersistanceServiceBase<T> where T : class, IEquatable<T>, new()
8 +
    internal class XmlContractPersistenceService<T> : XmlPersistenceServiceBase<T> where T : class, IEquatable<T>, new()
9 9
    {
10 10
        private const string DefaultConfigFile = "rubberduck.references";
11 11
@@ -15,7 +15,7 @@
Loading
15 15
            RootNamespace = XmlDictionaryString.Empty            
16 16
        };
17 17
18 -
        public XmlContractPersistanceService(IPersistancePathProvider pathProvider) : base(pathProvider) { }
18 +
        public XmlContractPersistenceService(IPersistencePathProvider pathProvider) : base(pathProvider) { }
19 19
20 20
        private string _filePath;
21 21
        public override string FilePath
22 22
imilarity index 94%
23 23
ename from Rubberduck.SettingsProvider/XmlPersistanceService.cs
24 24
ename to Rubberduck.SettingsProvider/Persistence/XmlPersistenceService.cs

@@ -11,12 +11,13 @@
Loading
11 11
using System.Globalization;
12 12
using System;
13 13
using Rubberduck.Resources.Settings;
14 +
using Rubberduck.CodeAnalysis.Settings;
14 15
15 16
namespace Rubberduck.UI.Settings
16 17
{
17 18
    public sealed class InspectionSettingsViewModel : SettingsViewModelBase<CodeInspectionSettings>, ISettingsViewModel<CodeInspectionSettings>
18 19
    {
19 -
        public InspectionSettingsViewModel(Configuration config, IFilePersistanceService<CodeInspectionSettings> service) 
20 +
        public InspectionSettingsViewModel(Configuration config, IFilePersistenceService<CodeInspectionSettings> service) 
20 21
            : base(service)
21 22
        {
22 23
            InspectionSettings = new ListCollectionView(

@@ -148,8 +148,8 @@
Loading
148 148
                    return;
149 149
                }
150 150
151 -
                var pathProvider = PersistancePathProvider.Instance;
152 -
                var configLoader = new XmlPersistanceService<GeneralSettings>(pathProvider)
151 +
                var pathProvider = PersistencePathProvider.Instance;
152 +
                var configLoader = new XmlPersistenceService<GeneralSettings>(pathProvider)
153 153
                {
154 154
                    FilePath =
155 155
                        Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
@@ -157,7 +157,7 @@
Loading
157 157
                };
158 158
                var configProvider = new GeneralConfigProvider(configLoader);
159 159
160 -
                _initialSettings = configProvider.Create();
160 +
                _initialSettings = configProvider.Read();
161 161
                if (_initialSettings != null)
162 162
                {
163 163
                    try

@@ -2,8 +2,8 @@
Loading
2 2
using System.Linq;
3 3
using System.Windows.Controls;
4 4
using System.Collections.ObjectModel;
5 -
using Rubberduck.Settings;
6 5
using Rubberduck.Parsing.Inspections;
6 +
using Rubberduck.CodeAnalysis.Settings;
7 7
8 8
namespace Rubberduck.UI.Settings
9 9
{

@@ -13,19 +13,19 @@
Loading
13 13
{
14 14
    public class AddRemoveReferencesUserSettingsViewModel : SettingsViewModelBase<ReferenceSettings>, ISettingsViewModel<ReferenceSettings>
15 15
    {
16 -
        private readonly IConfigProvider<ReferenceSettings> _provider;
16 +
        private readonly IConfigurationService<ReferenceSettings> _provider;
17 17
        private readonly IFileSystemBrowserFactory _browserFactory;
18 18
        private readonly ReferenceSettings _clean;
19 19
20 20
        public AddRemoveReferencesUserSettingsViewModel(
21 -
            IConfigProvider<ReferenceSettings> provider, 
21 +
            IConfigurationService<ReferenceSettings> provider, 
22 22
            IFileSystemBrowserFactory browserFactory,
23 -
            IFilePersistanceService<ReferenceSettings> service)
23 +
            IFilePersistenceService<ReferenceSettings> service)
24 24
            : base(service)
25 25
        {
26 26
            _provider = provider;
27 27
            _browserFactory = browserFactory;
28 -
            _clean = _provider.Create();
28 +
            _clean = _provider.Read();
29 29
30 30
            TransferSettingsToView(_clean);
31 31
@@ -118,7 +118,7 @@
Loading
118 118
119 119
        public void SetToDefaults(Configuration config)
120 120
        {
121 -
            var temp = _provider.CreateDefaults();
121 +
            var temp = _provider.ReadDefaults();
122 122
            var user = new ReferenceSettings(_clean)
123 123
            {
124 124
                RecentReferencesTracked = temp.RecentReferencesTracked,

@@ -5,6 +5,7 @@
Loading
5 5
using Rubberduck.Interaction;
6 6
using Rubberduck.Resources.Settings;
7 7
using Rubberduck.Settings;
8 +
using Rubberduck.SettingsProvider;
8 9
using Rubberduck.UI.Command;
9 10
10 11
namespace Rubberduck.UI.Settings
@@ -12,11 +13,11 @@
Loading
12 13
    public class SettingsControlViewModel : ViewModelBase
13 14
    {
14 15
        private readonly IMessageBox _messageBox;
15 -
        private readonly IGeneralConfigService _configService;
16 +
        private readonly IConfigurationService<Configuration> _configService;
16 17
        private readonly Configuration _config;
17 18
18 19
        public SettingsControlViewModel(IMessageBox messageBox,
19 -
            IGeneralConfigService configService,
20 +
            IConfigurationService<Configuration> configService,
20 21
            Configuration config,
21 22
            SettingsView generalSettings,
22 23
            SettingsView todoSettings,
@@ -79,7 +80,7 @@
Loading
79 80
                vm.UpdateConfig(_config);
80 81
            }
81 82
82 -
            _configService.SaveConfiguration(_config);
83 +
            _configService.Save(_config);
83 84
        }
84 85
85 86
        private void CloseWindow()
@@ -100,7 +101,7 @@
Loading
100 101
                return;
101 102
            }
102 103
103 -
            var defaultConfig = _configService.GetDefaultConfiguration();
104 +
            var defaultConfig = _configService.ReadDefaults();
104 105
            foreach (var vm in SettingsViews.Select(v => v.Control.ViewModel))
105 106
            {
106 107
                vm.SetToDefaults(defaultConfig);

@@ -3,48 +3,39 @@
Loading
3 3
4 4
namespace Rubberduck.Settings
5 5
{
6 -
    public class GeneralConfigProvider : IConfigProvider<GeneralSettings>
6 +
    public class GeneralConfigProvider : ConfigurationServiceBase<GeneralSettings>
7 7
    {
8 -
        private GeneralSettings _current;
9 -
        private readonly IPersistanceService<GeneralSettings> _persister;
10 -
        private readonly GeneralSettings _defaultSettings;
11 8
12 -
        public GeneralConfigProvider(IPersistanceService<GeneralSettings> persister)
9 +
        public GeneralConfigProvider(IPersistenceService<GeneralSettings> persister)
10 +
            : base(persister, new DefaultSettings<GeneralSettings, Properties.Settings>())
13 11
        {
14 -
            _persister = persister;
15 -
            _defaultSettings = new DefaultSettings<GeneralSettings>().Default;
16 12
        }
17 13
18 -
        public GeneralSettings Create()
14 +
        public override GeneralSettings Read()
19 15
        {
20 -
            var updated = _persister.Load(_defaultSettings) ?? _defaultSettings;
21 -
22 -
            CheckForEventsToRaise(updated);
23 -
            _current = updated;
24 -
25 -
            return _current;
26 -
        }
27 -
28 -
        public GeneralSettings CreateDefaults()
29 -
        {
30 -
            return _defaultSettings;
16 +
            var before = CurrentValue;
17 +
            var updated = LoadCacheValue();
18 +
            CheckForEventsToRaise(before, updated);
19 +
            return updated;
31 20
        }
32 21
33 -
        public void Save(GeneralSettings settings)
22 +
        public override void Save(GeneralSettings settings)
34 23
        {
35 -
            CheckForEventsToRaise(settings);
36 -
            _persister.Save(settings);
24 +
            var before = CurrentValue;
25 +
            PersistValue(settings);
26 +
            CheckForEventsToRaise(before, settings);
27 +
            OnSettingsChanged();
37 28
        }
38 29
39 -
        private void CheckForEventsToRaise(GeneralSettings other)
30 +
        private void CheckForEventsToRaise(GeneralSettings before, GeneralSettings after)
40 31
        {
41 -
            if (_current == null || !Equals(other.Language, _current.Language))
32 +
            if (before == null || !Equals(after.Language, before.Language))
42 33
            {
43 34
                OnLanguageChanged(EventArgs.Empty);
44 35
            }
45 -
            if (_current == null || 
46 -
                other.IsAutoSaveEnabled != _current.IsAutoSaveEnabled || 
47 -
                other.AutoSavePeriod != _current.AutoSavePeriod)
36 +
            if (before == null ||
37 +
                after.IsAutoSaveEnabled != before.IsAutoSaveEnabled ||
38 +
                after.AutoSavePeriod != before.AutoSavePeriod)
48 39
            {
49 40
                OnAutoSaveSettingsChanged(EventArgs.Empty);
50 41
            }

@@ -31,13 +31,13 @@
Loading
31 31
        private readonly RubberduckParserState _state;
32 32
        private readonly GeneralSettings _settings;
33 33
34 -
        public ReparseCommand(IVBE vbe, IConfigProvider<GeneralSettings> settingsProvider, RubberduckParserState state, IVBETypeLibsAPI typeLibApi, IVbeSettings vbeSettings, IMessageBox messageBox) : base(LogManager.GetCurrentClassLogger())
34 +
        public ReparseCommand(IVBE vbe, IConfigurationService<GeneralSettings> settingsProvider, RubberduckParserState state, IVBETypeLibsAPI typeLibApi, IVbeSettings vbeSettings, IMessageBox messageBox) : base(LogManager.GetCurrentClassLogger())
35 35
        {
36 36
            _vbe = vbe;
37 37
            _vbeSettings = vbeSettings;
38 38
            _typeLibApi = typeLibApi;
39 39
            _state = state;
40 -
            _settings = settingsProvider.Create();
40 +
            _settings = settingsProvider.Read();
41 41
            _messageBox = messageBox;
42 42
43 43
            AddToCanExecuteEvaluation(SpecialEvaluateCanExecute);

@@ -6,7 +6,7 @@
Loading
6 6
{
7 7
    internal class TestExplorerDockablePresenter : DockableToolwindowPresenter
8 8
    {
9 -
        public TestExplorerDockablePresenter(IVBE vbe, IAddIn addin, TestExplorerWindow view, IConfigProvider<WindowSettings> settings)
9 +
        public TestExplorerDockablePresenter(IVBE vbe, IAddIn addin, TestExplorerWindow view, IConfigurationService<WindowSettings> settings)
10 10
            : base(vbe, addin, view, settings)
11 11
        {
12 12
        }

@@ -27,14 +27,14 @@
Loading
27 27
28 28
        private readonly IVBE _vbe;
29 29
        private readonly RubberduckParserState _state;
30 -
        private readonly IConfigProvider<ReferenceSettings> _settings;
30 +
        private readonly IConfigurationService<ReferenceSettings> _settings;
31 31
        private readonly IRegisteredLibraryFinderService _finder;
32 32
        private readonly IReferenceReconciler _reconciler;
33 33
        private readonly IFileSystemBrowserFactory _browser;
34 34
35 35
        public AddRemoveReferencesPresenterFactory(IVBE vbe,
36 36
            RubberduckParserState state,
37 -
            IConfigProvider<ReferenceSettings> settingsProvider, 
37 +
            IConfigurationService<ReferenceSettings> settingsProvider, 
38 38
            IRegisteredLibraryFinderService finder,
39 39
            IReferenceReconciler reconciler,
40 40
            IFileSystemBrowserFactory browser)
@@ -116,7 +116,7 @@
Loading
116 116
                    models.Add(reference.Key, new ReferenceModel(reference.Value));
117 117
                }
118 118
119 -
                var settings = _settings.Create();
119 +
                var settings = _settings.Read();
120 120
                model = new AddRemoveReferencesModel(_state, project, models.Values, settings);
121 121
                if (AddRemoveReferencesViewModel.HostHasProjects)
122 122
                {

@@ -9,7 +9,7 @@
Loading
9 9
{
10 10
    public sealed class UnitTestSettingsViewModel : SettingsViewModelBase<Rubberduck.UnitTesting.Settings.UnitTestSettings>, ISettingsViewModel<Rubberduck.UnitTesting.Settings.UnitTestSettings>
11 11
    {
12 -
        public UnitTestSettingsViewModel(Configuration config, IFilePersistanceService<Rubberduck.UnitTesting.Settings.UnitTestSettings> service) 
12 +
        public UnitTestSettingsViewModel(Configuration config, IFilePersistenceService<Rubberduck.UnitTesting.Settings.UnitTestSettings> service) 
13 13
            : base(service)
14 14
        {
15 15
            BindingMode = config.UserSettings.UnitTestSettings.BindingMode;

@@ -6,7 +6,7 @@
Loading
6 6
{
7 7
    public class CodeExplorerDockablePresenter : DockableToolwindowPresenter
8 8
    {
9 -
        public CodeExplorerDockablePresenter(IVBE vbe, IAddIn addIn, CodeExplorerWindow view, IConfigProvider<WindowSettings> settings)
9 +
        public CodeExplorerDockablePresenter(IVBE vbe, IAddIn addIn, CodeExplorerWindow view, IConfigurationService<WindowSettings> settings)
10 10
            : base(vbe, addIn, view, settings)
11 11
        {
12 12
        }

@@ -11,7 +11,7 @@
Loading
11 11
{
12 12
    public sealed class TodoSettingsViewModel : SettingsViewModelBase<ToDoListSettings>, ISettingsViewModel<ToDoListSettings>
13 13
    {
14 -
        public TodoSettingsViewModel(Configuration config, IFilePersistanceService<ToDoListSettings> service) 
14 +
        public TodoSettingsViewModel(Configuration config, IFilePersistenceService<ToDoListSettings> service) 
15 15
            : base(service)
16 16
        {
17 17
            TodoSettings = new ObservableCollection<ToDoMarker>(config.UserSettings.ToDoListSettings.ToDoMarkers);

@@ -9,7 +9,7 @@
Loading
9 9
    /// </summary>
10 10
    public class ToDoExplorerDockablePresenter : DockableToolwindowPresenter
11 11
    {
12 -
        public ToDoExplorerDockablePresenter(IVBE vbe, IAddIn addin, ToDoExplorerWindow window, IConfigProvider<WindowSettings> settings)
12 +
        public ToDoExplorerDockablePresenter(IVBE vbe, IAddIn addin, ToDoExplorerWindow window, IConfigurationService<WindowSettings> settings)
13 13
            : base(vbe, addin, window, settings)
14 14
        {
15 15
        }

@@ -3,23 +3,22 @@
Loading
3 3
4 4
namespace Rubberduck.Settings
5 5
{
6 -
    public class HotkeyConfigProvider : IConfigProvider<HotkeySettings>
6 +
    public class HotkeyConfigProvider : ConfigurationServiceBase<HotkeySettings>
7 7
    {
8 -
        private readonly IPersistanceService<HotkeySettings> _persister;
9 8
        private readonly IEnumerable<HotkeySetting> _defaultHotkeys;
10 9
11 -
        public HotkeyConfigProvider(IPersistanceService<HotkeySettings> persister)
10 +
        public HotkeyConfigProvider(IPersistenceService<HotkeySettings> persister)
11 +
            : base(persister, new DefaultSettings<HotkeySettings, Properties.Settings>())
12 12
        {
13 -
            _persister = persister;
14 -
            _defaultHotkeys = new DefaultSettings<HotkeySetting>().Defaults;
13 +
            _defaultHotkeys = new DefaultSettings<HotkeySetting, Properties.Settings>().Defaults;
15 14
        }
16 15
17 -
        public HotkeySettings Create()
16 +
        public override HotkeySettings Read()
18 17
        {
19 18
            var prototype = new HotkeySettings(_defaultHotkeys);
20 19
21 20
            // Loaded settings don't contain defaults, so we need to use the `Settings` property to combine user settings with defaults.
22 -
            var loaded = _persister.Load(prototype);
21 +
            var loaded = LoadCacheValue();
23 22
            if (loaded != null)
24 23
            {
25 24
                prototype.Settings = loaded.Settings;
@@ -28,14 +27,9 @@
Loading
28 27
            return prototype;
29 28
        }
30 29
31 -
        public HotkeySettings CreateDefaults()
30 +
        public override HotkeySettings ReadDefaults()
32 31
        {
33 32
            return new HotkeySettings(_defaultHotkeys);
34 33
        }
35 -
36 -
        public void Save(HotkeySettings settings)
37 -
        {
38 -
            _persister.Save(settings);
39 -
        }
40 34
    }
41 35
}

@@ -3,6 +3,7 @@
Loading
3 3
using System.Diagnostics;
4 4
using NLog;
5 5
using Rubberduck.Settings;
6 +
using Rubberduck.SettingsProvider;
6 7
using Rubberduck.VBEditor.Events;
7 8
8 9
namespace Rubberduck.AutoComplete
@@ -15,7 +16,7 @@
Loading
15 16
    {
16 17
        private static readonly ILogger Logger = LogManager.GetCurrentClassLogger();
17 18
18 -
        private readonly IGeneralConfigService _configService;
19 +
        private readonly IConfigurationService<Configuration> _configService;
19 20
        private readonly IEnumerable<AutoCompleteHandlerBase> _handlers;
20 21
21 22
        private AutoCompleteSettings _settings;
@@ -23,7 +24,7 @@
Loading
23 24
        private bool _enabled;
24 25
        private bool _initialized;
25 26
26 -
        public AutoCompleteService(IGeneralConfigService configService, IEnumerable<AutoCompleteHandlerBase> handlers)
27 +
        public AutoCompleteService(IConfigurationService<Configuration> configService, IEnumerable<AutoCompleteHandlerBase> handlers)
27 28
        {
28 29
            _configService = configService;
29 30
            _configService.SettingsChanged += ConfigServiceSettingsChanged;
@@ -42,7 +43,7 @@
Loading
42 43
            {
43 44
                if (!_initialized)
44 45
                {
45 -
                    var config = _configService.LoadConfiguration();
46 +
                    var config = _configService.Read();
46 47
                    ApplyAutoCompleteSettings(config);
47 48
                }
48 49
            }
@@ -85,7 +86,7 @@
Loading
85 86
86 87
        private void ConfigServiceSettingsChanged(object sender, ConfigurationChangedEventArgs e)
87 88
        {
88 -
            var config = _configService.LoadConfiguration();
89 +
            var config = _configService.Read();
89 90
            ApplyAutoCompleteSettings(config);
90 91
        }
91 92
        

@@ -3,16 +3,16 @@
Loading
3 3
using Rubberduck.Inspections.Concrete;
4 4
using Rubberduck.Parsing.Inspections.Abstract;
5 5
using Rubberduck.Parsing.Rewriter;
6 -
using Rubberduck.Settings;
6 +
using Rubberduck.CodeAnalysis.Settings;
7 7
using Rubberduck.SettingsProvider;
8 8
9 9
namespace Rubberduck.Inspections.QuickFixes
10 10
{
11 11
    public sealed class AddIdentifierToWhiteListQuickFix : QuickFixBase
12 12
    {
13 -
        private readonly IPersistanceService<CodeInspectionSettings> _settings;
13 +
        private readonly IPersistenceService<CodeInspectionSettings> _settings;
14 14
15 -
        public AddIdentifierToWhiteListQuickFix(IPersistanceService<CodeInspectionSettings> settings)
15 +
        public AddIdentifierToWhiteListQuickFix(IPersistenceService<CodeInspectionSettings> settings)
16 16
            : base(typeof(HungarianNotationInspection), typeof(UseMeaningfulNameInspection))
17 17
        {
18 18
            _settings = settings;

@@ -38,8 +38,8 @@
Loading
38 38
        // ReSharper disable NotAccessedField.Local - The settings providers aren't used, but several enhancement requests will need them.
39 39
        private readonly RubberduckParserState _state;
40 40
        private readonly RemoveCommand _externalRemoveCommand;
41 -
        private readonly IConfigProvider<GeneralSettings> _generalSettingsProvider;      
42 -
        private readonly IConfigProvider<WindowSettings> _windowSettingsProvider;
41 +
        private readonly IConfigurationService<GeneralSettings> _generalSettingsProvider;      
42 +
        private readonly IConfigurationService<WindowSettings> _windowSettingsProvider;
43 43
        private readonly IUiDispatcher _uiDispatcher;
44 44
        private readonly IVBE _vbe;
45 45
        private readonly ITemplateProvider _templateProvider;
@@ -48,8 +48,8 @@
Loading
48 48
        public CodeExplorerViewModel(
49 49
            RubberduckParserState state,
50 50
            RemoveCommand removeCommand,
51 -
            IConfigProvider<GeneralSettings> generalSettingsProvider, 
52 -
            IConfigProvider<WindowSettings> windowSettingsProvider, 
51 +
            IConfigurationService<GeneralSettings> generalSettingsProvider, 
52 +
            IConfigurationService<WindowSettings> windowSettingsProvider, 
53 53
            IUiDispatcher uiDispatcher,
54 54
            IVBE vbe,
55 55
            ITemplateProvider templateProvider,

@@ -1,6 +1,7 @@
Loading
1 1
using System.Collections.Generic;
2 2
using System.Globalization;
3 3
using System.Linq;
4 +
using Rubberduck.CodeAnalysis.Settings;
4 5
using Rubberduck.Common;
5 6
using Rubberduck.Inspections.Abstract;
6 7
using Rubberduck.Inspections.Results;
@@ -9,7 +10,6 @@
Loading
9 10
using Rubberduck.Parsing.Symbols;
10 11
using Rubberduck.Parsing.VBA;
11 12
using Rubberduck.Resources;
12 -
using Rubberduck.Settings;
13 13
using Rubberduck.SettingsProvider;
14 14
using static Rubberduck.Parsing.Grammar.VBAParser;
15 15
@@ -17,9 +17,9 @@
Loading
17 17
{
18 18
    public sealed class UseMeaningfulNameInspection : InspectionBase
19 19
    {
20 -
        private readonly IPersistanceService<CodeInspectionSettings> _settings;
20 +
        private readonly IPersistenceService<CodeInspectionSettings> _settings;
21 21
22 -
        public UseMeaningfulNameInspection(RubberduckParserState state, IPersistanceService<CodeInspectionSettings> settings)
22 +
        public UseMeaningfulNameInspection(RubberduckParserState state, IPersistenceService<CodeInspectionSettings> settings)
23 23
            : base(state)
24 24
        {
25 25
            _settings = settings;
26 26
imilarity index 100%
27 27
ename from Rubberduck.Core/Common/VariableNameValidator.cs
28 28
ename to Rubberduck.CodeAnalysis/Inspections/Helper/VariableNameValidator.cs
29 29
imilarity index 100%
30 30
ename from Rubberduck.Core/CodeAnalysis/Inspections/IInspectionProvider.cs
31 31
ename to Rubberduck.CodeAnalysis/Inspections/IInspectionProvider.cs
32 32
imilarity index 90%
33 33
ename from Rubberduck.Core/CodeAnalysis/Inspections/InspectionProvider.cs
34 34
ename to Rubberduck.CodeAnalysis/Inspections/InspectionProvider.cs

@@ -2,6 +2,7 @@
Loading
2 2
using System.Linq;
3 3
using Rubberduck.Parsing.Inspections.Abstract;
4 4
using Rubberduck.Settings;
5 +
using Rubberduck.CodeAnalysis.Settings;
5 6
6 7
namespace Rubberduck.CodeAnalysis.Inspections
7 8
{
@@ -9,7 +10,7 @@
Loading
9 10
    {
10 11
        public InspectionProvider(IEnumerable<IInspection> inspections)
11 12
        {
12 -
            var defaultSettings = new DefaultSettings<CodeInspectionSettings>().Default;
13 +
            var defaultSettings = new DefaultSettings<CodeInspectionSettings, Properties.CodeInspectionDefaults>().Default;
13 14
            var defaultNames = defaultSettings.CodeInspections.Select(x => x.Name);
14 15
            var defaultInspections = inspections.Where(inspection => defaultNames.Contains(inspection.Name));
15 16

@@ -20,7 +20,7 @@
Loading
20 20
        protected static readonly Logger Logger = LogManager.GetCurrentClassLogger();
21 21
22 22
        private readonly bool _isAccess;
23 -
        private readonly IConfigProvider<UnitTestSettings> _settings;
23 +
        private readonly IConfigurationService<UnitTestSettings> _settings;
24 24
        private readonly RubberduckParserState _state;
25 25
        private readonly IMessageBox _messageBox;
26 26
        private readonly IIndenter _indenter;
@@ -32,7 +32,7 @@
Loading
32 32
            RubberduckParserState state, 
33 33
            IMessageBox messageBox, 
34 34
            IVBEInteraction interaction, 
35 -
            IConfigProvider<UnitTestSettings> settings, 
35 +
            IConfigurationService<UnitTestSettings> settings, 
36 36
            IIndenter indenter, 
37 37
            ICompilationArgumentsProvider argumentsProvider)
38 38
        {
@@ -62,7 +62,7 @@
Loading
62 62
                return;
63 63
            }
64 64
65 -
            var settings = _settings.Create();
65 +
            var settings = _settings.Read();
66 66
67 67
            AddReferenceIfNeeded(project, settings);
68 68
@@ -133,7 +133,7 @@
Loading
133 133
134 134
        private string GetNewTestModuleCode(IVBComponent component)
135 135
        {
136 -
            var settings = _settings.Create();
136 +
            var settings = _settings.Read();
137 137
            var baseModule = (GetBaseTestModule(settings) + Environment.NewLine);
138 138
139 139
            if (settings.DefaultTestStubInNewModule)
@@ -162,7 +162,7 @@
Loading
162 162
        {
163 163
            if (settings is null)
164 164
            {
165 -
                settings = _settings.Create();
165 +
                settings = _settings.Read();
166 166
            }
167 167
168 168
            string declaration;

@@ -1,39 +1,13 @@
Loading
1 -
using Rubberduck.SettingsProvider;
1 +
using Rubberduck.Settings;
2 +
using Rubberduck.SettingsProvider;
2 3
3 4
namespace Rubberduck.UnitTesting.Settings
4 5
{
5 -
    public class UnitTestConfigProvider : IConfigProvider<UnitTestSettings>
6 +
    public class UnitTestConfigProvider : ConfigurationServiceBase<UnitTestSettings>
6 7
    {
7 -
        private readonly IPersistanceService<UnitTestSettings> _persister;
8 -
        private readonly UnitTestSettings _defaultSettings;
9 -
10 -
        public UnitTestConfigProvider(IPersistanceService<UnitTestSettings> persister)
11 -
        {
12 -
            _persister = persister;
13 -
14 -
            _defaultSettings = new UnitTestSettings
15 -
            {
16 -
                BindingMode = BindingMode.LateBinding,
17 -
                AssertMode = AssertMode.StrictAssert,
18 -
                ModuleInit = true,
19 -
                MethodInit = true,
20 -
                DefaultTestStubInNewModule = false
21 -
            };
22 -
        }
23 -
24 -
        public UnitTestSettings Create()
25 -
        {
26 -
            return _persister.Load(_defaultSettings) ?? _defaultSettings;
27 -
        }
28 -
29 -
        public UnitTestSettings CreateDefaults()
30 -
        {
31 -
            return _defaultSettings;
32 -
        }
33 -
34 -
        public void Save(UnitTestSettings settings)
8 +
        public UnitTestConfigProvider(IPersistenceService<UnitTestSettings> persister)
9 +
            : base(persister, new DefaultSettings<UnitTestSettings, Properties.UnitTestDefaults>())
35 10
        {
36 -
            _persister.Save(settings);
37 11
        }
38 12
    }
39 13
}

@@ -2,6 +2,7 @@
Loading
2 2
using Rubberduck.Settings;
3 3
using Rubberduck.Interaction;
4 4
using Rubberduck.SettingsProvider;
5 +
using Rubberduck.CodeAnalysis.Settings;
5 6
6 7
namespace Rubberduck.UI.Settings
7 8
{
@@ -26,13 +27,13 @@
Loading
26 27
            InitializeComponent();
27 28
        }
28 29
29 -
        public SettingsForm(IGeneralConfigService configService, 
30 +
        public SettingsForm(IConfigurationService<Configuration> configService, 
30 31
            IMessageBox messageBox, 
31 32
            ISettingsViewModelFactory viewModelFactory,
32 33
            SettingsViews activeView = SettingsViews.GeneralSettings) 
33 34
            : this()
34 35
        {
35 -
            var config = configService.LoadConfiguration();
36 +
            var config = configService.Read();
36 37
37 38
            ViewModel = new SettingsControlViewModel(messageBox, configService,
38 39
                config,

@@ -8,12 +8,13 @@
Loading
8 8
using Rubberduck.VBEditor.SafeComWrappers.Abstract;
9 9
using Rubberduck.VBEditor.WindowsApi;
10 10
using Rubberduck.AutoComplete;
11 +
using Rubberduck.SettingsProvider;
11 12
12 13
namespace Rubberduck.Common
13 14
{
14 15
    public class RubberduckHooks : SubclassingWindow, IRubberduckHooks
15 16
    {
16 -
        private readonly IGeneralConfigService _config;
17 +
        private readonly IConfigurationService<Configuration> _config;
17 18
        private readonly HotkeyFactory _hotkeyFactory;
18 19
        private readonly IList<IAttachable> _hooks = new List<IAttachable>();
19 20
        private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
@@ -28,7 +29,7 @@
Loading
28 29
29 30
        private RubberduckHooks(IntPtr ptr) : base(ptr, ptr) { }
30 31
31 -
        public RubberduckHooks(IVBE vbe, IGeneralConfigService config, HotkeyFactory hotkeyFactory,
32 +
        public RubberduckHooks(IVBE vbe, IConfigurationService<Configuration> config, HotkeyFactory hotkeyFactory,
32 33
            AutoCompleteService autoComplete)
33 34
            : this(GetVbeMainWindowPtr(vbe))
34 35
        {
@@ -42,7 +43,7 @@
Loading
42 43
            Detach();
43 44
            _hooks.Clear();
44 45
45 -
            var config = _config.LoadConfiguration();
46 +
            var config = _config.Read();
46 47
            var settings = config.UserSettings.HotkeySettings;
47 48
48 49
            foreach (var hotkeySetting in settings.Settings.Where(hotkeySetting => hotkeySetting.IsEnabled))

@@ -3,43 +3,30 @@
Loading
3 3
using Rubberduck.SettingsProvider;
4 4
using Rubberduck.SmartIndenter;
5 5
using Rubberduck.UnitTesting.Settings;
6 +
using Rubberduck.CodeAnalysis.Settings;
6 7
7 8
namespace Rubberduck.Settings
8 9
{
9 -
    public class ConfigurationChangedEventArgs : EventArgs
10 -
    {
11 -
        public bool LanguageChanged { get; }
12 -
        public bool InspectionSettingsChanged { get; }
13 -
        public bool RunInspectionsOnReparse { get; }
14 -
        public bool AutoCompleteSettingsChanged { get; }
15 -
16 -
        public ConfigurationChangedEventArgs(bool runInspections, bool languageChanged, bool inspectionSettingsChanged, bool autoCompleteSettingsChanged)
17 -
        {
18 -
            AutoCompleteSettingsChanged = autoCompleteSettingsChanged;
19 -
            RunInspectionsOnReparse = runInspections;
20 -
            LanguageChanged = languageChanged;
21 -
            InspectionSettingsChanged = inspectionSettingsChanged;
22 -
        }
23 -
    }
24 -
25 -
    public interface IGeneralConfigService : IConfigurationService<Configuration>
26 -
    {
27 -
        Configuration GetDefaultConfiguration();
28 -
    }
29 10
30 -
    public class ConfigurationLoader : IGeneralConfigService
11 +
    public class ConfigurationLoader : IConfigurationService<Configuration>
31 12
    {
32 -
        private readonly IConfigProvider<GeneralSettings> _generalProvider;
33 -
        private readonly IConfigProvider<HotkeySettings> _hotkeyProvider;
34 -
        private readonly IConfigProvider<AutoCompleteSettings> _autoCompleteProvider;
35 -
        private readonly IConfigProvider<ToDoListSettings> _todoProvider;
36 -
        private readonly IConfigProvider<CodeInspectionSettings> _inspectionProvider;
37 -
        private readonly IConfigProvider<UnitTestSettings> _unitTestProvider;
38 -
        private readonly IConfigProvider<IndenterSettings> _indenterProvider;
39 -
        private readonly IConfigProvider<WindowSettings> _windowProvider;
13 +
        private readonly IConfigurationService<GeneralSettings> _generalProvider;
14 +
        private readonly IConfigurationService<HotkeySettings> _hotkeyProvider;
15 +
        private readonly IConfigurationService<AutoCompleteSettings> _autoCompleteProvider;
16 +
        private readonly IConfigurationService<ToDoListSettings> _todoProvider;
17 +
        private readonly IConfigurationService<CodeInspectionSettings> _inspectionProvider;
18 +
        private readonly IConfigurationService<UnitTestSettings> _unitTestProvider;
19 +
        private readonly IConfigurationService<IndenterSettings> _indenterProvider;
20 +
        private readonly IConfigurationService<WindowSettings> _windowProvider;
40 21
41 -
        public ConfigurationLoader(IConfigProvider<GeneralSettings> generalProvider, IConfigProvider<HotkeySettings> hotkeyProvider, IConfigProvider<AutoCompleteSettings> autoCompleteProvider, IConfigProvider<ToDoListSettings> todoProvider,
42 -
                                   IConfigProvider<CodeInspectionSettings> inspectionProvider, IConfigProvider<UnitTestSettings> unitTestProvider, IConfigProvider<IndenterSettings> indenterProvider, IConfigProvider<WindowSettings> windowProvider)
22 +
        public ConfigurationLoader(IConfigurationService<GeneralSettings> generalProvider, 
23 +
            IConfigurationService<HotkeySettings> hotkeyProvider, 
24 +
            IConfigurationService<AutoCompleteSettings> autoCompleteProvider, 
25 +
            IConfigurationService<ToDoListSettings> todoProvider,
26 +
            IConfigurationService<CodeInspectionSettings> inspectionProvider, 
27 +
            IConfigurationService<UnitTestSettings> unitTestProvider, 
28 +
            IConfigurationService<IndenterSettings> indenterProvider, 
29 +
            IConfigurationService<WindowSettings> windowProvider)
43 30
        {
44 31
            _generalProvider = generalProvider;
45 32
            _hotkeyProvider = hotkeyProvider;
@@ -54,52 +41,53 @@
Loading
54 41
        /// <summary>
55 42
        /// Loads the configuration from Rubberduck.config xml file.
56 43
        /// </summary>
57 -
        public virtual Configuration LoadConfiguration()
44 +
        // marked virtual for Mocking
45 +
        public virtual Configuration Read()
58 46
        {
59 47
            var config = new Configuration
60 48
            {
61 49
                UserSettings = new UserSettings
62 50
                (
63 -
                    _generalProvider.Create(),
64 -
                    _hotkeyProvider.Create(),
65 -
                    _autoCompleteProvider.Create(),
66 -
                    _todoProvider.Create(),
67 -
                    _inspectionProvider.Create(),
68 -
                    _unitTestProvider.Create(),
69 -
                    _indenterProvider.Create(),
70 -
                    _windowProvider.Create()
51 +
                    _generalProvider.Read(),
52 +
                    _hotkeyProvider.Read(),
53 +
                    _autoCompleteProvider.Read(),
54 +
                    _todoProvider.Read(),
55 +
                    _inspectionProvider.Read(),
56 +
                    _unitTestProvider.Read(),
57 +
                    _indenterProvider.Read(),
58 +
                    _windowProvider.Read()
71 59
                )
72 60
            };            
73 61
            return config;
74 62
        }
75 63
76 -
        public Configuration GetDefaultConfiguration()
64 +
        public Configuration ReadDefaults()
77 65
        {
78 66
            return new Configuration
79 67
            {
80 68
                UserSettings = new UserSettings
81 69
                (
82 -
                    _generalProvider.CreateDefaults(),
83 -
                    _hotkeyProvider.CreateDefaults(),
84 -
                    _autoCompleteProvider.CreateDefaults(),
85 -
                    _todoProvider.CreateDefaults(),
86 -
                    _inspectionProvider.CreateDefaults(),
87 -
                    _unitTestProvider.CreateDefaults(),
88 -
                    _indenterProvider.CreateDefaults(),
89 -
                    _windowProvider.CreateDefaults()
70 +
                    _generalProvider.ReadDefaults(),
71 +
                    _hotkeyProvider.ReadDefaults(),
72 +
                    _autoCompleteProvider.ReadDefaults(),
73 +
                    _todoProvider.ReadDefaults(),
74 +
                    _inspectionProvider.ReadDefaults(),
75 +
                    _unitTestProvider.ReadDefaults(),
76 +
                    _indenterProvider.ReadDefaults(),
77 +
                    _windowProvider.ReadDefaults()
90 78
                )
91 79
            };
92 80
        }
93 81
        
94 -
        public void SaveConfiguration(Configuration toSerialize)
82 +
        public void Save(Configuration toSerialize)
95 83
        {
96 -
            var langChanged = _generalProvider.Create().Language.Code != toSerialize.UserSettings.GeneralSettings.Language.Code;
97 -
            var oldInspectionSettings = _inspectionProvider.Create().CodeInspections.Select(s => Tuple.Create(s.Name, s.Severity));
84 +
            var langChanged = _generalProvider.Read().Language.Code != toSerialize.UserSettings.GeneralSettings.Language.Code;
85 +
            var oldInspectionSettings = _inspectionProvider.Read().CodeInspections.Select(s => Tuple.Create(s.Name, s.Severity));
98 86
            var newInspectionSettings = toSerialize.UserSettings.CodeInspectionSettings.CodeInspections.Select(s => Tuple.Create(s.Name, s.Severity));
99 87
            var inspectionsChanged = !oldInspectionSettings.SequenceEqual(newInspectionSettings);
100 88
            var inspectOnReparse = toSerialize.UserSettings.CodeInspectionSettings.RunInspectionsOnSuccessfulParse;
101 89
102 -
            var oldAutoCompleteSettings = _autoCompleteProvider.Create();
90 +
            var oldAutoCompleteSettings = _autoCompleteProvider.Read();
103 91
            var newAutoCompleteSettings = toSerialize.UserSettings.AutoCompleteSettings;
104 92
            var autoCompletesChanged = oldAutoCompleteSettings.Equals(newAutoCompleteSettings);
105 93

@@ -2,6 +2,7 @@
Loading
2 2
using System.Globalization;
3 3
using System.Linq;
4 4
using System.Text.RegularExpressions;
5 +
using Rubberduck.CodeAnalysis.Settings;
5 6
using Rubberduck.Inspections.Abstract;
6 7
using Rubberduck.Inspections.Inspections.Extensions;
7 8
using Rubberduck.Inspections.Results;
@@ -9,7 +10,6 @@
Loading
9 10
using Rubberduck.Parsing.Symbols;
10 11
using Rubberduck.Parsing.VBA;
11 12
using Rubberduck.Resources;
12 -
using Rubberduck.Settings;
13 13
using Rubberduck.SettingsProvider;
14 14
15 15
namespace Rubberduck.Inspections.Concrete
@@ -104,9 +104,9 @@
Loading
104 104
105 105
        #endregion
106 106
107 -
        private readonly IPersistanceService<CodeInspectionSettings> _settings;
107 +
        private readonly IPersistenceService<CodeInspectionSettings> _settings;
108 108
109 -
        public HungarianNotationInspection(RubberduckParserState state, IPersistanceService<CodeInspectionSettings> settings)
109 +
        public HungarianNotationInspection(RubberduckParserState state, IPersistenceService<CodeInspectionSettings> settings)
110 110
            : base(state)
111 111
        {
112 112
            _settings = settings;

@@ -8,7 +8,7 @@
Loading
8 8
{
9 9
    public sealed class WindowSettingsViewModel : SettingsViewModelBase<Rubberduck.Settings.WindowSettings>, ISettingsViewModel<Rubberduck.Settings.WindowSettings>
10 10
    {
11 -
        public WindowSettingsViewModel(Configuration config, IFilePersistanceService<Rubberduck.Settings.WindowSettings> service) 
11 +
        public WindowSettingsViewModel(Configuration config, IFilePersistenceService<Rubberduck.Settings.WindowSettings> service) 
12 12
            : base(service)
13 13
        {
14 14
            CodeExplorerVisibleOnStartup = config.UserSettings.WindowSettings.CodeExplorerVisibleOnStartup;

@@ -8,9 +8,9 @@
Loading
8 8
    public abstract class SettingsViewModelBase<TSettings> : ViewModelBase 
9 9
        where TSettings : new()
10 10
    {
11 -
        protected readonly IFilePersistanceService<TSettings> Service;
11 +
        protected readonly IFilePersistenceService<TSettings> Service;
12 12
13 -
        protected SettingsViewModelBase(IFilePersistanceService<TSettings> service)
13 +
        protected SettingsViewModelBase(IFilePersistenceService<TSettings> service)
14 14
        {
15 15
            Service = service;
16 16
        }

@@ -20,6 +20,7 @@
Loading
20 20
using Rubberduck.Parsing.VBA;
21 21
using Rubberduck.Parsing.VBA.Extensions;
22 22
using Rubberduck.Settings;
23 +
using Rubberduck.SettingsProvider;
23 24
using Rubberduck.UI.Command;
24 25
using Rubberduck.UI.Settings;
25 26
using Rubberduck.VBEditor;
@@ -66,7 +67,7 @@
Loading
66 67
        private readonly IInspector _inspector;
67 68
        private readonly IQuickFixProvider _quickFixProvider;
68 69
        private readonly IClipboardWriter _clipboard;
69 -
        private readonly IGeneralConfigService _configService;
70 +
        private readonly IConfigurationService<Configuration> _configService;
70 71
        private readonly ISettingsFormFactory _settingsFormFactory;
71 72
        private readonly IUiDispatcher _uiDispatcher;
72 73
@@ -78,8 +79,8 @@
Loading
78 79
            IQuickFixProvider quickFixProvider,
79 80
            INavigateCommand navigateCommand, 
80 81
            ReparseCommand reparseCommand,
81 -
            IClipboardWriter clipboard, 
82 -
            IGeneralConfigService configService, 
82 +
            IClipboardWriter clipboard,
83 +
            IConfigurationService<Configuration> configService, 
83 84
            ISettingsFormFactory settingsFormFactory,
84 85
            IUiDispatcher uiDispatcher)
85 86
        {
@@ -120,7 +121,7 @@
Loading
120 121
            _configService.SettingsChanged += _configService_SettingsChanged;
121 122
            
122 123
            // todo: remove I/O work in constructor
123 -
            _runInspectionsOnReparse = _configService.LoadConfiguration().UserSettings.CodeInspectionSettings.RunInspectionsOnSuccessfulParse;
124 +
            _runInspectionsOnReparse = _configService.Read().UserSettings.CodeInspectionSettings.RunInspectionsOnSuccessfulParse;
124 125
125 126
            if (CollectionViewSource.GetDefaultView(_results) is ListCollectionView results)
126 127
            {
@@ -539,12 +540,12 @@
Loading
539 540
                return;
540 541
            }
541 542
542 -
            var config = _configService.LoadConfiguration();
543 +
            var config = _configService.Read();
543 544
544 545
            var setting = config.UserSettings.CodeInspectionSettings.CodeInspections.Single(e => e.Name == _selectedInspection.Name);
545 546
            setting.Severity = CodeInspectionSeverity.DoNotShow;
546 547
547 -
            Task.Run(() => _configService.SaveConfiguration(config));
548 +
            Task.Run(() => _configService.Save(config));
548 549
549 550
            _uiDispatcher.Invoke(() =>
550 551
            {

@@ -16,13 +16,14 @@
Loading
16 16
using Rubberduck.VBEditor.Utility;
17 17
using Rubberduck.VersionCheck;
18 18
using Application = System.Windows.Forms.Application;
19 +
using Rubberduck.SettingsProvider;
19 20
20 21
namespace Rubberduck
21 22
{
22 23
    public sealed class App : IDisposable
23 24
    {
24 25
        private readonly IMessageBox _messageBox;
25 -
        private readonly IGeneralConfigService _configService;
26 +
        private readonly IConfigurationService<Configuration> _configService;
26 27
        private readonly IAppMenu _appMenus;
27 28
        private readonly IRubberduckHooks _hooks;
28 29
        private readonly IVersionCheck _version;
@@ -33,7 +34,7 @@
Loading
33 34
        private Configuration _config;
34 35
35 36
        public App(IMessageBox messageBox,
36 -
            IGeneralConfigService configService,
37 +
            IConfigurationService<Configuration> configService,
37 38
            IAppMenu appMenus,
38 39
            IRubberduckHooks hooks,
39 40
            IVersionCheck version,
@@ -53,7 +54,7 @@
Loading
53 54
54 55
        private void _configService_SettingsChanged(object sender, ConfigurationChangedEventArgs e)
55 56
        {
56 -
            _config = _configService.LoadConfiguration();
57 +
            _config = _configService.Read();
57 58
            _hooks.HookHotkeys();
58 59
            UpdateLoggingLevel();
59 60
@@ -119,7 +120,7 @@
Loading
119 120
            }
120 121
121 122
            _config.UserSettings.GeneralSettings.MinimumLogLevel = LogLevel.Off.Ordinal;
122 -
            _configService.SaveConfiguration(_config);
123 +
            _configService.Save(_config);
123 124
        }
124 125
125 126
        public void Startup()
@@ -159,7 +160,7 @@
Loading
159 160
160 161
        private void ApplyCultureConfig()
161 162
        {
162 -
            _config = _configService.LoadConfiguration();
163 +
            _config = _configService.Read();
163 164
164 165
            var currentCulture = Resources.RubberduckUI.Culture;
165 166
            try
@@ -175,7 +176,7 @@
Loading
175 176
                // not accessing resources here, because setting resource culture literally just failed.
176 177
                _messageBox.NotifyWarn(exception.Message, "Rubberduck");
177 178
                _config.UserSettings.GeneralSettings.Language.Code = currentCulture.Name;
178 -
                _configService.SaveConfiguration(_config);
179 +
                _configService.Save(_config);
179 180
            }
180 181
        }
181 182
@@ -215,7 +216,7 @@
Loading
215 216
                    _config.UserSettings.IndenterSettings.LoadLegacyFromRegistry();
216 217
                }
217 218
                _config.UserSettings.GeneralSettings.IsSmartIndenterPrompted = true;
218 -
                _configService.SaveConfiguration(_config);
219 +
                _configService.Save(_config);
219 220
            }
220 221
            catch 
221 222
            {

@@ -15,10 +15,10 @@
Loading
15 15
using Rubberduck.Parsing.Inspections.Abstract;
16 16
using Rubberduck.Parsing.VBA;
17 17
using Rubberduck.Parsing.VBA.Parsing;
18 -
using Rubberduck.Settings;
19 -
using Rubberduck.UI.Inspections;
20 18
using Rubberduck.VBEditor;
21 19
using Rubberduck.Resources;
20 +
using Rubberduck.SettingsProvider;
21 +
using Rubberduck.CodeAnalysis.Settings;
22 22
23 23
namespace Rubberduck.Inspections
24 24
{
@@ -27,29 +27,28 @@
Loading
27 27
        public class Inspector : IInspector
28 28
        {
29 29
            private const int _maxDegreeOfInspectionParallelism = -1;
30 -
31 -
            private readonly IGeneralConfigService _configService;
30 +
            private readonly IConfigurationService<CodeInspectionSettings> _configService;
32 31
            private readonly List<IInspection> _inspections;
33 32
34 -
            public Inspector(IGeneralConfigService configService, IInspectionProvider inspectionProvider)
33 +
            public Inspector(IConfigurationService<CodeInspectionSettings> configService, IInspectionProvider inspectionProvider)
35 34
            {
36 35
                _inspections = inspectionProvider.Inspections.ToList();
37 -
36 +
                
38 37
                _configService = configService;
39 38
                configService.SettingsChanged += ConfigServiceSettingsChanged;
40 39
            }
41 40
42 41
            private void ConfigServiceSettingsChanged(object sender, EventArgs e)
43 42
            {
44 -
                var config = _configService.LoadConfiguration();
43 +
                var config = _configService.Read();
45 44
                UpdateInspectionSeverity(config);
46 45
            }
47 46
48 -
            private void UpdateInspectionSeverity(Configuration config)
47 +
            private void UpdateInspectionSeverity(CodeInspectionSettings config)
49 48
            {
50 49
                foreach (var inspection in _inspections)
51 50
                {
52 -
                    foreach (var setting in config.UserSettings.CodeInspectionSettings.CodeInspections)
51 +
                    foreach (var setting in config.CodeInspections)
53 52
                    {
54 53
                        if (inspection.Name == setting.Name)
55 54
                        {
@@ -72,7 +71,7 @@
Loading
72 71
                var allIssues = new ConcurrentBag<IInspectionResult>();
73 72
                token.ThrowIfCancellationRequested();
74 73
75 -
                var config = _configService.LoadConfiguration();
74 +
                var config = _configService.Read();
76 75
                UpdateInspectionSeverity(config);
77 76
                token.ThrowIfCancellationRequested();
78 77
@@ -93,7 +92,7 @@
Loading
93 92
                {
94 93
                    try
95 94
                    {
96 -
                        WalkTrees(config.UserSettings.CodeInspectionSettings, state, parseTreeInspections.Where(i => i.TargetKindOfCode == parsePass), parsePass);
95 +
                        WalkTrees(config, state, parseTreeInspections.Where(i => i.TargetKindOfCode == parsePass), parsePass);
97 96
                    }
98 97
                    catch (Exception e)
99 98
                    {

@@ -3,17 +3,17 @@
Loading
3 3
4 4
namespace Rubberduck.SettingsProvider
5 5
{
6 -
    public class PersistancePathProvider : IPersistancePathProvider
6 +
    internal class PersistencePathProvider : IPersistencePathProvider
7 7
    {
8 -
        private static readonly Lazy<IPersistancePathProvider> LazyInstance;
8 +
        private static readonly Lazy<IPersistencePathProvider> LazyInstance;
9 9
10 -
        static PersistancePathProvider()
10 +
        static PersistencePathProvider()
11 11
        {
12 -
            LazyInstance = new Lazy<IPersistancePathProvider>(() => new PersistancePathProvider());
12 +
            LazyInstance = new Lazy<IPersistencePathProvider>(() => new PersistencePathProvider());
13 13
        }
14 14
15 15
        // Disallow instancing of the class except via static method
16 -
        private PersistancePathProvider() { }
16 +
        private PersistencePathProvider() { }
17 17
18 18
        public string DataRootPath => Path.Combine(
19 19
            Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
@@ -24,6 +24,6 @@
Loading
24 24
            return Path.Combine(DataRootPath, folderName);
25 25
        }
26 26
27 -
        public static IPersistancePathProvider Instance => LazyInstance.Value;
27 +
        public static IPersistencePathProvider Instance => LazyInstance.Value;
28 28
    }
29 29
}
30 30
imilarity index 92%
31 31
ename from Rubberduck.SettingsProvider/XmlContractPersistanceService.cs
32 32
ename to Rubberduck.SettingsProvider/Persistence/XmlContractPersistenceService.cs

@@ -11,23 +11,22 @@
Loading
11 11
12 12
namespace Rubberduck.Settings
13 13
{
14 -
    public class ReferenceConfigProvider : IConfigProvider<ReferenceSettings>, IDisposable
14 +
    public class ReferenceConfigProvider : ConfigurationServiceBase<ReferenceSettings>, IDisposable
15 15
    {
16 16
        private static readonly string HostApplication = Path.GetFileName(Application.ExecutablePath).ToUpperInvariant();
17 -
18 -
        private readonly IPersistanceService<ReferenceSettings> _persister;
17 +
        
19 18
        private readonly IEnvironmentProvider _environment;
20 19
        private readonly IVBEEvents _events;
21 20
        private bool _listening;
22 21
23 -
        public ReferenceConfigProvider(IPersistanceService<ReferenceSettings> persister, IEnvironmentProvider environment, IVBEEvents events)
22 +
        public ReferenceConfigProvider(IPersistenceService<ReferenceSettings> persister, IEnvironmentProvider environment, IVBEEvents events)
23 +
            : base(persister, new DefaultSettings<ReferenceSettings, Properties.Settings>())
24 24
        {
25 -
            _persister = persister;
26 25
            _environment = environment;
27 26
            _events = events;
28 27
29 28
            
30 -
            var settings = Create();
29 +
            var settings = Read();
31 30
            _listening = settings.AddToRecentOnReferenceEvents;
32 31
            if (_listening && _events != null)
33 32
            {
@@ -35,13 +34,7 @@
Loading
35 34
            }
36 35
        }
37 36
38 -
        public ReferenceSettings Create()
39 -
        {
40 -
            var defaults = CreateDefaults();
41 -
            return _persister.Load(defaults) ?? defaults;
42 -
        }
43 -
44 -
        public ReferenceSettings CreateDefaults()
37 +
        public override ReferenceSettings ReadDefaults()
45 38
        {
46 39
            var defaults = new ReferenceSettings
47 40
            {
@@ -77,7 +70,7 @@
Loading
77 70
            return defaults;
78 71
        }
79 72
80 -
        public void Save(ReferenceSettings settings)
73 +
        public override void Save(ReferenceSettings settings)
81 74
        {
82 75
            if (_listening && _events != null && !settings.AddToRecentOnReferenceEvents)
83 76
            {
@@ -90,8 +83,8 @@
Loading
90 83
                _events.ProjectReferenceAdded += ReferenceAddedHandler;
91 84
                _listening = true;
92 85
            }
93 -
94 -
            _persister.Save(settings);
86 +
            OnSettingsChanged();
87 +
            PersistValue(settings);
95 88
        }
96 89
97 90
        private void ReferenceAddedHandler(object sender, ReferenceEventArgs e)
@@ -101,9 +94,9 @@
Loading
101 94
                return;
102 95
            }
103 96
104 -
            var settings = Create();
97 +
            var settings = Read();
105 98
            settings.TrackUsage(e.Reference, e.Type == ReferenceKind.Project ? HostApplication : null);
106 -
            _persister.Save(settings);
99 +
            Save(settings);
107 100
        }
108 101
109 102
        public void Dispose()

@@ -0,0 +1,45 @@
Loading
1 +
using System;
2 +
using System.Collections.Generic;
3 +
using System.Linq;
4 +
using System.Reflection;
5 +
6 +
namespace Rubberduck.Settings
7 +
{
8 +
    public interface IDefaultSettings<T>
9 +
    {
10 +
        IEnumerable<T> Defaults { get; }
11 +
        T Default { get; }
12 +
    }
13 +
14 +
    public class FixedValueDefault<T> : IDefaultSettings<T>
15 +
    {
16 +
        public IEnumerable<T> Defaults { get => new[] { Default }; }
17 +
        public T Default { get; }
18 +
19 +
        public FixedValueDefault(T value)
20 +
        {
21 +
            Default = value;
22 +
        }
23 +
    }
24 +
25 +
    public class DefaultSettings<T, S>  : IDefaultSettings<T>
26 +
        where S : System.Configuration.ApplicationSettingsBase
27 +
    {
28 +
        public IEnumerable<T> Defaults { get; }
29 +
        public T Default => Defaults.First();
30 +
31 +
        public DefaultSettings()
32 +
        {
33 +
            var properties = typeof(S).GetProperties().Where(prop => prop.PropertyType == typeof(T));
34 +
            var defaultInstance = typeof(S).GetProperty("Default", BindingFlags.Static | BindingFlags.Public).GetValue(null);
35 +
36 +
            Defaults = properties.Select(prop => prop.GetValue(defaultInstance)).Cast<T>();
37 +
        }
38 +
39 +
        public DefaultSettings(S settingsInstance)
40 +
        {
41 +
            var properties = typeof(S).GetProperties().Where(prop => prop.PropertyType == typeof(T));
42 +
            Defaults = properties.Select(prop => prop.GetValue(settingsInstance)).Cast<T>();
43 +
        }
44 +
    }
45 +
}

@@ -9,6 +9,7 @@
Loading
9 9
using Rubberduck.Common;
10 10
using Rubberduck.Interaction.Navigation;
11 11
using Rubberduck.Settings;
12 +
using Rubberduck.SettingsProvider;
12 13
using Rubberduck.UI.Command;
13 14
using Rubberduck.UI.Settings;
14 15
using Rubberduck.UI.UnitTesting.Commands;
@@ -37,7 +38,7 @@
Loading
37 38
            TestExplorerModel model,
38 39
            IClipboardWriter clipboard,
39 40
            // ReSharper disable once UnusedParameter.Local - left in place because it will likely be needed for app wide font settings, etc.
40 -
            IGeneralConfigService configService,
41 +
            IConfigurationService<Configuration> configService,
41 42
            ISettingsFormFactory settingsFormFactory)
42 43
        {
43 44
            _clipboard = clipboard;

@@ -9,7 +9,7 @@
Loading
9 9
{
10 10
    public sealed class AutoCompleteSettingsViewModel : SettingsViewModelBase<Rubberduck.Settings.AutoCompleteSettings>, ISettingsViewModel<Rubberduck.Settings.AutoCompleteSettings>
11 11
    {
12 -
        public AutoCompleteSettingsViewModel(Configuration config, IFilePersistanceService<Rubberduck.Settings.AutoCompleteSettings> service) 
12 +
        public AutoCompleteSettingsViewModel(Configuration config, IFilePersistenceService<Rubberduck.Settings.AutoCompleteSettings> service) 
13 13
            : base(service)
14 14
        {
15 15
            TransferSettingsToView(config.UserSettings.AutoCompleteSettings);

@@ -1,6 +1,6 @@
Loading
1 1
using System.Xml.Serialization;
2 2
3 -
namespace Rubberduck.Settings
3 +
namespace Rubberduck.CodeAnalysis.Settings
4 4
{
5 5
    [XmlType(AnonymousType = true)]
6 6
    public class WhitelistedIdentifierSetting

@@ -6,7 +6,7 @@
Loading
6 6
{
7 7
    public class InspectionResultsDockablePresenter : DockableToolwindowPresenter
8 8
    {
9 -
        public InspectionResultsDockablePresenter(IVBE vbe, IAddIn addin, InspectionResultsWindow window, IConfigProvider<WindowSettings> settings)
9 +
        public InspectionResultsDockablePresenter(IVBE vbe, IAddIn addin, InspectionResultsWindow window, IConfigurationService<WindowSettings> settings)
10 10
            : base(vbe, addin, window, settings)
11 11
        {
12 12
        }

@@ -7,10 +7,10 @@
Loading
7 7
8 8
namespace Rubberduck.SettingsProvider
9 9
{
10 -
    public class XmlPersistanceService<T> : XmlPersistanceServiceBase<T> 
10 +
    internal class XmlPersistenceService<T> : XmlPersistenceServiceBase<T> 
11 11
        where T : class, IEquatable<T>, new()
12 12
    {
13 -
        public XmlPersistanceService(IPersistancePathProvider pathProvider) : base(pathProvider) { }
13 +
        public XmlPersistenceService(IPersistencePathProvider pathProvider) : base(pathProvider) { }
14 14
15 15
        public override T Load(T toDeserialize, string nonDefaultFilePath = null)
16 16
        {
17 17
imilarity index 93%
18 18
ename from Rubberduck.SettingsProvider/XmlPersistanceServiceBase.cs
19 19
ename to Rubberduck.SettingsProvider/Persistence/XmlPersistenceServiceBase.cs

@@ -231,11 +231,13 @@
Loading
231 231
            foreach (var assembly in assembliesToRegister)
232 232
            {
233 233
                container.Register(Classes.FromAssembly(assembly)
234 -
                    .IncludeNonPublicTypes()
235 -
                    .Where(type => type.Namespace == typeof(Configuration).Namespace 
236 -
                                   && type.NotDisabledOrExperimental(_initialSettings)
237 -
                                   && type != typeof(ExperimentalTypesProvider))
238 -
                    .WithService.AllInterfaces()
234 +
                    .BasedOn(typeof(ConfigurationServiceBase<>))
235 +
                    .WithServiceSelect((type, hierarchy) =>
236 +
                    {
237 +
                        // select closed generic interface
238 +
                        return type.GetInterfaces().Where(iface => iface.IsGenericType 
239 +
                            && iface.GetGenericTypeDefinition() == typeof(IConfigurationService<>));
240 +
                    })
239 241
                    .LifestyleSingleton());
240 242
241 243
                experimentalTypes.AddRange(assembly.GetTypes()
@@ -251,20 +253,16 @@
Loading
251 253
            container.Register(Component.For<IComProjectSerializationProvider>()
252 254
                .ImplementedBy<XmlComProjectSerializer>()
253 255
                .LifestyleTransient());
254 -
            container.Register(Component.For(typeof(IPersistanceService<>), typeof(IFilePersistanceService<>))
255 -
                .ImplementedBy(typeof(XmlPersistanceService<>))
256 -
                .LifestyleSingleton());
257 -
258 -
            container.Register(Component.For(typeof(IPersistanceService<ReferenceSettings>), typeof(IFilePersistanceService<>))
259 -
                .ImplementedBy(typeof(XmlContractPersistanceService<>))
256 +
            container.Register(Component.For(typeof(IPersistenceService<>), typeof(IFilePersistenceService<>))
257 +
                .ImplementedBy(typeof(XmlPersistenceService<>))
260 258
                .LifestyleSingleton());
261 259
262 -
            container.Register(Component.For<IConfigProvider<IndenterSettings>>()
263 -
                .ImplementedBy<IndenterConfigProvider>()
260 +
            container.Register(Component.For(typeof(IPersistenceService<ReferenceSettings>), typeof(IFilePersistenceService<>))
261 +
                .ImplementedBy(typeof(XmlContractPersistenceService<>))
264 262
                .LifestyleSingleton());
265 263
266 -
            container.Register(Component.For<IConfigProvider<UnitTesting.Settings.UnitTestSettings>>()
267 -
                .ImplementedBy<UnitTestConfigProvider>()
264 +
            container.Register(Component.For(typeof(IConfigurationService<Configuration>))
265 +
                .ImplementedBy(typeof(ConfigurationLoader))
268 266
                .LifestyleSingleton());
269 267
        }
270 268
@@ -786,8 +784,8 @@
Loading
786 784
                .ImplementedBy<IndenterSettings>()
787 785
                .LifestyleSingleton());
788 786
            container.Register(Component.For<Func<IIndenterSettings>>()
789 -
                .UsingFactoryMethod(kernel => (Func<IIndenterSettings>)(() => kernel.Resolve<IGeneralConfigService>()
790 -
                   .LoadConfiguration().UserSettings.IndenterSettings))
787 +
                .UsingFactoryMethod(kernel => (Func<IIndenterSettings>)(() => kernel.Resolve<IConfigurationService<Configuration>>()
788 +
                   .Read().UserSettings.IndenterSettings))
791 789
                .LifestyleTransient()); //todo: clean up this registration
792 790
        }
793 791
@@ -991,7 +989,7 @@
Loading
991 989
            container.Register(Component.For<IUiContextProvider>().Instance(UiContextProvider.Instance()).LifestyleSingleton());
992 990
            container.Register(Component.For<IVBEEvents>().Instance(VBEEvents.Initialize(_vbe)).LifestyleSingleton());
993 991
            container.Register(Component.For<ITempSourceFileHandler>().Instance(_vbe.TempSourceFileHandler).LifestyleSingleton());
994 -
            container.Register(Component.For<IPersistancePathProvider>().Instance(PersistancePathProvider.Instance).LifestyleSingleton());
992 +
            container.Register(Component.For<IPersistencePathProvider>().Instance(PersistencePathProvider.Instance).LifestyleSingleton());
995 993
            container.Register(Component.For<IVbeNativeApi>().Instance(_vbeNativeApi).LifestyleSingleton());
996 994
        }
997 995
    }

@@ -2,30 +2,9 @@
Loading
2 2
3 3
namespace Rubberduck.Settings
4 4
{
5 -
    public class AutoCompleteConfigProvider : IConfigProvider<AutoCompleteSettings>
5 +
    public class AutoCompleteConfigProvider : ConfigurationServiceBase<AutoCompleteSettings>
6 6
    {
7 -
        private readonly IPersistanceService<AutoCompleteSettings> _persister;
8 -
        private readonly AutoCompleteSettings _defaultSettings;
9 -
10 -
        public AutoCompleteConfigProvider(IPersistanceService<AutoCompleteSettings> persister)
11 -
        {
12 -
            _persister = persister;
13 -
            _defaultSettings = new DefaultSettings<AutoCompleteSettings>().Default;
14 -
        }
15 -
16 -
        public AutoCompleteSettings Create()
17 -
        {
18 -
            return _persister.Load(_defaultSettings) ?? _defaultSettings;
19 -
        }
20 -
21 -
        public AutoCompleteSettings CreateDefaults()
22 -
        {
23 -
            return _defaultSettings;
24 -
        }
25 -
26 -
        public void Save(AutoCompleteSettings settings)
27 -
        {
28 -
            _persister.Save(settings);
29 -
        }
7 +
        public AutoCompleteConfigProvider(IPersistenceService<AutoCompleteSettings> persister)
8 +
            : base(persister, new DefaultSettings<AutoCompleteSettings, Properties.Settings>()) { }
30 9
    }
31 10
}

@@ -1,30 +1,12 @@
Loading
1 -
using Rubberduck.SettingsProvider;
1 +
using Rubberduck.Settings;
2 +
using Rubberduck.SettingsProvider;
2 3
3 4
namespace Rubberduck.SmartIndenter
4 5
{
5 -
    public class IndenterConfigProvider : IConfigProvider<IndenterSettings>
6 +
    public class IndenterConfigProvider : ConfigurationServiceBase<IndenterSettings>
6 7
    {
7 -
        private readonly IPersistanceService<IndenterSettings> _persister;
8 -
9 -
        public IndenterConfigProvider(IPersistanceService<IndenterSettings> persister)
10 -
        {
11 -
            _persister = persister;
12 -
        }
13 -
14 -
        public IndenterSettings Create()
15 -
        {
16 -
            var prototype = new IndenterSettings(false);
17 -
            return _persister.Load(prototype) ?? prototype;
18 -
        }
19 -
20 -
        public IndenterSettings CreateDefaults()
21 -
        {
22 -
            return new IndenterSettings(false);
23 -
        }
24 -
25 -
        public void Save(IndenterSettings settings)
26 -
        {
27 -
            _persister.Save(settings);
28 -
        }
8 +
        public IndenterConfigProvider(IPersistenceService<IndenterSettings> persister)
9 +
            : base (persister, new FixedValueDefault<IndenterSettings>(new IndenterSettings(false)))
10 +
        { }
29 11
    }
30 12
}

@@ -19,6 +19,7 @@
Loading
19 19
using Rubberduck.Interaction.Navigation;
20 20
using Rubberduck.Parsing.UIContext;
21 21
using Rubberduck.VBEditor.Utility;
22 +
using Rubberduck.SettingsProvider;
22 23
23 24
namespace Rubberduck.UI.ToDoItems
24 25
{
@@ -32,13 +33,13 @@
Loading
32 33
    public sealed class ToDoExplorerViewModel : ViewModelBase, INavigateSelection, IDisposable
33 34
    {
34 35
        private readonly RubberduckParserState _state;
35 -
        private readonly IGeneralConfigService _configService;
36 +
        private readonly IConfigurationService<Configuration> _configService;
36 37
        private readonly ISettingsFormFactory _settingsFormFactory;
37 38
        private readonly IUiDispatcher _uiDispatcher;
38 39
39 40
        public ToDoExplorerViewModel(
40 -
            RubberduckParserState state, 
41 -
            IGeneralConfigService configService, 
41 +
            RubberduckParserState state,
42 +
            IConfigurationService<Configuration> configService, 
42 43
            ISettingsFormFactory settingsFormFactory, 
43 44
            ISelectionService selectionService, 
44 45
            IUiDispatcher uiDispatcher)
@@ -224,7 +225,7 @@
Loading
224 225
225 226
        private IEnumerable<ToDoItem> GetToDoMarkers(CommentNode comment)
226 227
        {
227 -
            var markers = _configService.LoadConfiguration().UserSettings.ToDoListSettings.ToDoMarkers;
228 +
            var markers = _configService.Read().UserSettings.ToDoListSettings.ToDoMarkers;
228 229
            return markers.Where(marker => !string.IsNullOrEmpty(marker.Text)
229 230
                                         && Regex.IsMatch(comment.CommentText, @"\b" + Regex.Escape(marker.Text) + @"\b", RegexOptions.IgnoreCase))
230 231
                           .Select(marker => new ToDoItem(marker.Text, comment));

@@ -7,7 +7,7 @@
Loading
7 7
using Rubberduck.Parsing.Inspections.Abstract;
8 8
using Rubberduck.Parsing.Inspections;
9 9
10 -
namespace Rubberduck.Settings
10 +
namespace Rubberduck.CodeAnalysis.Settings
11 11
{
12 12
    public interface ICodeInspectionSettings
13 13
    {
14 14
imilarity index 89%
15 15
ename from Rubberduck.Core/Settings/WhitelistedIdentifierSetting.cs
16 16
ename to Rubberduck.CodeAnalysis/Settings/WhitelistedIdentifierSetting.cs
Files Coverage
Rubberduck.CodeAnalysis 88.89%
Rubberduck.Core 31.97%
Rubberduck.Interaction 9.80%
Rubberduck.Main 45.91%
Rubberduck.Parsing 81.00%
Rubberduck.Refactorings 89.20%
Rubberduck.RegexAssistant 65.19%
Rubberduck.Resources 66.67%
Rubberduck.SettingsProvider 28.19%
Rubberduck.SmartIndenter 78.72%
Rubberduck.UnitTesting 68.22%
RubberduckCodeAnalysis 99.28%
Rubberduck.JunkDrawer/Output/StringExtensions.cs 87.50%
Project Totals (1065 files) 64.56%
1janhd6490e5b2jw
1
codecov:
2
  branch: next
3
  ci:
4
    - appveyor
5
  max_report_age: off
6
  
7
ignore:
8
  # as requested by MDoerner, because they aren't really testable
9
  - Rubberduck.VBEEditor
10
  - Rubberduck.VBEditor.*
11
  # it makes no sense to track coverage on unit-tests
12
  - RubberduckTests
13
  # xaml files are not checked for coverage
14
  # AutoGenerated files are not contributing to coverage
15
  - **/*.Designer.cs
16
    
17
coverage:
18
  round: nearest
19
  precision: 2
20
  range: 40..80 
21
  status:
22
    # don't check patch coverage
23
    patch: off
24
    project:
25
      default:
26
        target: 0 # don't force a minimum coverage
27
        # allow decrease by up to 5 %
28
        threshold: 5
29
        base: auto
30
  
31
comment:
32
  layout: "flags, diff, files"
33
  behavior: once
34
  require_changes: yes
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading