Ejemplo n.º 1
0
        public Array System__Method__Signature___(string MethodName)
        {
            //TODO: support overloaded methods
            XmlRpcServiceInfo svcInfo = XmlRpcServiceInfo.CreateServiceInfo(
                this.GetType());
            XmlRpcMethodInfo mthdInfo = svcInfo.GetMethod(MethodName);

            if (mthdInfo == null)
            {
                throw new XmlRpcFaultException(880,
                                               "Request for information on unsupported method");
            }
            if (mthdInfo.IsHidden)
            {
                throw new XmlRpcFaultException(881,
                                               "Information not available on this method");
            }
            //XmlRpcTypes.CheckIsXmlRpcMethod(mi);
            ArrayList alist = new ArrayList();

            alist.Add(XmlRpcServiceInfo.GetXmlRpcTypeString(mthdInfo.ReturnType));
            foreach (XmlRpcParameterInfo paramInfo in mthdInfo.Parameters)
            {
                alist.Add(XmlRpcServiceInfo.GetXmlRpcTypeString(paramInfo.Type));
            }
            string[]  types    = (string[])alist.ToArray(typeof(string));
            ArrayList retalist = new ArrayList();

            retalist.Add(types);
            Array retarray = retalist.ToArray(typeof(string[]));

            return(retarray);
        }
Ejemplo n.º 2
0
        public static void WriteDoc(HtmlTextWriter wrtr, Type type,
                                    bool autoDocVersion)
        {
            XmlRpcServiceInfo svcInfo = XmlRpcServiceInfo.CreateServiceInfo(type);

            wrtr.WriteFullBeginTag("html");
            wrtr.WriteLine();
            WriteHead(wrtr, svcInfo.Name);
            wrtr.WriteLine();
            WriteBody(wrtr, type, autoDocVersion);
            wrtr.WriteEndTag("html");
        }
Ejemplo n.º 3
0
 public override void Add(object key, object value)
 {
     if (!(key is string))
     {
         throw new ArgumentException("XmlRpcStruct key must be a string.");
     }
     if (XmlRpcServiceInfo.GetXmlRpcType(value.GetType())
         == XmlRpcType.tInvalid)
     {
         throw new ArgumentException(String.Format(
                                         "Type {0} cannot be mapped to an XML-RPC type", value.GetType()));
     }
     base.Add(key, value);
 }
Ejemplo n.º 4
0
        public string[] System__List__Methods___()
        {
            XmlRpcServiceInfo svcInfo = XmlRpcServiceInfo.CreateServiceInfo(
                this.GetType());
            ArrayList alist = new ArrayList();

            foreach (XmlRpcMethodInfo mthdInfo in svcInfo.Methods)
            {
                if (!mthdInfo.IsHidden)
                {
                    alist.Add(mthdInfo.XmlRpcName);
                }
            }
            return((String[])alist.ToArray(typeof(string)));
        }
Ejemplo n.º 5
0
        Header[] GetChannelHeaders(
            ITransportHeaders requestHeaders,
            XmlRpcRequest xmlRpcReq,
            Type svcType)
        {
            string            requestUri = (string)requestHeaders["__RequestUri"];
            XmlRpcServiceInfo svcInfo    = XmlRpcServiceInfo.CreateServiceInfo(svcType);
            ArrayList         hdrList    = new ArrayList();

            hdrList.Add(new Header("__Uri", requestUri));
            hdrList.Add(new Header("__TypeName", svcType.AssemblyQualifiedName));
            hdrList.Add(new Header("__MethodName",
                                   svcInfo.GetMethodName(xmlRpcReq.method)));
            hdrList.Add(new Header("__Args", xmlRpcReq.args));
            return((Header[])hdrList.ToArray(typeof(Header)));
        }
Ejemplo n.º 6
0
        public string System__Method__Help___(string MethodName)
        {
            //TODO: support overloaded methods?
            XmlRpcServiceInfo svcInfo = XmlRpcServiceInfo.CreateServiceInfo(
                this.GetType());
            XmlRpcMethodInfo mthdInfo = svcInfo.GetMethod(MethodName);

            if (mthdInfo == null)
            {
                throw new XmlRpcFaultException(880,
                                               "Request for information on unsupported method");
            }
            if (mthdInfo.IsHidden)
            {
                throw new XmlRpcFaultException(881,
                                               "Information not available for this method");
            }
            return(mthdInfo.Doc);
        }
Ejemplo n.º 7
0
 public override object this[object key]
 {
     get
     {
         return(base[key]);
     }
     set
     {
         if (!(key is string))
         {
             throw new ArgumentException("XmlRpcStruct key must be a string.");
         }
         if (XmlRpcServiceInfo.GetXmlRpcType(value.GetType())
             == XmlRpcType.tInvalid)
         {
             throw new ArgumentException(String.Format(
                                             "Type {0} cannot be mapped to an XML-RPC type", value.GetType()));
         }
         base[key] = value;
     }
 }
Ejemplo n.º 8
0
        static void WriteType(
            HtmlTextWriter wrtr,
            Type type,
            bool isparams,
            ArrayList structs)
        {
            // TODO: following is hack for case when type is Object
            string xmlRpcType;

            if (!isparams)
            {
                if (type != typeof(Object))
                {
                    xmlRpcType = XmlRpcServiceInfo.GetXmlRpcTypeString(type);
                }
                else
                {
                    xmlRpcType = "any";
                }
            }
            else
            {
                xmlRpcType = "varargs";
            }
            wrtr.Write(xmlRpcType);
            if (xmlRpcType == "struct" && type != typeof(XmlRpcStruct))
            {
                if (!structs.Contains(type))
                {
                    structs.Add(type);
                }
                wrtr.Write(" ");
                wrtr.WriteBeginTag("a");
                wrtr.WriteAttribute("href", "#" + type.Name);
                wrtr.Write(HtmlTextWriter.TagRightChar);
                wrtr.Write(type.Name);
                wrtr.WriteEndTag("a");
            }
            else if (xmlRpcType == "array" || xmlRpcType == "varargs")
            {
                if (type.GetArrayRank() == 1) // single dim array
                {
                    wrtr.Write(" of ");
                    Type   elemType = type.GetElementType();
                    string elemXmlRpcType;
                    if (elemType != typeof(Object))
                    {
                        elemXmlRpcType = XmlRpcServiceInfo.GetXmlRpcTypeString(elemType);
                    }
                    else
                    {
                        elemXmlRpcType = "any";
                    }
                    wrtr.Write(elemXmlRpcType);
                    if (elemXmlRpcType == "struct" && elemType != typeof(XmlRpcStruct))
                    {
                        if (!structs.Contains(elemType))
                        {
                            structs.Add(elemType);
                        }
                        wrtr.Write(" ");
                        wrtr.WriteBeginTag("a");
                        wrtr.WriteAttribute("href", "#" + elemType.Name);
                        wrtr.Write(HtmlTextWriter.TagRightChar);
                        wrtr.Write(elemType.Name);
                        wrtr.WriteEndTag("a");
                    }
                }
            }
        }
Ejemplo n.º 9
0
        public static void WriteType(
            HtmlTextWriter wrtr,
            Type type)
        {
            ArrayList structs = new ArrayList();

            wrtr.WriteBeginTag("div");
            wrtr.WriteAttribute("id", "content");
            wrtr.Write(HtmlTextWriter.TagRightChar);
            wrtr.WriteLine();

            XmlRpcServiceInfo svcInfo =
                XmlRpcServiceInfo.CreateServiceInfo(type);

            wrtr.WriteBeginTag("p");
            wrtr.WriteAttribute("class", "heading1");
            wrtr.Write(HtmlTextWriter.TagRightChar);
            wrtr.Write(svcInfo.Name);
            wrtr.WriteEndTag("p");
            wrtr.WriteFullBeginTag("br");
            wrtr.WriteEndTag("br");
            wrtr.WriteLine();

            if (svcInfo.Doc != "")
            {
                wrtr.WriteBeginTag("p");
                wrtr.WriteAttribute("class", "intro");
                wrtr.Write(HtmlTextWriter.TagRightChar);
                wrtr.Write(svcInfo.Doc);
                wrtr.WriteEndTag("p");
                wrtr.WriteLine();
            }
            wrtr.WriteBeginTag("p");
            wrtr.WriteAttribute("class", "intro");
            wrtr.Write(HtmlTextWriter.TagRightChar);
            wrtr.Write("The following methods are supported:");
            wrtr.WriteEndTag("p");
            wrtr.WriteLine();

            wrtr.WriteFullBeginTag("ul");
            wrtr.WriteLine();
            foreach (XmlRpcMethodInfo mthdInfo in svcInfo.Methods)
            {
                if (!mthdInfo.IsHidden)
                {
                    wrtr.WriteFullBeginTag("li");
                    wrtr.WriteBeginTag("a");
                    wrtr.WriteAttribute("href", "#" + mthdInfo.XmlRpcName);
                    wrtr.Write(HtmlTextWriter.TagRightChar);
                    wrtr.Write(mthdInfo.XmlRpcName);
                    wrtr.WriteEndTag("a");
                    wrtr.WriteEndTag("li");
                    wrtr.WriteLine();
                }
            }

            wrtr.WriteEndTag("ul");
            wrtr.WriteLine();

            foreach (XmlRpcMethodInfo mthdInfo in svcInfo.Methods)
            {
                if (mthdInfo.IsHidden == false)
                {
                    WriteMethod(wrtr, mthdInfo, structs);
                }
            }

            for (int j = 0; j < structs.Count; j++)
            {
                WriteStruct(wrtr, structs[j] as Type, structs);
            }

            wrtr.WriteEndTag("div");
            wrtr.WriteLine();
        }
Ejemplo n.º 10
0
        public static XmlRpcServiceInfo CreateServiceInfo(Type type)
        {
            XmlRpcServiceInfo svcInfo = new XmlRpcServiceInfo();
            // extract service info
            XmlRpcServiceAttribute svcAttr = (XmlRpcServiceAttribute)
                                             Attribute.GetCustomAttribute(type, typeof(XmlRpcServiceAttribute));

            if (svcAttr != null && svcAttr.Description != "")
            {
                svcInfo.doc = svcAttr.Description;
            }
            if (svcAttr != null && svcAttr.Name != "")
            {
                svcInfo.Name = svcAttr.Name;
            }
            else
            {
                svcInfo.Name = type.Name;
            }
            // extract method info
            Hashtable methods = new Hashtable();

            foreach (Type itf in type.GetInterfaces())
            {
                XmlRpcServiceAttribute itfAttr = (XmlRpcServiceAttribute)
                                                 Attribute.GetCustomAttribute(itf, typeof(XmlRpcServiceAttribute));
                if (itfAttr != null)
                {
                    svcInfo.doc = itfAttr.Description;
                }
#if (!COMPACT_FRAMEWORK)
                InterfaceMapping imap = type.GetInterfaceMap(itf);
                foreach (MethodInfo mi in imap.InterfaceMethods)
                {
                    ExtractMethodInfo(methods, mi, itf);
                }
#else
                foreach (MethodInfo mi in itf.GetMethods())
                {
                    ExtractMethodInfo(methods, mi, itf);
                }
#endif
            }

            foreach (MethodInfo mi in type.GetMethods())
            {
                ArrayList mthds = new ArrayList();
                mthds.Add(mi);
                MethodInfo curMi = mi;
                while (true)
                {
                    MethodInfo baseMi = curMi.GetBaseDefinition();
                    if (baseMi.DeclaringType == curMi.DeclaringType)
                    {
                        break;
                    }
                    mthds.Insert(0, baseMi);
                    curMi = baseMi;
                }
                foreach (MethodInfo mthd in mthds)
                {
                    ExtractMethodInfo(methods, mthd, type);
                }
            }
            svcInfo.methodInfos = new XmlRpcMethodInfo[methods.Count];
            methods.Values.CopyTo(svcInfo.methodInfos, 0);
            Array.Sort(svcInfo.methodInfos);
            return(svcInfo);
        }