Exemplo n.º 1
0
        public LibraryManager(string pluginFileMask, string loggerName)
        {
            Logger = Extensions.LogFactory.CreateLogger(loggerName);
            Logger.LogDebug("Searching directory {0} for extensions with mask {1}", EXTENSION_SEARCH_PATH,
                            pluginFileMask);
            foreach (var file in Directory.GetFiles(EXTENSION_SEARCH_PATH, pluginFileMask))
            {
                Logger.LogDebug("Loading Assembly from {0}", file);

                var loader = PluginLoader.CreateFromAssemblyFile(
                    file,
                    new[] { typeof(Plugin), typeof(PluginResult), typeof(ServiceHook), typeof(ILogger) });
                var asm = loader.LoadDefaultAssembly();

                var plugins = asm.GetTypes().Where(t => typeof(TBaseType).IsAssignableFrom(t));
                Logger.LogDebug("Found {0} plugins in {1}", plugins.Count(), file);
                foreach (var plugin in plugins)
                {
                    LoadedLibraryTypes.Add(plugin);
                }
            }

            RecognizedIdentifiers = LoadedLibraryTypes.ToDictionary(k => GetTypeIdentifier(k), v => v);

            Logger.LogInformation("Created {0} instance with {1} available extension types of base type '{2}': {3}",
                                  GetType().Name, LoadedLibraryTypes.Count, typeof(TBaseType).Name,
                                  string.Join(", ", RecognizedIdentifiers.Keys));
        }
Exemplo n.º 2
0
 internal Type GetLibraryType(PluginPointerModel pointer)
 {
     return(LoadedLibraryTypes.FirstOrDefault(p => GetTypeIdentifier(p) == pointer.Plugin));
 }