/// <summary> /// Initializes a new instance of the <see cref="SoluiNetPluginException"/> class. /// </summary> /// <param name="message">The message.</param> /// <param name="innerException">The inner exception.</param> /// <param name="plugin">The plugin object.</param> public SoluiNetPluginException(string message, Exception innerException, IBasePlugin plugin) : base(message, innerException) { if (plugin == null) { throw new ArgumentNullException(nameof(plugin)); } this.Plugin = plugin.Name; }
public void LoadFromObjectTest() { MapWindow.PluginInterfaces.PluginTracker target = new Plugins_IBasePlugin(); // TODO: Initialize to an appropriate value IBasePlugin Plugin = null; // TODO: Initialize to an appropriate value string PluginKey = string.Empty; // TODO: Initialize to an appropriate value bool expected = false; // TODO: Initialize to an appropriate value bool actual; actual = target.LoadFromObject(Plugin, PluginKey); Assert.AreEqual(expected, actual); Assert.Inconclusive("Verify the correctness of this test method."); }
public void ClosePlugin(IBasePlugin plugin) { for (int i = 0; i < this.availablePlugins.Count; i++) { if (this.availablePlugins[i].Instance == plugin) { this.availablePlugins.RemoveAt(i); plugin.Dispose(); plugin = null; break; } } }
public void InitializePlugin(string fileExePath) { Assembly assembly = Assembly.LoadFrom(fileExePath); Type objectType = (from type in assembly.GetTypes() where type.IsClass && type.Name == "PluginApp" select type).Single(); IBasePlugin basePlugin = (IBasePlugin)Activator.CreateInstance(objectType); WpfConsole.WriteLine("Initialize: " + basePlugin.GetPluginName()); var result = basePlugin.Initialize(SimpleEventBus.GetDefaultEventBus()); WpfConsole.WriteLine("Initialize result: " + result); }
/// <summary> /// Get the embedded resource names of a plugin. /// </summary> /// <param name="plugin">The plugin in which the resources are contained.</param> /// <param name="type">The type of the resources. If not provided "Script" will be used.</param> /// <returns>A <see cref="IList{T}"/> which contains a list of all the embedded resource names in the overgiven plugin.</returns> public static IList <string> GetEmbeddedResources(IBasePlugin plugin, string type = "Script") { if (plugin == null) { return(null); } var pluginNamespace = plugin.GetType().Namespace; var embeddedResources = plugin.GetType().Assembly.GetManifestResourceNames().Where(x => x.StartsWith(string.Format(CultureInfo.InvariantCulture, "{0}.{1}", pluginNamespace, type), StringComparison.InvariantCulture)) .ToList(); return(embeddedResources); }
public void LoadPlugins() { Plugins = new List <IBasePlugin>(); var pluginsDirectory = Path.Combine(Directory.GetCurrentDirectory(), "Plugins"); if (!Directory.Exists(pluginsDirectory)) { return; } var files = Directory.GetFiles(pluginsDirectory).ToList().Where(x => x.Contains("SwagCore.Plugin") && x.EndsWith(".dll")); foreach (var file in files) { Console.WriteLine("Plugin: " + file); var myAssembly = AssemblyLoader.LoadFromAssemblyPath(file); var myType = myAssembly.GetTypes().SingleOrDefault(x => x.GetInterfaces().Any(y => y.Name == nameof(IBasePlugin))); if (myType == null) { continue; } IBasePlugin myInstance = (IBasePlugin)Activator.CreateInstance(myType); var configuration = Program.Configuration.GetSection("Plugins:" + myInstance.PluginName); //find plugin parameters in appsettings.json if (configuration != null) { var children = configuration.GetChildren(); var parameters = children.Select(x => new KeyValuePair <string, string>(x.Key, x.Value)); myInstance.Init(new Dictionary <string, string>(parameters)); } if (!Plugins.Any(x => x.PluginName == myInstance.PluginName || x.ActionsName == myInstance.ActionsName) ) //if plugin keywords empty - add plugin { Plugins.Add(myInstance); Console.WriteLine("Plugin added " + myInstance.PluginName + " - " + string.Join(", ", myInstance.ActionsName)); } } }
public void AddRequirePlugin(IBasePlugin plugin) { ActivePluginsListAdd(plugin.InnerName, plugin.Version); }
/// <summary> /// Helper object that stores the services available in this plug-in /// </summary> /// <param name="serviceProvider">IServiceProvider</param> /// <param name="events">List of <see href="RegisteredEvents" /> for the plugin</param> /// <param name="plugin">Plugin handler</param> public BasePluginContext(IServiceProvider serviceProvider, IEnumerable <RegisteredEvent> events, IBasePlugin plugin) { if (serviceProvider == null) { throw new ArgumentNullException(nameof(serviceProvider)); } _provider = serviceProvider; // Obtain the organization factory service from the service provider _factory = (IOrganizationServiceFactory)_provider.GetService(typeof(IOrganizationServiceFactory)); // Set Event Event = PluginExecutionContext.GetEvent(events); PluginTypeName = plugin.GetType().FullName; }