public void OnPerforming(PerformingContext filterContext)
        {
            var resource = GetResource(filterContext.BackgroundJob.Job);

            var timeout = TimeSpan.FromSeconds(_timeoutInSeconds);

            var distributedLock = filterContext.Connection.AcquireDistributedLock(resource, timeout);
            filterContext.Items["DistributedLock"] = distributedLock;
        }
        public void OnPerforming(PerformingContext filterContext)
        {
            var resource = String.Format(
                "{0}.{1}",
                filterContext.Job.Type.FullName,
                filterContext.Job.Method.Name);

            var timeout = TimeSpan.FromSeconds(_timeoutInSeconds);

            var distributedLock = filterContext.Connection.AcquireDistributedLock(resource, timeout);
            filterContext.Items["DistributedLock"] = distributedLock;
        }
        public PreserveCultureAttributeFacts()
        {
            _connection = new Mock<IStorageConnection>();

            var storage = new Mock<JobStorage>();
            var backgroundJob = new BackgroundJobMock { Id = JobId };
            var state = new Mock<IState>();

            var createContext = new CreateContext(
                storage.Object, _connection.Object, backgroundJob.Job, state.Object);
            _creatingContext = new CreatingContext(createContext);

            var performContext = new PerformContext(
                _connection.Object, backgroundJob.Object, new Mock<IJobCancellationToken>().Object);
            _performingContext = new PerformingContext(performContext);
            _performedContext = new PerformedContext(performContext, null, false, null);
        }
        private static void PerformJobWithFilters(
            PerformContext context,
            IJobPerformer performer,
            IEnumerable <IServerFilter> filters)
        {
            var preContext = new PerformingContext(context);
            Func <PerformedContext> continuation = () =>
            {
                performer.Perform(context.Activator, context.CancellationToken);
                return(new PerformedContext(context, false, null));
            };

            var thunk = filters.Reverse().Aggregate(continuation,
                                                    (next, filter) => () => InvokePerformFilter(filter, preContext, next));

            thunk();
        }
        public PreserveCultureAttributeFacts()
        {
            _connection = new Mock<IStorageConnection>();
            var job = Job.FromExpression(() => Sample());
            var state = new Mock<IState>();

            var createContext = new CreateContext(
                _connection.Object, job, state.Object);
            _creatingContext = new CreatingContext(createContext);

            var workerContext = new WorkerContextMock();

            var performContext = new PerformContext(
                workerContext.Object, _connection.Object, JobId, job, DateTime.UtcNow, new Mock<IJobExecutionContext>().Object);
            _performingContext = new PerformingContext(performContext);
            _performedContext = new PerformedContext(performContext, null, false, null);
        }
        public void OnPerforming(PerformingContext filterContext)
        {
            var cultureName = filterContext.GetJobParameter<string>("CurrentCulture");
            var uiCultureName = filterContext.GetJobParameter<string>("CurrentUICulture");

            if (!String.IsNullOrEmpty(cultureName))
            {
                filterContext.Items["PreviousCulture"] = CultureInfo.CurrentCulture;
                SetCurrentCulture(new CultureInfo(cultureName));
            }

            if (!String.IsNullOrEmpty(uiCultureName))
            {
                filterContext.Items["PreviousUICulture"] = CultureInfo.CurrentUICulture;
                SetCurrentUICulture(new CultureInfo(uiCultureName));
            }
        }
        private static void PerformJobWithFilters(
            PerformContext context,
            IJobPerformer performer,
            IEnumerable<IServerFilter> filters)
        {
            var preContext = new PerformingContext(context);
            Func<PerformedContext> continuation = () =>
            {
                performer.Perform(context.Activator, context.CancellationToken);
                return new PerformedContext(context, false, null);
            };

            var thunk = filters.Reverse().Aggregate(continuation,
                (next, filter) => () => InvokePerformFilter(filter, preContext, next));
            
            thunk();
        }
        private object PerformJobWithFilters(PerformContext context, IEnumerable <IServerFilter> filters)
        {
            object result = null;

            var preContext = new PerformingContext(context);
            Func <PerformedContext> continuation = () =>
            {
                result = _innerPerformer.Perform(context);
                return(new PerformedContext(context, result, false, null));
            };

            var thunk = filters.Reverse().Aggregate(continuation,
                                                    (next, filter) => () => InvokePerformFilter(filter, preContext, next));

            thunk();

            return(result);
        }
		public void OnPerforming(PerformingContext context)
		{
			JobId = context.BackgroundJob.Id;
		}
        private static PerformedContext InvokePerformFilter(
            IServerFilter filter,
            PerformingContext preContext,
            Func <PerformedContext> continuation)
        {
            try
            {
                preContext.Profiler.InvokeMeasured(
                    filter,
                    x => x.OnPerforming(preContext),
                    $"OnPerforming for {preContext.BackgroundJob.Id}");
            }
            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
                {
                    postContext.Profiler.InvokeMeasured(
                        filter,
                        x => x.OnPerformed(postContext),
                        $"OnPerformed for {postContext.BackgroundJob.Id}");
                }
                catch (Exception filterException)
                {
                    CoreBackgroundJobPerformer.HandleJobPerformanceException(
                        filterException,
                        postContext.CancellationToken.ShutdownToken);

                    throw;
                }

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

            if (!wasError)
            {
                try
                {
                    postContext.Profiler.InvokeMeasured(
                        filter,
                        x => x.OnPerformed(postContext),
                        $"OnPerformed for {postContext.BackgroundJob.Id}");
                }
                catch (Exception filterException)
                {
                    CoreBackgroundJobPerformer.HandleJobPerformanceException(
                        filterException,
                        postContext.CancellationToken.ShutdownToken);

                    throw;
                }
            }

            return(postContext);
        }
Exemple #11
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);
        }
        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;
        }
 public void OnPerforming(PerformingContext filterContext)
 {
     var jobService = new JobServices();
     var scriptName = filterContext.BackgroundJob.Job.Args[0].ToString();
     jobService.UpdateJob(filterContext.BackgroundJob.Id, Status.Running, null, scriptName);
 }
 public void OnPerforming(PerformingContext filterContext)
 {
     //UnityJobActivator.CreateChildContainer();
 }
        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;
        }
 public void OnPerforming(PerformingContext filterContext)
 {
     //UnityJobActivator.CreateChildContainer();
 }
        private object PerformJobWithFilters(PerformContext context, IEnumerable<IServerFilter> filters)
        {
            object result = null;

            var preContext = new PerformingContext(context);
            Func<PerformedContext> continuation = () =>
            {
                result = _innerPerformer.Perform(context);
                return new PerformedContext(context, result, false, null);
            };

            var thunk = filters.Reverse().Aggregate(continuation,
                (next, filter) => () => InvokePerformFilter(filter, preContext, next));
            
            thunk();

            return result;
        }