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);
 }
 public bool CanInterpret(Script script, out string errorMessage)
 {
     try
     {
         InterpretScript(script);
         errorMessage = string.Empty;
         return(true);
     }
     catch (Exception e)
     {
         errorMessage = e.ToString();
         return(false);
     }
 }
        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;
            }
        }
 public void SaveScript(Script script)
 {
     _scriptRepository.SaveOrUpdate(script);
     _scriptCache.Remove(script.Name);
 }
        public IDocument Process(IDocument document, Script script)
        {
            var compiledScript = InterpretScript(script);

            return(Process(document, compiledScript));
        }
 public ScriptWrapper(Script script, IScript interpretedScript)
 {
     Script            = script;
     InterpretedScript = interpretedScript;
 }