示例#1
0
        public System.Tuple <Task, CancellationTokenSource> Execute(ScriptLanguage language, string scriptCode, TextWriter outputChannel)
        {
            // If there is an existing runner then nuke that one
            if (m_CurrentlyRunningScript != null)
            {
                throw new CannotInterruptRunningScriptException();
            }

            if ((m_CurrentLanguageDomainPair != null) && (m_CurrentLanguageDomainPair.Item1 != language))
            {
                // Different language requested so nuke the domain
                UnloadCurrentScriptDomain();
            }

            if (m_CurrentLanguageDomainPair == null)
            {
                var scriptDomain = m_AppDomainBuilder("ScriptDomain", AppDomainPaths.Core);
                m_CurrentLanguageDomainPair = new System.Tuple <ScriptLanguage, AppDomain>(language, scriptDomain);
            }

            IExecuteScripts executor = LoadExecutor(language, m_CurrentLanguageDomainPair.Item2, outputChannel);

            var source = new CancellationTokenSource();
            var token  = new CancelScriptToken(source.Token);
            var result = Task.Factory.StartNew(
                () =>
            {
                try
                {
                    executor.Execute(scriptCode, token);
                }
                finally
                {
                    m_CurrentlyRunningScript = null;
                    if (m_CurrentToken != null)
                    {
                        m_CurrentToken.Dispose();
                        m_CurrentToken = null;
                    }
                }
            },
                source.Token,
                TaskCreationOptions.LongRunning,
                m_Scheduler);

            m_CurrentlyRunningScript = result;
            m_CurrentToken           = source;

            return(new System.Tuple <Task, CancellationTokenSource>(result, source));
        }
示例#2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SyntaxVerifier"/> class.
 /// </summary>
 /// <param name="executorDomain">The <see cref="AppDomain"/> in which the <paramref name="executor"/> lives.</param>
 /// <param name="executor">The object that performs the actual verification of the script syntax.</param>
 public SyntaxVerifier(AppDomain executorDomain, IExecuteScripts executor)
 {
     m_Domain = executorDomain;
     m_Executor = executor;
 }
示例#3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SyntaxVerifier"/> class.
 /// </summary>
 /// <param name="executorDomain">The <see cref="AppDomain"/> in which the <paramref name="executor"/> lives.</param>
 /// <param name="executor">The object that performs the actual verification of the script syntax.</param>
 public SyntaxVerifier(AppDomain executorDomain, IExecuteScripts executor)
 {
     m_Domain   = executorDomain;
     m_Executor = executor;
 }