예제 #1
0
        public static ServerMethodPluginRegistration Create(string pluginAssemblyInstanceId, PluginInfo pluginInfo)
        {
            var reg = new ServerMethodPluginRegistration(pluginInfo.Assembly, pluginInfo.TypeInfo, pluginInfo.Guid, pluginAssemblyInstanceId);

            var classLevelAttrib = pluginInfo.TypeInfo.GetCustomAttribute(typeof(ServerMethodAttribute)) as ServerMethodAttribute;

            // static methods not supported
            var methods = pluginInfo.TypeInfo.GetMethods(BindingFlags.Public /* | BindingFlags.Static*/ | BindingFlags.Instance);

            string classLevelNamespace = classLevelAttrib?.Namespace;

            var serverMethodCollection = (from mi in methods
                                          select new
            {
                MethodInfo = mi,
                ServerMethodAttribute = mi.GetCustomAttribute(typeof(ServerMethodAttribute)) as ServerMethodAttribute
            })
                                         .Where(m => m.ServerMethodAttribute != null);

            if (serverMethodCollection.Count() == 0)
            {
                SessionLog.Warning($"No server method's found in plugin '{pluginInfo.Name}' ({pluginInfo.Guid}) from assembly {pluginInfo.Assembly.FullName}. Add a [ServerMethod] attribute to the methods you want to expose.");
            }
            else
            {
                foreach (var m in serverMethodCollection)
                {
                    string ns = m.ServerMethodAttribute?.Namespace;

                    if (ns == null)
                    {
                        ns = classLevelNamespace;
                    }

                    reg.AddMethod(m.MethodInfo.Name, ns, m.MethodInfo);
                }
            }

            reg.ScriptGenerator = ServerMethodScriptGenerator.Create(reg, pluginInfo);


            return(reg);
        }