public void OnCreating(CreatingContext filterContext)
        {
            if (filterContext == null) throw new ArgumentNullException("filterContext");

            filterContext.SetJobParameter(
                "CurrentCulture", Thread.CurrentThread.CurrentCulture.Name);
            filterContext.SetJobParameter(
                "CurrentUICulture", Thread.CurrentThread.CurrentUICulture.Name);
        }
        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);
        }
        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();
        }
        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();
        }
        public PreserveCultureAttributeFacts()
        {
            _connection = new Mock<IStorageConnection>();
            var job = Job.FromExpression(() => Sample());
            var state = new Mock<IState>();
            var stateMachineFactory = new Mock<IStateMachineFactory>();

            var createContext = new CreateContext(
                _connection.Object, stateMachineFactory.Object, job, state.Object);
            _creatingContext = new CreatingContext(createContext);
            _createdContext = new CreatedContext(createContext, false, null);

            var workerContext = new WorkerContextMock();

            var performContext = new PerformContext(
                workerContext.Object, _connection.Object, JobId, job, DateTime.UtcNow, new Mock<IJobCancellationToken>().Object);
            _performingContext = new PerformingContext(performContext);
            _performedContext = new PerformedContext(performContext, false, null);
        }
        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);
        }
        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;
        }