Exemplo n.º 1
0
        public void Execute(TextWriter output)
        {
            context = new Context();
            context.Output = output;
            context.Variables = attributes;
            context.Variables["true"] = true;
            context.Variables["false"] = false;
            context.Variables["null"] = null;
            context.Using.Add("System");
            if(this.Usings!=null)
                foreach (string nameSpace in this.Usings)
                    if(!string.IsNullOrEmpty(nameSpace))
                        context.Using.Add(nameSpace);
            Context.code = this.Code;
            context.Interpreter = this;

            Stopwatch watch = new Stopwatch();
            watch.Start();
            try
            {
                StatementCollection coll = new StatementCollection(statements, false);
                coll.Execute(context, null, null);
                this.ExecutionSuccessful = true;
            }
            catch (Exception ex)
            {
                this.ExecutionSuccessful = false;
                context.Output.Write(ex.Message + (ex.InnerException != null ? " - " + ex.InnerException.Message : "") + " at line " + (Context.CurrentStatement.LineNumber + 1));
            }
            watch.Stop();
            this.ExecutingTime = watch.ElapsedMilliseconds;

            if (Context.debuggerWindow != null)
            {
                Context.debugging = false;
                Context.debuggerWindow.Close();
                Context.debuggerWindow = null;
            }
        }