示例#1
0
        static string MakeFullPluginAssemblyPath(string pluginName)
        {
            var plugins      = InEngineSettings.Make().Plugins;
            var isCorePlugin = Assembly.GetCallingAssembly().GetName().Name == pluginName;

            if (!isCorePlugin && !plugins.ContainsKey(pluginName))
            {
                throw new PluginNotRegisteredException(pluginName);
            }
            return(Path.Combine(
                       Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
                       isCorePlugin ? "" : plugins[pluginName],
                       $"{pluginName}.dll"
                       ));
        }
示例#2
0
        public static List <PluginAssembly> Load <T>(bool shouldLoadCorePlugin = true) where T : IPlugin
        {
            RegisterPluginAssemblyResolver();
            var pluginList = new List <PluginAssembly>();

            try
            {
                if (shouldLoadCorePlugin)
                {
                    pluginList.Add(new PluginAssembly(Assembly.GetExecutingAssembly()));
                }
            }
            catch (Exception exception)
            {
                LogManager.GetLogger <PluginAssembly>().Error(exception);
                throw new PluginNotFoundException("Could not load InEngine.Core plugin.", exception);
            }

            var assemblies = InEngineSettings
                             .Make()
                             .Plugins
                             .Select(x => Assembly.LoadFrom(Path.Combine(x.Value, $"{x.Key}.dll")));

            foreach (var assembly in assemblies)
            {
                try
                {
                    if (assembly.GetTypes().Any(x => x.IsClass && typeof(T).IsAssignableFrom(x) && !x.IsAbstract))
                    {
                        pluginList.Add(new PluginAssembly(assembly));
                    }
                }
                catch (Exception exception)
                {
                    throw new PluginNotFoundException($"Could not load {assembly.GetName().Name} plugin.", exception);
                }
            }
            if (!pluginList.Any())
            {
                throw new PluginNotFoundException("There are no plugins available.");
            }
            return(pluginList.OrderBy(x => x.Name).ToList());
        }