/// <summary> /// <p>Searches for the "Plugin.[filetype]" (e.g. Plugin.js) and runs it</p> /// <p>Will generate a new plugin instance if context is null</p> /// </summary> /// <param name="path">The path to the directory containing the script files</param> /// <param name="context">The script context. Can be null if there is none.</param> public virtual ScriptResult LoadPluginFromDirectory(string path, ref IScriptContext context) { var files = Directory.GetFiles(path); if (files.Length == 0) { return(new ScriptResult(ScriptExecutionResult.FileNotFound)); } ScriptPluginMeta meta = GetPluginMeta(path); string targetFile = null; foreach (var file in files) { string fileName = Path.GetFileNameWithoutExtension(file); string ext = Path.GetExtension(file); if (fileName.Equals("plugin", StringComparison.OrdinalIgnoreCase) && FileTypes.Any(c => c.Equals(ext, StringComparison.OrdinalIgnoreCase))) { targetFile = file; } } if (targetFile == null) { return(new ScriptResult(ScriptExecutionResult.FileNotFound)); } return(ExecuteFile(targetFile, Container, ref context, meta, true)); }
protected ScriptPlugin(ScriptPluginMeta pluginMeta, IDependencyContainer container, ScriptingProvider provider, IScriptContext scriptContext) { _provider = provider; Container = container; Name = pluginMeta.Name; PluginMeta = pluginMeta; ScriptContext = scriptContext; }
/// <summary> /// Executes the given script file /// </summary> /// <param name="path">The path to the file.</param> /// <param name="entryPoint">The entry function to call.</param> /// <param name="context">The script context. Can be null if there is none.</param> /// <param name="createPluginInstanceOnNull">Create a new plugin instance when <paramref name="context"/> is null?</param> /// <param name="container">The dependency container.</param> /// <param name="meta">Metadata for the plugin if <paramref name="createPluginInstanceOnNull"/> is true and <paramref name="context"/> is null. Can be null if <paramref name="createPluginInstanceOnNull"/> is false.</param> /// <param name="arguments">The arguments for the entry point.</param> /// <returns>The result of the script execution.</returns> public abstract ScriptResult ExecuteFile( string path, IDependencyContainer container, ref IScriptContext context, ScriptPluginMeta meta, bool createPluginInstanceOnNull = false, string entryPoint = null, params object[] arguments );