Exemplo n.º 1
0
        public DesultoryIf(Func <DesultoryIf, object, DesultoryBoolean> ifCondition,
                           DesultoryStatementBase trueStatement, DesultoryStatementBase falseStatement = null)
        {
            if (null == ifCondition)
            {
                throw new ArgumentNullException("ifCondition is null");
            }

            if (null == trueStatement)
            {
                throw new ArgumentNullException("trueStatement is null");
            }

            this.IfCondition = IfCondition;

            trueStatement.ID   = ID_True;
            this.TrueStatement = trueStatement;

            if (null != falseStatement)
            {
                falseStatement.ID   = ID_False;
                this.FalseStatement = falseStatement;
            }
        }
Exemplo n.º 2
0
        public bool Run(object processState = null, object argument = null, bool failed = false, object runState = null)
        {
            try
            {
                if (0 == _items.Count)
                {
                    throw new ArgumentException("No tasks to run");
                }

                bool bRet = true;
                lock (_syncRoot)
                {
                    if (this.IsFailed)
                    {
                        _pendingItemCount--;
                        return(false);
                    }

                    if (failed)
                    {
                        this.IsFailed = true;
                        if (null != _errorItem)
                        {
                            _errorItem.Argument = argument;
                            _errorItem.Run();
                        }
                    }
                    else
                    {
                        DesultoryStatementBase item = null;
                        if (-1 == _currentIndex)
                        {
                            item = _items[++_currentIndex];
                        }
                        else
                        {
                            _pendingItemCount--;
                            item = _items[_currentIndex];
                            switch (item.CanNext(processState, runState))
                            {
                            case DesultoryTaskNextFunction.Next:
                            {
                                if (_currentIndex == _items.Count - 1)
                                {
                                    item = null;
                                    if (!_done)
                                    {
                                        if (0 == _pendingItemCount)
                                        {
                                            _done = true;
                                            if (null != _finishedItem)
                                            {
                                                _finishedItem.Run();
                                            }
                                        }
                                    }

                                    bRet = false;
                                }
                                else
                                {
                                    item = _items[++_currentIndex];
                                }
                                _stacks.Clear();
                            }
                            break;

                            case DesultoryTaskNextFunction.Current:
                                item = _items[_currentIndex];
                                break;

                            case DesultoryTaskNextFunction.Stop:
                            case DesultoryTaskNextFunction.Done:
                                item = null;
                                _stacks.Clear();
                                break;
                            }
                        }

                        if (null == item)
                        {
                            bRet = false;
                        }
                        else
                        {
                            item.Argument = argument;
                            int nCount = item.Run(runState);
                            if (0 == nCount)
                            {
                                bRet = false;
                            }
                            else
                            {
                                _pendingItemCount += nCount;
                            }
                        }
                    }
                }

                return(bRet);
            }
            catch
            {
                throw;
            }
        }