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
|
#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.IO;
/// <summary>
/// Abstract class representing a hierarchical storage used to hold
/// application settings. The actual implementation is left to
/// derived classes, and may be based on the registry, isolated
/// storage or any other mechanism.
/// </summary>
public abstract class SettingsStorage : IDisposable
{
#region Instance Variables
/// <summary>
/// The name of this storage
/// </summary>
private string storageName;
/// <summary>
/// The parent storage containing this storage
/// </summary>
private SettingsStorage parentStorage;
#endregion
#region Construction and Disposal
/// <summary>
/// Construct a SettingsStorage under a parent storage
/// </summary>
/// <param name="storageName">Name of the storage</param>
/// <param name="parentStorage">The parent which contains the new storage</param>
public SettingsStorage( string storageName, SettingsStorage parentStorage )
{
this.storageName = storageName;
this.parentStorage = parentStorage;
}
/// <summary>
/// Dispose of resources held by this storage
/// </summary>
public abstract void Dispose();
#endregion
#region Properties
/// <summary>
/// The number of settings in this group
/// </summary>
public abstract int SettingsCount
{
get;
}
/// <summary>
/// The name of the storage
/// </summary>
public string StorageName
{
get { return storageName; }
}
/// <summary>
/// The storage that contains this one
/// </summary>
public SettingsStorage ParentStorage
{
get { return parentStorage; }
}
#endregion
#region Methods
/// <summary>
/// Find out if a substorage exists
/// </summary>
/// <param name="name">Name of the child storage</param>
/// <returns>True if the storage exists</returns>
public abstract bool ChildStorageExists( string name );
/// <summary>
/// Create a child storage of the same type
/// </summary>
/// <param name="name">Name of the child storage</param>
/// <returns>New child storage</returns>
public abstract SettingsStorage MakeChildStorage( string name );
/// <summary>
/// Clear all settings from the storage - empty storage remains
/// </summary>
public abstract void Clear();
/// <summary>
/// Load a setting from the storage.
/// </summary>
/// <param name="settingName">Name of the setting to load</param>
/// <returns>Value of the setting or null</returns>
public abstract object LoadSetting( string settingName );
/// <summary>
/// Load an integer setting from the storage
/// </summary>
/// <param name="settingName">Name of the setting to load</param>
/// <returns>Value of the setting or null</returns>
public abstract int LoadIntSetting( string settingName );
/// <summary>
/// Load a string setting from the storage
/// </summary>
/// <param name="settingName">Name of the setting to load</param>
/// <returns>Value of the setting or null</returns>
public abstract string LoadStringSetting( string settingName );
/// <summary>
/// Load a setting from the storage or return a default value
/// </summary>
/// <param name="settingName">Name of the setting to load</param>
/// <param name="settingName">Value to return if the setting is missing</param>
/// <returns>Value of the setting or the default value</returns>
public abstract object LoadSetting( string settingName, object defaultValue );
/// <summary>
/// Load an integer setting from the storage or return a default value
/// </summary>
/// <param name="settingName">Name of the setting to load</param>
/// <param name="settingName">Value to return if the setting is missing</param>
/// <returns>Value of the setting or the default value</returns>
public abstract int LoadIntSetting( string settingName, int defaultValue );
/// <summary>
/// Load a string setting from the storage or return a default value
/// </summary>
/// <param name="settingName">Name of the setting to load</param>
/// <param name="settingName">Value to return if the setting is missing</param>
/// <returns>Value of the setting or the default value</returns>
public abstract string LoadStringSetting( string settingName, string defaultValue );
/// <summary>
/// Remove a setting from the storage
/// </summary>
/// <param name="settingName">Name of the setting to remove</param>
public abstract void RemoveSetting( string settingName );
/// <summary>
/// Save a setting in the storage
/// </summary>
/// <param name="settingName">Name of the setting to save</param>
/// <param name="settingValue">Value to be saved</param>
public abstract void SaveSetting( string settingName, object settingValue );
#endregion
}
}
|