Esempio n. 1
0
        /// <summary>
        /// Retrieve the command name for this action
        /// </summary>
        /// <param name="action"></param>
        /// <returns></returns>
        public static string GetCommandName(this IAction action)
        {
            Type   type = action.GetType();
            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;
            }
            return(commandName);
        }
Esempio n. 2
0
 /// <summary>
 /// Retrieve the action attributes for this action
 /// </summary>
 /// <param name="action"></param>
 /// <returns></returns>
 public static ActionAttribute GetAttributes(this IAction action)
 {
     return(ActionAttribute.ExtractFrom(action));
 }
Esempio n. 3
0
        /// <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;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }