/// <summary>
        /// This method supports the Enterprise Library infrastructure and is not intended to be used directly from your code.
        /// Builds a <see cref="ExceptionPolicyImpl"/> based on an instance of <see cref="ExceptionPolicyData"/>.
        /// </summary>
        /// <param name="context">The <see cref="IBuilderContext"/> that represents the current building process.</param>
        /// <param name="name">The name of the <see cref="ExceptionPolicyImpl"/> that should be created.</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="ExceptionPolicyImpl"/>.</returns>
        public object CreateObject(IBuilderContext context, string name, IConfigurationSource configurationSource, ConfigurationReflectionCache reflectionCache)
        {
            ExceptionPolicyData objectConfiguration = GetConfiguration(name, configurationSource);

            if (objectConfiguration == null)
            {
                throw new ConfigurationErrorsException();                              //TODO: temp fix. this whole class needs to be removed
            }
            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);
        }
Example #2
0
        /// <summary>
        /// The main entry point into the Exception Handling Application Block.
        /// Handles the specified <see cref="Exception"/>
        /// object according to the given <paramref name="policyName"></paramref>.
        /// </summary>
        /// <param name="exceptionToHandle">An <see cref="Exception"/> object.</param>
        /// <param name="policyName">The name of the policy to handle.</param>
        /// <returns>
        /// Whether or not a rethrow is recommended.
        /// </returns>
        /// <example>
        /// The following code shows the usage of the
        /// exception handling framework.
        /// <code>
        /// try
        ///	{
        ///		DoWork();
        ///	}
        ///	catch (Exception e)
        ///	{
        ///		if (ExceptionPolicy.HandleException(e, name)) throw;
        ///	}
        /// </code>
        /// </example>
        public static bool HandleException(Exception exceptionToHandle, string policyName)
        {
            if (exceptionToHandle == null)
            {
                throw new ArgumentNullException("exceptionToHandle");
            }
            if (string.IsNullOrEmpty(policyName))
            {
                throw new ArgumentException(Resources.ExceptionStringNullOrEmpty);
            }

            ExceptionPolicyImpl policy = GetExceptionPolicy(exceptionToHandle, policyName);

            return(policy.HandleException(exceptionToHandle));
        }
        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);
        }
        /// <summary>
        /// This method supports the Enterprise Library infrastructure and is not intended to be used directly from your code.
        /// Builds a <see cref="ExceptionPolicyImpl"/> based on an instance of <see cref="ExceptionPolicyData"/>.
        /// </summary>
        /// <param name="context">The <see cref="IBuilderContext"/> that represents the current building process.</param>
        /// <param name="name">The name of the <see cref="ExceptionPolicyImpl"/> that should be created.</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="ExceptionPolicyImpl"/>.</returns>
        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;
        }
        /// <summary>
        /// This method supports the Enterprise Library infrastructure and is not intended to be used directly from your code.
        /// Builds a <see cref="ExceptionPolicyImpl"/> based on an instance of <see cref="ExceptionPolicyData"/>.
        /// </summary>
        /// <param name="context">The <see cref="IBuilderContext"/> that represents the current building process.</param>
        /// <param name="name">The name of the <see cref="ExceptionPolicyImpl"/> that should be created.</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="ExceptionPolicyImpl"/>.</returns>
        public object CreateObject(IBuilderContext context, string name, IConfigurationSource configurationSource, ConfigurationReflectionCache reflectionCache)
		{
			ExceptionPolicyData objectConfiguration = GetConfiguration(name, configurationSource);
            if (objectConfiguration == null) throw new ConfigurationErrorsException(); //TODO: temp fix. this whole class needs to be removed


			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;
		}
 public ExceptionWithContextCallHandler(ExceptionPolicyImpl exceptionPolicy, int order)
     : base(exceptionPolicy, order)
 {
 }
 public ExceptionWithContextCallHandler(ExceptionPolicyImpl exceptionPolicy)
     : base(exceptionPolicy)
 {
 }
Example #8
0
        private static bool HandleException(Exception exceptionToHandle, string policyName, ExceptionPolicyFactory policyFactory)
        {
            ExceptionPolicyImpl policy = GetExceptionPolicy(exceptionToHandle, policyName, policyFactory);

            return(policy.HandleException(exceptionToHandle));
        }