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); } })); }
public bool CanExecute(object parameter) { bool result = true; if (CanExecuteAction != null) { result = CanExecuteAction.Invoke(); } return(result); }
/// <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; }
/// <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); }; }
public bool CanExecute(object parameter) { return(CanExecuteAction?.Invoke(parameter) ?? true); }
/// <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) { }
/// <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()) { }
/// <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) { }