示例#1
0
        private List <State> ExtractEventActionStates(Cdn.Variable v)
        {
            var ret = new List <State>();

            Cdn.EdgeAction[] actions;

            if (!d_actionedVariables.TryGetValue(v, out actions))
            {
                return(ret);
            }

            foreach (Cdn.EdgeAction action in actions)
            {
                var      ph = action.Phases;
                string[] eph;

                if (action.Edge != null)
                {
                    eph = action.Edge.Phases;
                }
                else
                {
                    eph = new string[] {};
                }

                if (ph.Length != 0 || eph.Length != 0)
                {
                    var node = FindStateNode(action.Edge.Input as Cdn.Node);

                    HashSet <string> hs;

                    if (ph.Length != 0)
                    {
                        hs = new HashSet <string>(ph);

                        if (eph.Length != 0)
                        {
                            hs.IntersectWith(eph);
                        }
                    }
                    else
                    {
                        hs = new HashSet <string>(eph);
                    }

                    if (node == null)
                    {
                        return(ret);
                    }

                    foreach (var h in hs)
                    {
                        EventStateContainerAdd(AddEventStateContainer(node), node, h);
                    }

                    var nm = UniqueVariableName(action.Edge, String.Format("__action_{0}", action.Target));
                    var nv = new Cdn.Variable(nm, action.Equation.Copy(), Cdn.VariableFlags.None);

                    action.Edge.AddVariable(nv);
                    d_eventActionProperties[action] = nv;

                    var evst = new EventActionState(action, nv);
                    ret.Add(evst);

                    List <int> indices = new List <int>();

                    foreach (var st in hs)
                    {
                        var        evstdid = EventStateId(node, st);
                        EventState revst;

                        if (d_eventStateIdMap.TryGetValue(evstdid, out revst))
                        {
                            indices.Add(revst.Index);
                            revst.ActiveActions.Add(action);
                        }
                    }

                    if (indices.Count != 0)
                    {
                        indices.Sort();
                        string key = String.Join(",", indices.ConvertAll(a => a.ToString()));

                        EventStateGroup grp;

                        if (!d_eventStateGroups.TryGetValue(key, out grp))
                        {
                            grp = new EventStateGroup {
                                Node     = node,
                                Actions  = new List <Cdn.EdgeAction>(),
                                States   = new List <State>(),
                                Indices  = indices,
                                ActiveIn = hs
                            };

                            d_eventStateGroups[key] = grp;
                        }

                        grp.Actions.Add(action);
                        grp.States.Add(evst);

                        d_eventStateToGroup[evst] = grp;
                    }
                }
            }

            return(ret);
        }
示例#2
0
        public bool TryEventStateGroupLookup(Cdn.Node node, string state, out EventStateGroup grp)
        {
            var key = EventStateId(node, state);

            return(d_eventStateGroups.TryGetValue(key, out grp));
        }