Ejemplo n.º 1
0
        WxeStepList _stepList = null; // represents Then or Else step list, depending on result of If()

        public override void Execute(WxeContext context)
        {
            Type type = this.GetType();

            if (_stepList == null)
            {
                MethodInfo ifMethod = type.GetMethod(
                    "If", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly, null, new Type[0], null);
                if (ifMethod == null || ifMethod.ReturnType != typeof(bool))
                {
                    throw new WxeException("If-block " + type.FullName + " does not define method \"bool If()\".");
                }

                bool result = (bool)ifMethod.Invoke(this, new object[0]);
                if (result)
                {
                    _stepList = GetResultList("Then");
                    if (_stepList == null)
                    {
                        throw new WxeException("If-block " + type.FullName + " does not define nested class \"Then\".");
                    }
                }
                else
                {
                    _stepList = GetResultList("Else");
                }
            }

            if (_stepList != null)
            {
                _stepList.Execute(context);
            }
        }
Ejemplo n.º 2
0
        public override void Execute(WxeContext context)
        {
            if (_executingCatchBlock == -1) // tryBlock
            {
                try
                {
                    _trySteps.Execute(context);
                }
                catch (Exception ex)
                {
                    if (ex is System.Threading.ThreadAbortException)
                    {
                        throw;
                    }

                    Exception unwrappedException = WxeHttpExceptionPreservingException.GetUnwrappedException(ex) ?? ex;

                    for (int i = 0; i < _catchBlocks.Count; ++i)
                    {
                        WxeCatchBlock catchBlock = (WxeCatchBlock)_catchBlocks[i];
                        if (catchBlock.ExceptionType.IsInstanceOfType(ex))
                        {
                            _executingCatchBlock = i;
                            catchBlock.Exception = ex;
                            break;
                        }
                        else if (catchBlock.ExceptionType.IsInstanceOfType(unwrappedException))
                        {
                            _executingCatchBlock = i;
                            catchBlock.Exception = unwrappedException;
                            break;
                        }
                    }

                    if (_executingCatchBlock == -1)
                    {
                        throw;
                    }

                    ExecutingStepList.Execute(context);
                }

                if (_finallySteps != null)
                {
                    _executingCatchBlock = -2;
                    ExecutingStepList.Execute(context);
                }
            }
            else if (_executingCatchBlock == -2) // finallyBlock
            {
                _finallySteps.Execute(context);
            }
            else
            {
                ExecutingStepList.Execute(context);
                if (_finallySteps != null)
                {
                    _executingCatchBlock = -2;
                    _finallySteps.Execute(context);
                }
            }
        }