1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
|
#region Copyright (c) 2002, James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Philip A. Craig
/************************************************************************************
'
' Copyright © 2002 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov
' Copyright © 2000-2002 Philip A. Craig
'
' This software is provided 'as-is', without any express or implied warranty. In no
' event will the authors be held liable for any damages arising from the use of this
' software.
'
' Permission is granted to anyone to use this software for any purpose, including
' commercial applications, and to alter it and redistribute it freely, subject to the
' following restrictions:
'
' 1. The origin of this software must not be misrepresented; you must not claim that
' you wrote the original software. If you use this software in a product, an
' acknowledgment (see the following) in the product documentation is required.
'
' Portions Copyright © 2002 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov
' or Copyright © 2000-2002 Philip A. Craig
'
' 2. Altered source versions must be plainly marked as such, and must not be
' misrepresented as being the original software.
'
' 3. This notice may not be removed or altered from any source distribution.
'
'***********************************************************************************/
#endregion
namespace NUnit.Util
{
using System;
using System.Collections;
/// <summary>
/// SettingsGroup is the base class representing a group
/// of user or system settings. A pimpl idiom is used
/// to provide implementation-independence.
/// </summary>
public class SettingsGroup : IDisposable
{
#region Instance Variables
/// <summary>
/// The name of this group of settings
/// </summary>
private string name;
/// <summary>
/// If not null, the storage implementation holding the group settings.
/// </summary>
private SettingsStorage storageImpl;
/// <summary>
/// If not null, the settings group that contains this one.
/// </summary>
private SettingsGroup parentSettings;
#endregion
#region Construction and Disposal
/// <summary>
/// Construct a settings group based on a storage implementation.
/// </summary>
/// <param name="name">Name of the group</param>
/// <param name="storageImpl">Storage for the group settings</param>
public SettingsGroup( string name, SettingsStorage storageImpl )
{
this.name = name;
this.storageImpl = storageImpl;
}
/// <summary>
/// Construct a settings group based on a parent group that contains it.
/// </summary>
/// <param name="name">Name of the group</param>
/// <param name="parentSettings">Containing group</param>
public SettingsGroup( string name, SettingsGroup parentSettings )
{
this.name = name;
this.parentSettings = parentSettings;
this.storageImpl = parentSettings.Storage.MakeChildStorage( name );
}
/// <summary>
/// Dispose of this group by disposing of it's storage implementation
/// </summary>
public void Dispose()
{
if ( storageImpl != null )
{
storageImpl.Dispose();
storageImpl = null;
}
}
#endregion
#region Properties
/// <summary>
/// The name of the group
/// </summary>
public string Name
{
get { return name; }
}
/// <summary>
/// The storage used for the group settings
/// </summary>
public SettingsStorage Storage
{
get { return storageImpl; }
}
/// <summary>
/// The number of settings in this group
/// </summary>
public int SettingsCount
{
get { return storageImpl.SettingsCount; }
}
#endregion
#region Methods
/// <summary>
/// Clear all settings and subgroups in this group
/// </summary>
public virtual void Clear()
{
storageImpl.Clear();
}
/// <summary>
/// Load the value of one of the group's settings
/// </summary>
/// <param name="settingName">Name of setting to load</param>
/// <returns>Value of the setting or null</returns>
public object LoadSetting( string settingName )
{
return storageImpl.LoadSetting( settingName );
}
/// <summary>
/// Load the value of one of the group's integer settings
/// in a type-safe manner.
/// </summary>
/// <param name="settingName">Name of setting to load</param>
/// <returns>Value of the setting or null</returns>
public int LoadIntSetting( string settingName )
{
return storageImpl.LoadIntSetting( settingName );
}
/// <summary>
/// Load the value of one of the group's string settings
/// in a type-safe manner.
/// </summary>
/// <param name="settingName">Name of setting to load</param>
/// <returns>Value of the setting or null</returns>
public string LoadStringSetting( string settingName )
{
return storageImpl.LoadStringSetting( settingName );
}
/// <summary>
/// Load the value of one of the group's settings or return a default value
/// </summary>
/// <param name="settingName">Name of setting to load</param>
/// <param name="defaultValue">Value to return if the seeting is not present</param>
/// <returns>Value of the setting or the default</returns>
public object LoadSetting( string settingName, object defaultValue )
{
return storageImpl.LoadSetting( settingName, defaultValue );
}
/// <summary>
/// Load the value of one of the group's integer settings
/// in a type-safe manner or return a default value
/// </summary>
/// <param name="settingName">Name of setting to load</param>
/// <param name="defaultValue">Value to return if the seeting is not present</param>
/// <returns>Value of the setting or the default</returns>
public int LoadIntSetting( string settingName, int defaultValue )
{
return storageImpl.LoadIntSetting( settingName, defaultValue );
}
/// <summary>
/// Load the value of one of the group's string settings
/// in a type-safe manner or return a default value
/// </summary>
/// <param name="settingName">Name of setting to load</param>
/// <param name="defaultValue">Value to return if the seeting is not present</param>
/// <returns>Value of the setting or the default</returns>
public string LoadStringSetting( string settingName, string defaultValue )
{
return storageImpl.LoadStringSetting( settingName, defaultValue );
}
/// <summary>
/// Remove a setting from the group
/// </summary>
/// <param name="settingName">Name of the setting to remove</param>
public void RemoveSetting( string settingName )
{
storageImpl.RemoveSetting( settingName );
}
/// <summary>
/// Save the value of one of the group's settings
/// </summary>
/// <param name="settingName">Name of the setting to save</param>
/// <param name="settingValue">Value to be saved</param>
public void SaveSetting( string settingName, object settingValue )
{
storageImpl.SaveSetting( settingName, settingValue );
}
/// <summary>
/// Save the value of one of the group's integer settings
/// in a type-safe manner.
/// </summary>
/// <param name="settingName">Name of the setting to save</param>
/// <param name="settingValue">Value to be saved</param>
public void SaveIntSetting( string settingName, int settingValue )
{
storageImpl.SaveSetting( settingName, settingValue );
}
/// <summary>
/// Save the value of one of the group's string settings
/// in a type-safe manner.
/// </summary>
/// <param name="settingName">Name of the setting to save</param>
/// <param name="settingValue">Value to be saved</param>
public void SaveStringSetting( string settingName, string settingValue )
{
storageImpl.SaveSetting( settingName, settingValue );
}
#endregion
}
}
|