예제 #1
0
 /// <summary>
 /// Get the type of the action with the specified command name
 /// </summary>
 /// <param name="commandName"></param>
 /// <returns></returns>
 public Type GetActionDefinition(string commandName)
 {
     if (LoadedActions.ContainsKey(commandName))
     {
         return(LoadedActions[commandName]);
     }
     return(null);
 }
예제 #2
0
        /// <summary>
        /// Get an action by its command name, without executing it
        /// </summary>
        /// <param name="commandName"></param>
        /// <returns></returns>
        public IAction GetAction(string commandName)
        {
            IAction action = null;

            if (LoadedActions.ContainsKey(commandName))
            {
                Type type = LoadedActions[commandName];
                action = (IAction)Activator.CreateInstance(type, true);
            }
            else if (string.IsNullOrWhiteSpace(commandName))
            {
                action = LastCommand;
            }
            else
            {
                Core.PrintLine("Newt command '" + commandName + "' is not loaded or is not available within this host environment.");
            }
            return(action);
        }
예제 #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;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }