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
|
//------------------------------------------------------------------------------
// <copyright file="ConfigurationSchemaErrors.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
namespace System.Configuration {
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Text;
internal class ConfigurationSchemaErrors {
// Errors with ExceptionAction.Local are logged to this list.
// This list is reset when processing of a section is complete.
// Errors on this list may be added to the _errorsAll list
// when RetrieveAndResetLocalErrors is called.
private List<ConfigurationException> _errorsLocal;
// Errors with ExceptionAction.Global are logged to this list.
private List<ConfigurationException> _errorsGlobal;
// All errors related to a config file are logged to this list.
// This includes all global errors, all non-specific errors,
// and local errors for input that applies to this config file.
private List<ConfigurationException> _errorsAll;
internal ConfigurationSchemaErrors() {}
internal bool HasLocalErrors {
get {
return ErrorsHelper.GetHasErrors(_errorsLocal);
}
}
internal bool HasGlobalErrors {
get {
return ErrorsHelper.GetHasErrors(_errorsGlobal);
}
}
private bool HasAllErrors {
get {
return ErrorsHelper.GetHasErrors(_errorsAll);
}
}
internal int GlobalErrorCount {
get {
return ErrorsHelper.GetErrorCount(_errorsGlobal);
}
}
//
// Add a configuration Error.
//
internal void AddError(ConfigurationException ce, ExceptionAction action) {
switch (action) {
case ExceptionAction.Global:
ErrorsHelper.AddError(ref _errorsAll, ce);
ErrorsHelper.AddError(ref _errorsGlobal, ce);
break;
case ExceptionAction.NonSpecific:
ErrorsHelper.AddError(ref _errorsAll, ce);
break;
case ExceptionAction.Local:
ErrorsHelper.AddError(ref _errorsLocal, ce);
break;
}
}
internal void SetSingleGlobalError(ConfigurationException ce) {
_errorsAll = null;
_errorsLocal = null;
_errorsGlobal = null;
AddError(ce, ExceptionAction.Global);
}
internal bool HasErrors(bool ignoreLocal) {
if (ignoreLocal) {
return HasGlobalErrors;
}
else {
return HasAllErrors;
}
}
// ThrowIfErrors
//
// Throw if Errors were detected and remembered.
//
// Parameters:
// IgnoreLocal - Should we be using the local errors also to
// detemine if we should throw?
//
// Note: We will always return all the errors, no matter what
// IgnoreLocal is.
//
internal void ThrowIfErrors(bool ignoreLocal) {
if (HasErrors(ignoreLocal)) {
if (HasGlobalErrors) {
// Throw just the global errors, as they invalidate
// all other config file parsing.
throw new ConfigurationErrorsException(_errorsGlobal);
}
else {
// Throw all errors no matter what
throw new ConfigurationErrorsException(_errorsAll);
}
}
}
// RetrieveAndResetLocalErrors
//
// Retrieve the Local Errors, and Reset them to none.
//
internal List<ConfigurationException> RetrieveAndResetLocalErrors(bool keepLocalErrors) {
List<ConfigurationException> list = _errorsLocal;
_errorsLocal = null;
if (keepLocalErrors) {
ErrorsHelper.AddErrors(ref _errorsAll, list);
}
return list;
}
//
// Add errors that have been saved for a specific section.
//
internal void AddSavedLocalErrors(ICollection<ConfigurationException> coll) {
ErrorsHelper.AddErrors(ref _errorsAll, coll);
}
// ResetLocalErrors
//
// Remove all the Local Errors, so we can start from scratch
//
internal void ResetLocalErrors() {
RetrieveAndResetLocalErrors(false);
}
}
}
|