Пример #1
0
        /// <summary>
        /// Validate the statements for errors.
        /// </summary>
        /// <param name="stmts">Statements to validate</param>
        /// <returns></returns>
        public RunResult Validate(List<Expr> stmts)
        {
            var start = DateTime.Now;
            if (stmts == null || stmts.Count == 0)
                return new RunResult(start, start, true, "No nodes to validate");

            _ctx = stmts[0].Ctx;

            // Reset the errors.
            _errors = new List<ScriptError>();
            _parseStk = new ParseStackManager();

            // Use the visitor to walk the AST tree of statements/expressions
            var visitor = new AstVisitor((astnode1) => Validate(astnode1), (astnode2) =>OnNodeEnd(astnode2));
            visitor.Visit(stmts);

            var end = DateTime.Now;
            // Now check for success.
            bool success = _errors.Count == 0;
            _results = new RunResult(start, end, success, _errors);
            _results.Errors = _errors;
            return _results;
        }
Пример #2
0
 /// <summary>
 /// Builds up a phase result from start, end, success/message fields.
 /// </summary>
 /// <param name="start"></param>
 /// <param name="end"></param>
 /// <param name="success"></param>
 /// <param name="message"></param>
 /// <returns></returns>
 public PhaseResult ToPhaseResult(DateTime start, DateTime end, bool success, string message)
 {
     var runResult = new RunResult(start, end, success, message);
     return new PhaseResult(runResult);
 }
Пример #3
0
 /// <summary>
 /// Empty phase result, 0 time duration.
 /// </summary>
 /// <param name="success"></param>
 /// <param name="message"></param>
 /// <returns></returns>
 public PhaseResult ToEmptyPhaseResult(bool success, string message)
 {
     var now = DateTime.Now;
     var runResult = new RunResult(now, now, success, message);
     return new PhaseResult(runResult);
 }
Пример #4
0
 /// <summary>
 /// Initialize
 /// </summary>
 /// <param name="started"></param>
 /// <param name="ended"></param>
 /// <param name="success"></param>
 /// <param name="message"></param>
 /// <param name="result"></param>
 public PhaseResult(RunResult result)
     : base(result.StartTime, result.EndTime, result.Success, result.Message)
 {
     this.Errors = result.Errors;
     this.Result = result;
 }
Пример #5
0
        private void Execute(Action action, Func<string> exceptionMessageFetcher = null)
        {
            DateTime start = DateTime.Now;
            bool success = true;
            string message = string.Empty;
            Exception scriptError = null;
            try
            {
                action();
            }
            catch (Exception ex)
            {
                success = false;
                if (ex is LangException)
                {
                    var lex = ex as LangException;
                    const string langerror = "{0} : {1} at line : {2}, position: {3}";
                    message = string.Format(langerror, lex.Error.ErrorType, lex.Message, lex.Error.Line, lex.Error.Column);
                }
                else message = ex.Message;

                scriptError = ex;
                if (exceptionMessageFetcher != null)
                    message += exceptionMessageFetcher();
            }
            DateTime end = DateTime.Now;
            _runResult = new RunResult(start, end, success, message);
            _runResult.Ex = scriptError;
        }
Пример #6
0
        /// <summary>
        /// Executes the script
        /// </summary>
        /// <param name="script">Script text</param>
        /// <param name="clearExistingCode">Whether or not to clear existing parsed code and start fresh.</param>
        public void Execute(string script, bool clearExistingCode, bool resetScript, params IPhase[] phases)
        {
            this.InitPlugins();
            if(_parser != null)
            {
                var execution = new Execution();
                execution.Ctx = _context;
                EvalHelper.Ctx = _context;
                _parser.OnDemandEvaluator = execution;
            }
            var phaseExecutor = new PhaseExecutor();

            // 1. Create the execution phase
            if (clearExistingCode)
            {
                _phaseCtx = new PhaseContext();
                _phaseCtx.Ctx = _context;
            }
            if (resetScript)
                _phaseCtx.ScriptText = script;

            var phasesList = phases.ToList();
            var result = phaseExecutor.Execute(script, _phaseCtx, _context, phasesList);
            this._runResult = result.Result;
        }