Showing the changes to Source/Libraries/GSF.Core/Configuration/CategorizedSettingsElementCollection.cs (1 of 628 files). Show all
Unified · Split
| @@ -0,0 +1,523 @@ | ||
| 1 | +//******************************************************************************************************* | |
| 2 | +// CategorizedSettingsElementCollection.cs - Gbtc | |
| 3 | +// | |
| 4 | +// Tennessee Valley Authority, 2009 | |
| 5 | +// No copyright is claimed pursuant to 17 USC § 105. All Other Rights Reserved. | |
| 6 | +// | |
| 7 | +// This software is made freely available under the TVA Open Source Agreement (see below). | |
| 8 | +// | |
| 9 | +// Code Modification History: | |
| 10 | +// ----------------------------------------------------------------------------------------------------- | |
| 11 | +// 04/11/2006 - Pinal C. Patel | |
| 12 | +// Generated original version of source code. | |
| 13 | +// 05/25/2006 - Pinal C. Patel | |
| 14 | +// Modified the Item(name) property to add a configuration element if it does not exist. | |
| 15 | +// 08/17/2007 - Darrell Zuercher | |
| 16 | +// Edited code comments. | |
| 17 | +// 09/17/2008 - Pinal C. Patel | |
| 18 | +// Converted code to C#. | |
| 19 | +// 09/29/2008 - Pinal C. Patel | |
| 20 | +// Reviewed code comments. | |
| 21 | +// 09/14/2009 - Stephen C. Wills | |
| 22 | +// Added new header and license agreement. | |
| 23 | +// 04/20/2010 - Pinal C. Patel | |
| 24 | +// Added new Name and Section properties for the purpose of managing user scope setting. | |
| 25 | +// 04/21/2010 - Pinal C. Patel | |
| 26 | +// Removed unnecessary overloads of Add() for manageability. | |
| 27 | +// | |
| 28 | +//******************************************************************************************************* | |
| 29 | + | |
| 30 | +#region [ TVA Open Source Agreement ] | |
| 31 | +/* | |
| 32 | + | |
| 33 | + THIS OPEN SOURCE AGREEMENT ("AGREEMENT") DEFINES THE RIGHTS OF USE,REPRODUCTION, DISTRIBUTION, | |
| 34 | + MODIFICATION AND REDISTRIBUTION OF CERTAIN COMPUTER SOFTWARE ORIGINALLY RELEASED BY THE | |
| 35 | + TENNESSEE VALLEY AUTHORITY, A CORPORATE AGENCY AND INSTRUMENTALITY OF THE UNITED STATES GOVERNMENT | |
| 36 | + ("GOVERNMENT AGENCY"). GOVERNMENT AGENCY IS AN INTENDED THIRD-PARTY BENEFICIARY OF ALL SUBSEQUENT | |
| 37 | + DISTRIBUTIONS OR REDISTRIBUTIONS OF THE SUBJECT SOFTWARE. ANYONE WHO USES, REPRODUCES, DISTRIBUTES, | |
| 38 | + MODIFIES OR REDISTRIBUTES THE SUBJECT SOFTWARE, AS DEFINED HEREIN, OR ANY PART THEREOF, IS, BY THAT | |
| 39 | + ACTION, ACCEPTING IN FULL THE RESPONSIBILITIES AND OBLIGATIONS CONTAINED IN THIS AGREEMENT. | |
| 40 | + | |
| 41 | + Original Software Designation: openPDC | |
| 42 | + Original Software Title: The GSF Open Source Phasor Data Concentrator | |
| 43 | + User Registration Requested. Please Visit https://naspi.tva.com/Registration/ | |
| 44 | + Point of Contact for Original Software: J. Ritchie Carroll <mailto:jrcarrol@tva.gov> | |
| 45 | + | |
| 46 | + 1. DEFINITIONS | |
| 47 | + | |
| 48 | + A. "Contributor" means Government Agency, as the developer of the Original Software, and any entity | |
| 49 | + that makes a Modification. | |
| 50 | + | |
| 51 | + B. "Covered Patents" mean patent claims licensable by a Contributor that are necessarily infringed by | |
| 52 | + the use or sale of its Modification alone or when combined with the Subject Software. | |
| 53 | + | |
| 54 | + C. "Display" means the showing of a copy of the Subject Software, either directly or by means of an | |
| 55 | + image, or any other device. | |
| 56 | + | |
| 57 | + D. "Distribution" means conveyance or transfer of the Subject Software, regardless of means, to | |
| 58 | + another. | |
| 59 | + | |
| 60 | + E. "Larger Work" means computer software that combines Subject Software, or portions thereof, with | |
| 61 | + software separate from the Subject Software that is not governed by the terms of this Agreement. | |
| 62 | + | |
| 63 | + F. "Modification" means any alteration of, including addition to or deletion from, the substance or | |
| 64 | + structure of either the Original Software or Subject Software, and includes derivative works, as that | |
| 65 | + term is defined in the Copyright Statute, 17 USC § 101. However, the act of including Subject Software | |
| 66 | + as part of a Larger Work does not in and of itself constitute a Modification. | |
| 67 | + | |
| 68 | + G. "Original Software" means the computer software first released under this Agreement by Government | |
| 69 | + Agency entitled openPDC, including source code, object code and accompanying documentation, if any. | |
| 70 | + | |
| 71 | + H. "Recipient" means anyone who acquires the Subject Software under this Agreement, including all | |
| 72 | + Contributors. | |
| 73 | + | |
| 74 | + I. "Redistribution" means Distribution of the Subject Software after a Modification has been made. | |
| 75 | + | |
| 76 | + J. "Reproduction" means the making of a counterpart, image or copy of the Subject Software. | |
| 77 | + | |
| 78 | + K. "Sale" means the exchange of the Subject Software for money or equivalent value. | |
| 79 | + | |
| 80 | + L. "Subject Software" means the Original Software, Modifications, or any respective parts thereof. | |
| 81 | + | |
| 82 | + M. "Use" means the application or employment of the Subject Software for any purpose. | |
| 83 | + | |
| 84 | + 2. GRANT OF RIGHTS | |
| 85 | + | |
| 86 | + A. Under Non-Patent Rights: Subject to the terms and conditions of this Agreement, each Contributor, | |
| 87 | + with respect to its own contribution to the Subject Software, hereby grants to each Recipient a | |
| 88 | + non-exclusive, world-wide, royalty-free license to engage in the following activities pertaining to | |
| 89 | + the Subject Software: | |
| 90 | + | |
| 91 | + 1. Use | |
| 92 | + | |
| 93 | + 2. Distribution | |
| 94 | + | |
| 95 | + 3. Reproduction | |
| 96 | + | |
| 97 | + 4. Modification | |
| 98 | + | |
| 99 | + 5. Redistribution | |
| 100 | + | |
| 101 | + 6. Display | |
| 102 | + | |
| 103 | + B. Under Patent Rights: Subject to the terms and conditions of this Agreement, each Contributor, with | |
| 104 | + respect to its own contribution to the Subject Software, hereby grants to each Recipient under Covered | |
| 105 | + Patents a non-exclusive, world-wide, royalty-free license to engage in the following activities | |
| 106 | + pertaining to the Subject Software: | |
| 107 | + | |
| 108 | + 1. Use | |
| 109 | + | |
| 110 | + 2. Distribution | |
| 111 | + | |
| 112 | + 3. Reproduction | |
| 113 | + | |
| 114 | + 4. Sale | |
| 115 | + | |
| 116 | + 5. Offer for Sale | |
| 117 | + | |
| 118 | + C. The rights granted under Paragraph B. also apply to the combination of a Contributor's Modification | |
| 119 | + and the Subject Software if, at the time the Modification is added by the Contributor, the addition of | |
| 120 | + such Modification causes the combination to be covered by the Covered Patents. It does not apply to | |
| 121 | + any other combinations that include a Modification. | |
| 122 | + | |
| 123 | + D. The rights granted in Paragraphs A. and B. allow the Recipient to sublicense those same rights. | |
| 124 | + Such sublicense must be under the same terms and conditions of this Agreement. | |
| 125 | + | |
| 126 | + 3. OBLIGATIONS OF RECIPIENT | |
| 127 | + | |
| 128 | + A. Distribution or Redistribution of the Subject Software must be made under this Agreement except for | |
| 129 | + additions covered under paragraph 3H. | |
| 130 | + | |
| 131 | + 1. Whenever a Recipient distributes or redistributes the Subject Software, a copy of this Agreement | |
| 132 | + must be included with each copy of the Subject Software; and | |
| 133 | + | |
| 134 | + 2. If Recipient distributes or redistributes the Subject Software in any form other than source code, | |
| 135 | + Recipient must also make the source code freely available, and must provide with each copy of the | |
| 136 | + Subject Software information on how to obtain the source code in a reasonable manner on or through a | |
| 137 | + medium customarily used for software exchange. | |
| 138 | + | |
| 139 | + B. Each Recipient must ensure that the following copyright notice appears prominently in the Subject | |
| 140 | + Software: | |
| 141 | + | |
| 142 | + No copyright is claimed pursuant to 17 USC § 105. All Other Rights Reserved. | |
| 143 | + | |
| 144 | + C. Each Contributor must characterize its alteration of the Subject Software as a Modification and | |
| 145 | + must identify itself as the originator of its Modification in a manner that reasonably allows | |
| 146 | + subsequent Recipients to identify the originator of the Modification. In fulfillment of these | |
| 147 | + requirements, Contributor must include a file (e.g., a change log file) that describes the alterations | |
| 148 | + made and the date of the alterations, identifies Contributor as originator of the alterations, and | |
| 149 | + consents to characterization of the alterations as a Modification, for example, by including a | |
| 150 | + statement that the Modification is derived, directly or indirectly, from Original Software provided by | |
| 151 | + Government Agency. Once consent is granted, it may not thereafter be revoked. | |
| 152 | + | |
| 153 | + D. A Contributor may add its own copyright notice to the Subject Software. Once a copyright notice has | |
| 154 | + been added to the Subject Software, a Recipient may not remove it without the express permission of | |
| 155 | + the Contributor who added the notice. | |
| 156 | + | |
| 157 | + E. A Recipient may not make any representation in the Subject Software or in any promotional, | |
| 158 | + advertising or other material that may be construed as an endorsement by Government Agency or by any | |
| 159 | + prior Recipient of any product or service provided by Recipient, or that may seek to obtain commercial | |
| 160 | + advantage by the fact of Government Agency's or a prior Recipient's participation in this Agreement. | |
| 161 | + | |
| 162 | + F. In an effort to track usage and maintain accurate records of the Subject Software, each Recipient, | |
| 163 | + upon receipt of the Subject Software, is requested to register with Government Agency by visiting the | |
| 164 | + following website: https://naspi.tva.com/Registration/. Recipient's name and personal information | |
| 165 | + shall be used for statistical purposes only. Once a Recipient makes a Modification available, it is | |
| 166 | + requested that the Recipient inform Government Agency at the web site provided above how to access the | |
| 167 | + Modification. | |
| 168 | + | |
| 169 | + G. Each Contributor represents that that its Modification does not violate any existing agreements, | |
| 170 | + regulations, statutes or rules, and further that Contributor has sufficient rights to grant the rights | |
| 171 | + conveyed by this Agreement. | |
| 172 | + | |
| 173 | + H. A Recipient may choose to offer, and to charge a fee for, warranty, support, indemnity and/or | |
| 174 | + liability obligations to one or more other Recipients of the Subject Software. A Recipient may do so, | |
| 175 | + however, only on its own behalf and not on behalf of Government Agency or any other Recipient. Such a | |
| 176 | + Recipient must make it absolutely clear that any such warranty, support, indemnity and/or liability | |
| 177 | + obligation is offered by that Recipient alone. Further, such Recipient agrees to indemnify Government | |
| 178 | + Agency and every other Recipient for any liability incurred by them as a result of warranty, support, | |
| 179 | + indemnity and/or liability offered by such Recipient. | |
| 180 | + | |
| 181 | + I. A Recipient may create a Larger Work by combining Subject Software with separate software not | |
| 182 | + governed by the terms of this agreement and distribute the Larger Work as a single product. In such | |
| 183 | + case, the Recipient must make sure Subject Software, or portions thereof, included in the Larger Work | |
| 184 | + is subject to this Agreement. | |
| 185 | + | |
| 186 | + J. Notwithstanding any provisions contained herein, Recipient is hereby put on notice that export of | |
| 187 | + any goods or technical data from the United States may require some form of export license from the | |
| 188 | + U.S. Government. Failure to obtain necessary export licenses may result in criminal liability under | |
| 189 | + U.S. laws. Government Agency neither represents that a license shall not be required nor that, if | |
| 190 | + required, it shall be issued. Nothing granted herein provides any such export license. | |
| 191 | + | |
| 192 | + 4. DISCLAIMER OF WARRANTIES AND LIABILITIES; WAIVER AND INDEMNIFICATION | |
| 193 | + | |
| 194 | + A. No Warranty: THE SUBJECT SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY OF ANY KIND, EITHER | |
| 195 | + EXPRESSED, IMPLIED, OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, ANY WARRANTY THAT THE SUBJECT | |
| 196 | + SOFTWARE WILL CONFORM TO SPECIFICATIONS, ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A | |
| 197 | + PARTICULAR PURPOSE, OR FREEDOM FROM INFRINGEMENT, ANY WARRANTY THAT THE SUBJECT SOFTWARE WILL BE ERROR | |
| 198 | + FREE, OR ANY WARRANTY THAT DOCUMENTATION, IF PROVIDED, WILL CONFORM TO THE SUBJECT SOFTWARE. THIS | |
| 199 | + AGREEMENT DOES NOT, IN ANY MANNER, CONSTITUTE AN ENDORSEMENT BY GOVERNMENT AGENCY OR ANY PRIOR | |
| 200 | + RECIPIENT OF ANY RESULTS, RESULTING DESIGNS, HARDWARE, SOFTWARE PRODUCTS OR ANY OTHER APPLICATIONS | |
| 201 | + RESULTING FROM USE OF THE SUBJECT SOFTWARE. FURTHER, GOVERNMENT AGENCY DISCLAIMS ALL WARRANTIES AND | |
| 202 | + LIABILITIES REGARDING THIRD-PARTY SOFTWARE, IF PRESENT IN THE ORIGINAL SOFTWARE, AND DISTRIBUTES IT | |
| 203 | + "AS IS." | |
| 204 | + | |
| 205 | + B. Waiver and Indemnity: RECIPIENT AGREES TO WAIVE ANY AND ALL CLAIMS AGAINST GOVERNMENT AGENCY, ITS | |
| 206 | + AGENTS, EMPLOYEES, CONTRACTORS AND SUBCONTRACTORS, AS WELL AS ANY PRIOR RECIPIENT. IF RECIPIENT'S USE | |
| 207 | + OF THE SUBJECT SOFTWARE RESULTS IN ANY LIABILITIES, DEMANDS, DAMAGES, EXPENSES OR LOSSES ARISING FROM | |
| 208 | + SUCH USE, INCLUDING ANY DAMAGES FROM PRODUCTS BASED ON, OR RESULTING FROM, RECIPIENT'S USE OF THE | |
| 209 | + SUBJECT SOFTWARE, RECIPIENT SHALL INDEMNIFY AND HOLD HARMLESS GOVERNMENT AGENCY, ITS AGENTS, | |
| 210 | + EMPLOYEES, CONTRACTORS AND SUBCONTRACTORS, AS WELL AS ANY PRIOR RECIPIENT, TO THE EXTENT PERMITTED BY | |
| 211 | + LAW. THE FOREGOING RELEASE AND INDEMNIFICATION SHALL APPLY EVEN IF THE LIABILITIES, DEMANDS, DAMAGES, | |
| 212 | + EXPENSES OR LOSSES ARE CAUSED, OCCASIONED, OR CONTRIBUTED TO BY THE NEGLIGENCE, SOLE OR CONCURRENT, OF | |
| 213 | + GOVERNMENT AGENCY OR ANY PRIOR RECIPIENT. RECIPIENT'S SOLE REMEDY FOR ANY SUCH MATTER SHALL BE THE | |
| 214 | + IMMEDIATE, UNILATERAL TERMINATION OF THIS AGREEMENT. | |
| 215 | + | |
| 216 | + 5. GENERAL TERMS | |
| 217 | + | |
| 218 | + A. Termination: This Agreement and the rights granted hereunder will terminate automatically if a | |
| 219 | + Recipient fails to comply with these terms and conditions, and fails to cure such noncompliance within | |
| 220 | + thirty (30) days of becoming aware of such noncompliance. Upon termination, a Recipient agrees to | |
| 221 | + immediately cease use and distribution of the Subject Software. All sublicenses to the Subject | |
| 222 | + Software properly granted by the breaching Recipient shall survive any such termination of this | |
| 223 | + Agreement. | |
| 224 | + | |
| 225 | + B. Severability: If any provision of this Agreement is invalid or unenforceable under applicable law, | |
| 226 | + it shall not affect the validity or enforceability of the remainder of the terms of this Agreement. | |
| 227 | + | |
| 228 | + C. Applicable Law: This Agreement shall be subject to United States federal law only for all purposes, | |
| 229 | + including, but not limited to, determining the validity of this Agreement, the meaning of its | |
| 230 | + provisions and the rights, obligations and remedies of the parties. | |
| 231 | + | |
| 232 | + D. Entire Understanding: This Agreement constitutes the entire understanding and agreement of the | |
| 233 | + parties relating to release of the Subject Software and may not be superseded, modified or amended | |
| 234 | + except by further written agreement duly executed by the parties. | |
| 235 | + | |
| 236 | + E. Binding Authority: By accepting and using the Subject Software under this Agreement, a Recipient | |
| 237 | + affirms its authority to bind the Recipient to all terms and conditions of this Agreement and that | |
| 238 | + Recipient hereby agrees to all terms and conditions herein. | |
| 239 | + | |
| 240 | + F. Point of Contact: Any Recipient contact with Government Agency is to be directed to the designated | |
| 241 | + representative as follows: J. Ritchie Carroll <mailto:jrcarrol@tva.gov>. | |
| 242 | + | |
| 243 | +*/ | |
| 244 | +#endregion | |
| 245 | + | |
| 246 | +using System; | |
| 247 | +using System.Configuration; | |
| 248 | + | |
| 249 | +namespace GSF.Configuration | |
| 250 | +{ | |
| 251 | + /// <summary> | |
| 252 | + /// Represents a collection of <see cref="CategorizedSettingsElement"/> objects. | |
| 253 | + /// </summary> | |
| 254 | + public class CategorizedSettingsElementCollection : ConfigurationElementCollection | |
| 255 | + { | |
| 256 | + #region [ Members ] | |
| 257 | + | |
| 258 | + // Fields | |
| 259 | + private string m_name; | |
| 260 | + private string m_cryptoKey; | |
| 261 | + private CategorizedSettingsSection m_section; | |
| 262 | + | |
| 263 | + #endregion | |
| 264 | + | |
| 265 | + #region [ Properties ] | |
| 266 | + | |
| 267 | + /// <summary> | |
| 268 | + /// Gets or sets the name of the <see cref="CategorizedSettingsElementCollection"/>. | |
| 269 | + /// </summary> | |
| 270 | + public string Name | |
| 271 | + { | |
| 272 | + get | |
| 273 | + { | |
| 274 | + return m_name; | |
| 275 | + } | |
| 276 | + internal set | |
| 277 | + { | |
| 278 | + m_name = value; | |
| 279 | + } | |
| 280 | + } | |
| 281 | + | |
| 282 | + /// <summary> | |
| 283 | + /// Gets or sets the <see cref="CategorizedSettingsSection"/> to which this <see cref="CategorizedSettingsElementCollection"/> belongs. | |
| 284 | + /// </summary> | |
| 285 | + public CategorizedSettingsSection Section | |
| 286 | + { | |
| 287 | + get | |
| 288 | + { | |
| 289 | + return m_section; | |
| 290 | + } | |
| 291 | + internal set | |
| 292 | + { | |
| 293 | + m_section = value; | |
| 294 | + } | |
| 295 | + } | |
| 296 | + | |
| 297 | + /// <summary> | |
| 298 | + /// Gets or sets the <see cref="CategorizedSettingsElement"/> object at the specified index. | |
| 299 | + /// </summary> | |
| 300 | + /// <param name="index">Zero-based index for the <see cref="CategorizedSettingsElement"/> object to retrieve.</param> | |
| 301 | + /// <returns>The <see cref="CategorizedSettingsElement"/> object at the specified index if it exists; otherwise null.</returns> | |
| 302 | + public CategorizedSettingsElement this[int index] | |
| 303 | + { | |
| 304 | + get | |
| 305 | + { | |
| 306 | + if (index >= base.Count) | |
| 307 | + throw new IndexOutOfRangeException(); | |
| 308 | + | |
| 309 | + CategorizedSettingsElement setting = (CategorizedSettingsElement)base.BaseGet(index); | |
| 310 | + setting.SetCryptoKey(m_cryptoKey); | |
| 311 | + | |
| 312 | + return setting; | |
| 313 | + } | |
| 314 | + set | |
| 315 | + { | |
| 316 | + if ((object)base.BaseGet(index) != null) | |
| 317 | + base.BaseRemoveAt(index); | |
| 318 | + | |
| 319 | + base.BaseAdd(index, value); | |
| 320 | + } | |
| 321 | + } | |
| 322 | + | |
| 323 | + /// <summary> | |
| 324 | + /// Gets the <see cref="CategorizedSettingsElement"/> object with the specified name. | |
| 325 | + /// </summary> | |
| 326 | + /// <param name="name">Name of the <see cref="CategorizedSettingsElement"/> object to retrieve.</param> | |
| 327 | + /// <returns>The <see cref="CategorizedSettingsElement"/> object with the specified name if it exists; otherwise null.</returns> | |
| 328 | + public new CategorizedSettingsElement this[string name] | |
| 329 | + { | |
| 330 | + get | |
| 331 | + { | |
| 332 | + return this[name, false]; | |
| 333 | + } | |
| 334 | + } | |
| 335 | + | |
| 336 | + /// <summary> | |
| 337 | + /// Gets the <see cref="CategorizedSettingsElement"/> object with the specified name. | |
| 338 | + /// </summary> | |
| 339 | + /// <param name="name">Name of the <see cref="CategorizedSettingsElement"/> object to retrieve.</param> | |
| 340 | + /// <param name="ensureExistance">true if the <see cref="CategorizedSettingsElement"/> object is to be created if it does not exist; otherwise false.</param> | |
| 341 | + /// <returns>The <see cref="CategorizedSettingsElement"/> object with the specified name if it exists; otherwise null.</returns> | |
| 342 | + public CategorizedSettingsElement this[string name, bool ensureExistance] | |
| 343 | + { | |
| 344 | + get | |
| 345 | + { | |
| 346 | + if (ensureExistance && (object)base.BaseGet(name) == null) | |
| 347 | + { | |
| 348 | + // Add setting since it's not there. | |
| 349 | + Add(name, string.Empty); | |
| 350 | + } | |
| 351 | + | |
| 352 | + CategorizedSettingsElement setting = (CategorizedSettingsElement)base.BaseGet(name); | |
| 353 | + if ((object)setting != null) | |
| 354 | + { | |
| 355 | + // Set the crypto key for the setting. | |
| 356 | + setting.SetCryptoKey(m_cryptoKey); | |
| 357 | + } | |
| 358 | + | |
| 359 | + return setting; | |
| 360 | + } | |
| 361 | + } | |
| 362 | + | |
| 363 | + #endregion | |
| 364 | + | |
| 365 | + #region [ Methods ] | |
| 366 | + | |
| 367 | + /// <summary> | |
| 368 | + /// Sets the key to be used for encrypting and decrypting setting values. | |
| 369 | + /// </summary> | |
| 370 | + /// <param name="cryptoKey">New crypto key.</param> | |
| 371 | + public void SetCryptoKey(string cryptoKey) | |
| 372 | + { | |
| 373 | + m_cryptoKey = cryptoKey; | |
| 374 | + } | |
| 375 | + | |
| 376 | + /// <summary> | |
| 377 | + /// Gets the index of the specified <see cref="CategorizedSettingsElement"/> object. | |
| 378 | + /// </summary> | |
| 379 | + /// <param name="setting">The <see cref="CategorizedSettingsElement"/> object whose index is to be retrieved.</param> | |
| 380 | + /// <returns>Index of the specified <see cref="CategorizedSettingsElement"/> object if found; otherwise -1.</returns> | |
| 381 | + public int IndexOf(CategorizedSettingsElement setting) | |
| 382 | + { | |
| 383 | + return base.BaseIndexOf(setting); | |
| 384 | + } | |
| 385 | + | |
| 386 | + /// <summary> | |
| 387 | + /// Adds a new <see cref="CategorizedSettingsElement"/> object if one does not exist. | |
| 388 | + /// </summary> | |
| 389 | + /// <param name="name">Name of the <see cref="CategorizedSettingsElement"/> object.</param> | |
| 390 | + /// <param name="value">Value of the <see cref="CategorizedSettingsElement"/> object.</param> | |
| 391 | + public void Add(string name, object value) | |
| 392 | + { | |
| 393 | + Add(name, value, CategorizedSettingsElement.DefaultDescription, CategorizedSettingsElement.DefaultEncrypted, CategorizedSettingsElement.DefaultScope); | |
| 394 | + } | |
| 395 | + | |
| 396 | + /// <summary> | |
| 397 | + /// Adds a new <see cref="CategorizedSettingsElement"/> object if one does not exist. | |
| 398 | + /// </summary> | |
| 399 | + /// <param name="name">Name of the <see cref="CategorizedSettingsElement"/> object.</param> | |
| 400 | + /// <param name="value">Value of the <see cref="CategorizedSettingsElement"/> object.</param> | |
| 401 | + /// <param name="description">Description of the <see cref="CategorizedSettingsElement"/> object.</param> | |
| 402 | + public void Add(string name, object value, string description) | |
| 403 | + { | |
| 404 | + Add(name, value, description, CategorizedSettingsElement.DefaultEncrypted, CategorizedSettingsElement.DefaultScope); | |
| 405 | + } | |
| 406 | + | |
| 407 | + /// <summary> | |
| 408 | + /// Adds a new <see cref="CategorizedSettingsElement"/> object if one does not exist. | |
| 409 | + /// </summary> | |
| 410 | + /// <param name="name">Name of the <see cref="CategorizedSettingsElement"/> object.</param> | |
| 411 | + /// <param name="value">Value of the <see cref="CategorizedSettingsElement"/> object.</param> | |
| 412 | + /// <param name="description">Description of the <see cref="CategorizedSettingsElement"/> object.</param> | |
| 413 | + /// <param name="encryptValue">true if the Value of <see cref="CategorizedSettingsElement"/> object is to be encrypted; otherwise false.</param> | |
| 414 | + public void Add(string name, object value, string description, bool encryptValue) | |
| 415 | + { | |
| 416 | + Add(name, value, description, encryptValue, CategorizedSettingsElement.DefaultScope); | |
| 417 | + } | |
| 418 | + | |
| 419 | + /// <summary> | |
| 420 | + /// Adds a new <see cref="CategorizedSettingsElement"/> object if one does not exist. | |
| 421 | + /// </summary> | |
| 422 | + /// <param name="name">Name of the <see cref="CategorizedSettingsElement"/> object.</param> | |
| 423 | + /// <param name="value">Value of the <see cref="CategorizedSettingsElement"/> object.</param> | |
| 424 | + /// <param name="description">Description of the <see cref="CategorizedSettingsElement"/> object.</param> | |
| 425 | + /// <param name="encryptValue">true if the Value of <see cref="CategorizedSettingsElement"/> object is to be encrypted; otherwise false.</param> | |
| 426 | + /// <param name="scope">One of the <see cref="SettingScope"/> values.</param> | |
| 427 | + public void Add(string name, object value, string description, bool encryptValue, SettingScope scope) | |
| 428 | + { | |
| 429 | + if ((object)base.BaseGet(name) == null) | |
| 430 | + { | |
| 431 | + // Add the element only if it does not exist. | |
| 432 | + CategorizedSettingsElement setting = new CategorizedSettingsElement(this, name); | |
| 433 | + setting.Update(value, description, encryptValue, scope); | |
| 434 | + | |
| 435 | + Add(setting); | |
| 436 | + } | |
| 437 | + } | |
| 438 | + | |
| 439 | + /// <summary> | |
| 440 | + /// Adds a new <see cref="CategorizedSettingsElement"/> object if one does not exist. | |
| 441 | + /// </summary> | |
| 442 | + /// <param name="setting">The <see cref="CategorizedSettingsElement"/> object to add.</param> | |
| 443 | + public void Add(CategorizedSettingsElement setting) | |
| 444 | + { | |
| 445 | + if ((object)base.BaseGet(setting.Name) == null) | |
| 446 | + { | |
| 447 | + // Add the element only if it does not exist. | |
| 448 | + setting.Category = this; | |
| 449 | + setting.SetCryptoKey(m_cryptoKey); | |
| 450 | + base.BaseAdd(setting); | |
| 451 | + } | |
| 452 | + } | |
| 453 | + | |
| 454 | + /// <summary> | |
| 455 | + /// Removes a <see cref="CategorizedSettingsElement"/> object if it exists. | |
| 456 | + /// </summary> | |
| 457 | + /// <param name="name">Name of the <see cref="CategorizedSettingsElement"/> object to remove.</param> | |
| 458 | + public void Remove(string name) | |
| 459 | + { | |
| 460 | + base.BaseRemove(name); | |
| 461 | + } | |
| 462 | + | |
| 463 | + /// <summary> | |
| 464 | + /// Removes a <see cref="CategorizedSettingsElement"/> object if it exists. | |
| 465 | + /// </summary> | |
| 466 | + /// <param name="setting">The <see cref="CategorizedSettingsElement"/> object to remove.</param> | |
| 467 | + public void Remove(CategorizedSettingsElement setting) | |
| 468 | + { | |
| 469 | + if (base.BaseIndexOf(setting) >= 0) | |
| 470 | + { | |
| 471 | + Remove(setting.Name); | |
| 472 | + } | |
| 473 | + } | |
| 474 | + | |
| 475 | + /// <summary> | |
| 476 | + /// Removes the <see cref="CategorizedSettingsElement"/> object at the specified index location. | |
| 477 | + /// </summary> | |
| 478 | + /// <param name="index">Index location of the <see cref="CategorizedSettingsElement"/> object to remove.</param> | |
| 479 | + public void RemoveAt(int index) | |
| 480 | + { | |
| 481 | + base.BaseRemoveAt(index); | |
| 482 | + } | |
| 483 | + | |
| 484 | + /// <summary> | |
| 485 | + /// Removes all existing <see cref="CategorizedSettingsElement"/> objects. | |
| 486 | + /// </summary> | |
| 487 | + public void Clear() | |
| 488 | + { | |
| 489 | + base.BaseClear(); | |
| 490 | + } | |
| 491 | + | |
| 492 | + /// <summary> | |
| 493 | + /// Creates a new <see cref="CategorizedSettingsElement"/> object. | |
| 494 | + /// </summary> | |
| 495 | + /// <returns>Instance of <see cref="CategorizedSettingsElement"/>.</returns> | |
| 496 | + protected override ConfigurationElement CreateNewElement() | |
| 497 | + { | |
| 498 | + return new CategorizedSettingsElement(this); | |
| 499 | + } | |
| 500 | + | |
| 501 | + /// <summary> | |
| 502 | + /// Creates a new <see cref="CategorizedSettingsElement"/> object. | |
| 503 | + /// </summary> | |
| 504 | + /// <param name="elementName">Name identifying the <see cref="CategorizedSettingsElement"/> object.</param> | |
| 505 | + /// <returns>Instance of <see cref="CategorizedSettingsElement"/>.</returns> | |
| 506 | + protected override ConfigurationElement CreateNewElement(string elementName) | |
| 507 | + { | |
| 508 | + return new CategorizedSettingsElement(this, elementName); | |
| 509 | + } | |
| 510 | + | |
| 511 | + /// <summary> | |
| 512 | + /// Gets the key for a <see cref="CategorizedSettingsElement"/> object. | |
| 513 | + /// </summary> | |
| 514 | + /// <param name="element"><see cref="CategorizedSettingsElement"/> object whose key is to be retrieved.</param> | |
| 515 | + /// <returns>String key value for a <see cref="CategorizedSettingsElement"/> object.</returns> | |
| 516 | + protected override object GetElementKey(ConfigurationElement element) | |
| 517 | + { | |
| 518 | + return ((CategorizedSettingsElement)element).Name; | |
| 519 | + } | |
| 520 | + | |
| 521 | + #endregion | |
| 522 | + } | |
| 523 | +} | |