예제 #1
0
        MethodInfo FindMethodInfo(Type serviceType, string calledMethod, XmlNode[] paramNodes)
        {
            var possibleMethods = new MethodInfo[0];
            var parameterInfos  = new ParameterInfo[0];

            var serviceInfo = XmlRpcServiceInfo.CreateServiceInfo(serviceType);

            possibleMethods = serviceInfo.GetMethodInfos(calledMethod);
            if (!possibleMethods.Any())
            {
                throw new XmlRpcUnsupportedMethodException($"unsupported method called: {calledMethod}");
            }

            var methodInfo = possibleMethods.FirstOrDefault(m => m.GetParameters().Length == paramNodes.Length);

            if (methodInfo == null)
            {
                throw new XmlRpcInvalidParametersException($"The method {methodInfo} was called with wrong parameter count");
            }

            var rpcAttribute = Attribute.GetCustomAttribute(methodInfo, typeof(XmlRpcMethodAttribute));

            if (rpcAttribute == null)
            {
                throw new XmlRpcMethodAttributeException($"Method {calledMethod} must be marked with the XmlRpcMethod attribute.");
            }

            return(methodInfo);
        }
예제 #2
0
        public void DerivedInterfaces()
        {
            XmlRpcServiceInfo svcinfo = XmlRpcServiceInfo.CreateServiceInfo(
                typeof(FooBar));

            Assert.AreEqual(2, svcinfo.Methods.Length);
        }
예제 #3
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);
        }
예제 #4
0
        public void RecursiveClass()
        {
            var type    = typeof(Example);
            var rpcType = XmlRpcServiceInfo.GetXmlRpcType(type);

            Assert.AreEqual(XmlRpcType.tStruct, rpcType);
        }
예제 #5
0
        public void RecursiveArrayClass()
        {
            Type       type    = typeof(ExampleWithArray);
            XmlRpcType rpcType = XmlRpcServiceInfo.GetXmlRpcType(type);

            Assert.AreEqual(XmlRpcType.tStruct, rpcType);
        }
예제 #6
0
        public string[] SystemListMethods()
        {
            var svcInfo = XmlRpcServiceInfo.CreateServiceInfo(GetType());
            var list    = svcInfo.Methods.Where(m => !m.IsHidden).Select(m => m.XmlRpcName);

            return(list.Distinct().ToArray());
        }
예제 #7
0
        static void WriteType(XmlWriter writer, Type type, bool isParams)
        {
            // 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";
            }

            writer.WriteString(xmlRpcType);
            if (xmlRpcType == "struct" && type != typeof(XmlRpcStruct))
            {
                writer.WriteString(" ");
                writer.WriteStartElement("a");
                writer.WriteAttributeString("href", "#" + type.Name);
                writer.WriteString(type.Name);
                writer.WriteEndElement();
            }
            else if (xmlRpcType == "array" || xmlRpcType == "varargs")
            {
                if (type.GetArrayRank() == 1)  // single dim array
                {
                    writer.WriteString(" of ");
                    var elemType = type.GetElementType();

                    string elemXmlRpcType;
                    if (elemType != typeof(object))
                    {
                        elemXmlRpcType = XmlRpcServiceInfo.GetXmlRpcTypeString(elemType);
                    }
                    else
                    {
                        elemXmlRpcType = "any";
                    }

                    writer.WriteString(elemXmlRpcType);
                    if (elemXmlRpcType == "struct" && elemType != typeof(XmlRpcStruct))
                    {
                        writer.WriteString(" ");
                        writer.WriteStartElement("a");
                        writer.WriteAttributeString("href", "#" + elemType.Name);
                        writer.WriteString(elemType.Name);
                        writer.WriteEndElement();
                    }
                }
            }
        }
예제 #8
0
        public void StructWithEnum()
        {
            Type       type    = typeof(struct2);
            XmlRpcType rpcType = XmlRpcServiceInfo.GetXmlRpcType(type);

            Assert.AreEqual(XmlRpcType.tInvalid, rpcType,
                            "struct doesn't map to XmlRpcType.tInvalid");
        }
예제 #9
0
        public void DBNull()
        {
            DBNull     value   = System.DBNull.Value;
            Type       type    = value.GetType();
            XmlRpcType rpcType = XmlRpcServiceInfo.GetXmlRpcType(type);

            Assert.AreEqual(XmlRpcType.tInvalid, rpcType,
                            "GetXmlRpcType return DBNull as tInvalid");
        }
예제 #10
0
        public void DBNull()
        {
            var value   = System.DBNull.Value;
            var type    = value.GetType();
            var rpcType = XmlRpcServiceInfo.GetXmlRpcType(type);

            Assert.AreEqual(XmlRpcType.tStruct, rpcType,
                            "GetXmlRpcType return DBNull as tStruct");
        }
예제 #11
0
        static void WriteType(XmlWriter writer, Type type)
        {
            writer.WriteStartElement("div");
            writer.WriteAttributeString("id", "content");

            var serviceInfo = XmlRpcServiceInfo.CreateServiceInfo(type);

            writer.WriteStartElement("p");
            writer.WriteAttributeString("class", "heading1");
            writer.WriteString(serviceInfo.Name);
            writer.WriteEndElement();
            writer.WriteStartElement("br");
            writer.WriteEndElement();

            if (!string.IsNullOrWhiteSpace(serviceInfo.Doc))
            {
                writer.WriteStartElement("p");
                writer.WriteAttributeString("class", "intro");
                writer.WriteString(serviceInfo.Doc);
                writer.WriteEndElement();
            }

            writer.WriteStartElement("p");
            writer.WriteAttributeString("class", "intro");
            writer.WriteString("The following methods are supported:");
            writer.WriteEndElement();

            writer.WriteStartElement("ul");

            foreach (var methodInfo in serviceInfo.Methods)
            {
                if (methodInfo.IsHidden)
                {
                    continue;
                }

                writer.WriteStartElement("li");
                writer.WriteStartElement("a");
                writer.WriteAttributeString("href", "#" + methodInfo.XmlRpcName);
                writer.WriteString(methodInfo.XmlRpcName);
                writer.WriteEndElement();
                writer.WriteEndElement();
            }

            writer.WriteEndElement();

            foreach (var methodInfo in serviceInfo.Methods)
            {
                if (!methodInfo.IsHidden)
                {
                    WriteMethod(writer, methodInfo);
                }
            }

            writer.WriteEndElement();
        }
예제 #12
0
        public static void WriteDoc(XmlWriter wrtr, Type type,
                                    bool autoDocVersion)
        {
            XmlRpcServiceInfo svcInfo = XmlRpcServiceInfo.CreateServiceInfo(type);

            wrtr.WriteStartElement("html");
            WriteHead(wrtr, svcInfo.Name);
            WriteBody(wrtr, type, autoDocVersion);
            wrtr.WriteEndElement();
        }
예제 #13
0
        //public XmlRpcStruct(IEnumerable<KeyValuePair<string, object>> dictionary) : base(dictionary)
        //{

        //}
        //public XmlRpcStruct(IDictionary<string, object> dictionary): base(dictionary)
        //{

        //}

        public new void Add(string key, object value)
        {
            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);
        }
예제 #14
0
        public void String()
        {
            Type       type    = typeof(string);
            XmlRpcType rpcType = XmlRpcServiceInfo.GetXmlRpcType(type);

            Assert.AreEqual(XmlRpcType.tString, rpcType,
                            "String doesn't map to XmlRpcType.tString");
            string rpcString = XmlRpcServiceInfo.GetXmlRpcTypeString(type);

            Assert.AreEqual(rpcString, "string", "String doesn't map to 'string'");
        }
예제 #15
0
        public void Int64()
        {
            var type    = typeof(long);
            var rpcType = XmlRpcServiceInfo.GetXmlRpcType(type);

            Assert.AreEqual(XmlRpcType.tInt64, rpcType,
                            "Int64 doesn't map to XmlRpcType.tInt64");
            var rpcString = XmlRpcServiceInfo.GetXmlRpcTypeString(type);

            Assert.AreEqual(rpcString, "i8", "Int64 doesn't map to 'i8'");
        }
예제 #16
0
        public void MultiDimIntArray()
        {
            var type    = typeof(int[, ]);
            var rpcType = XmlRpcServiceInfo.GetXmlRpcType(type);

            Assert.AreEqual(XmlRpcType.tMultiDimArray, rpcType,
                            "Int32[] doesn't map to XmlRpcType.tMultiDimArray");
            var rpcString = XmlRpcServiceInfo.GetXmlRpcTypeString(type);

            Assert.AreEqual(rpcString, "array", "Int32['] doesn't map to 'array'");
        }
예제 #17
0
        public void JaggedIntArray()
        {
            Type       type    = typeof(Int32[][]);
            XmlRpcType rpcType = XmlRpcServiceInfo.GetXmlRpcType(type);

            Assert.AreEqual(XmlRpcType.tArray, rpcType,
                            "Int32[] doesn't map to XmlRpcType.tArray");
            string rpcString = XmlRpcServiceInfo.GetXmlRpcTypeString(type);

            Assert.AreEqual(rpcString, "array", "Int32[] doesn't map to 'array'");
        }
예제 #18
0
        public void Base64()
        {
            Type       type    = typeof(byte[]);
            XmlRpcType rpcType = XmlRpcServiceInfo.GetXmlRpcType(type);

            Assert.AreEqual(XmlRpcType.tBase64, rpcType,
                            "Byte[] doesn't map to XmlRpcType.tBase64");
            string rpcString = XmlRpcServiceInfo.GetXmlRpcTypeString(type);

            Assert.AreEqual(rpcString, "base64", "Byte[] doesn't map to 'base64'");
        }
예제 #19
0
        public void Int32()
        {
            Type       type    = typeof(int);
            XmlRpcType rpcType = XmlRpcServiceInfo.GetXmlRpcType(type);

            Assert.AreEqual(XmlRpcType.tInt32, rpcType,
                            "Int32 doesn't map to XmlRpcType.tInt32");
            string rpcString = XmlRpcServiceInfo.GetXmlRpcTypeString(type);

            Assert.AreEqual(rpcString, "integer", "Int32 doesn't map to 'integer'");
        }
예제 #20
0
        public void Array()
        {
            var type    = typeof(Array);
            var rpcType = XmlRpcServiceInfo.GetXmlRpcType(type);

            Assert.AreEqual(XmlRpcType.tArray, rpcType,
                            "Array doesn't map to XmlRpcType.tArray");
            var rpcString = XmlRpcServiceInfo.GetXmlRpcTypeString(type);

            Assert.AreEqual(rpcString, "array", "Array doesn't map to 'array'");
        }
예제 #21
0
        public void Double()
        {
            Type       type    = typeof(double);
            XmlRpcType rpcType = XmlRpcServiceInfo.GetXmlRpcType(type);

            Assert.AreEqual(XmlRpcType.tDouble, rpcType,
                            "Double doesn't map to XmlRpcType.tDouble");
            string rpcString = XmlRpcServiceInfo.GetXmlRpcTypeString(type);

            Assert.AreEqual(rpcString, "double", "Double doesn't map to 'double'");
        }
예제 #22
0
        public void Void()
        {
            Type       type    = typeof(void);
            XmlRpcType rpcType = XmlRpcServiceInfo.GetXmlRpcType(type);

            Assert.AreEqual(XmlRpcType.tVoid, rpcType,
                            "void doesn't map to XmlRpcType.tVoid");
            string rpcString = XmlRpcServiceInfo.GetXmlRpcTypeString(type);

            Assert.AreEqual(rpcString, "void", "void doesn't map to 'void'");
        }
예제 #23
0
        public void XmlRpcBoolean()
        {
            Type       type    = typeof(XmlRpcBoolean);
            XmlRpcType rpcType = XmlRpcServiceInfo.GetXmlRpcType(type);

            Assert.AreEqual(XmlRpcType.tBoolean, rpcType,
                            "XmlRpcBoolean doesn't map to XmlRpcType.tBoolean");
            string rpcString = XmlRpcServiceInfo.GetXmlRpcTypeString(type);

            Assert.AreEqual(rpcString, "boolean",
                            "XmlRpcBoolean doesn't map to 'boolean'");
        }
예제 #24
0
        public void NullableStruct()
        {
            Type       type    = typeof(TestStruct?);
            XmlRpcType rpcType = XmlRpcServiceInfo.GetXmlRpcType(type);

            Assert.AreEqual(XmlRpcType.tStruct, rpcType,
                            "TestStruct? doesn't map to XmlRpcType.tStruct");
            string rpcString = XmlRpcServiceInfo.GetXmlRpcTypeString(type);

            Assert.AreEqual(rpcString, "struct",
                            "TestStruct? doesn't map to 'struct'");
        }
예제 #25
0
        public void NullableDateTime()
        {
            Type       type    = typeof(DateTime?);
            XmlRpcType rpcType = XmlRpcServiceInfo.GetXmlRpcType(type);

            Assert.AreEqual(XmlRpcType.tDateTime, rpcType,
                            "DateTime? doesn't map to XmlRpcType.tDateTime");
            string rpcString = XmlRpcServiceInfo.GetXmlRpcTypeString(type);

            Assert.AreEqual(rpcString, "dateTime",
                            "DateTime? doesn't map to 'dateTime'");
        }
예제 #26
0
        public void Boolean()
        {
            var type    = typeof(bool);
            var rpcType = XmlRpcServiceInfo.GetXmlRpcType(type);

            Assert.AreEqual(XmlRpcType.tBoolean, rpcType,
                            "Boolean doesn't map to XmlRpcType.tBoolean");
            var rpcString = XmlRpcServiceInfo.GetXmlRpcTypeString(type);

            Assert.AreEqual(rpcString, "boolean",
                            "Boolean doesn't map to 'boolean'");
        }
예제 #27
0
        public void XmlRpcStruct()
        {
            Type       type    = typeof(XmlRpcStruct);
            XmlRpcType rpcType = XmlRpcServiceInfo.GetXmlRpcType(type);

            Assert.AreEqual(XmlRpcType.tHashtable, rpcType,
                            "XmlRpcStruct doesn't map to XmlRpcType.tHashtable");
            string rpcString = XmlRpcServiceInfo.GetXmlRpcTypeString(type);

            Assert.AreEqual(rpcString, "struct",
                            "XmlRpcStruct doesn't map to 'struct'");
        }
예제 #28
0
        public void NullableDouble()
        {
            var type    = typeof(double?);
            var rpcType = XmlRpcServiceInfo.GetXmlRpcType(type);

            Assert.AreEqual(XmlRpcType.tDouble, rpcType,
                            "double? doesn't map to XmlRpcType.tDouble");
            var rpcString = XmlRpcServiceInfo.GetXmlRpcTypeString(type);

            Assert.AreEqual(rpcString, "double",
                            "double? doesn't map to 'double'");
        }
예제 #29
0
        public void CreateXmlRpcServiceInfoForInterface()
        {
            XmlRpcServiceInfo serviceInfo =
                XmlRpcServiceInfo.CreateXmlRpcServiceInfo(typeof(IMathXmlRpcService));

            Assert.IsNotEmpty((ICollection)serviceInfo.Methods);

            Assert.AreEqual("math:add", serviceInfo.Methods[0].Name);
            Assert.AreEqual("Adds up two values", serviceInfo.Methods[0].Description);
            Assert.AreEqual(typeof(int), serviceInfo.Methods[0].ParameterTypes[0]);
            Assert.AreEqual(typeof(int), serviceInfo.Methods[0].ParameterTypes[1]);
        }
예제 #30
0
        public void DateTime()
        {
            var type    = typeof(DateTime);
            var rpcType = XmlRpcServiceInfo.GetXmlRpcType(type);

            Assert.AreEqual(XmlRpcType.tDateTime, rpcType,
                            "DateTime doesn't map to XmlRpcType.tDateTime");
            var rpcString = XmlRpcServiceInfo.GetXmlRpcTypeString(type);

            Assert.AreEqual(rpcString, "dateTime",
                            "DateTime doesn't map to 'dateTime'");
        }