Esempio n. 1
0
        public void TestSetString()
        {
            EventObject       eo  = new EventObject();
            AsyncEventManager aem = new AsyncEventManager();

            aem.Add(eo);
            Assert.AreEqual(eo.i, 0);
            aem.Invoke("test");
            Assert.AreEqual(eo.i, 1);
        }
Esempio n. 2
0
        protected FSMState()
        {
            asm              = new AsyncEventManager();
            enters           = new List <MethodInfoObject>();
            exits            = new List <MethodInfoObject>();
            updates          = new List <MethodInfoObject>();
            timersDictionary = new Dictionary <string, TimingObject>();

            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 = TimingObject.fromAttribute((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 = TimingObject.fromAttribute((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);
        }