MyCMMIConfiguration.cs
9.0 KB
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
using System;
using System.Collections;
using System.Configuration;
using System.Xml;
using System.Collections.Specialized;
namespace Comm
{
using SysFramework;
/// <summary>
/// Configuration类中用静态变量保存缺省的配置信息。并提供动态获取配置信息的功能,
/// 动态配置信息写在 MyCMMI.config中
/// <remarks>
/// Special considerations:
/// The MyCMMI application's configuaration settings are kept in
/// the T1Configuration section of the Config.web file. A new
/// instance of this class is created automatically whenever the
/// settings file changes, so there is no need to cache any values.
/// </remarks>
/// </summary>
public class Configuration : IConfigurationSectionHandler
{
//
// Constant values for all expected entries in the T1Configuration section
//
private const String WEB_ENABLEPAGECACHE = "MyCMMI.Web.EnablePageCache";
private const String WEB_PAGECACHEEXPIRESINSECONDS = "MyCMMI.Web.PageCacheExpiresInSeconds";
private const String DATAACCESS_CONNECTIONSTRING = "MyCMMI.DataAccess.ConnectionString";
private const String BIZRULE_SMTPSERVER = "MyCMMI.BizRule.SmtpServer";
private const String BIZRULE_SMTPUSERNAME = "MyCMMI.BizRule.SmtpUserName";
private const String BIZRULE_SMTPPASSWORD = "MyCMMI.BizRule.SmtpPassword";
private const String WEB_ENABLESSL = "MyCMMI.Web.EnableSsl";
private const String WEBSERVICE_CLIENTPATH = "MyCMMI.WebService.ClientPath";
private const String MyCMMI_LICENCEPATH = "MyCMMI.MyCMMI.LicencePath";
private const String MyCMMI_UPDATESWITCH = "MyCMMI.MyCMMI.UpdateSwitch";
private const bool WEB_ENABLEPAGECACHE_DEFAULT = true;
private const int WEB_PAGECACHEEXPIRESINSECONDS_DEFAULT = 3600;
private const String DATAACCESS_CONNECTIONSTRING_DEFAULT = "222207218231207218162222224204201209218208224226179200212216221138179175165228198178197211219213219221212197174221197172217198230206211198229207174219222213216222206158155154155172168217214211203205229207212223151184215228201222170183171177189171";
private const bool WEB_ENABLESSL_DEFAULT = false;
private const String WEBSERVICE_CLIENTPATH_DEFAULT = @"C:\Program Files\Contamination Explorer";
private const String MyCMMI_LICENCEPATH_DEFAULT = @"D:\MyCMMI.lic";
private const String MyCMMI_UPDATESWITCH_DEFAULT = @"True";
private static String dbConnectionString = DATAACCESS_CONNECTIONSTRING_DEFAULT;
private static int pageCacheExpiresInSeconds = WEB_PAGECACHEEXPIRESINSECONDS_DEFAULT;
private static bool enablePageCache = WEB_ENABLEPAGECACHE_DEFAULT;
private static bool enableSsl = WEB_ENABLESSL_DEFAULT;
private static string strClientPath = WEBSERVICE_CLIENTPATH_DEFAULT;
private static string strMyCMMILicencePath = MyCMMI_LICENCEPATH_DEFAULT;
private static string strMyCMMIUpdateSwitch = MyCMMI_UPDATESWITCH_DEFAULT;
/// <summary>
/// Called by ASP+ before the application starts to initialize
/// settings from the Config.Web file(s).
/// <remarks>
/// The app domain will restart if these settings change, so
/// there is no reason to read these values more than once. This
/// function uses the NameValueSectionHandler base class to generate
/// a hashtable from the XML, which is then used to store the current
/// settings. Because all settings are read here, we do not actually
/// store the generated hashtable object for later retrieval by
/// Context.GetConfig
/// . The application should use the accessor
/// functions directly.
/// </remarks>
/// <param name="parent">
/// An object created by processing a section with this name
/// in a Config.Web file in a parent directory.
/// </param>
/// <param name="configContext">An array of Xml information.</param>
/// <param name="section">
/// The Path of the Config.Web file relative to the root
/// of the web server.
/// </param>
/// <returns>
/// <para>
/// A ConfigOutput object, which we leave empty because all settings
/// are stored at this point.
/// </para>
/// </returns>
/// </summary>
public Object Create(Object parent, object configContext, XmlNode section)
{
NameValueCollection settings;
try
{
NameValueSectionHandler baseHandler = new NameValueSectionHandler();
settings = (NameValueCollection)baseHandler.Create(parent, configContext, section);
}
catch
{
settings = null;
}
if (settings == null)
{
dbConnectionString = DATAACCESS_CONNECTIONSTRING_DEFAULT;
pageCacheExpiresInSeconds = WEB_PAGECACHEEXPIRESINSECONDS_DEFAULT;
enablePageCache = WEB_ENABLEPAGECACHE_DEFAULT;
enableSsl = WEB_ENABLESSL_DEFAULT;
strClientPath = WEBSERVICE_CLIENTPATH_DEFAULT;
strMyCMMILicencePath = MyCMMI_LICENCEPATH_DEFAULT;
strMyCMMIUpdateSwitch = MyCMMI_UPDATESWITCH_DEFAULT;
}
else
{
dbConnectionString = ApplicationConfiguration.ReadSetting(settings, DATAACCESS_CONNECTIONSTRING, DATAACCESS_CONNECTIONSTRING_DEFAULT);
pageCacheExpiresInSeconds = ApplicationConfiguration.ReadSetting(settings, WEB_PAGECACHEEXPIRESINSECONDS, WEB_PAGECACHEEXPIRESINSECONDS_DEFAULT);
enablePageCache = ApplicationConfiguration.ReadSetting(settings, WEB_ENABLEPAGECACHE, WEB_ENABLEPAGECACHE_DEFAULT);
enableSsl = ApplicationConfiguration.ReadSetting(settings, WEB_ENABLESSL, WEB_ENABLESSL_DEFAULT);
strClientPath = ApplicationConfiguration.ReadSetting(settings, WEBSERVICE_CLIENTPATH, WEBSERVICE_CLIENTPATH_DEFAULT);
strMyCMMILicencePath = ApplicationConfiguration.ReadSetting(settings, MyCMMI_LICENCEPATH, MyCMMI_LICENCEPATH_DEFAULT);
strMyCMMIUpdateSwitch = ApplicationConfiguration.ReadSetting(settings, MyCMMI_UPDATESWITCH, MyCMMI_UPDATESWITCH_DEFAULT);
}
return settings;
}
/// <value>
/// Property EnablePageCache is used to get MyCMMI's page cache setting.
/// <remarks>Returns true if page caching is enabled, false otherwise.</remarks>
/// </value>
public static bool EnablePageCache
{
get
{
return enablePageCache;
}
}
/// <value>
/// Property PageCacheExpiresInSeconds is used to get MyCMMI's page cache expiration timeout setting.
/// <remarks>The number of seconds before a page cache should expire.</remarks>
/// </value>
public static int PageCacheExpiresInSeconds
{
get
{
return pageCacheExpiresInSeconds;
}
}
/// <value>
/// Property ConnectionString is used to get MyCMMI's database connection string.
/// <remarks>The database connection string.</remarks>
/// </value>
public static String ConnectionString
{
get
{
return dbConnectionString;
}
set
{
dbConnectionString = value;
}
}
/// <value>
/// Property ClientPath is used to get MyCMMI's Client Path string for Auto Client Update Utility.
/// <remarks>Get Client Path</remarks>
/// </value>
public static string ClientPath
{
get
{
return strClientPath;
}
}
/// <summary>
/// Property ClientPath is used to get MyCMMI's Licence Path string for Validate Authority.
/// <remarks>Get Licence Path.</remarks>
/// </summary>
public static string MyCMMILicencePath
{
get
{
return strMyCMMILicencePath;
}
}
/// <summary>
/// Property ClientPath is used to get MyCMMI's Update Switch string for Update .
/// <remarks>Get Update Switch.</remarks>
/// </summary>
public static string MyCMMIUpdateSwitch
{
get
{
return strMyCMMIUpdateSwitch;
}
}
/// <value>
/// Property EnableSsl is used to get MyCMMI's SSL setting.
/// <remarks>True if SSL is enabled, false otherwise.</remarks>
/// </value>
public static bool EnableSsl
{
get
{
return enableSsl;
}
}
}
}