public DynamicTriggerBehaviour(TTrigger trigger, Func <object[], TState> destination, TransitionGuard transitionGuard, Reflection.DynamicTransitionInfo info) : base(trigger, transitionGuard) { _destination = destination ?? throw new ArgumentNullException(nameof(destination)); TransitionInfo = info ?? throw new ArgumentNullException(nameof(info)); }
/// <summary> /// Configures transition guard based on specified list user of roles. /// </summary> /// <typeparam name="TState">The type of the state.</typeparam> /// <typeparam name="TActivity">The type of the activity.</typeparam> /// <param name="stateConfig">The state configuration.</param> /// <param name="trigger">The trigger.</param> /// <param name="destinationState">State of the destination.</param> /// <param name="roleGuard">The role guard, use this.PermitFor() helper method to define list of permitted roles.</param> /// <returns></returns> public static StateMachine <TState, TActivity> .StateConfiguration PermitForRoles <TState, TActivity>( this StateMachine <TState, TActivity> .StateConfiguration stateConfig, TActivity trigger, TState destinationState, TransitionGuard roleGuard) { return(stateConfig .PermitIf(trigger, destinationState, roleGuard.GuardMethod, roleGuard.Description)); }
/// <summary> /// Permits the trigger only if all conditions are met. /// </summary> /// <typeparam name="TState">The type of the state.</typeparam> /// <typeparam name="TActivity">The type of the activity.</typeparam> /// <param name="stateConfig">The state configuration.</param> /// <param name="trigger">The trigger.</param> /// <param name="destinationState">State of the destination.</param> /// <param name="roleGuard">The role guard.</param> /// <param name="guards">The guards.</param> /// <returns>State machine configuration</returns> public static StateMachine <TState, TActivity> .StateConfiguration PermitOnlyIf <TState, TActivity>( this StateMachine <TState, TActivity> .StateConfiguration stateConfig, TActivity trigger, TState destinationState, TransitionGuard roleGuard, params Func <bool>[] guards) { var listOfGuards = new List <TransitionGuard>(new[] { roleGuard }); var otherGuards = guards .Select(g => new TransitionGuard(g, g.Method.Name)) .ToList(); listOfGuards .AddRange(otherGuards); var triggerName = trigger.ToString(); var destinationStateName = destinationState.ToString(); var currentStateName = stateConfig.State.ToString(); Func <bool> aggregateGuardExpression = () => { var failedGuards = listOfGuards .Where(g => !g.GuardMethod()) .Select(g => g.Description) .ToArray(); if (failedGuards.Any()) { throw new UnmetTransitionGuardsException(currentStateName, triggerName, destinationStateName, failedGuards); } return (true); }; var otherGuardsSummary = otherGuards .Select(g => g.Description.SplitCamelCase()) .ToSeparatedString(", "); var otherGuardsDescritpion = otherGuards.Any() ? $" and {otherGuardsSummary}" : ""; return(stateConfig .PermitIf(trigger, destinationState, aggregateGuardExpression, $"{roleGuard.Description}{otherGuardsDescritpion}")); }
protected InternalTriggerBehaviour(TTrigger trigger, TransitionGuard guard) : base(trigger, guard) { }
// transitionGuard can be null if there is no guard function on the transition public ReentryTriggerBehaviour(TTrigger trigger, TState destination, TransitionGuard transitionGuard) : base(trigger, transitionGuard) { _destination = destination; }
public IgnoredTriggerBehaviour(TTrigger trigger, TransitionGuard transitionGuard) : base(trigger, transitionGuard) { }
/// <summary> /// TriggerBehaviour constructor /// </summary> /// <param name="trigger"></param> /// <param name="guard">TransitionGuard (null if no guard function)</param> protected TriggerBehaviour(TTrigger trigger, TransitionGuard guard) { _guard = guard ?? TransitionGuard.Empty; Trigger = trigger; }
// transitionGuard can be null if there is no guard function on the transition public TransitioningTriggerBehaviour(TTrigger trigger, TState destination, TransitionGuard transitionGuard) : base(trigger, transitionGuard) { Destination = destination; }