/// <summary> /// Retrieve the default importer for the given file type /// </summary> /// <param name="extension"></param> /// <returns></returns> public IImportAction GetImporterFor(string extension) { extension = extension.ToLower(); if (ExtensionImporters.ContainsKey(extension)) { Type type = ExtensionImporters[extension]; if (type != null) { return((IImportAction)Activator.CreateInstance(type, true)); } } return(null); }
/// <summary> /// Load a plugin action set from an assembly /// </summary> /// <param name="filePath"></param> public void LoadPlugin(Assembly pluginAss) { if (pluginAss != null) { Type[] types = pluginAss.GetTypes(); foreach (Type type in types) { if (typeof(IAction).IsAssignableFrom(type) && !type.IsAbstract) { string commandName; object[] typeAtts = type.GetCustomAttributes(typeof(ActionAttribute), false); if (typeAtts.Count() > 0) { ActionAttribute aAtt = (ActionAttribute)typeAtts[0]; commandName = aAtt.CommandName; } else { commandName = type.Name; } if (LoadedActions.ContainsKey(commandName)) { Core.PrintLine("Could not load action with command name '" + commandName + "' from assembly '" + pluginAss.Location + "' - an action with the same name is already loaded"); } else { LoadedActions.Add(commandName, type); //Importer actions if (typeof(IImportAction).IsAssignableFrom(type)) { ImportActionAttribute importAtt = ImportActionAttribute.ExtractFrom(type); if (importAtt != null) { foreach (string extension in importAtt.Extensions) { string ext = extension.ToLower(); if (ExtensionImporters.ContainsKey(ext)) { Core.PrintLine("Warning: Importer for file extension '" + extension + "' is already loaded. Extension is ambiguous."); } ExtensionImporters[ext] = type; } } } //Exporter actions: if (typeof(IExportAction).IsAssignableFrom(type)) { ExportActionAttribute exportAtt = ExportActionAttribute.ExtractFrom(type); if (exportAtt != null) { foreach (string extension in exportAtt.Extensions) { string ext = extension.ToLower(); if (ExtensionExporters.ContainsKey(ext)) { Core.PrintLine("Warning: Exporter for file extension '" + extension + "' is already loaded. Extension is ambiguous."); } ExtensionExporters[ext] = type; } } } } } } } }