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 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326
|
//------------------------------------------------------------------------------
// <copyright file="FactoryRecord.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
namespace System.Configuration {
using System.Configuration.Internal;
using System.Collections;
using System.Collections.Specialized;
using System.Collections.Generic;
using System.Configuration;
using System.Text;
using System.Threading;
using System.Reflection;
using System.Xml;
[System.Diagnostics.DebuggerDisplay("FactoryRecord {ConfigKey}")]
internal class FactoryRecord : IConfigErrorInfo {
private const int Flag_AllowLocation = 0x0001; // Does the factory allow location directives?
private const int Flag_RestartOnExternalChanges = 0x0002; // Restart on external changes?
private const int Flag_RequirePermission = 0x0004; // Does access to the section require unrestricted ConfigurationPermission?
private const int Flag_IsGroup = 0x0008; // factory represents a group
private const int Flag_IsFromTrustedConfigRecord = 0x0010; // Factory is defined in trusted config record
private const int Flag_IsFactoryTrustedWithoutAptca = 0x0020; // Factory is from trusted assembly without aptca
private const int Flag_IsUndeclared = 0x0040; // Factory is not declared - either implicit or unrecognized
private string _configKey; // full config key = group name + section name
private string _group; // group name
private string _name; // section name
private SimpleBitVector32 _flags; // factory flags
private string _factoryTypeName; // the factory's type name
private ConfigurationAllowDefinition _allowDefinition; // the allowed definition
private ConfigurationAllowExeDefinition _allowExeDefinition; // the allowed Exe definition
private OverrideModeSetting _overrideModeDefault; // the default override mode for the section
private string _filename; // filename of the factory type name
private int _lineNumber; // line number of the factory type name
private object _factory; // the created factory
private List<ConfigurationException> _errors; // errors
// constructor used for Clone()
FactoryRecord(
string configKey,
string group,
string name,
object factory,
string factoryTypeName,
SimpleBitVector32 flags,
ConfigurationAllowDefinition allowDefinition,
ConfigurationAllowExeDefinition allowExeDefinition,
OverrideModeSetting overrideModeDefault,
string filename,
int lineNumber,
ICollection<ConfigurationException> errors) {
_configKey = configKey;
_group = group;
_name = name;
_factory = factory;
_factoryTypeName = factoryTypeName;
_flags = flags;
_allowDefinition = allowDefinition;
_allowExeDefinition = allowExeDefinition;
_overrideModeDefault = overrideModeDefault;
_filename = filename;
_lineNumber = lineNumber;
AddErrors(errors);
}
// constructor used for group
internal FactoryRecord(string configKey, string group, string name, string factoryTypeName, string filename, int lineNumber) {
_configKey = configKey;
_group = group;
_name = name;
_factoryTypeName = factoryTypeName;
IsGroup = true;
_filename = filename;
_lineNumber = lineNumber;
}
// constructor used for a section
internal FactoryRecord(
string configKey,
string group,
string name,
string factoryTypeName,
bool allowLocation,
ConfigurationAllowDefinition allowDefinition,
ConfigurationAllowExeDefinition allowExeDefinition,
OverrideModeSetting overrideModeDefault,
bool restartOnExternalChanges,
bool requirePermission,
bool isFromTrustedConfigRecord,
bool isUndeclared,
string filename,
int lineNumber) {
_configKey = configKey;
_group = group;
_name = name;
_factoryTypeName = factoryTypeName;
_allowDefinition = allowDefinition;
_allowExeDefinition = allowExeDefinition;
_overrideModeDefault = overrideModeDefault;
AllowLocation = allowLocation;
RestartOnExternalChanges = restartOnExternalChanges;
RequirePermission = requirePermission;
IsFromTrustedConfigRecord = isFromTrustedConfigRecord;
IsUndeclared = isUndeclared;
_filename = filename;
_lineNumber = lineNumber;
}
// by cloning we contain a single copy of the strings referred to in the factory and section records
internal FactoryRecord CloneSection(string filename, int lineNumber) {
return new FactoryRecord( _configKey,
_group,
_name,
_factory,
_factoryTypeName,
_flags,
_allowDefinition,
_allowExeDefinition,
_overrideModeDefault,
filename,
lineNumber,
Errors);
}
// by cloning we contain a single copy of the strings referred to in the factory and section records
internal FactoryRecord CloneSectionGroup(string factoryTypeName, string filename, int lineNumber) {
if (_factoryTypeName != null) {
factoryTypeName = _factoryTypeName;
}
return new FactoryRecord( _configKey,
_group,
_name,
_factory,
factoryTypeName,
_flags,
_allowDefinition,
_allowExeDefinition,
_overrideModeDefault,
filename,
lineNumber,
Errors);
}
internal string ConfigKey {
get {return _configKey;}
}
internal string Group {
get {return _group;}
}
internal string Name {
get {return _name;}
}
internal object Factory {
get {return _factory;}
set {_factory = value;}
}
internal string FactoryTypeName {
get {return _factoryTypeName;}
set {_factoryTypeName = value;}
}
internal ConfigurationAllowDefinition AllowDefinition {
get {return _allowDefinition;}
set {_allowDefinition = value;}
}
internal ConfigurationAllowExeDefinition AllowExeDefinition {
get {return _allowExeDefinition;}
set {_allowExeDefinition = value;}
}
internal OverrideModeSetting OverrideModeDefault {
get {return _overrideModeDefault;}
}
internal bool AllowLocation {
get {return _flags[Flag_AllowLocation];}
set {_flags[Flag_AllowLocation] = value;}
}
internal bool RestartOnExternalChanges {
get {return _flags[Flag_RestartOnExternalChanges];}
set {_flags[Flag_RestartOnExternalChanges] = value;}
}
internal bool RequirePermission {
get {return _flags[Flag_RequirePermission];}
set {_flags[Flag_RequirePermission] = value;}
}
internal bool IsGroup {
get {return _flags[Flag_IsGroup];}
set {_flags[Flag_IsGroup] = value;}
}
internal bool IsFromTrustedConfigRecord {
get {return _flags[Flag_IsFromTrustedConfigRecord];}
set {_flags[Flag_IsFromTrustedConfigRecord] = value;}
}
internal bool IsUndeclared {
get {return _flags[Flag_IsUndeclared];}
set {_flags[Flag_IsUndeclared] = value;}
}
internal bool IsFactoryTrustedWithoutAptca {
get {
Debug.Assert(_factory != null, "_factory != null");
return _flags[Flag_IsFactoryTrustedWithoutAptca];
}
set {_flags[Flag_IsFactoryTrustedWithoutAptca] = value;}
}
// This is used in HttpConfigurationRecord.EnsureSectionFactory() to give file and line source
// when a section handler type is invalid or cannot be loaded.
public string Filename {
get {return _filename;}
set {_filename = value;}
}
public int LineNumber {
get {return _lineNumber;}
set {_lineNumber = value;}
}
internal bool HasFile {
get {return _lineNumber >= 0;}
}
internal bool IsEquivalentType(IInternalConfigHost host, string typeName) {
try {
if (_factoryTypeName == typeName)
return true;
Type t1, t2;
if (host != null) {
t1 = TypeUtil.GetTypeWithReflectionPermission(host, typeName, false);
t2 = TypeUtil.GetTypeWithReflectionPermission(host, _factoryTypeName, false);
}
else {
t1 = TypeUtil.GetTypeWithReflectionPermission(typeName, false);
t2 = TypeUtil.GetTypeWithReflectionPermission(_factoryTypeName, false);
}
return (t1 != null) && (t1 == t2);
}
catch {
}
return false;
}
internal bool IsEquivalentSectionGroupFactory(IInternalConfigHost host, string typeName) {
if (typeName == null || _factoryTypeName == null)
return true;
return IsEquivalentType(host, typeName);
}
internal bool IsEquivalentSectionFactory(
IInternalConfigHost host,
string typeName,
bool allowLocation,
ConfigurationAllowDefinition allowDefinition,
ConfigurationAllowExeDefinition allowExeDefinition,
bool restartOnExternalChanges,
bool requirePermission) {
if ( allowLocation != this.AllowLocation ||
allowDefinition != this.AllowDefinition ||
allowExeDefinition != this.AllowExeDefinition ||
restartOnExternalChanges != this.RestartOnExternalChanges ||
requirePermission != this.RequirePermission) {
return false;
}
return IsEquivalentType(host, typeName);
}
//
// Errors associated with the parse of a factory.
//
internal List<ConfigurationException> Errors {
get {
return _errors;
}
}
internal bool HasErrors {
get {
return ErrorsHelper.GetHasErrors(_errors);
}
}
internal void AddErrors(ICollection<ConfigurationException> coll) {
ErrorsHelper.AddErrors(ref _errors, coll);
}
internal void ThrowOnErrors() {
ErrorsHelper.ThrowOnErrors(_errors);
}
internal bool IsIgnorable() {
if (_factory != null)
return (_factory is IgnoreSectionHandler);
else if (_factoryTypeName != null)
return _factoryTypeName.Contains("System.Configuration.IgnoreSection");
else
return false;
}
}
}
|