示例#1
0
        public IReleasable AddAction(string name, Action <Step> executeAction, Func <Step, bool> canExecuteAction)
        {
            if (executeAction == null)
            {
                throw new ArgumentNullException("executeAction");
            }
            if (canExecuteAction == null)
            {
                throw new ArgumentNullException("canExecuteAction");
            }

            var execute = new ExecuteAction(executeAction);

            myExecuteActions[name] = execute;
            var canExecute = new CanExecuteAction(canExecuteAction);

            myCanExecuteActions[name] = canExecute;

            Log.Debug("ActionRepository: Action '" + name + "' added (with CanExecute).");

            return(new ReleasableAction(() =>
            {
                ExecuteAction executeStored;
                if (myExecuteActions.TryGetValue(name, out executeStored) && executeStored == execute)
                {
                    myExecuteActions.Remove(name);
                }

                CanExecuteAction canExecuteStored;
                if (myCanExecuteActions.TryGetValue(name, out canExecuteStored) && canExecuteStored == canExecute)
                {
                    myCanExecuteActions.Remove(name);
                }
            }));
        }
示例#2
0
        public bool CanExecute(object parameter)
        {
            bool result = true;

            if (CanExecuteAction != null)
            {
                result = CanExecuteAction.Invoke();
            }
            return(result);
        }
示例#3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DelegateJob" /> class.
        /// </summary>
        /// <param name="id">The ID of the job.</param>
        /// <param name="execAction">An action for a <see cref="DelegateJob.OnExecute(IJobExecutionContext)" /> method.</param>
        /// <param name="canExecuteAction">An action for a <see cref="DelegateJob.OnCanExecute(DateTimeOffset, ref bool)" /> method.</param>
        /// <param name="isThreadSafe">Job schould work thread safe or not.</param>
        /// <param name="syncRoot">The object for thread safe operations.</param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="execAction" />, <paramref name="canExecuteAction" /> and/or <paramref name="syncRoot" /> are <see langword="null" />.
        /// </exception>
        public DelegateJob(Guid id, ExecuteAction execAction, CanExecuteAction canExecuteAction, bool isThreadSafe, object syncRoot)
            : base(id, false)
        {
            if (execAction == null)
            {
                throw new ArgumentNullException("execAction");
            }

            if (canExecuteAction == null)
            {
                throw new ArgumentNullException("canExecuteAction");
            }

            this._EXECUTE_ACTION     = execAction;
            this._CAN_EXECUTE_ACTION = canExecuteAction;
        }
示例#4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DelegateJob" /> class.
        /// </summary>
        /// <param name="id">The ID of the job.</param>
        /// <param name="execAction">An action for a <see cref="DelegateJob.OnExecute(IJobExecutionContext)" /> method.</param>
        /// <param name="canExecutePredicate">A predicate for a <see cref="DelegateJob.OnCanExecute(DateTimeOffset, ref bool)" /> method.</param>
        /// <param name="isThreadSafe">Job schould work thread safe or not.</param>
        /// <param name="syncRoot">The object for thread safe operations.</param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="execAction" />, <paramref name="canExecutePredicate" /> and/or <paramref name="syncRoot" /> are <see langword="null" />.
        /// </exception>
        public DelegateJob(Guid id, ExecuteAction execAction, CanExecutePredicate canExecutePredicate, bool isThreadSafe, object syncRoot)
            : base(id, isThreadSafe, syncRoot)
        {
            if (execAction == null)
            {
                throw new ArgumentNullException("execAction");
            }

            if (canExecutePredicate == null)
            {
                throw new ArgumentNullException("canExecutePredicate");
            }

            this._EXECUTE_ACTION     = execAction;
            this._CAN_EXECUTE_ACTION = delegate(DateTimeOffset time, ref bool canExecuteJob)
            {
                canExecuteJob = canExecutePredicate(time);
            };
        }
示例#5
0
 public bool CanExecute(object parameter)
 {
     return(CanExecuteAction?.Invoke(parameter) ?? true);
 }
示例#6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DelegateJob" /> class.
 /// </summary>
 /// <param name="id">The ID of the job.</param>
 /// <param name="execAction">An action for a <see cref="DelegateJob.OnExecute(IJobExecutionContext)" /> method.</param>
 /// <param name="canExecuteAction">An action for a <see cref="DelegateJob.OnCanExecute(DateTimeOffset, ref bool)" /> method.</param>
 /// <param name="syncRoot">The object for thread safe operations.</param>
 /// <exception cref="ArgumentNullException">
 /// <paramref name="execAction" />, <paramref name="canExecuteAction" /> and/or <paramref name="syncRoot" /> are <see langword="null" />.
 /// </exception>
 public DelegateJob(Guid id, ExecuteAction execAction, CanExecuteAction canExecuteAction, object syncRoot)
     : this(id, execAction, canExecuteAction, false, syncRoot)
 {
 }
示例#7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DelegateJob" /> class.
 /// </summary>
 /// <param name="id">The ID of the job.</param>
 /// <param name="execAction">An action for a <see cref="DelegateJob.OnExecute(IJobExecutionContext)" /> method.</param>
 /// <param name="canExecuteAction">An action for a <see cref="DelegateJob.OnCanExecute(DateTimeOffset, ref bool)" /> method.</param>
 /// <param name="isThreadSafe">Job schould work thread safe or not.</param>
 /// <exception cref="ArgumentNullException">
 /// <paramref name="execAction" /> and/or <paramref name="canExecuteAction" /> are <see langword="null" />.
 /// </exception>
 public DelegateJob(Guid id, ExecuteAction execAction, CanExecuteAction canExecuteAction, bool isThreadSafe)
     : this(id, execAction, canExecuteAction, isThreadSafe, new object())
 {
 }
示例#8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DelegateJob" /> class.
 /// </summary>
 /// <param name="id">The ID of the job.</param>
 /// <param name="execAction">An action for a <see cref="DelegateJob.OnExecute(IJobExecutionContext)" /> method.</param>
 /// <param name="canExecuteAction">An action for a <see cref="DelegateJob.OnCanExecute(DateTimeOffset, ref bool)" /> method.</param>
 /// <exception cref="ArgumentNullException">
 /// <paramref name="execAction" /> and/or <paramref name="canExecuteAction" /> are <see langword="null" />.
 /// </exception>
 public DelegateJob(Guid id, ExecuteAction execAction, CanExecuteAction canExecuteAction)
     : this(id, execAction, canExecuteAction, false)
 {
 }