public static void Apply <TStateEnum>(FSMWrapper fsmw)
        where TStateEnum : IConvertible
    {
        if (!(fsmw is IFSMExecutableStateSpecifier <TStateEnum>))
        {
            return;
        }

        foreach (TStateEnum s in Enum.GetValues(typeof(TStateEnum)))
        {
            var actions = (fsmw as IFSMExecutableStateSpecifier <TStateEnum>).GetStateActions(s);
            if (actions.Length == 0)
            {
                continue;
            }

            var      sn    = Enum.GetName(typeof(TStateEnum), s);
            FsmState state = fsmw.targetFsm.GetState(sn);

            var missingActions = actions.Where(
                x => !Array.Exists(state.Actions, (a) => a.GetType() == x));
            state.Actions = state.Actions.Concat(
                missingActions.Select(x => (FsmStateAction)Activator.CreateInstance(x))
                ).ToArray();
        }
    }
Exemplo n.º 2
0
    public static void Apply <TEventEnum, TStateEnum>(FSMWrapper <TEventEnum> fsmw)
        where TStateEnum : IConvertible
        where TEventEnum : IConvertible
    {
        if (!(fsmw is IFSMEventRouteSpecifier <TEventEnum, TStateEnum>))
        {
            return;
        }
        foreach (TStateEnum s in Enum.GetValues(typeof(TStateEnum)))
        {
            var      sn    = Enum.GetName(typeof(TStateEnum), s);
            FsmState state = fsmw.targetFsm.GetState(sn);

            var transitions     = (fsmw as IFSMEventRouteSpecifier <TEventEnum, TStateEnum>).EventsFrom(s);
            var transitionNames = transitions.Select(
                (x) => Enum.GetName(typeof(TEventEnum), x));
            var missingTransitions = transitionNames.Where(
                x => state.Transitions.All(y => y.EventName != x));
            state.Transitions = state.Transitions.Concat(
                missingTransitions.Select(x => {
                var t      = new FsmTransition();
                t.FsmEvent = fsmw.targetFsm.GetEvent(x);
                return(t);
            })).ToArray();

            foreach (var t in state.Transitions)
            {
                if (transitionNames.Contains(t.EventName))
                {
                    t.ColorIndex = fsmw.eventColour;
                    t.LinkStyle  = FsmTransition.CustomLinkStyle.Circuit;
                }
            }
        }
    }
Exemplo n.º 3
0
    public static void Apply <TStateEnum>(FSMWrapper fsmw)
        where TStateEnum : IConvertible
    {
        //check states for signal wrapper action
        var allStateNames = Enum.GetNames(typeof(TStateEnum));

        foreach (var state in fsmw.targetFsm.States)
        {
            bool shouldContainSignal = false;
            if (allStateNames.Contains(state.Name))
            {
                state.ColorIndex    = (fsmw as IFSMStateDescriber).stateColour;
                shouldContainSignal = true;
            }

            if (shouldContainSignal)
            {
                if (Array.Find(state.Actions, (a) => a is SignalWrapper) == null)
                {
                    var newAction = new SignalWrapper(typeof(TStateEnum));
                    state.Actions = new FsmStateAction[] { newAction }.Concat(
                        state.Actions
                        ).ToArray();
                }
            }
            else
            {
                var i = Array.FindIndex(state.Actions,
                                        (a) => (a is SignalWrapper && (a as SignalWrapper).enumType == typeof(TStateEnum).ToString()));
                if (i >= 0)
                {
                    var dest = new FsmStateAction[state.Actions.Length - 1];
                    if (i > 0)
                    {
                        Array.Copy(state.Actions, 0, dest, 0, i);
                    }

                    if (i < state.Actions.Length - 1)
                    {
                        Array.Copy(state.Actions, i + 1, dest, i, state.Actions.Length - i - 1);
                    }

                    state.Actions = dest;
                }
            }

            state.SaveActions();
        }
    }
Exemplo n.º 4
0
 public static void Apply(FSMWrapper fsmw)
 {
     if (!(fsmw is IFSMWrappedVariableSpecifier))
     {
         return;
     }
     foreach (var wrapper in (fsmw as IFSMWrappedVariableSpecifier).GetWrappedVariables())
     {
         if (wrapper.name != "" && !fsmw.targetFsm.Variables.Contains(wrapper.name))
         {
             wrapper.AddTo(fsmw.targetFsm.Variables);
             wrapper.Initialise(fsmw.fsm);
         }
     }
 }