Exemplo n.º 1
0
 public DynamicModel(Dictionary <string, object> construct)
 {
     dataObject = construct;
     aem        = new AsyncEventManager();
     aem.Add(this);
 }
Exemplo n.º 2
0
        protected FSMState()
        {
            asm              = new AsyncEventManager();
            enters           = new List <MethodInfoObject>();
            exits            = new List <MethodInfoObject>();
            updates          = new List <MethodInfoObject>();
            timersDictionary = new Dictionary <string, Timing>();

            foreach (var methodInfo in GetType()
                     .GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance))
            {
                foreach (var o in methodInfo.GetCustomAttributes(false))
                {
                    if (o.GetType() == typeof(Enter))
                    {
                        var enter = (Enter)o;
                        enters.Add(new MethodInfoObject {
                            Method = methodInfo, Target = this, Priority = enter.Priority
                        });
                    }
                    else if (o.GetType() == typeof(Exit))
                    {
                        var exit = (Exit)o;
                        exits.Add(new MethodInfoObject {
                            Method = methodInfo, Target = this, Priority = exit.Priority
                        });
                    }
                    else if (o.GetType() == typeof(Loop))
                    {
                        var loop = (Loop)o;
                        if (loop.Time == 0)
                        {
                            updates.Add(new MethodInfoObject
                            {
                                Method   = methodInfo,
                                Target   = this,
                                Priority = loop.Priority
                            });
                        }
                        else
                        {
                            loop.Method = methodInfo;
                            loop.Target = this;
                            timersDictionary.Add(loop.Name ?? methodInfo.Name, loop);
                        }
                        break;
                    }
                    else if (o.GetType() == typeof(One))
                    {
                        var one = (One)o;
                        timersDictionary.Add(one.Name ?? methodInfo.Name, one);
                        one.Method = methodInfo;
                        one.Target = this;
                    }
                }
            }

            enters  = enters.OrderBy(i => i.Priority).ToList();
            exits   = exits.OrderBy(i => i.Priority).ToList();
            updates = updates.OrderBy(i => i.Priority).ToList();
            timers  = timersDictionary.Select(i => i.Value).OrderBy(i => i.Priority).ToList();
            asm.Add(this);
        }