protected override void execute()
        {
            var ifToken = Token as IfToken;

            var executer = Context.Get<IIfBlockExecuter>();

            bool setComplete = true;

            var completeResult = new CompletionEventArgs();
            var hasKey = Context.LocalVars.HasKey(ifToken.Blocks.IfEval);

            if(Context.DebugLevel > 0) {
                Context.Get<IScriptLog>().Log(Context.Name, ifToken.Value, Context.LineNumber);
                Context.Get<IScriptLog>().Log(Context.Name, "if result {0}".ToFormat(hasKey), Context.LineNumber);
            }

            if(hasKey)
            {
                try
                {
                    var task = executer.ExecuteBlocks(ifToken.Blocks.IfBlock, Context);
                    task.Wait();
                    completeResult = task.Result;
                }
                catch(AggregateException)
                {
                    setComplete = false;
                    TaskSource.TrySetCanceled();
                }
                catch(Exception exc)
                {
                    setComplete = false;
                    TaskSource.TrySetException(exc);
                }
            }

            if(setComplete)
                TaskSource.TrySetResult(completeResult);
        }
Beispiel #2
0
        protected override void execute()
        {
            var ifToken = Token as IfToken;

            var executer = Context.Get<IIfBlockExecuter>();

            bool setComplete = true;

            var completeResult = new CompletionEventArgs();

            try
            {
                var executeBlock = string.Empty;
                if(executer.Evaluate(ifToken.Blocks.IfEval, Context))
                {
                    executeBlock = ifToken.Blocks.IfBlock;
                    Context.LineNumber = ifToken.Blocks.IfBlockLineNumber;
                }
                else if (!string.IsNullOrWhiteSpace(ifToken.Blocks.ElseIf)
                    && executer.Evaluate(ifToken.Blocks.ElseIf, Context))
                {
                    executeBlock = ifToken.Blocks.ElseIfBlock;
                    Context.LineNumber = ifToken.Blocks.ElseIfBlockLineNumber;
                }
                else if(!string.IsNullOrWhiteSpace(ifToken.Blocks.ElseBlock))
                {
                    executeBlock = ifToken.Blocks.ElseBlock;
                    Context.LineNumber = ifToken.Blocks.ElseBlockLineNumber;
                }

                var task = executer.ExecuteBlocks(executeBlock, Context);
                task.Wait();
                if(string.IsNullOrWhiteSpace(task.Result.Goto))
                {
                    // jump to end if if/else statement
                    Context.LineNumber = ifToken.Blocks.LastLineNumber;
                }
                completeResult = task.Result;
            }
            catch(AggregateException)
            {
                setComplete = false;
                TaskSource.TrySetCanceled();
            }
            catch(Exception exc)
            {
                setComplete = false;
                TaskSource.TrySetException(exc);
            }

            if(setComplete)
                TaskSource.TrySetResult(completeResult);
        }