Beispiel #1
0
        /// <summary>
        /// Find the index of the specified import filter from loaded importers
        /// </summary>
        /// <param name="extension"></param>
        /// <returns></returns>
        public int ExportFilterIndex(string extension)
        {
            int count = -1;

            foreach (KeyValuePair <string, Type> kvp in LoadedActions)
            {
                Type t = kvp.Value;
                if (typeof(IExportAction).IsAssignableFrom(t))
                {
                    ExportActionAttribute exportAtt = ExportActionAttribute.ExtractFrom(t);
                    if (exportAtt != null)
                    {
                        count++;
                        foreach (string ext in exportAtt.Extensions)
                        {
                            if (extension.EqualsIgnoreCase(ext))
                            {
                                return(count);
                            }
                        }
                    }
                }
            }
            return(-1);
        }
Beispiel #2
0
        /// <summary>
        /// Returns a list of all exporter filters combined into one string
        /// </summary>
        /// <returns></returns>
        public string GetExportFilters()
        {
            StringBuilder sb  = new StringBuilder();
            StringBuilder sbX = new StringBuilder(); //All extensions set

            string separator  = "";
            string separatorX = "";

            foreach (KeyValuePair <string, Type> kvp in LoadedActions)
            {
                Type t = kvp.Value;
                if (typeof(IExportAction).IsAssignableFrom(t))
                {
                    ExportActionAttribute exportAtt = ExportActionAttribute.ExtractFrom(t);
                    if (exportAtt != null)
                    {
                        sb.Append(separator);
                        sb.Append(exportAtt.Filter);
                        separator = "|";
                        foreach (string ext in exportAtt.Extensions)
                        {
                            sbX.Append(separatorX);
                            sbX.Append("*");
                            sbX.Append(ext);
                            separatorX = "; ";
                        }
                    }
                }
            }
            return(sb.ToString()); //"All compatible file types (" + sbX.ToString() + ")|" + sbX.ToString() + "|" + sb.ToString();
        }
Beispiel #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;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }