示例#1
0
        public void GetFilename2()
        {
            XmlNode node;
            string  filename;

            string      xmlfile = Path.Combine(foldername, "test.xml");
            XmlDocument doc     = new XmlDocument();

            doc.AppendChild(doc.CreateElement("test"));
            doc.Save(xmlfile);

            node     = new XmlDocument();
            filename = ConfigurationErrorsException.GetFilename(node);
            Assert.IsNull(filename, "#1");

            doc = new XmlDocument();
            doc.Load(xmlfile);

            node     = doc.DocumentElement;
            filename = ConfigurationErrorsException.GetFilename(node);
            Assert.IsNull(filename, "#2");

            doc = new ConfigXmlDocument();
            doc.Load(xmlfile);

            node     = doc.DocumentElement;
            filename = ConfigurationErrorsException.GetFilename(node);
            Assert.AreEqual(xmlfile, filename, "#3");
        }
        [Fact] // OpenExeConfiguration (String)
        public void OpenExeConfiguration2_ExePath_DoesNotExist()
        {
            using (var temp = new TempDirectory())
            {
                string exePath = Path.Combine(temp.Path, "DoesNotExist.exe");

                ConfigurationErrorsException ex = Assert.Throws <ConfigurationErrorsException>(
                    () => ConfigurationManager.OpenExeConfiguration(exePath));

                // An error occurred loading a configuration file:
                // The parameter 'exePath' is invalid
                Assert.Equal(typeof(ConfigurationErrorsException), ex.GetType());
                Assert.Null(ex.Filename);
                Assert.NotNull(ex.InnerException);
                Assert.Equal(0, ex.Line);
                Assert.NotNull(ex.Message);

                // The parameter 'exePath' is invalid
                ArgumentException inner = ex.InnerException as ArgumentException;
                Assert.NotNull(inner);
                Assert.Equal(typeof(ArgumentException), inner.GetType());
                Assert.Null(inner.InnerException);
                Assert.NotNull(inner.Message);
                Assert.Equal("exePath", inner.ParamName);
            }
        }
示例#3
0
        public void GetLineNumber2()
        {
            XmlNode node;
            int     line;

            string      xmlfile = Path.Combine(foldername, "test.xml");
            XmlDocument doc     = new XmlDocument();

            doc.AppendChild(doc.CreateElement("test"));
            doc.Save(xmlfile);

            node = new XmlDocument();
            line = ConfigurationErrorsException.GetLineNumber(node);
            Assert.AreEqual(0, line, "#1");

            doc = new XmlDocument();
            doc.Load(xmlfile);

            node = doc.DocumentElement;
            line = ConfigurationErrorsException.GetLineNumber(node);
            Assert.AreEqual(0, line, "#2");

            doc = new ConfigXmlDocument();
            doc.Load(xmlfile);

            node = doc.DocumentElement;
            line = ConfigurationErrorsException.GetLineNumber(node);
            Assert.AreEqual(1, line, "#3");
        }
示例#4
0
        public static Exception GetException(int code, Exception innerEception = null)
        {
            Exception exception;

            switch (code)
            {
            case ClientTokenNotSet:
                exception = new ClientTokenNotSetException(GetMessage(code));
                break;

            case CannotAutomaticallyRetrieveAssembly:
            case CannotChangeFirstAssembly:
                exception = new FirstAssemblyException(GetMessage(code));
                break;

            case CannotSetLocation:
            case CannotSetClientToken:
            case CannotSetEnvironment:
            case CannotSetTimeout:
                exception = new ConfigurationErrorsException(GetMessage(code), innerEception);
                break;

            case Timeout:
                exception = new TimeoutException(GetMessage(code), innerEception);
                break;

            default:
                exception = new InvalidOperationException(GetMessage(code), innerEception);
                break;
            }

            exception.HelpLink = GetHelpLink(code);
            return(exception);
        }
示例#5
0
        private void HandleConfigurationErrorsException(ConfigurationErrorsException ex)
        {
#if DEBUG
            Debugger.Break();
#endif
            string filename = ex.Filename;
            if (string.IsNullOrEmpty(filename) &&
                ex.InnerException != null &&
                ex.InnerException is ConfigurationErrorsException)
            {
                filename = ((ConfigurationErrorsException)ex.InnerException).Filename;
            }

            if (filename != null && File.Exists(filename))
            {
                File.Delete(filename);
            }

            string directory = Path.GetDirectoryName(filename);

            Configuration config       = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal);
            string        settingsPath = Path.GetDirectoryName(config.FilePath);
            Shell.ExecuteShellProcess_(settingsPath);

            DebugFix.Assert(directory == settingsPath);

            Settings.Default.Reset();
            //Settings.Default.Reload();
            //Settings.Default.Upgrade();
        }
示例#6
0
        /// <summary>
        /// Get schools closures data from Azure storage.
        /// </summary>
        /// <param name="alerts"></param>
        private async tasks.Task AddSchoolClosureAlerts(List <AlertViewModel> alerts)
        {
            const string cacheKey  = "Escc.EastSussexGovUK.Umbraco.SchoolClosures";
            var          alertHtml = String.Empty;

            if (HttpContext.Cache[cacheKey] != null && Request.QueryString["ForceCacheRefresh"] != "true")
            {
                alertHtml = HttpContext.Cache[cacheKey] as string;
                AddSchoolClosureAlert(alerts, alertHtml);
                return;
            }

            if (ConfigurationManager.ConnectionStrings["Escc.ServiceClosures.AzureStorage"] == null || String.IsNullOrEmpty(ConfigurationManager.ConnectionStrings["Escc.ServiceClosures.AzureStorage"].ConnectionString))
            {
                var error = new ConfigurationErrorsException("The Escc.ServiceClosures.AzureStorage connection string is missing from web.config");
                LogHelper.Error <AlertsController>(error.Message, error);
                error.ToExceptionless().Submit();
                return;
            }

            var closureDataSource = new AzureBlobStorageDataSource(ConfigurationManager.ConnectionStrings["Escc.ServiceClosures.AzureStorage"].ConnectionString, "service-closures");
            var closureData       = await closureDataSource.ReadClosureDataAsync(new ServiceType("school"));

            if (closureData != null && (TooLateForToday() ? closureData.EmergencyClosureExists(DateTime.Today.AddDays(1)) : closureData.EmergencyClosureExists(DateTime.Today)))
            {
                alertHtml = "<p><a href=\"https://www.eastsussex.gov.uk/educationandlearning/schools/schoolclosures/\">Emergency school closures</a> &#8211; check if your school is affected, and subscribe to alerts.</p>";

                AddSchoolClosureAlert(alerts, alertHtml);
            }

            // Cache the HTML returned, even if it's String.Empty, so that we don't make too many web requests
            HttpContext.Cache.Insert(cacheKey, alertHtml, null, DateTime.Now.AddMinutes(5),
                                     Cache.NoSlidingExpiration, CacheItemPriority.AboveNormal, null);
        }
        private static void AppendLines(ArrayList setlist, string text, XmlNode node)
        {
            int lineNumber = ConfigurationErrorsException.GetLineNumber(node);
            int startat    = 0;

            while (true)
            {
                Match match;
                if ((match = wsRegex.Match(text, startat)).Success)
                {
                    lineNumber += Util.LineCount(text, startat, match.Index + match.Length);
                    startat     = match.Index + match.Length;
                }
                if (startat == text.Length)
                {
                    return;
                }
                if (!(match = lineRegex.Match(text, startat)).Success)
                {
                    match = errRegex.Match(text, startat);
                    throw new ConfigurationErrorsException(System.Web.SR.GetString("Problem_reading_caps_config", new object[] { match.ToString() }), ConfigurationErrorsException.GetFilename(node), lineNumber);
                }
                setlist.Add(new CapabilitiesAssignment(match.Groups["var"].Value, new CapabilitiesPattern(match.Groups["pat"].Value)));
                lineNumber += Util.LineCount(text, startat, match.Index + match.Length);
                startat     = match.Index + match.Length;
            }
        }
        private static Exception GetConfigException(string key, Exception innerException)
        {
            var result = new ConfigurationErrorsException(
                string.Format("Not found or cannot parse {0} key from appSettings or connectionStrings of config", key), innerException);

            return(result);
        }
示例#9
0
    static void Main(string[] args)
    {
        try {
            NameValueCollection AppSettings = ConfigurationManager.AppSettings;
            Assert.Fail("#1:" + AppSettings);
        } catch (ConfigurationErrorsException ex) {
            // Configuration system failed to initialize
            Assert.AreEqual(typeof(ConfigurationErrorsException), ex.GetType(), "#2");
            Assert.IsNull(ex.Filename, "#3");
            Assert.IsNotNull(ex.InnerException, "#6");
            Assert.AreEqual(0, ex.Line, "#7");
            Assert.IsNotNull(ex.Message, "#8");

            // <location> sections are allowed only within <configuration> sections
            ConfigurationErrorsException inner = ex.InnerException as ConfigurationErrorsException;
            Assert.AreEqual(typeof(ConfigurationErrorsException), inner.GetType(), "#9");
            Assert.AreEqual(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile, inner.Filename, "#10");
            Assert.IsNull(inner.InnerException, "#11");
            Assert.AreEqual(3, inner.Line, "#12");
            Assert.IsNotNull(inner.Message, "#13");
            Assert.IsTrue(inner.Message.IndexOf("<location>") != -1, "#14:" + inner.Message);
            Assert.IsTrue(inner.Message.IndexOf("<configuration>") != -1, "#15:" + inner.Message);

            Console.WriteLine("configuration exception thrown.");
        }
    }
示例#10
0
        [Fact] // GetFilename (XmlNode)
        // Doesn't pass on Mono
        // [Category("NotWorking")]
        public void GetFilename2()
        {
            using (var temp = new TempDirectory())
            {
                XmlNode node;
                string  filename;

                string      xmlfile = Path.Combine(temp.Path, "test.xml");
                XmlDocument doc     = new XmlDocument();
                doc.AppendChild(doc.CreateElement("test"));
                doc.Save(xmlfile);

                node     = new XmlDocument();
                filename = ConfigurationErrorsException.GetFilename(node);
                Assert.Null(filename);

                doc = new XmlDocument();
                doc.Load(xmlfile);

                node     = doc.DocumentElement;
                filename = ConfigurationErrorsException.GetFilename(node);
                Assert.Null(filename);

                doc = new ConfigXmlDocument();
                doc.Load(xmlfile);

                node     = doc.DocumentElement;
                filename = ConfigurationErrorsException.GetFilename(node);
                Assert.Equal(xmlfile, filename);
            }
        }
示例#11
0
        [Fact] // GetLineNumber (XmlReader)
        public void GetLineNumber1_Reader_Null()
        {
            XmlReader reader = null;
            int       line   = ConfigurationErrorsException.GetLineNumber(reader);

            Assert.Equal(0, line);
        }
示例#12
0
        [Fact] // GetLineNumber (XmlNode)
        public void GetLineNumber2_Node_Null()
        {
            XmlNode node = null;
            int     line = ConfigurationErrorsException.GetLineNumber(node);

            Assert.Equal(0, line);
        }
示例#13
0
        [Fact] // GetLineNumber (XmlNode)
        // Doesn't pass on Mono
        // [Category("NotWorking")]
        public void GetLineNumber2()
        {
            using (var temp = new TempDirectory())
            {
                XmlNode node;
                int     line;

                string      xmlfile = Path.Combine(temp.Path, "test.xml");
                XmlDocument doc     = new XmlDocument();
                doc.AppendChild(doc.CreateElement("test"));
                doc.Save(xmlfile);

                node = new XmlDocument();
                line = ConfigurationErrorsException.GetLineNumber(node);
                Assert.Equal(0, line);

                doc = new XmlDocument();
                doc.Load(xmlfile);

                node = doc.DocumentElement;
                line = ConfigurationErrorsException.GetLineNumber(node);
                Assert.Equal(0, line);

                doc = new ConfigXmlDocument();
                doc.Load(xmlfile);

                node = doc.DocumentElement;
                line = ConfigurationErrorsException.GetLineNumber(node);
                Assert.Equal(1, line);
            }
        }
示例#14
0
 internal void FireConfigurationFailureEvent(ConfigurationErrorsException configurationException)
 {
     if (configurationFailure != null)
     {
         configurationFailure(this, new ValidationConfigurationFailureEventArgs(configurationException));
     }
 }
示例#15
0
        [Fact] // ctor (String, Exception)
        public void Constructor3()
        {
            string    msg;
            Exception inner;
            ConfigurationErrorsException cee;

            msg   = "MSG";
            inner = new Exception();
            cee   = new ConfigurationErrorsException(msg, inner);
            Assert.Same(msg, cee.BareMessage);
            Assert.NotNull(cee.Data);
            Assert.Equal(0, cee.Data.Count);
            Assert.Null(cee.Filename);
            Assert.Same(inner, cee.InnerException);
            Assert.Equal(0, cee.Line);
            Assert.Same(msg, cee.Message);

            msg   = null;
            inner = null;
            cee   = new ConfigurationErrorsException(msg, inner);
            Assert.Equal(new ConfigurationErrorsException().Message, cee.BareMessage);
            Assert.NotNull(cee.Data);
            Assert.Equal(0, cee.Data.Count);
            Assert.Null(cee.Filename);
            Assert.Same(inner, cee.InnerException);
            Assert.Equal(0, cee.Line);
            Assert.Equal(cee.BareMessage, cee.Message);
        }
        /// <summary>
        /// Gets a config object from a given file path.
        /// </summary>
        /// <typeparam name="TConfig">
        /// The type used for registering the config element.
        /// </typeparam>
        /// <typeparam name="TDeserializationConfig">
        /// The type used for deserializing the config element. This type must implement the TConfig type.
        /// </typeparam>
        /// <param name="filePath">
        /// The file path to the JSON file.
        /// </param>
        /// <returns>The derserialized object from the file path.</returns>
        private static TConfig GetJsonConfig <TConfig, TDeserializationConfig>(string filePath)
            where TConfig : class
            where TDeserializationConfig : class, TConfig
        {
            var mappedPath = IOHelper.MapPath(filePath);

            if (File.Exists(mappedPath))
            {
                try
                {
                    using (var file = File.OpenText(mappedPath))
                    {
                        using (var jsonReader = new JsonTextReader(file))
                        {
                            var serializer = new JsonSerializer();
                            return(serializer.Deserialize <TDeserializationConfig>(jsonReader));
                        }
                    }
                }
                catch (Exception ex)
                {
                    Current.Logger.Error(typeof(Configs), ex, "Config error");
                    throw ex;
                }
            }

            var configEx = new ConfigurationErrorsException($"Could not get JSON configuration from file path \"{mappedPath}\".");

            Current.Logger.Error(typeof(Configs), configEx, "Config error");
            throw configEx;
        }
        /// <summary>
        /// Returns a default instance of type <typeparamref name="T"/> based on configuration information
        /// from <paramref name="configurationSource"/>.
        /// </summary>
        /// <typeparam name="T">The type to build.</typeparam>
        /// <param name="locator">The locator to be used for this build operation.</param>
        /// <param name="lifetimeContainer">The lifetime container to be used for this build operation.</param>
        /// <param name="configurationSource">The source for configuration information.</param>
        /// <returns>A new instance of <typeparamref name="T"/> or any of it subtypes, or an existing instance
        /// if type <typeparamref name="T"/> is a singleton that is already present in the <paramref name="locator"/>.
        /// </returns>
        public static T BuildUp <T>(IReadWriteLocator locator,
                                    ILifetimeContainer lifetimeContainer,
                                    IConfigurationSource configurationSource)
        {
            if (configurationSource == null)
            {
                throw new ArgumentNullException("configurationSource");
            }

            try
            {
                return(GetObjectBuilder()
                       .BuildUp <T>(locator,
                                    lifetimeContainer,
                                    GetPolicies(configurationSource),
                                    strategyChain,
                                    NamedTypeBuildKey.Make <T>(),
                                    null));
            }
            catch (BuildFailedException e)
            {
                // look for the wrapped ConfigurationErrorsException, if any, and throw it
                ConfigurationErrorsException cee = GetConfigurationErrorsException(e);
                if (cee != null)
                {
                    throw cee;
                }

                // unknown exception, bubble it up
                throw;
            }
        }
示例#18
0
        static internal ConfigurationException Configuration(string message, XmlNode node)
        {
            ConfigurationException e = new ConfigurationErrorsException(message, node);

            TraceExceptionAsReturnValue(e);
            return(e);
        }
示例#19
0
        public void AddConfigurationError(ConfigurationErrorsException /*!*/ e)
        {
            if (e == null)
            {
                throw new ArgumentNullException("e");
            }

#if SILVERLIGHT
            StringBuilder message = new StringBuilder(e.Message);
            Exception     inner   = e.InnerException;
            while (inner != null)
            {
                message.Append(" ");
                message.Append(inner.Message);
                inner = inner.InnerException;
            }
            Add(FatalErrors.ConfigurationError, "<configuration>", new ErrorPosition(), message.ToString());
#else
            ErrorPosition pos     = new ErrorPosition(e.Line, 0, e.Line, 0);
            StringBuilder message = new StringBuilder(e.BareMessage);
            Exception     inner   = e.InnerException;
            while (inner != null)
            {
                message.Append(" ");
                message.Append(inner.Message);
                inner = inner.InnerException;
            }
            Add(FatalErrors.ConfigurationError, e.Filename, pos, message.ToString());
#endif
        }
示例#20
0
        private static void InitializeDefaultProvider(RoleManagerSection settings)
        {
            bool canInitializeDefaultProvider = (!HostingEnvironment.IsHosted || BuildManager.PreStartInitStage == PreStartInitStage.AfterPreStartInit);

            if (!s_InitializedDefaultProvider && canInitializeDefaultProvider)
            {
                Debug.Assert(s_Providers != null);
                s_Providers.SetReadOnly();

                if (settings.DefaultProvider == null)
                {
                    s_InitializeException = new ProviderException(SR.GetString(SR.Def_role_provider_not_specified));
                }
                else
                {
                    try {
                        s_Provider = s_Providers[settings.DefaultProvider];
                    }
                    catch { }
                }

                if (s_Provider == null)
                {
                    s_InitializeException = new ConfigurationErrorsException(SR.GetString(SR.Def_role_provider_not_found), settings.ElementInformation.Properties["defaultProvider"].Source, settings.ElementInformation.Properties["defaultProvider"].LineNumber);
                }

                s_InitializedDefaultProvider = true;
            }
        }
示例#21
0
        [Fact] // GetFilename (XmlReader)
        public void GetFilename1_Reader_Null()
        {
            XmlReader reader   = null;
            string    filename = ConfigurationErrorsException.GetFilename(reader);

            Assert.Null(filename);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="defaultConfiguration"></param>
        /// <param name="errors"></param>
        /// <returns></returns>
        public override TConfiguration Create(
            Lazy <TConfiguration> defaultConfiguration,
            out ConfigurationErrorsException errors)
        {
            errors = null;

            if (null == defaultConfiguration)
            {
                throw new ArgumentNullException(nameof(defaultConfiguration));
            }

            TConfiguration result = null;

            try
            {
                result = (TConfiguration)ConfigurationManager.GetSection(this.SectionName);
            }
            catch (ConfigurationErrorsException exception)
            {
                errors = exception;
            }

            if (null == result)
            {
                result = defaultConfiguration.Value;
            }

            return(result);
        }
示例#23
0
        [Fact] // GetFilename (XmlNode)
        public void GetFilename2_Node_Null()
        {
            XmlNode node     = null;
            string  filename = ConfigurationErrorsException.GetFilename(node);

            Assert.Null(filename);
        }
示例#24
0
        [Test]         // ctor (String)
        public void Constructor2()
        {
            string msg;
            ConfigurationErrorsException cee;

            msg = "MSG";
            cee = new ConfigurationErrorsException(msg);
            Assert.AreSame(msg, cee.BareMessage, "#A1");
            Assert.IsNotNull(cee.Data, "#A2");
            Assert.AreEqual(0, cee.Data.Count, "#A3");
            Assert.IsNull(cee.Filename, "#A4");
            Assert.IsNull(cee.InnerException, "#A5");
            Assert.AreEqual(0, cee.Line, "#A6");
            Assert.AreSame(msg, cee.Message, "#A7");

            msg = null;
            cee = new ConfigurationErrorsException(msg);
            Assert.AreEqual(new ConfigurationErrorsException().Message, cee.BareMessage, "#B1");
            Assert.IsNotNull(cee.Data, "#B2");
            Assert.AreEqual(0, cee.Data.Count, "#B3");
            Assert.IsNull(cee.Filename, "#B4");
            Assert.IsNull(cee.InnerException, "#B5");
            Assert.AreEqual(0, cee.Line, "#B6");
            Assert.AreEqual(cee.BareMessage, cee.Message, "#B7");
        }
示例#25
0
        static CasOwaAuthHandler()
        {
            XmlConfigurator.Configure();
            log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);

            ClearPassUrl = ConfigurationManager.AppSettings.Get("CasOwa.ClearPassUrl");
            if (String.IsNullOrEmpty(ClearPassUrl))
            {
                Exception ex = new ConfigurationErrorsException("ClearPassUrl is missing. It must be set in <appSettings> section of <web.conf>.  Example: <add key=\"ClearPassUrl\" value=\"https://cashostname/cas/clearPass\"/>");
                if (log.IsErrorEnabled)
                {
                    log.Error(ex.Message, ex);
                }
                throw ex;
            }

            try
            {
                ClearPassUri = new Uri(ClearPassUrl);
            }
            catch (UriFormatException ufe)
            {
                Exception ex = new ConfigurationErrorsException("ClearPassUrl is invalid.  Check your settings in <appSettings> section of <web.conf>. " + ufe.Message, ufe);
                if (log.IsErrorEnabled)
                {
                    log.Error(ex.Message, ex);
                }
                throw ex;
            }

            ArtifactParameterName = ConfigurationManager.AppSettings.Get("CasOwa.ArtifactParameterName") ?? ArtifactParameterName;
            ServiceParameterName  = ConfigurationManager.AppSettings.Get("CasOwa.ServiceParameterName") ?? ServiceParameterName;

            OwaUrl = ConfigurationManager.AppSettings.Get("CasOwa.OwaUrl");
            if (String.IsNullOrEmpty(OwaUrl))
            {
                Exception ex = new ConfigurationErrorsException("CasOwa.OwaUrl is missing. It must be set in <appSettings> section of <web.conf>.  Example: <add key=\"CasOwa.OwaAuthUrl\" value=\"https://exchangehostname/owa\"/>");
                if (log.IsErrorEnabled)
                {
                    log.Error(ex.Message, ex);
                }
                throw ex;
            }

            OwaAuthPath = ConfigurationManager.AppSettings.Get("CasOwa.OwaAuthPath") ?? OwaAuthPath;
            OwaAuthUrl  = OwaUrl + OwaAuthPath;

            OwaOptionalFormFields = ConfigurationManager.AppSettings.Get("CasOwa.OwaOptionalFormFields") ?? OwaOptionalFormFields;

            OwaInboxUrl = ConfigurationManager.AppSettings.Get("CasOwa.OwaInboxUrl");

            // This is setting is necessary when using untrusted certificates, typically in a development or testing.
            var skipOwaUrlCertificateValidation = ConfigurationManager.AppSettings.Get("CasOwa.skipOwaUrlCertificateValidation");

            if (!String.IsNullOrEmpty(skipOwaUrlCertificateValidation) && bool.Parse(skipOwaUrlCertificateValidation))
            {
                ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(delegate { return(true); });
            }
        }
示例#26
0
 /// <summary>
 /// 使用缓冲池的键、缓冲对象的类型和发生的内部异常初始化 <see cref="CacheResolveEventArgs"/> 类的新实例。
 /// </summary>
 /// <param name="key">缓冲池的键。</param>
 /// <param name="keyType">缓冲对象的键的类型。</param>
 /// <param name="valueType">缓冲对象的类型。</param>
 /// <param name="innerException">发生的内部异常。</param>
 public CacheResolveEventArgs(string key, Type keyType, Type valueType, ConfigurationErrorsException innerException)
 {
     Contract.Requires(key != null && keyType != null && valueType != null);
     this.key            = key;
     this.keyType        = keyType;
     this.valueType      = valueType;
     this.innerException = innerException;
 }
 ///<summary>
 ///</summary>
 ///<param name="configurationException"></param>
 public void NotifyConfigurationFailure(ConfigurationErrorsException configurationException)
 {
     if (EventLoggingEnabled)
     {
         string entryText = eventLogEntryFormatter.GetEntryText(Resources.ConfigurationErrorMessage, configurationException);
         EventLog.WriteEntry(GetEventSourceName(), entryText, EventLogEntryType.Error);
     }
 }
 /// <summary>
 /// 使用缓冲池的键、缓冲对象的类型和已发生的
 /// <see cref="System.Configuration.ConfigurationErrorsException"/> 初始化
 /// <see cref="CacheResolveEventArgs"/> 类的新实例。
 /// </summary>
 /// <param name="key">缓冲池的键。</param>
 /// <param name="keyType">缓冲对象的键的类型。</param>
 /// <param name="valueType">缓冲对象的类型。</param>
 /// <param name="exception">已发生的 <see cref="System.Exception"/>。</param>
 public CacheResolveEventArgs(string key, Type keyType, Type valueType,
                              ConfigurationErrorsException exception)
 {
     this.Key            = key;
     this.CacheKeyType   = keyType;
     this.CacheValueType = valueType;
     this.Exception      = exception;
 }
示例#29
0
 /// <summary>
 /// Returns the line number of the specified node.
 /// </summary>
 /// <param name="node">Node to get the line number for.</param>
 /// <returns>The line number of the specified node.</returns>
 public static int GetLineNumber(XmlNode node)
 {
     if (node is ITextPosition)
     {
         return(((ITextPosition)node).LineNumber);
     }
     return(ConfigurationErrorsException.GetLineNumber(node));
 }
示例#30
0
 /// <summary>
 /// Returns the name of the file specified node is defined in.
 /// </summary>
 /// <param name="node">Node to get the file name for.</param>
 /// <returns>The name of the file specified node is defined in.</returns>
 public static string GetFileName(XmlNode node)
 {
     if (node is ITextPosition)
     {
         return(((ITextPosition)node).Filename);
     }
     return(ConfigurationErrorsException.GetFilename(node));
 }
示例#31
0
		public void AddConfigurationError(ConfigurationErrorsException/*!*/ e)
		{
			if (e == null)
				throw new ArgumentNullException("e");

#if SILVERLIGHT
			StringBuilder message = new StringBuilder(e.Message);
			Exception inner = e.InnerException;
			while (inner != null)
			{
				message.Append(" ");
				message.Append(inner.Message);
				inner = inner.InnerException;
			}
			Add(FatalErrors.ConfigurationError, "<configuration>", new ErrorPosition(), message.ToString());
#else
			ErrorPosition pos = new ErrorPosition(e.Line, 0, e.Line, 0);
			StringBuilder message = new StringBuilder(e.BareMessage);
			Exception inner = e.InnerException;
			while (inner != null)
			{
				message.Append(" ");
				message.Append(inner.Message);
				inner = inner.InnerException;
			}
			Add(FatalErrors.ConfigurationError, e.Filename, pos, message.ToString());
#endif
		}