Ejemplo n.º 1
0
        /// <summary>
        /// Parses a Block inside an open ReplSession
        /// </summary>
        /// <param name="expression">the Expression-Block that must be executed</param>
        /// <param name="replSession">the current repl-session</param>
        /// <returns>the result of the Execution-block</returns>
        public static object ParseBlock(string expression, IDisposable replSession)
        {
            if (replSession is InterpreterBuffer.RunnerItem rii)
            {
                ITVScriptingBaseVisitor <ScriptValue> visitor  = InterpreterBuffer.GetInterpreter(rii);
                ITVScriptingParser.ProgramContext     executor = GetProgramTree(expression);
                ScriptValue retVal = visitor.VisitProgram(executor);
                return(ScriptValueHelper.GetScriptValueResult <object>(retVal, false));
            }

            return(ParseBlock(expression, replSession, null));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Runs a script inside a specific Scripting context
        /// </summary>
        /// <param name="scriptingContext">the scripting context in which a script is running</param>
        /// <returns>the result of the script</returns>
        public TOutput Execute(IDisposable scriptingContext)
        {
            CheckDate();
            bool ok = false;

            while (!ok)
            {
                lock (runCounterLock)
                {
                    ok = executionWait.WaitOne(100);
                    if (ok)
                    {
                        currentRuns++;
                    }
                }

                if (!ok)
                {
                    executionWait.WaitOne();
                }
            }

            try
            {
                if (!runnable)
                {
                    throw new ScriptException(string.Format("Script is not runnable! Suspect Line: {0}{2}Complete Error-List:{2} {1}", suspectLine, errors, Environment.NewLine));
                }

                var         visitor = InterpreterBuffer.GetInterpreter(scriptingContext);
                ScriptValue retVal  = visitor.VisitProgram(program);
                return(ScriptValueHelper.GetScriptValueResult <TOutput>(retVal, false));
            }
            finally
            {
                lock (runCounterLock)
                {
                    currentRuns--;
                    Monitor.Pulse(runCounterLock);
                }
            }
        }