protected PluginHost([NotNull] PluginInfo plugin, [NotNull] Application hostApplication) { if (plugin == null) { throw new ArgumentNullException(nameof(plugin)); } if (hostApplication == null) { throw new ArgumentNullException(nameof(hostApplication)); } if (string.IsNullOrWhiteSpace(plugin.AssemblyLocation)) { throw new ArgumentException("The plugin doesn't contain a valid assembly location.", nameof(plugin)); } if (!File.Exists(plugin.AssemblyLocation)) { throw new FileNotFoundException("The assembly specified in the plugin info can't be found.", plugin.AssemblyLocation); } mHostApplication = hostApplication; mPluginInfo = plugin; var directory = Path.GetDirectoryName(plugin.AssemblyLocation) ?? Directory.GetCurrentDirectory(); mContext = new PluginHostContext(new FileSystemStore(directory.AsKey(), isReadOnly: true)); mLog = hostApplication.Log; }
protected Plugin([NotNull] IPluginHostContext hostContext) { if (hostContext == null) { throw new ArgumentNullException(nameof(hostContext)); } Context = hostContext; }
protected PluginHost([NotNull] PluginInfo plugin, [CanBeNull] ILogWriter log = null) { if (plugin == null) { throw new ArgumentNullException(nameof(plugin)); } mPluginInfo = plugin; mContext = new PluginHostContext(new FileSystemStore((Path.GetDirectoryName(plugin.AssemblyLocation) ?? Directory.GetCurrentDirectory()).AsKey(), isReadOnly: true)); mLog = log; }
public void Shutdown(PluginShutdownArgs args) { if (args == null) { throw new ArgumentNullException(nameof(args)); } OnShutdown(args); Context = null; Log = null; }
public Result <object> CreateInstance <TInterface>(PluginInfo pluginInfo, IPluginHostContext context) where TInterface : class, IPlugin { if (pluginInfo == null) { throw new ArgumentNullException(nameof(pluginInfo)); } if (context == null) { throw new ArgumentNullException(nameof(context)); } return(CreateInstance(pluginInfo, typeof(TInterface), context)); }
public Result <object> CreateInstance(PluginInfo pluginInfo, Type interfaceType, IPluginHostContext context) { if (pluginInfo == null) { throw new ArgumentNullException(nameof(pluginInfo)); } if (interfaceType == null) { throw new ArgumentNullException(nameof(interfaceType)); } if (context == null) { throw new ArgumentNullException(nameof(context)); } Assembly assembly; Type implementationType; object instance; try { assembly = LoadAssembly(pluginInfo.AssemblyLocation); } catch (Exception exception) { return(Result.CreateError <Result <object> >(new Exception($"Failed load plugin assembly at \"{pluginInfo.AssemblyLocation}\": {exception.Message}", exception))); } try { implementationType = GetPluginImplementationType(assembly, interfaceType); if (implementationType == null) { return(Result.CreateError <Result <object> >(new Exception($"Failed load plugin assembly at \"{pluginInfo.AssemblyLocation}\": no suitable plugin implementation type fouund."))); } } catch (Exception exception) { return(Result.CreateError <Result <object> >(new Exception($"Failed locate plugin implementation type: {exception.Message}", exception))); } try { instance = Activator.CreateInstance(implementationType, context); } catch (Exception exception) { return(Result.CreateError <Result <object> >(new Exception($"Failed create plugin instance: {exception.Message}", exception))); } return(new Result <object>(instance)); }