Пример #1
0
            private bool TryFindLocalHandler(TTrigger trigger, object[] args, out TriggerBehaviourResult handlerResult)
            {
                // Get list of candidate trigger handlers
                if (!TriggerBehaviours.TryGetValue(trigger, out ICollection <TriggerBehaviour> possible))
                {
                    handlerResult = null;
                    return(false);
                }

                // Guard functions are executed here
                var actual = possible
                             .Select(h => new TriggerBehaviourResult(h, h.UnmetGuardConditions(args)))
                             .ToArray();

                // Find a handler for the trigger
                handlerResult = TryFindLocalHandlerResult(trigger, actual)
                                ?? TryFindLocalHandlerResultWithUnmetGuardConditions(actual);

                if (handlerResult == null)
                {
                    return(false);
                }

                return(!handlerResult.UnmetGuardConditions.Any());
            }
Пример #2
0
 public void AddTriggerBehaviour(TriggerBehaviour triggerBehaviour)
 {
     if (!TriggerBehaviours.TryGetValue(triggerBehaviour.Trigger, out ICollection <TriggerBehaviour> allowed))
     {
         allowed = new List <TriggerBehaviour>();
         TriggerBehaviours.Add(triggerBehaviour.Trigger, allowed);
     }
     allowed.Add(triggerBehaviour);
 }
Пример #3
0
            private bool TryFindLocalHandler(TTrigger trigger, out TriggerBehaviour handler, params Func <TriggerBehaviour, bool>[] filters)
            {
                ICollection <TriggerBehaviour> possible;

                if (!TriggerBehaviours.TryGetValue(trigger, out possible))
                {
                    handler = null;
                    return(false);
                }

                var actual = filters.Aggregate(possible, (current, filter) => current.Where(filter).ToArray());

                if (actual.Count() > 1)
                {
                    throw new InvalidOperationException(
                              string.Format(StateRepresentationResources.MultipleTransitionsPermitted,
                                            trigger, UnderlyingState));
                }

                handler = actual.FirstOrDefault();
                return(handler != null);
            }