コード例 #1
0
 private IScript GetCompiledScript(Script script)
 {
     if (!_compiledScriptCache.TryGetValue(script.Name, out ScriptWrapper cachedScript) ||
         cachedScript.Script.LastUpdated <= script.LastUpdated)    //recompile the script
     {
         var compiledScript = InterpretScript(script);
         _compiledScriptCache[script.Name] = new ScriptWrapper(script, compiledScript);
         return(compiledScript);
     }
     return(cachedScript.InterpretedScript);
 }
コード例 #2
0
 public bool CanInterpret(Script script, out string errorMessage)
 {
     try
     {
         InterpretScript(script);
         errorMessage = string.Empty;
         return(true);
     }
     catch (Exception e)
     {
         errorMessage = e.ToString();
         return(false);
     }
 }
コード例 #3
0
        private IScript InterpretScript(Script script)
        {
            var option = ScriptOptions.Default
                         .WithReferences(typeof(IScript).GetTypeInfo().Assembly);

            try
            {
                var createdScript = CSharpScript.Create(script.Code, option)
                                    .ContinueWith <IScript>(
                    $"new {script.Name}() as IScript")
                                    .CreateDelegate()
                                    .Invoke()
                                    .Result;
                return(createdScript);
            }
            catch (Exception e)
            {
                Log.Error(e, $"Error when interpreting script {script.Name}: {e.Message}");
                throw;
            }
        }
コード例 #4
0
 public void SaveScript(Script script)
 {
     _scriptRepository.SaveOrUpdate(script);
     _scriptCache.Remove(script.Name);
 }
コード例 #5
0
        public IDocument Process(IDocument document, Script script)
        {
            var compiledScript = InterpretScript(script);

            return(Process(document, compiledScript));
        }
コード例 #6
0
 public ScriptWrapper(Script script, IScript interpretedScript)
 {
     Script            = script;
     InterpretedScript = interpretedScript;
 }