New test.
[mono.git] / mcs / nunit20 / util / SettingsStorage.cs
1 #region Copyright (c) 2002-2003, James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole, Philip A. Craig
2 /************************************************************************************
3 '
4 ' Copyright  2002-2003 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole
5 ' Copyright  2000-2002 Philip A. Craig
6 '
7 ' This software is provided 'as-is', without any express or implied warranty. In no 
8 ' event will the authors be held liable for any damages arising from the use of this 
9 ' software.
10
11 ' Permission is granted to anyone to use this software for any purpose, including 
12 ' commercial applications, and to alter it and redistribute it freely, subject to the 
13 ' following restrictions:
14 '
15 ' 1. The origin of this software must not be misrepresented; you must not claim that 
16 ' you wrote the original software. If you use this software in a product, an 
17 ' acknowledgment (see the following) in the product documentation is required.
18 '
19 ' Portions Copyright  2002-2003 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole
20 ' or Copyright  2000-2002 Philip A. Craig
21 '
22 ' 2. Altered source versions must be plainly marked as such, and must not be 
23 ' misrepresented as being the original software.
24 '
25 ' 3. This notice may not be removed or altered from any source distribution.
26 '
27 '***********************************************************************************/
28 #endregion
29
30 namespace NUnit.Util
31 {
32         using System;
33         using System.IO;
34
35         /// <summary>
36         /// Abstract class representing a hierarchical storage used to hold
37         /// application settings. The actual implementation is left to 
38         /// derived classes, and may be based on the registry, isolated
39         /// storage or any other mechanism.
40         /// </summary>
41         public abstract class SettingsStorage : IDisposable
42         {
43                 #region Instance Variables
44
45                 /// <summary>
46                 /// The name of this storage
47                 /// </summary>
48                 private string storageName;
49                 
50                 /// <summary>
51                 /// The parent storage containing this storage
52                 /// </summary>
53                 private SettingsStorage parentStorage;
54                 #endregion
55
56                 #region Construction and Disposal
57
58                 /// <summary>
59                 /// Construct a SettingsStorage under a parent storage
60                 /// </summary>
61                 /// <param name="storageName">Name of the storage</param>
62                 /// <param name="parentStorage">The parent which contains the new storage</param>
63                 public SettingsStorage( string storageName, SettingsStorage parentStorage )
64                 {
65                         this.storageName = storageName;
66                         this.parentStorage = parentStorage;
67                 }
68
69                 /// <summary>
70                 /// Dispose of resources held by this storage
71                 /// </summary>
72                 public abstract void Dispose();
73
74                 #endregion
75
76                 #region Properties
77
78                 /// <summary>
79                 /// The number of settings in this group
80                 /// </summary>
81                 public abstract int SettingsCount
82                 {
83                         get;
84                 }
85
86                 /// <summary>
87                 /// The name of the storage
88                 /// </summary>
89                 public string StorageName
90                 {
91                         get { return storageName; }
92                 }
93
94                 /// <summary>
95                 /// The storage that contains this one
96                 /// </summary>
97                 public SettingsStorage ParentStorage
98                 {
99                         get { return parentStorage; }
100                 }
101
102                 #endregion
103
104                 #region Methods
105
106                 /// <summary>
107                 /// Find out if a substorage exists
108                 /// </summary>
109                 /// <param name="name">Name of the child storage</param>
110                 /// <returns>True if the storage exists</returns>
111                 public abstract bool ChildStorageExists( string name );
112
113                 /// <summary>
114                 /// Create a child storage of the same type
115                 /// </summary>
116                 /// <param name="name">Name of the child storage</param>
117                 /// <returns>New child storage</returns>
118                 public abstract SettingsStorage MakeChildStorage( string name );
119
120                 /// <summary>
121                 /// Clear all settings from the storage - empty storage remains
122                 /// </summary>
123                 public abstract void Clear();
124
125                 /// <summary>
126                 /// Load a setting from the storage.
127                 /// </summary>
128                 /// <param name="settingName">Name of the setting to load</param>
129                 /// <returns>Value of the setting or null</returns>
130                 public abstract object LoadSetting( string settingName );
131
132                 /// <summary>
133                 /// Load an integer setting from the storage
134                 /// </summary>
135                 /// <param name="settingName">Name of the setting to load</param>
136                 /// <returns>Value of the setting or null</returns>
137                 public abstract int LoadIntSetting( string settingName );
138
139                 /// <summary>
140                 /// Load a string setting from the storage
141                 /// </summary>
142                 /// <param name="settingName">Name of the setting to load</param>
143                 /// <returns>Value of the setting or null</returns>
144                 public abstract string LoadStringSetting( string settingName );
145
146                 /// <summary>
147                 /// Load a setting from the storage or return a default value
148                 /// </summary>
149                 /// <param name="settingName">Name of the setting to load</param>
150                 /// <param name="settingName">Value to return if the setting is missing</param>
151                 /// <returns>Value of the setting or the default value</returns>
152                 public abstract object LoadSetting( string settingName, object defaultValue );
153
154                 /// <summary>
155                 /// Load an integer setting from the storage or return a default value
156                 /// </summary>
157                 /// <param name="settingName">Name of the setting to load</param>
158                 /// <param name="settingName">Value to return if the setting is missing</param>
159                 /// <returns>Value of the setting or the default value</returns>
160                 public abstract int LoadIntSetting( string settingName, int defaultValue );
161
162                 /// <summary>
163                 /// Load a string setting from the storage or return a default value
164                 /// </summary>
165                 /// <param name="settingName">Name of the setting to load</param>
166                 /// <param name="settingName">Value to return if the setting is missing</param>
167                 /// <returns>Value of the setting or the default value</returns>
168                 public abstract string LoadStringSetting( string settingName, string defaultValue );
169
170                 /// <summary>
171                 /// Remove a setting from the storage
172                 /// </summary>
173                 /// <param name="settingName">Name of the setting to remove</param>
174                 public abstract void RemoveSetting( string settingName );
175
176                 /// <summary>
177                 /// Save a setting in the storage
178                 /// </summary>
179                 /// <param name="settingName">Name of the setting to save</param>
180                 /// <param name="settingValue">Value to be saved</param>
181                 public abstract void SaveSetting( string settingName, object settingValue );
182
183                 #endregion
184         }
185 }