Пример #1
0
        private static PerformedContext InvokePerformFilter(
            IServerFilter filter,
            PerformingContext preContext,
            Func <PerformedContext> continuation)
        {
            try
            {
                filter.OnPerforming(preContext);
            }
            catch (OperationCanceledException)
            {
                throw;
            }
            catch (Exception filterException)
            {
                throw new JobPerformanceException(
                          "An exception occurred during execution of one of the filters",
                          filterException);
            }

            if (preContext.Canceled)
            {
                return(new PerformedContext(
                           preContext, null, true, null));
            }

            var wasError = false;
            PerformedContext postContext;

            try
            {
                postContext = continuation();
            }
            catch (Exception ex)
            {
                wasError    = true;
                postContext = new PerformedContext(
                    preContext, null, false, ex);

                try
                {
                    filter.OnPerformed(postContext);
                }
                catch (Exception filterException)
                {
                    throw new JobPerformanceException(
                              "An exception occurred during execution of one of the filters",
                              filterException);
                }

                if (!postContext.ExceptionHandled)
                {
                    throw;
                }
            }

            if (!wasError)
            {
                try
                {
                    filter.OnPerformed(postContext);
                }
                catch (OperationCanceledException)
                {
                    throw;
                }
                catch (Exception filterException)
                {
                    throw new JobPerformanceException(
                              "An exception occurred during execution of one of the filters",
                              filterException);
                }
            }

            return(postContext);
        }
Пример #2
0
        private static PerformedContext InvokePerformFilter(
            IServerFilter filter, 
            PerformingContext preContext,
            Func<PerformedContext> continuation)
        {
            try
            {
                filter.OnPerforming(preContext);
            }
            catch (OperationCanceledException)
            {
                throw;
            }
            catch (Exception filterException)
            {
                throw new JobPerformanceException(
                    "An exception occurred during execution of one of the filters",
                    filterException);
            }
            
            if (preContext.Canceled)
            {
                return new PerformedContext(
                    preContext, null, true, null);
            }

            var wasError = false;
            PerformedContext postContext;
            try
            {
                postContext = continuation();
            }
            catch (Exception ex)
            {
                wasError = true;
                postContext = new PerformedContext(
                    preContext, null, false, ex);

                try
                {
                    filter.OnPerformed(postContext);
                }
                catch (Exception filterException)
                {
                    throw new JobPerformanceException(
                        "An exception occurred during execution of one of the filters",
                        filterException);
                }

                if (!postContext.ExceptionHandled)
                {
                    throw;
                }
            }

            if (!wasError)
            {
                try
                {
                    filter.OnPerformed(postContext);
                }
                catch (OperationCanceledException)
                {
                    throw;
                }
                catch (Exception filterException)
                {
                    throw new JobPerformanceException(
                        "An exception occurred during execution of one of the filters",
                        filterException);
                }
            }

            return postContext;
        }
Пример #3
0
        private static PerformedContext InvokePerformFilter(
            IServerFilter filter,
            PerformingContext preContext,
            Func <PerformedContext> continuation)
        {
            try
            {
                filter.OnPerforming(preContext);
            }
            catch (Exception filterException)
            {
                CoreBackgroundJobPerformer.HandleJobPerformanceException(
                    filterException,
                    preContext.CancellationToken.ShutdownToken);
                throw;
            }

            if (preContext.Canceled)
            {
                return(new PerformedContext(
                           preContext, null, true, null));
            }

            var wasError = false;
            PerformedContext postContext;

            try
            {
                postContext = continuation();
            }
            catch (Exception ex)
            {
                wasError    = true;
                postContext = new PerformedContext(
                    preContext, null, false, ex);

                try
                {
                    filter.OnPerformed(postContext);
                }
                catch (Exception filterException)
                {
                    CoreBackgroundJobPerformer.HandleJobPerformanceException(
                        filterException,
                        postContext.CancellationToken.ShutdownToken);

                    throw;
                }

                if (!postContext.ExceptionHandled)
                {
                    throw;
                }
            }

            if (!wasError)
            {
                try
                {
                    filter.OnPerformed(postContext);
                }
                catch (Exception filterException)
                {
                    CoreBackgroundJobPerformer.HandleJobPerformanceException(
                        filterException,
                        postContext.CancellationToken.ShutdownToken);

                    throw;
                }
            }

            return(postContext);
        }
Пример #4
0
        private static PerformedContext InvokePerformFilter(
            IServerFilter filter, 
            PerformingContext preContext,
            Func<PerformedContext> continuation)
        {
            try
            {
                filter.OnPerforming(preContext);
            }
            catch (Exception filterException)
            {
                CoreBackgroundJobPerformer.HandleJobPerformanceException(
                    filterException,
                    preContext.CancellationToken.ShutdownToken);
                throw;
            }
            
            if (preContext.Canceled)
            {
                return new PerformedContext(
                    preContext, null, true, null);
            }

            var wasError = false;
            PerformedContext postContext;
            try
            {
                postContext = continuation();
            }
            catch (Exception ex)
            {
                wasError = true;
                postContext = new PerformedContext(
                    preContext, null, false, ex);

                try
                {
                    filter.OnPerformed(postContext);
                }
                catch (Exception filterException)
                {
                    CoreBackgroundJobPerformer.HandleJobPerformanceException(
                        filterException,
                        postContext.CancellationToken.ShutdownToken);

                    throw;
                }

                if (!postContext.ExceptionHandled)
                {
                    throw;
                }
            }

            if (!wasError)
            {
                try
                {
                    filter.OnPerformed(postContext);
                }
                catch (Exception filterException)
                {
                    CoreBackgroundJobPerformer.HandleJobPerformanceException(
                        filterException,
                        postContext.CancellationToken.ShutdownToken);

                    throw;
                }
            }

            return postContext;
        }