示例#1
0
        public PetriController()
        {
            Transitions        = new List <Transition <T> >();
            GeneralTransitions = new List <GeneralTransition <T> >();
            gLocker            = new GeneralLocker();

            Objects = new List <T>();
        }
示例#2
0
        public GeneralTransition(Predicate <IEnumerable <T> > _Function, Predicate <T> _SolvePredicate, Action <T> _DecreaseAction, Action <T> _IncreaseAction,
                                 ExecutionMode _mode, int _key, GeneralLocker _gLocker, int _TimePeriod, List <T> _Objects)
        {
            Function       = _Function;
            SolvePredicate = _SolvePredicate;
            DecreaseAction = _DecreaseAction;
            IncreaseAction = _IncreaseAction;
            mode           = _mode;
            key            = _key;

            gLocker = _gLocker;

            gLocker.LockDic[key] = false;
            if (_TimePeriod > 0)
            {
                gLocker.TimerDic[key] = new Timer(new TimeSpan(0, 0, _TimePeriod));
            }
            Objects = _Objects;
        }
示例#3
0
        public void WasChangedGeneralTransitionTest()
        {
            //test1
            IEnumerable<TestClass> Objects = ParallelEnumerable.Repeat<TestClass>(new TestClass(), 2);

            Objects.AsParallel().ForAll(o => { o.Number = 2; o.Word = "ccc"; });

            GeneralLocker gLocker = new GeneralLocker();

            GeneralTransition<TestClass> genTrans = new GeneralTransition<TestClass>(o => true, o => o.Number == 2 && o.Word == "ccc", o => { }, o => { o.Number = 3; o.Word = "ddd"; },
                ExecutionMode.Synch, 0, gLocker, 0, Objects.ToList());

            genTrans.Do();

            Assert.IsTrue(gLocker.WasChanged);
        }