예제 #1
0
        public static void RegisterFunctions(Assembly assembly)
        {
            string assemblyName      = Path.GetFileName(assembly.Location);
            string assemblyNameLower = assemblyName.ToLowerInvariant();

            if (Plugins.ContainsKey(assemblyNameLower))
            {
                return;
            }

            Jolt.XmlDocCommentReader xmlReader = null;
            string xmlPath = Path.GetDirectoryName(assembly.Location) + @"\" + Path.GetFileNameWithoutExtension(assembly.Location) + ".xml";

            if (File.Exists(xmlPath))
            {
                xmlReader = new Jolt.XmlDocCommentReader(xmlPath);
            }

            List <FunctionBase> assemblyFunctions = new List <FunctionBase>();

            Plugins.Add(assemblyNameLower, new Tuple <string, List <FunctionBase> >(assemblyName, assemblyFunctions));
            foreach (var type in assembly.GetTypes())
            {
                if (type.GetCustomAttributes(typeof(Plugin), false).Length > 0)
                {
                    string name = type.Name.ToLowerInvariant();
                    List <FunctionBase> pluginClasses;
                    if (!Functions.TryGetValue(name, out pluginClasses))
                    {
                        pluginClasses = new List <FunctionBase>();
                        Functions.Add(name, pluginClasses);
                    }
                    foreach (var constructor in type.GetConstructors(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly))
                    {
                        FunctionClass function;
                        XElement      element = null;
                        if ((xmlReader != null) && ((element = xmlReader.GetComments(constructor)) != null))
                        {
                            function = new FunctionClass(constructor, new XmlComments(element));
                        }
                        else
                        {
                            function = new FunctionClass(constructor, null);
                        }
                        pluginClasses.Add(function);
                        assemblyFunctions.Add(function);
                    }

                    var opensFileAttribs = type.GetCustomAttributes(typeof(PluginOpensFile), false);
                    for (int i = 0; i < opensFileAttribs.Length; i++)
                    {
                        var    attrib = (PluginOpensFile)opensFileAttribs[i];
                        string ext    = attrib.FileExtension.ToLowerInvariant();

                        List <string> opensFileList;
                        if (!OpensFile.TryGetValue(ext, out opensFileList))
                        {
                            opensFileList = new List <string>();
                            OpensFile.Add(ext, opensFileList);
                        }
                        opensFileList.Add(type.Name);
                    }

                    var toolAttribs = type.GetCustomAttributes(typeof(PluginTool), false);
                    if (toolAttribs.Length > 0)
                    {
                        var attrib = (PluginTool)toolAttribs[0];
                        Tools.Add(new string[] { type.Name, attrib.Name, attrib.Shortcut });
                    }
                }

                foreach (var method in type.GetMethods(BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance | BindingFlags.DeclaredOnly))
                {
                    if (method.GetCustomAttributes(typeof(Plugin), false).Length > 0)
                    {
                        string name = method.Name.ToLowerInvariant();
                        List <FunctionBase> pluginMethods;
                        if (!Functions.TryGetValue(name, out pluginMethods))
                        {
                            pluginMethods = new List <FunctionBase>();
                            Functions.Add(name, pluginMethods);
                        }

                        FunctionMethod function;
                        XElement       element = null;
                        if ((xmlReader != null) && ((element = xmlReader.GetComments(method)) != null))
                        {
                            function = new FunctionMethod(method, new XmlComments(element));
                        }
                        else
                        {
                            function = new FunctionMethod(method, null);
                        }
                        pluginMethods.Add(function);
                        assemblyFunctions.Add(function);

                        var opensFileAttribs = method.GetCustomAttributes(typeof(PluginOpensFile), false);
                        for (int i = 0; i < opensFileAttribs.Length; i++)
                        {
                            var    attrib = (PluginOpensFile)opensFileAttribs[i];
                            string ext    = attrib.FileExtension.ToLowerInvariant();

                            List <string> opensFileList;
                            if (!OpensFile.TryGetValue(ext, out opensFileList))
                            {
                                opensFileList = new List <string>();
                                OpensFile.Add(ext, opensFileList);
                            }
                            opensFileList.Add(method.Name);
                        }

                        var toolAttribs = method.GetCustomAttributes(typeof(PluginTool), false);
                        if (toolAttribs.Length > 0)
                        {
                            var attrib = (PluginTool)toolAttribs[0];
                            Tools.Add(new string[] { method.Name, attrib.Name, attrib.Shortcut });
                        }
                    }
                }
            }
        }
예제 #2
0
        public static void RegisterFunctions(Assembly assembly)
        {
            string assemblyName = Path.GetFileName(assembly.Location);
            string assemblyNameLower = assemblyName.ToLowerInvariant();
            if (Plugins.ContainsKey(assemblyNameLower))
            {
                return;
            }

            Jolt.XmlDocCommentReader xmlReader = null;
            string xmlPath = Path.GetDirectoryName(assembly.Location) + @"\" + Path.GetFileNameWithoutExtension(assembly.Location) + ".xml";
            if (File.Exists(xmlPath))
            {
                xmlReader = new Jolt.XmlDocCommentReader(xmlPath);
            }

            List<FunctionBase> assemblyFunctions = new List<FunctionBase>();
            Plugins.Add(assemblyNameLower, new Tuple<string, List<FunctionBase>>(assemblyName, assemblyFunctions));
            foreach (var type in assembly.GetTypes())
            {
                if (type.GetCustomAttributes(typeof(Plugin), false).Length > 0)
                {
                    string name = type.Name.ToLowerInvariant();
                    List<FunctionBase> pluginClasses;
                    if (!Functions.TryGetValue(name, out pluginClasses))
                    {
                        pluginClasses = new List<FunctionBase>();
                        Functions.Add(name, pluginClasses);
                    }
                    foreach (var constructor in type.GetConstructors(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly))
                    {
                        FunctionClass function;
                        XElement element = null;
                        if ((xmlReader != null) && ((element = xmlReader.GetComments(constructor)) != null))
                        {
                            function = new FunctionClass(constructor, new XmlComments(element));
                        }
                        else
                        {
                            function = new FunctionClass(constructor, null);
                        }
                        pluginClasses.Add(function);
                        assemblyFunctions.Add(function);
                    }

                    var opensFileAttribs = type.GetCustomAttributes(typeof(PluginOpensFile), false);
                    for (int i = 0; i < opensFileAttribs.Length; i++)
                    {
                        var attrib = (PluginOpensFile)opensFileAttribs[i];
                        string ext = attrib.FileExtension.ToLowerInvariant();

                        List<string> opensFileList;
                        if (!OpensFile.TryGetValue(ext, out opensFileList))
                        {
                            opensFileList = new List<string>();
                            OpensFile.Add(ext, opensFileList);
                        }
                        opensFileList.Add(type.Name);
                    }

                    var toolAttribs = type.GetCustomAttributes(typeof(PluginTool), false);
                    if (toolAttribs.Length > 0)
                    {
                        var attrib = (PluginTool)toolAttribs[0];
                        Tools.Add(new string[] { type.Name, attrib.Name, attrib.Shortcut });
                    }
                }

                foreach (var method in type.GetMethods(BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance | BindingFlags.DeclaredOnly))
                {
                    if (method.GetCustomAttributes(typeof(Plugin), false).Length > 0)
                    {
                        string name = method.Name.ToLowerInvariant();
                        List<FunctionBase> pluginMethods;
                        if (!Functions.TryGetValue(name, out pluginMethods))
                        {
                            pluginMethods = new List<FunctionBase>();
                            Functions.Add(name, pluginMethods);
                        }

                        FunctionMethod function;
                        XElement element = null;
                        if ((xmlReader != null) && ((element = xmlReader.GetComments(method)) != null))
                        {
                            function = new FunctionMethod(method, new XmlComments(element));
                        }
                        else
                        {
                            function = new FunctionMethod(method, null);
                        }
                        pluginMethods.Add(function);
                        assemblyFunctions.Add(function);

                        var opensFileAttribs = method.GetCustomAttributes(typeof(PluginOpensFile), false);
                        for (int i = 0; i < opensFileAttribs.Length; i++)
                        {
                            var attrib = (PluginOpensFile)opensFileAttribs[i];
                            string ext = attrib.FileExtension.ToLowerInvariant();

                            List<string> opensFileList;
                            if (!OpensFile.TryGetValue(ext, out opensFileList))
                            {
                                opensFileList = new List<string>();
                                OpensFile.Add(ext, opensFileList);
                            }
                            opensFileList.Add(method.Name);
                        }

                        var toolAttribs = method.GetCustomAttributes(typeof(PluginTool), false);
                        if (toolAttribs.Length > 0)
                        {
                            var attrib = (PluginTool)toolAttribs[0];
                            Tools.Add(new string[] { method.Name, attrib.Name, attrib.Shortcut });
                        }
                    }
                }
            }
        }