Fixed the licensing statements - I had erroneously marked the files as covered by...
[lwes-dotnet/github-mirror.git] / Org.Lwes / Config / TemplateDBConfigurationSection.cs
bloba22353cf0f5a655248a1e43f6e2a54cc10f5fe6c
1 //
2 // This file is part of the LWES .NET Binding (LWES.net)
3 //
4 // COPYRIGHT (C) 2009, Phillip Clark (cerebralkungfu[at*g mail[dot*com)
5 // original .NET implementation
6 //
7 // LWES.net is free software: you can redistribute it and/or modify
8 // it under the terms of the Lesser GNU General Public License as published by
9 // the Free Software Foundation, either version 3 of the License, or
10 // (at your option) any later version.
12 // LWES.net is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the Lesser GNU General Public License
18 // along with LWES.net. If not, see <http://www.gnu.org/licenses/>.
20 namespace Org.Lwes.Config
22 using System;
23 using System.Collections.Generic;
24 using System.Configuration;
25 using System.Linq;
26 using System.Net;
27 using System.Text;
29 /// <summary>
30 /// Configuration section for an event template DB.
31 /// </summary>
32 public class TemplateDBConfigurationSection : ConfigurationSection
34 #region Fields
36 /// <summary>
37 /// Property name for includeSubdirectories
38 /// </summary>
39 public const string PropertyName_includeSubdirectories = "includeSubdirectories";
41 /// <summary>
42 /// Property name for the tempate DB's name.
43 /// </summary>
44 public const string PropertyName_name = "name";
46 /// <summary>
47 /// Property name for the path.
48 /// </summary>
49 public const string PropertyName_path = "path";
51 private static readonly string AppPathToken = "$(AppPath)";
52 private static readonly int AppPathTokenLength = AppPathToken.Length;
54 #endregion Fields
56 #region Properties
58 /// <summary>
59 /// Path where the template DB should look for '.esf' files.
60 /// </summary>
61 [ConfigurationProperty(PropertyName_includeSubdirectories
62 , IsRequired = false
63 , DefaultValue = false)]
64 public bool IncludeSubdirectories
66 get { return (bool)this[PropertyName_includeSubdirectories]; }
67 set
69 this[PropertyName_includeSubdirectories] = value;
73 /// <summary>
74 /// The name of the configured template DB.
75 /// </summary>
76 [ConfigurationProperty(PropertyName_name, IsRequired = true)]
77 public string Name
79 get { return (string)this[PropertyName_name]; }
80 set { this[PropertyName_name] = value; }
83 /// <summary>
84 /// Path where the template DB should look for '.esf' files.
85 /// </summary>
86 [ConfigurationProperty(PropertyName_path
87 , IsRequired = true)]
88 public string Path
90 get { return (string)this[PropertyName_path]; }
91 set
93 this[PropertyName_path] = (!String.IsNullOrEmpty(value) && value.Contains("$"))
94 ? ReplacePathTokens(value)
95 : value;
99 #endregion Properties
101 #region Methods
103 private string ReplacePathTokens(string value)
105 // The only token supported right now is the app-path, which must appear
106 // at the beginning of the string...
107 if (value.StartsWith(AppPathToken, StringComparison.InvariantCultureIgnoreCase))
109 return String.Concat(AppDomain.CurrentDomain.SetupInformation.ApplicationBase,
110 value.Substring(AppPathTokenLength - 1));
112 else return value;
115 #endregion Methods