Beispiel #1
0
        private void StartExtensions()
        {
            if (PluginRegistry == null || PluginRegistry.Count == 0)
            {
                Log.Info("No plugins loaded, skipping initalization.");
                return;
            }

            Log.Info("Initializing extensions...");

            for (var i = 0; i < PluginRegistry.Count; i++)
            {
                var pluginHost = PluginRegistry[i];

                try
                {
                    var pluginInfo   = PluginRegistry.GetPluginInfoByName(pluginHost.Manifest.FriendlyName);
                    var isLastPlugin = (i == PluginRegistry.Count - 1);

                    pluginHost.Instance.Initialize(this, pluginHost.Manifest.IPCIdentifier);
                    PluginInitialized?.Invoke(this, new PluginInitializationEventArgs(pluginInfo, isLastPlugin));

                    Log.Info($"Plugin {pluginHost.Manifest.FriendlyName} initialized");
                }
                catch (Exception ex)
                {
                    Log.Error($"Plugin {pluginHost.Manifest.FriendlyName} failed to initialize. Exception has been caught, see the log for details.");
                    Log.ExceptionSilent(ex);
                }
            }

            Log.Info("Extensions initialized.");
        }
Beispiel #2
0
        public async ValueTask Initialize(IPlugin plugin)
        {
            if (PluginStatus.ContainsKey(plugin) && !PluginStatus[plugin])
            {
                await plugin.Initialize(PluginScopes[plugin]);

                PluginStatus[plugin] = true;
                var pluginDesciptorAttr = plugin.GetType().GetCustomAttribute <EmberPluginAttribute>();
                PluginInitialized?.Invoke(PluginDescriptor.FromAttribute(pluginDesciptorAttr));
            }
        }
Beispiel #3
0
 /// <summary>
 /// Executes <paramref name="handler"/> when plugin with specified <paramref name="pluginName"/> is loaded. This
 /// can be used to add dynamic dependencies.
 /// </summary>
 /// <example>
 ///     PluginManager.Instance.AddPluginLoadedHandler("ClientSync", delegate() {
 ///         // do something that uses ClientSync plugin...
 ///     });
 /// </example>
 /// <param name="pluginName">Plugin to be loaded.</param>
 /// <param name="handler">Handler to be executed.</param>
 public void AddPluginLoadedHandler(string pluginName, Action handler)
 {
     if (IsPluginLoaded(pluginName))
     {
         handler();
     }
     else
     {
         PluginInitialized customPluginInitializedHandler = null;
         customPluginInitializedHandler = delegate(object sender, PluginInitializedEventArgs args) {
             if (args.pluginName == pluginName)
             {
                 OnAnyPluginInitialized -= customPluginInitializedHandler;
                 handler();
             }
         };
         OnAnyPluginInitialized += customPluginInitializedHandler;
     }
 }