Esempio n. 1
0
        /// <summary>
        /// Validates all the statements in the script.
        /// </summary>
        public override PhaseResult Execute(PhaseContext phaseCtx)
        {
            // 1. Check number of statements.
            var statements = _execAllNodes ? phaseCtx.Nodes : phaseCtx.NodesStack[phaseCtx.NodesStack.Count - 1];

            var now = DateTime.Now;

            // 2. No statements ? return
            if (statements == null || statements.Count == 0)
                return ToPhaseResult(now, now, true, "There are 0 nodes to lint");

            var semacts = new SemActs();
            var result = semacts.Validate(statements);

            // 4. Simply wrap the run-result ( success, message, start/end times )
            // inside of a phase result.
            return new PhaseResult(result);
        }
Esempio n. 2
0
        /// <summary>
        /// Executes each phase supplied.
        /// </summary>
        /// <param name="script">The script to execute</param>
        /// <param name="phaseCtx">Contextual information passed to all phases.</param>
        /// <param name="ctx">The context of the runtime</param>
        /// <param name="phases">The list of phases.</param>
        /// <returns></returns>
        public PhaseResult Execute(string script, PhaseContext phaseCtx, Context ctx, List<IPhase> phases)
        {
            if (phases == null || phases.Count == 0)
                throw new ArgumentException("No phases supplied to execute");

            // 2. Keep track of last phase result
            PhaseResult lastPhaseResult = null;
            foreach (var phase in phases)
            {
                // 3. Execute the phase and get it's result.
                phase.Ctx = ctx;
                lastPhaseResult = phase.Execute(phaseCtx);
                phase.Result = lastPhaseResult;

                // 4. Stop the phase execution.
                if (!phase.Result.Success)
                {
                    break;
                }
            }
            return lastPhaseResult;
        }
Esempio n. 3
0
        /// <summary>
        /// Executes all the statements in the script.
        /// </summary>
        public override PhaseResult Execute(PhaseContext phaseCtx)
        {
            // 1. Check number of statements.
            var statements = _execAllNodes ? phaseCtx.Nodes : phaseCtx.NodesStack[phaseCtx.NodesStack.Count - 1];

            var now = DateTime.Now;

            // 2. No statements ? return
            if (statements == null || statements.Count == 0)
                return ToPhaseResult(now, now, true, "There are 0 nodes to execute");

            // 3. Execute the nodes and get the run-result which captures various data
            var runResult = LangHelper.Execute(() =>
            {
                var execution = new Execution();
                execution.Ctx = this.Ctx;
                EvalHelper.Ctx = this.Ctx;
                execution.VisitExprs(statements);
            });

            // 4. Simply wrap the run-result ( success, message, start/end times )
            // inside of a phase result.
            return new PhaseResult(runResult);
        }
        /// <summary>
        /// Executes all the statements in the script.
        /// </summary>
        public override PhaseResult Execute(PhaseContext phaseCtx)
        {
            // 1. Check number of statements.
            var statements = phaseCtx.Nodes;

            var now = DateTime.Now;

            // 2. No statements ? return
            if (statements == null || statements.Count == 0)
                return ToPhaseResult(now, now, true, "There are 0 nodes to execute");

            // 3. Execute the nodes and get the run-result which captures various data
            var runResult = LangHelper.Execute(() =>
            {
                foreach (var stmt in statements)
                {

                }
            });

            // 4. Simply wrap the run-result ( success, message, start/end times )
            // inside of a phase result.
            return new PhaseResult(runResult);
        }
Esempio n. 5
0
        /// <summary>
        /// Executes all the statements in the script.
        /// </summary>
        public override PhaseResult Execute(PhaseContext phaseCtx)
        {
            var script = phaseCtx.ScriptText;
            var memory = phaseCtx.Ctx.Memory;

            var runResult = LangHelper.Execute( () =>
            {
                this.Ctx.Limits.CheckScriptLength(script);
                _parser.Parse(script, memory);

                if (phaseCtx.Nodes == null)
                    phaseCtx.Nodes = new List<Expr>();

                if (phaseCtx.NodesStack == null)
                    phaseCtx.NodesStack = new List<List<Expr>>();

                // 1. Keep track of all the statements.
                phaseCtx.Nodes.AddRange(_parser.Statements);

                // 2. Keep track of the each individual set of statements ( from multiple scripts )
                phaseCtx.NodesStack.Add(_parser.Statements);
            });
            return new PhaseResult(runResult);
        }
Esempio n. 6
0
 /// <summary>
 /// Executes all the statements in the script.
 /// </summary>
 public override PhaseResult Execute(PhaseContext phaseCtx)
 {
     var result = LangHelper.Execute(() => phaseCtx.Ctx.Plugins.Dispose());
     return new PhaseResult(result);
 }
Esempio n. 7
0
 /// <summary>
 /// Executes the phase
 /// </summary>
 /// <param name="phaseContext"></param>
 /// <returns></returns>
 public virtual PhaseResult Execute(PhaseContext phaseContext)
 {
     return ToEmptyPhaseResult(false, string.Empty);
 }
Esempio n. 8
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;
        }