Exemple #1
0
        public object Perform(PerformContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            var filterInfo = GetFilters(context.BackgroundJob.Job);

            try
            {
                return(PerformJobWithFilters(context, filterInfo.ServerFilters));
            }
            catch (OperationCanceledException)
            {
                throw;
            }
            catch (Exception ex)
            {
                var exceptionContext = new ServerExceptionContext(context, ex);
                InvokeServerExceptionFilters(exceptionContext, filterInfo.ServerExceptionFilters);

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

            return(null);
        }
        public object Run(PerformContext context, IJobPerformer performer)
        {
            if (context == null) throw new ArgumentNullException("context");
            if (performer == null) throw new ArgumentNullException("performer");

            var filterInfo = GetFilters(context.Job);

            try
            {
                return PerformJobWithFilters(context, performer, filterInfo.ServerFilters);
            }
            catch (OperationCanceledException)
            {
                throw;
            }
            catch (Exception ex)
            {
                var exceptionContext = new ServerExceptionContext(context, ex);
                InvokeServerExceptionFilters(exceptionContext, filterInfo.ServerExceptionFilters);

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

            return null;
        }
        public object Perform(PerformContext context)
        {
            if (context == null) throw new ArgumentNullException(nameof(context));

            var filterInfo = GetFilters(context.BackgroundJob.Job);

            try
            {
                return PerformJobWithFilters(context, filterInfo.ServerFilters);
            }
            catch (JobAbortedException)
            {
                throw;
            }
            catch (Exception ex)
            {
                // TODO: Catch only JobPerformanceException, and pass InnerException to filters in 2.0.0.

                if (ex is OperationCanceledException && context.CancellationToken.ShutdownToken.IsCancellationRequested)
                {
                    throw;
                }

                var exceptionContext = new ServerExceptionContext(context, ex);
                InvokeServerExceptionFilters(exceptionContext, filterInfo.ServerExceptionFilters);

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

            return null;
        }
        public void Run(PerformContext context, IJobPerformer performer)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }
            if (performer == null)
            {
                throw new ArgumentNullException("performer");
            }

            var filterInfo = GetFilters(context.Job);

            try
            {
                PerformJobWithFilters(context, performer, filterInfo.ServerFilters);
            }
            catch (OperationCanceledException)
            {
                throw;
            }
            catch (Exception ex)
            {
                var exceptionContext = new ServerExceptionContext(context, ex);
                InvokeServerExceptionFilters(exceptionContext, filterInfo.ServerExceptionFilters);

                if (!exceptionContext.ExceptionHandled)
                {
                    throw;
                }
            }
        }
 private static void InvokeServerExceptionFilters(
     ServerExceptionContext context,
     IEnumerable <IServerExceptionFilter> filters)
 {
     foreach (var filter in filters.Reverse())
     {
         filter.OnServerException(context);
     }
 }
 private static void InvokeServerExceptionFilters(
     ServerExceptionContext context,
     IEnumerable <IServerExceptionFilter> filters)
 {
     foreach (var filter in filters.Reverse())
     {
         context.Profiler.InvokeMeasured(
             Tuple.Create(filter, context),
             InvokeOnServerException,
             $"OnServerException for {context.BackgroundJob.Id}");
     }
 }
        public object Perform(PerformContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            var filterInfo = GetFilters(context.BackgroundJob.Job);

            try
            {
                return(PerformJobWithFilters(context, filterInfo.ServerFilters));
            }
            catch (JobAbortedException)
            {
                throw;
            }
            catch (Exception ex)
            {
                // TODO: Catch only JobPerformanceException, and pass InnerException to filters in 2.0.0.

                if (ex is OperationCanceledException && context.CancellationToken.ShutdownToken.IsCancellationRequested)
                {
                    throw;
                }

                var exceptionContext = new ServerExceptionContext(context, ex);
                InvokeServerExceptionFilters(exceptionContext, filterInfo.ServerExceptionFilters);

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

            return(null);
        }
 private static void InvokeServerExceptionFilters(
     ServerExceptionContext context,
     IEnumerable<IServerExceptionFilter> filters)
 {
     foreach (var filter in filters.Reverse())
     {
         filter.OnServerException(context);
     }
 }