C# Client Library
A C# Client Library for the AnalyzeRe REST API
Loading...
Searching...
No Matches
SharedSettingsProvider.cs
Go to the documentation of this file.
1using System;
2using System.Collections.Specialized;
3using System.Configuration;
4using System.Diagnostics;
5
7{
14 public class SharedSettingsProvider : SettingsProvider
15 {
17 public enum SettingsLocation
18 {
28 }
29
32
33 #region Private Fields
36 private SettingsLocation _currentSettingsLocation;
37
39 private SettingsProvider _currentSettingsProvider;
40
42 private bool _initialized;
43
45 private string _initializedName;
46
48 private NameValueCollection _initializedConfig;
49 #endregion Private Fields
50
51 private SettingsProvider CurrentSettingsProvider
52 {
53 get
54 {
55 if (GlobalSettingsLocation == _currentSettingsLocation && _currentSettingsProvider != null)
56 return _currentSettingsProvider;
57 _currentSettingsLocation = GlobalSettingsLocation;
58 Debug.WriteLine($"{nameof(SharedSettingsProvider)} - Creating {_currentSettingsLocation} settings provider");
59 switch (_currentSettingsLocation)
60 {
61 case SettingsLocation.Registry:
62 _currentSettingsProvider = new RegistrySettingsProvider();
63 break;
64 case SettingsLocation.NativeLocalFile:
65 _currentSettingsProvider = new LocalFileSettingsProvider();
66 break;
67 default:
68 throw new ArgumentOutOfRangeException();
69 }
70 if(_initialized)
71 _currentSettingsProvider.Initialize(_initializedName, _initializedConfig);
72 return _currentSettingsProvider;
73 }
74 }
75
77 public override string Name => CurrentSettingsProvider.Name;
78
80 public override string Description => CurrentSettingsProvider.Description;
81
83 public override string ApplicationName
84 {
85 get => CurrentSettingsProvider.ApplicationName;
86 set => CurrentSettingsProvider.ApplicationName = value;
87 }
88
89
96 {
97 _currentSettingsLocation = GlobalSettingsLocation;
98 }
99
103 public override void Initialize(string name, NameValueCollection config)
104 {
105 _initializedName = name;
106 _initializedConfig = config;
107 // If we've already constructed the current settings provider but haven't initialized
108 // it yet, initialize it now with these parameters. Otherwise, it will be initialized
109 // when it is constructed.
110 if(_currentSettingsProvider != null && !_initialized)
111 _currentSettingsProvider.Initialize(_initializedName, _initializedConfig);
112 _initialized = true;
113 }
114
120 public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection collection)
121 {
122 return CurrentSettingsProvider.GetPropertyValues(context, collection);
123 }
124
129 public override void SetPropertyValues(SettingsContext context, SettingsPropertyValueCollection collection)
130 {
131 CurrentSettingsProvider.SetPropertyValues(context, collection);
132 }
133 }
134}
A SettingsProvider that can be shared by both the AnalyzeRe.Client library, and users of the library ...
override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection collection)
Returns the collection of settings property values for the specified application instance and setting...
override void Initialize(string name, NameValueCollection config)
Recall initialization parameters so that we can appropriately initialize whichever provider we toggle...
static SettingsLocation GlobalSettingsLocation
Sets the location.
SettingsLocation
Allows configuration of the internal settings provider used by instances of this class.
@ Registry
Enables storing persistent user settings in the registry (instead of a user.config file)....
@ NativeLocalFile
Uses the default system settings provider, which creates a configuration file on disk in a someone am...
override void SetPropertyValues(SettingsContext context, SettingsPropertyValueCollection collection)
Sets the values of the specified group of property settings.
SharedSettingsProvider()
Constructs a new instance of the SharedSettingsProvider, using the configuration to determine which s...