Esempio n. 1
0
        private static void InvokeInitialize(Plugin plugin)
        {
            try
            {
                Debug.Write(LogType.Log, "Loading plugin " + plugin);

                PluginLoading?.Invoke(plugin);

                plugin.Initialize();

                PluginLoaded?.Invoke(plugin);
            }
            catch (Exception ex)
            {
                Debug.LogException(ex);
                Debug.LogErrorFormat("Failed to initialize plugin {0}. {1}", plugin, ex.Message);
            }
        }
Esempio n. 2
0
 protected virtual void OnPluginLoading(PluginEventArgs e)
 {
     PluginLoading?.Invoke(this, e);
 }
Esempio n. 3
0
        internal void LoadPluginsFromDirectory(string path)
        {
            _pluginFiles.Clear();
            LoadAssembliesFromDirectory(path);
            //LoadAssembliesFromDirectory(Environment.CurrentDirectory, false);

            foreach (var file in _pluginFiles.Values)
            {
                try
                {
                    PluginLoading?.Invoke(Path.GetFileNameWithoutExtension(file));

                    var pluginPath = Path.GetFullPath(file);
                    if (!string.IsNullOrEmpty(pluginPath))
                    {
                        var targetAssembly = Assembly.ReflectionOnlyLoadFrom(pluginPath);
                        foreach (var assembly in targetAssembly.GetReferencedAssemblies())
                        {
                            try
                            {
                                Assembly.Load(assembly.FullName);
                                continue;
                            }
                            catch (Exception e)
                            {
                                Logger.LogWarn(e, $"Unable to load assembly {assembly.FullName}");
                            }

                            var assemblyPath = Path.Combine(path, assembly.Name + ".dll");
                            try
                            {
                                Assembly.LoadFrom(assemblyPath);
                                continue;
                            }
                            catch (Exception e)
                            {
                                Logger.LogWarn(e, $"Unable to load assembly '{assembly.FullName}' from '{assemblyPath}'");
                            }
                        }

                        RegisterPlugin(targetAssembly, pluginPath);
                    }
                }
                catch (ReflectionTypeLoadException typeLoadException)
                {
                    Logger.LogWarn(string.Format("Cannot load type using reflection from '{1}': {0}",
                                                 typeLoadException.Message, file));
                    if (typeLoadException.LoaderExceptions != null)
                    {
                        foreach (var ex in typeLoadException.LoaderExceptions)
                        {
                            Logger.LogError(ex);
                        }
                    }
                }
                catch (TypeLoadException typeLoadException)
                {
                    Logger.LogWarn(string.Format("Cannot load type '{0}' from '{2}': {1}", typeLoadException.TypeName,
                                                 typeLoadException.Message, file));
                }
                catch (Exception e)
                {
                    Logger.LogWarn(e);
                }
            }
        }