Beispiel #1
0
        /// <summary>
        /// Checks if there is a policy entry that matches
        /// the type of the exception object specified by the
        /// <see cref="Exception"/> parameter,
        /// and if so, invokes the handlers associated with that entry.
        /// </summary>
        /// <param name="exceptionToHandle">The <c>Exception</c> to handle.</param>
        /// <returns><see langword="true"/> if  rethrowing an exception is recommended; otherwise, <see langword="false"/>.</returns>
        /// <remarks>
        /// The algorithm for matching the exception object to a
        /// set of handlers mimics that of a standard .NET Framework exception policy.
        /// The specified exception object will be matched to a single
        /// exception policy entry by traversing its inheritance hierarchy.
        /// This means that if a <c>FileNotFoundException</c>, for example, is
        /// caught, but the only exception type that the exception policy
        /// knows how to handle is System.Exception, the event handlers
        /// for <c>System.Exception</c> will be invoked because
        /// <c>FileNotFoundException</c> ultimately derives from <c>System.Exception</c>.
        /// </remarks>
        public bool HandleException(Exception exceptionToHandle)
        {
            if (exceptionToHandle == null)
            {
                throw new ArgumentNullException("exceptionToHandle");
            }

            ExceptionPolicyEntry entry = GetPolicyEntry(exceptionToHandle);

            if (entry == null)
            {
                return(true);
            }

            return(entry.Handle(exceptionToHandle));
        }
        /// <summary>
        /// This method supports the Enterprise Library infrastructure and is not intended to be used directly from your code.
        /// Builds a <see cref="ExceptionPolicyEntry"/> based on an instance of <see cref="ExceptionTypeData"/>.
        /// </summary>
        /// <param name="context">The <see cref="IBuilderContext"/> that represents the current building process.</param>
        /// <param name="objectConfiguration">The configuration object that describes the object to build.</param>
        /// <param name="configurationSource">The source for configuration objects.</param>
        /// <param name="reflectionCache">The cache to use retrieving reflection information.</param>
        /// <returns>A fully initialized instance of <see cref="ExceptionPolicyEntry"/>.</returns>
		public ExceptionPolicyEntry Create(IBuilderContext context, ExceptionTypeData objectConfiguration, IConfigurationSource configurationSource, ConfigurationReflectionCache reflectionCache)
		{
			List<IExceptionHandler> handlers = new List<IExceptionHandler>();
			foreach (ExceptionHandlerData handlerData in objectConfiguration.ExceptionHandlers)
			{
				IExceptionHandler handler
					= ExceptionHandlerCustomFactory.Instance.Create(context, handlerData, configurationSource, reflectionCache);
				handlers.Add(handler);
			}

			ExceptionPolicyEntry createdObject
				= new ExceptionPolicyEntry(
					objectConfiguration.PostHandlingAction,
					handlers);

			return createdObject;
		}
Beispiel #3
0
        public ExceptionPolicyEntry Create(IBuilderContext context, ExceptionTypeData objectConfiguration, IConfigurationSource configurationSource, ConfigurationReflectionCache reflectionCache)
        {
            List <IExceptionHandler> handlers = new List <IExceptionHandler>();

            foreach (ExceptionHandlerData handlerData in objectConfiguration.ExceptionHandlers)
            {
                IExceptionHandler handler
                    = ExceptionHandlerCustomFactory.Instance.Create(context, handlerData, configurationSource, reflectionCache);
                handlers.Add(handler);
            }
            ExceptionPolicyEntry createdObject
                = new ExceptionPolicyEntry(
                      objectConfiguration.PostHandlingAction,
                      handlers);

            return(createdObject);
        }
        private ExceptionPolicyEntry FindExceptionPolicyEntry(Type exceptionType)
        {
            ExceptionPolicyEntry entry = null;

            while (exceptionType != typeof(Object))
            {
                entry = this.GetPolicyEntry(exceptionType);
                if (entry == null)
                {
                    exceptionType = exceptionType.BaseType;
                }
                else
                {
                    break;
                }
            }
            return(entry);
        }
        public object CreateObject(IBuilderContext context, string name, IConfigurationSource configurationSource, ConfigurationReflectionCache reflectionCache)
        {
            ExceptionPolicyData objectConfiguration = GetConfiguration(name, configurationSource);
            Dictionary <Type, ExceptionPolicyEntry> policyEntries = new Dictionary <Type, ExceptionPolicyEntry>();

            foreach (ExceptionTypeData exceptionTypeData in objectConfiguration.ExceptionTypes)
            {
                ExceptionPolicyEntry entry
                    = ExceptionPolicyEntryCustomFactory.Instance.Create(context, exceptionTypeData, configurationSource, reflectionCache);
                policyEntries.Add(exceptionTypeData.Type, entry);
            }
            ExceptionPolicyImpl createdObject
                = new ExceptionPolicyImpl(
                      objectConfiguration.Name,
                      policyEntries);

            return(createdObject);
        }
        /// <devDoc>
        /// Traverses the specified type's inheritance hiearchy.
        /// </devDoc>
        private ExceptionPolicyEntry FindExceptionPolicyEntry(Type exceptionType)
        {
            ExceptionPolicyEntry entry = null;

            while (exceptionType != typeof(Object))
            {
                entry = GetPolicyEntry(exceptionType);

                if (entry == null)
                {
                    exceptionType = exceptionType.BaseType;
                }
                else
                {
                    //we've found the handlers, now continue on
                    break;
                }
            }

            return(entry);
        }
Beispiel #7
0
        private void AddPolicyEntriesToCache(ExceptionPolicyData policyData, ConfigurationContext context)
        {
            this.policyEntries = new Hashtable(policyData.ExceptionTypes.Count);

            foreach (ExceptionTypeData typeData in policyData.ExceptionTypes)
            {
                Type exceptionType = GetExceptionType(typeData, policyData.Name);
                ExceptionPolicyEntry exceptionEntry = new ExceptionPolicyEntry(policyData.Name, typeData, context);
                this.policyEntries.Add(exceptionType, exceptionEntry);
            }
        }