Exemplo n.º 1
0
        public void OnCreating(CreatingContext filterContext)
        {
            if (filterContext == null) throw new ArgumentNullException(nameof(filterContext));

            filterContext.SetJobParameter(
                "CurrentCulture", CultureInfo.CurrentCulture.Name);
            filterContext.SetJobParameter(
                "CurrentUICulture", CultureInfo.CurrentUICulture.Name);
        }
Exemplo n.º 2
0
        public void Ctor_CanceledProperty_IsFalseByDefault()
        {
            var connection = new Mock<IStorageConnection>();
            var job = Job.FromExpression(() => TestMethod());
            var state = new Mock<IState>();
            var stateMachineFactory = new Mock<IStateMachineFactory>();

            var createContext = new CreateContext(
                connection.Object, stateMachineFactory.Object, job, state.Object);
            var context = new CreatingContext(createContext);

            Assert.False(context.Canceled);
        }
Exemplo n.º 3
0
        private static void CreateWithFilters(
            CreateContext context,
            IEnumerable<IClientFilter> filters)
        {
            var preContext = new CreatingContext(context);
            Func<CreatedContext> continuation = () =>
            {
                context.CreateJob();
                return new CreatedContext(context, false, null);
            };

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

            thunk();
        }
Exemplo n.º 4
0
        private CreatedContext CreateWithFilters(
            CreateContext context, 
            IEnumerable<IClientFilter> filters)
        {
            var preContext = new CreatingContext(context);
            Func<CreatedContext> continuation = () =>
            {
                var backgroundJob = _innerFactory.Create(context);
                return new CreatedContext(context, backgroundJob, false, null);
            };

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

            return thunk();
        }
Exemplo n.º 5
0
        private CreatedContext CreateWithFilters(
            CreateContext context,
            IEnumerable <IClientFilter> filters)
        {
            var preContext = new CreatingContext(context);
            Func <CreatedContext> continuation = () =>
            {
                var backgroundJob = _innerFactory.Create(context);
                return(new CreatedContext(context, backgroundJob, false, null));
            };

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

            return(thunk());
        }
        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 CreatedContext CreateWithFilters(
            CreateContext context,
            IJobCreator creator,
            IEnumerable <IClientFilter> filters)
        {
            var preContext = new CreatingContext(context);
            Func <CreatedContext> continuation = () =>
            {
                var jobId = creator.CreateJob(context.Job, preContext.Parameters, context.InitialState);
                return(new CreatedContext(context, jobId, false, null));
            };

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

            return(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);
        }
Exemplo n.º 9
0
        private static CreatedContext CreateWithFilters(
            CreateContext context,
            IJobCreator creator,
            IEnumerable<IClientFilter> filters)
        {
            var preContext = new CreatingContext(context);
            Func<CreatedContext> continuation = () =>
            {
                var jobId = creator.CreateJob(context.Job, preContext.Parameters, context.InitialState);
                return new CreatedContext(context, jobId, false, null);
            };

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

            return thunk();
        }
Exemplo n.º 10
0
        private static CreatedContext InvokeClientFilter(
            IClientFilter filter,
            CreatingContext preContext,
            Func <CreatedContext> continuation)
        {
            filter.OnCreating(preContext);
            if (preContext.Canceled)
            {
                return(new CreatedContext(
                           preContext, true, null));
            }

            var            wasError = false;
            CreatedContext postContext;

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

                filter.OnCreated(postContext);

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

            if (!wasError)
            {
                filter.OnCreated(postContext);
            }

            return(postContext);
        }
Exemplo n.º 11
0
        private static CreatedContext InvokeClientFilter(
            IClientFilter filter,
            CreatingContext preContext,
            Func<CreatedContext> continuation)
        {
            filter.OnCreating(preContext);
            if (preContext.Canceled)
            {
                return new CreatedContext(
                    preContext, true, null);
            }

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

                filter.OnCreated(postContext);

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

            if (!wasError)
            {
                filter.OnCreated(postContext);
            }

            return postContext;
        }