Exemple #1
0
        public bool Update()
        {
            if (Disposed)
            {
                return(false);
            }

            if (!_started)
            {
                OnStart();
            }

            RunningTaskFinishCheck();
            if (_runningTask != null)
            {
                return(true);
            }

            var executeForce = new List <IApeAction>();
            var random       = new List <IApeAction>();

            try
            {
                foreach (var action in _actions)
                {
                    var state = action.CheckState();
                    if (state == State.ExecuteForce)
                    {
                        executeForce.Add(action);
                    }
                    if (state == State.Execute)
                    {
                        random.Add(action);
                    }
                }
            }
            catch (ApeTestFinishException e)
            {
                _logger.TestFinish(e);
                DisposeInternal();
                return(false);
            }

            if (executeForce.Count > 0)
            {
                var action = executeForce[0];
                _cancellationTokenSource = new CancellationTokenSource();
                _logger.ActionStart(action);
                _runningAction = action;
                _runningTask   = action.Run(_cancellationTokenSource.Token);
            }
            else
            {
                var pickedAction = random.RandomPick();
                if (pickedAction != null)
                {
                    _cancellationTokenSource = new CancellationTokenSource();
                    _logger.ActionStart(pickedAction);
                    _runningAction = pickedAction;
                    _runningTask   = pickedAction.Run(_cancellationTokenSource.Token);
                }
            }
            RunningTaskFinishCheck();

            return(true);
        }