示例#1
0
        /// <summary>
        /// TODO: Documentation GetMatchingXmlRpcType
        /// </summary>
        /// <param name="inputString"></param>
        /// <returns></returns>
        private Type GetMatchingXmlRpcType(String inputString)
        {
            Match  match      = Regex.Match(inputString, "<methodName>(?<methodName>.+?)</methodName>");
            String methodName = null;

            if (match.Success)
            {
                methodName = match.Groups["methodName"].Value;
            }

            foreach (Type type in this.xmlRpcServiceTypes)
            {
                foreach (MethodInfo method in type.GetMethods())
                {
                    Object[] attributes = method.GetCustomAttributes(typeof(XmlRpcMethodAttribute), false);
                    XmlRpcMethodAttribute methodAttribute = null;

                    if (attributes.Length > 0)
                    {
                        methodAttribute = attributes[0] as XmlRpcMethodAttribute;
                    }

                    if (methodAttribute != null && methodAttribute.Method.Equals(methodName))
                    {
                        return(type);
                    }

                    if (method.Name.Equals(methodName))
                    {
                        return(type);
                    }
                }
            }
            return(null);
        }
示例#2
0
        public static String[] GetSignature(MethodInfo mi)
        {
            XmlRpcMethodAttribute methodAttr = (XmlRpcMethodAttribute)Attribute.GetCustomAttribute(mi, typeof(XmlRpcMethodAttribute), true);

            if (methodAttr != null && methodAttr.Hidden)
            {
                return(null);
            }

            ParameterInfo[] pis = mi.GetParameters();
            String[]        sig = new String[pis.Length + 1];

            String s = GetSignatureType(mi.ReturnType);

            if (s == null)
            {
                return(null);
            }
            sig[0] = s;
            for (Int32 i = 0; i < pis.Length; i++)
            {
                s = GetSignatureType(pis[i].ParameterType);
                if (s == null)
                {
                    return(null);
                }
                sig[i + 1] = s;
            }
            return(sig);
        }
示例#3
0
        bool IsVisibleXmlRpcMethod(MethodInfo mi)
        {
            bool      ret  = false;
            Attribute attr = Attribute.GetCustomAttribute(mi,
                                                          typeof(XmlRpcMethodAttribute));

            if (attr != null)
            {
                XmlRpcMethodAttribute mattr = (XmlRpcMethodAttribute)attr;
                ret = !mattr.Hidden;
            }
            return(ret);
        }
示例#4
0
        static bool IsVisibleXmlRpcMethod(MethodInfo mi)
        {
            bool      ret  = false;
            Attribute attr = Attribute.GetCustomAttribute(mi,
                                                          typeof(XmlRpcMethodAttribute));

            if (attr != null)
            {
                XmlRpcMethodAttribute mattr = (XmlRpcMethodAttribute)attr;
                ret = !(mattr.Hidden || mattr.IntrospectionMethod == true);
            }
            return(ret);
        }
示例#5
0
        public static string GetXmlRpcMethodName(MethodInfo mi)
        {
            XmlRpcMethodAttribute attr = (XmlRpcMethodAttribute)
                                         Attribute.GetCustomAttribute(mi,
                                                                      typeof(XmlRpcMethodAttribute));

            if (attr != null &&
                attr.Method != null &&
                attr.Method != "")
            {
                return(attr.Method);
            }
            else
            {
                return(mi.Name);
            }
        }
示例#6
0
        private static string GetXmlRpcMethodName(MethodInfo mi)
        {
            Attribute attr = Attribute.GetCustomAttribute(mi,
                                                          typeof(XmlRpcMethodAttribute));

            if (attr == null)
            {
                return(null);
            }
            XmlRpcMethodAttribute xrmAttr = attr as XmlRpcMethodAttribute;
            string rpcMethod = xrmAttr.Method;

            if (rpcMethod.Length == 0)
            {
                rpcMethod = mi.Name;
            }
            return(rpcMethod);
        }
示例#7
0
 static void BuildMethods(TypeBuilder tb, ArrayList methods)
 {
     foreach (MethodData mthdData in methods)
     {
         MethodInfo mi         = mthdData.mi;
         Type[]     argTypes   = new Type[mi.GetParameters().Length];
         string[]   paramNames = new string[mi.GetParameters().Length];
         for (int i = 0; i < mi.GetParameters().Length; i++)
         {
             argTypes[i]   = mi.GetParameters()[i].ParameterType;
             paramNames[i] = mi.GetParameters()[i].Name;
         }
         XmlRpcMethodAttribute mattr = (XmlRpcMethodAttribute)
                                       Attribute.GetCustomAttribute(mi, typeof(XmlRpcMethodAttribute));
         BuildMethod(tb, mi.Name, mthdData.xmlRpcName, paramNames, argTypes,
                     mthdData.paramsMethod, mi.ReturnType, mattr.StructParams);
     }
 }
示例#8
0
        string[] IMovableType.mt_supportedMethods()
        {
            if (!siteConfig.EnableBloggerApi)
            {
                throw new ServiceDisabledException();
            }
            List <string> arrayList = new List <string>();

            foreach (MethodInfo method in GetType().GetMethods())
            {
                if (method.IsDefined(typeof(XmlRpcMethodAttribute), true))
                {
                    XmlRpcMethodAttribute attr = method.GetCustomAttributes(typeof(XmlRpcMethodAttribute), true)[0] as XmlRpcMethodAttribute;
                    arrayList.Add(attr.Method);
                }
            }
            return(arrayList.ToArray());
        }
示例#9
0
        private void RegisterMethod <T>(XmlRpcMethodAttribute methodAttribute, MethodInfo methodInfo, string methodSuffix, T methodsInterface)
        {
            if (methodAttribute == null)
            {
                return;
            }

            var methodName = string.IsNullOrEmpty(methodAttribute.MethodName)
                ? methodInfo.Name
                : methodAttribute.MethodName;

            if (!string.IsNullOrWhiteSpace(methodSuffix))
            {
                methodName = methodSuffix + "." + methodName;
            }
            var methodRegistration = new MethodRegistration(methodName, methodInfo, methodsInterface);

            _methods.Add(methodRegistration);
        }
示例#10
0
        public static String GetMethodHelp(Type type, MethodInfo mi)
        {
            XmlRpcMethodAttribute methodAttr = (XmlRpcMethodAttribute)Attribute.GetCustomAttribute(mi, typeof(XmlRpcMethodAttribute), true);

            if (methodAttr != null && methodAttr.Hidden)
            {
                return(null);
            }

            if (methodAttr != null)
            {
                if (methodAttr.Hidden)
                {
                    return(null);
                }
                else if (!String.IsNullOrEmpty(methodAttr.Description))
                {
                    return(methodAttr.Description);
                }
            }

            StringBuilder sb = new StringBuilder();

            sb.Append("Invokes the method ")
            .Append(type.Name).Append(".")
            .Append(mi.Name).Append("(");
            ParameterInfo[] pis = mi.GetParameters();
            for (Int32 i = 0; i < pis.Length; i++)
            {
                if (i > 0)
                {
                    sb.Append(", ");
                }
                sb.Append(pis[i].ParameterType.Name);
            }
            sb.Append(").");
            return(sb.ToString());
        }
示例#11
0
        string GetRpcMethodName(object clientObj, MethodInfo mi)
        {
            string    rpcMethod;
            string    MethodName = mi.Name;
            Attribute attr       = Attribute.GetCustomAttribute(mi,
                                                                typeof(XmlRpcBeginAttribute));

            if (attr != null)
            {
                rpcMethod = ((XmlRpcBeginAttribute)attr).Method;
                if (rpcMethod == "")
                {
                    if (!MethodName.StartsWith("Begin") || MethodName.Length <= 5)
                    {
                        throw new Exception(String.Format(
                                                "method {0} has invalid signature for begin method",
                                                MethodName));
                    }
                    rpcMethod = MethodName.Substring(5);
                }
                return(rpcMethod);
            }
            // if no XmlRpcBegin attribute, must have XmlRpcMethod attribute
            attr = Attribute.GetCustomAttribute(mi, typeof(XmlRpcMethodAttribute));
            if (attr == null)
            {
                throw new Exception("missing method attribute");
            }
            XmlRpcMethodAttribute xrmAttr = attr as XmlRpcMethodAttribute;

            rpcMethod = xrmAttr.Method;
            if (rpcMethod == "")
            {
                rpcMethod = mi.Name;
            }
            return(rpcMethod);
        }
示例#12
0
        private void RegisterMethod(Dictionary <String, MethodInfo[]> map, MethodInfo mi, String key, Type type)
        {
            if (!IsHandlerMethod(mi))
            {
                return;
            }
            XmlRpcMethodAttribute methodAttr = (XmlRpcMethodAttribute)Attribute.GetCustomAttribute(mi, typeof(XmlRpcMethodAttribute), true);

            if (methodAttr == null)
            {
                return;
            }
            String name = (methodAttr == null || String.IsNullOrEmpty(methodAttr.Name)) ? (key + "." + mi.Name) :
                          (methodAttr.Name.IndexOf('.') >= 0 ? methodAttr.Name : (key + "." + methodAttr.Name));

            MethodInfo[] mis;
            if (map.ContainsKey(name))
            {
                MethodInfo[] oldMis = map[name];
                if (HasDuplicateMethod(oldMis, mi))
                {
                    throw new XmlRpcException(String.Format("Duplicate XML-RPC name {0} for method {1} in type {2}.", name, mi.Name, type.Name));
                }
                else
                {
                    mis = new MethodInfo[oldMis.Length + 1];
                    oldMis.CopyTo(mis, 0);
                    mis[oldMis.Length] = mi;
                }
            }
            else
            {
                mis = new MethodInfo[] { mi }
            };

            map[name] = mis;
        }
        public void Ctor_NoName_NameIsEmpty()
        {
            var attribute = new XmlRpcMethodAttribute();

            Assert.Empty(attribute.MethodName);
        }
        public void Ctor_Name_NameIsSet()
        {
            var attribute = new XmlRpcMethodAttribute("Test1234");

            Assert.Equal("Test1234", attribute.MethodName);
        }
示例#15
0
        static void ExtractMethodInfo(Hashtable methods, MethodInfo mi, Type type)
        {
            XmlRpcMethodAttribute attr = (XmlRpcMethodAttribute)
                                         Attribute.GetCustomAttribute(mi,
                                                                      typeof(XmlRpcMethodAttribute));

            if (attr == null)
            {
                return;
            }
            XmlRpcMethodInfo mthdInfo = new XmlRpcMethodInfo();

            mthdInfo.MethodInfo = mi;
            mthdInfo.XmlRpcName = GetXmlRpcMethodName(mi);
            mthdInfo.MiName     = mi.Name;
            mthdInfo.Doc        = attr.Description;
            mthdInfo.IsHidden   = attr.IntrospectionMethod | attr.Hidden;
            // extract parameters information
            ArrayList parmList = new ArrayList();

            ParameterInfo[] parms = mi.GetParameters();
            foreach (ParameterInfo parm in parms)
            {
                XmlRpcParameterInfo parmInfo = new XmlRpcParameterInfo();
                parmInfo.Name       = parm.Name;
                parmInfo.Type       = parm.ParameterType;
                parmInfo.XmlRpcType = GetXmlRpcTypeString(parm.ParameterType);
                // retrieve optional attributed info
                parmInfo.Doc = "";
                XmlRpcParameterAttribute pattr = (XmlRpcParameterAttribute)
                                                 Attribute.GetCustomAttribute(parm,
                                                                              typeof(XmlRpcParameterAttribute));
                if (pattr != null)
                {
                    parmInfo.Doc        = pattr.Description;
                    parmInfo.XmlRpcName = pattr.Name;
                }
                parmInfo.IsParams = Attribute.IsDefined(parm,
                                                        typeof(ParamArrayAttribute));
                parmList.Add(parmInfo);
            }
            mthdInfo.Parameters = (XmlRpcParameterInfo[])
                                  parmList.ToArray(typeof(XmlRpcParameterInfo));
            // extract return type information
            mthdInfo.ReturnType       = mi.ReturnType;
            mthdInfo.ReturnXmlRpcType = GetXmlRpcTypeString(mi.ReturnType);
            object[] orattrs = mi.ReturnTypeCustomAttributes.GetCustomAttributes(
                typeof(XmlRpcReturnValueAttribute), false);
            if (orattrs.Length > 0)
            {
                mthdInfo.ReturnDoc = ((XmlRpcReturnValueAttribute)orattrs[0]).Description;
            }

            if (methods[mthdInfo.XmlRpcName] != null)
            {
                throw new XmlRpcDupXmlRpcMethodNames(String.Format("Method "
                                                                   + "{0} in type {1} has duplicate XmlRpc method name {2}",
                                                                   mi.Name, type.Name, mthdInfo.XmlRpcName));
            }
            else
            {
                methods.Add(mthdInfo.XmlRpcName, mthdInfo);
            }
        }
 public ApiMethodAnalyzer(MethodInfo methodInfo, IMethodExceptionHandler globalExceptionHandler)
 {
     _methodInfo             = methodInfo;
     _globalExceptionHandler = globalExceptionHandler;
     _methodAttr             = _methodInfo.GetCustomAttribute(typeof(XmlRpcMethodAttribute)) as XmlRpcMethodAttribute;
 }