Esempio n. 1
0
        public void StructWithEnum()
        {
            Type       type    = typeof(struct2);
            XmlRpcType rpcType = XmlRpcTypeInfo.GetXmlRpcType(type);

            Assert.AreEqual(XmlRpcType.tStruct, rpcType, "struct doesn't map to XmlRpcType.tInvalid");
        }
Esempio n. 2
0
        public void RecursiveArrayClass()
        {
            Type       type    = typeof(ExampleWithArray);
            XmlRpcType rpcType = XmlRpcTypeInfo.GetXmlRpcType(type);

            Assert.AreEqual(XmlRpcType.tStruct, rpcType);
        }
Esempio n. 3
0
        public void DBNull()
        {
            DBNull     value   = System.DBNull.Value;
            Type       type    = value.GetType();
            XmlRpcType rpcType = XmlRpcTypeInfo.GetXmlRpcType(type);

            Assert.AreEqual(XmlRpcType.tStruct, rpcType, "GetXmlRpcType return DBNull as tStruct");
        }
Esempio n. 4
0
        public void String()
        {
            Type       type    = typeof(string);
            XmlRpcType rpcType = XmlRpcTypeInfo.GetXmlRpcType(type);

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

            Assert.AreEqual(rpcString, "string", "String doesn't map to 'string'");
        }
Esempio n. 5
0
        public void XmlRpcBoolean()
        {
            Type       type    = typeof(bool?);
            XmlRpcType rpcType = XmlRpcTypeInfo.GetXmlRpcType(type);

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

            Assert.AreEqual(rpcString, "boolean", "XmlRpcBoolean doesn't map to 'boolean'");
        }
Esempio n. 6
0
        public void XmlRpcInt()
        {
            Type       type    = typeof(int?);
            XmlRpcType rpcType = XmlRpcTypeInfo.GetXmlRpcType(type);

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

            Assert.AreEqual(rpcString, "integer", "XmlRpcInt doesn't map to 'integer'");
        }
Esempio n. 7
0
        public void NullableStruct()
        {
            Type       type    = typeof(TestStruct?);
            XmlRpcType rpcType = XmlRpcTypeInfo.GetXmlRpcType(type);

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

            Assert.AreEqual(rpcString, "struct", "TestStruct? doesn't map to 'struct'");
        }
Esempio n. 8
0
        public void Base64()
        {
            Type       type    = typeof(byte[]);
            XmlRpcType rpcType = XmlRpcTypeInfo.GetXmlRpcType(type);

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

            Assert.AreEqual(rpcString, "base64", "Byte[] doesn't map to 'base64'");
        }
Esempio n. 9
0
        public void NullableIn64()
        {
            Type       type    = typeof(long?);
            XmlRpcType rpcType = XmlRpcTypeInfo.GetXmlRpcType(type);

            Assert.AreEqual(XmlRpcType.tInt64, rpcType, "long? doesn't map to XmlRpcType.tInt64");
            string rpcString = XmlRpcTypeInfo.GetXmlRpcTypeString(type);

            Assert.AreEqual(rpcString, "i8", "long? doesn't map to 'i8'");
        }
Esempio n. 10
0
        public void Void()
        {
            Type       type    = typeof(void);
            XmlRpcType rpcType = XmlRpcTypeInfo.GetXmlRpcType(type);

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

            Assert.AreEqual(rpcString, "void", "void doesn't map to 'void'");
        }
Esempio n. 11
0
        public void JaggedIntArray()
        {
            Type       type    = typeof(Int32[][]);
            XmlRpcType rpcType = XmlRpcTypeInfo.GetXmlRpcType(type);

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

            Assert.AreEqual(rpcString, "array", "Int32[] doesn't map to 'array'");
        }
Esempio n. 12
0
        public void Array()
        {
            Type       type    = typeof(Array);
            XmlRpcType rpcType = XmlRpcTypeInfo.GetXmlRpcType(type);

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

            Assert.AreEqual(rpcString, "array", "Array doesn't map to 'array'");
        }
Esempio n. 13
0
        public void XmlRpcStruct()
        {
            Type       type    = typeof(XmlRpcStruct);
            XmlRpcType rpcType = XmlRpcTypeInfo.GetXmlRpcType(type);

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

            Assert.AreEqual(rpcString, "struct", "XmlRpcStruct doesn't map to 'struct'");
        }
Esempio n. 14
0
        public void XmlRpcDouble()
        {
            Type       type    = typeof(double?);
            XmlRpcType rpcType = XmlRpcTypeInfo.GetXmlRpcType(type);

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

            Assert.AreEqual(rpcString, "double", "XmlRpcDouble doesn't map to 'double'");
        }
Esempio n. 15
0
        public void NullableDateTime()
        {
            Type       type    = typeof(DateTime?);
            XmlRpcType rpcType = XmlRpcTypeInfo.GetXmlRpcType(type);

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

            Assert.AreEqual(rpcString, "dateTime", "DateTime? doesn't map to 'dateTime'");
        }
Esempio n. 16
0
 public void EnumXmlRpcType()
 {
     Assert.AreEqual(XmlRpcType.tInt32, XmlRpcTypeInfo.GetXmlRpcType(typeof(ByteEnum)), "byte");
     Assert.AreEqual(XmlRpcType.tInt32, XmlRpcTypeInfo.GetXmlRpcType(typeof(SByteEnum)), "sbyte");
     Assert.AreEqual(XmlRpcType.tInt32, XmlRpcTypeInfo.GetXmlRpcType(typeof(ShortEnum)), "short");
     Assert.AreEqual(XmlRpcType.tInt32, XmlRpcTypeInfo.GetXmlRpcType(typeof(UShortEnum)), "ushort");
     Assert.AreEqual(XmlRpcType.tInt32, XmlRpcTypeInfo.GetXmlRpcType(typeof(IntEnum)), "int");
     Assert.AreEqual(XmlRpcType.tInt64, XmlRpcTypeInfo.GetXmlRpcType(typeof(UIntEnum)), "uint");
     Assert.AreEqual(XmlRpcType.tInt64, XmlRpcTypeInfo.GetXmlRpcType(typeof(LongEnum)), "long");
     Assert.AreEqual(XmlRpcType.tInvalid, XmlRpcTypeInfo.GetXmlRpcType(typeof(ULongEnum)), "ulong");
 }
Esempio n. 17
0
        private object MapArray(IEnumerator <Node> iter, Type valType,
                                MappingStack mappingStack, MappingAction mappingAction,
                                out Type mappedType)
        {
            mappedType = null;
            // required type must be an array
            if (valType != null &&
                !(valType.IsArray == true ||
                  valType == typeof(Array) ||
                  valType == typeof(object)))
            {
                throw new XmlRpcTypeMismatchException(mappingStack.MappingType
                                                      + " contains array value where "
                                                      + XmlRpcTypeInfo.GetXmlRpcTypeString(valType)
                                                      + " expected " + StackDump(mappingStack));
            }
            if (valType != null)
            {
                XmlRpcType xmlRpcType = XmlRpcTypeInfo.GetXmlRpcType(valType);
                if (xmlRpcType == XmlRpcType.tMultiDimArray)
                {
                    mappingStack.Push("array mapped to type " + valType.Name);
                    Object ret = MapMultiDimArray(iter, valType, mappingStack,
                                                  mappingAction);
                    return(ret);
                }
                mappingStack.Push("array mapped to type " + valType.Name);
            }
            else
            {
                mappingStack.Push("array");
            }

            var  values   = new List <object>();
            Type elemType = DetermineArrayItemType(valType);

            bool bGotType = false;
            Type useType  = null;

            while (iter.MoveNext() && iter.Current is ValueNode)
            {
                mappingStack.Push(String.Format("element {0}", values.Count));
                object value = MapValueNode(iter, elemType, mappingStack, mappingAction);
                values.Add(value);
                mappingStack.Pop();
            }

            foreach (object value in values)
            {
                if (value == null)
                {
                    continue;
                }
                if (bGotType == false)
                {
                    useType  = value.GetType();
                    bGotType = true;
                }
                else
                {
                    if (useType != value.GetType())
                    {
                        useType = null;
                    }
                }
            }

            Object[] args = new Object[1];
            args[0] = values.Count;
            Object retObj = null;

            if (valType != null &&
                valType != typeof(Array) &&
                valType != typeof(object))
            {
                retObj = CreateArrayInstance(valType, args);
            }
            else
            {
                if (useType == null)
                {
                    retObj = CreateArrayInstance(typeof(object[]), args);
                }
                else
                {
                    retObj = Array.CreateInstance(useType, (int)args[0]);
                };
            }
            for (int j = 0; j < values.Count; j++)
            {
                ((Array)retObj).SetValue(values[j], j);
            }

            mappingStack.Pop();

            return(retObj);
        }
Esempio n. 18
0
 //#endif
 void Serialize(
     XmlWriter xtw,
     Object o,
     MappingActions mappingActions,
     List <object> nestedObjs)
 {
     if (nestedObjs.Contains(o))
     {
         throw new XmlRpcUnsupportedTypeException(nestedObjs[0].GetType(),
                                                  "Cannot serialize recursive data structure");
     }
     nestedObjs.Add(o);
     try
     {
         xtw.WriteStartElement("", "value", "");
         XmlRpcType xType = XmlRpcTypeInfo.GetXmlRpcType(o);
         if (xType == XmlRpcType.tArray)
         {
             xtw.WriteStartElement("", "array", "");
             xtw.WriteStartElement("", "data", "");
             Array a = (Array)o;
             foreach (Object aobj in a)
             {
                 //if (aobj == null)
                 //  throw new XmlRpcMappingSerializeException(String.Format(
                 //    "Items in array cannot be null ({0}[]).",
                 //o.GetType().GetElementType()));
                 Serialize(xtw, aobj, mappingActions, nestedObjs);
             }
             WriteFullEndElement(xtw);
             WriteFullEndElement(xtw);
         }
         else if (xType == XmlRpcType.tMultiDimArray)
         {
             Array mda     = (Array)o;
             int[] indices = new int[mda.Rank];
             BuildArrayXml(xtw, mda, 0, indices, mappingActions, nestedObjs);
         }
         else if (xType == XmlRpcType.tBase64)
         {
             byte[] buf = (byte[])o;
             xtw.WriteStartElement("", "base64", "");
             xtw.WriteBase64(buf, 0, buf.Length);
             WriteFullEndElement(xtw);
         }
         else if (xType == XmlRpcType.tBoolean)
         {
             bool boolVal = (bool)o;
             if (boolVal)
             {
                 WriteFullElementString(xtw, "boolean", "1");
             }
             else
             {
                 WriteFullElementString(xtw, "boolean", "0");
             }
         }
         else if (xType == XmlRpcType.tDateTime)
         {
             DateTime dt  = (DateTime)o;
             string   sdt = dt.ToString(DateTimeFormat, DateTimeFormatInfo.InvariantInfo);
             WriteFullElementString(xtw, "dateTime.iso8601", sdt);
         }
         else if (xType == XmlRpcType.tDouble)
         {
             double doubleVal = (double)o;
             WriteFullElementString(xtw, "double", doubleVal.ToString(null,
                                                                      CultureInfo.InvariantCulture));
         }
         else if (xType == XmlRpcType.tHashtable)
         {
             xtw.WriteStartElement("", "struct", "");
             XmlRpcStruct xrs = o as XmlRpcStruct;
             foreach (object obj in xrs.Keys)
             {
                 string skey = obj as string;
                 xtw.WriteStartElement("", "member", "");
                 WriteFullElementString(xtw, "name", skey);
                 Serialize(xtw, xrs[skey], mappingActions, nestedObjs);
                 WriteFullEndElement(xtw);
             }
             WriteFullEndElement(xtw);
         }
         else if (xType == XmlRpcType.tInt32)
         {
             o = SerializeInt32(xtw, o, mappingActions);
         }
         else if (xType == XmlRpcType.tInt64)
         {
             o = SerializeInt64(xtw, o, mappingActions);
         }
         else if (xType == XmlRpcType.tString)
         {
             SerializeString(xtw, o);
         }
         else if (xType == XmlRpcType.tStruct)
         {
             MappingActions structActions
                 = GetMappingActions(o.GetType(), mappingActions);
             xtw.WriteStartElement("", "struct", "");
             MemberInfo[] mis = o.GetType().GetMembers();
             foreach (MemberInfo mi in mis)
             {
                 if (Attribute.IsDefined(mi, typeof(NonSerializedAttribute)))
                 {
                     continue;
                 }
                 if (mi.MemberType == MemberTypes.Field)
                 {
                     FieldInfo fi      = (FieldInfo)mi;
                     string    member  = fi.Name;
                     Attribute attrchk = Attribute.GetCustomAttribute(fi,
                                                                      typeof(XmlRpcMemberAttribute));
                     if (attrchk != null && attrchk is XmlRpcMemberAttribute)
                     {
                         string mmbr = ((XmlRpcMemberAttribute)attrchk).Member;
                         if (mmbr != "")
                         {
                             member = mmbr;
                         }
                     }
                     MappingActions memberActions = MemberMappingActions(o.GetType(),
                                                                         fi.Name, structActions);
                     if (fi.GetValue(o) == null)
                     {
                         if (memberActions.NullMappingAction == NullMappingAction.Ignore)
                         {
                             continue;
                         }
                         else if (memberActions.NullMappingAction == NullMappingAction.Error)
                         {
                             throw new XmlRpcMappingSerializeException(@"Member """ + member +
                                                                       @""" of struct """ + o.GetType().Name + @""" cannot be null.");
                         }
                     }
                     xtw.WriteStartElement("", "member", "");
                     WriteFullElementString(xtw, "name", member);
                     Serialize(xtw, fi.GetValue(o), memberActions, nestedObjs);
                     WriteFullEndElement(xtw);
                 }
                 else if (mi.MemberType == MemberTypes.Property)
                 {
                     PropertyInfo pi      = (PropertyInfo)mi;
                     string       member  = pi.Name;
                     Attribute    attrchk = Attribute.GetCustomAttribute(pi,
                                                                         typeof(XmlRpcMemberAttribute));
                     if (attrchk != null && attrchk is XmlRpcMemberAttribute)
                     {
                         string mmbr = ((XmlRpcMemberAttribute)attrchk).Member;
                         if (mmbr != "")
                         {
                             member = mmbr;
                         }
                     }
                     MappingActions memberActions = MemberMappingActions(o.GetType(),
                                                                         pi.Name, structActions);
                     if (pi.GetValue(o, null) == null)
                     {
                         if (memberActions.NullMappingAction == NullMappingAction.Ignore)
                         {
                             continue;
                         }
                         else if (memberActions.NullMappingAction == NullMappingAction.Error)
                         {
                             throw new XmlRpcMappingSerializeException(@"Member """ + member +
                                                                       @""" of struct """ + o.GetType().Name + @""" cannot be null.");
                         }
                     }
                     xtw.WriteStartElement("", "member", "");
                     WriteFullElementString(xtw, "name", member);
                     Serialize(xtw, pi.GetValue(o, null), memberActions, nestedObjs);
                     WriteFullEndElement(xtw);
                 }
             }
             WriteFullEndElement(xtw);
         }
         else if (xType == XmlRpcType.tVoid)
         {
             WriteFullElementString(xtw, "string", "");
         }
         else if (xType == XmlRpcType.tNil)
         {
             xtw.WriteStartElement("nil");
             WriteFullEndElement(xtw);
         }
         else
         {
             throw new XmlRpcUnsupportedTypeException(o.GetType());
         }
         WriteFullEndElement(xtw);
     }
     catch (System.NullReferenceException)
     {
         throw new XmlRpcNullReferenceException("Attempt to serialize data "
                                                + "containing null reference");
     }
     finally
     {
         nestedObjs.RemoveAt(nestedObjs.Count - 1);
     }
 }
Esempio n. 19
0
        public void Serialize(XmlWriter xtw, object o, MappingActions mappingActions, List <object> nestedObjs)
        {
            if (nestedObjs.Contains(o))
            {
                throw new XmlRpcUnsupportedTypeException(
                          nestedObjs[0].GetType(),
                          "Cannot serialize recursive data structure");
            }

            nestedObjs.Add(o);
            try
            {
                xtw.WriteStartElement(string.Empty, "value", string.Empty);

                var xmlRpcType = XmlRpcTypeInfo.GetXmlRpcType(o);
                switch (xmlRpcType)
                {
                case XmlRpcType.tArray:
                    SerializeArray(xtw, o, mappingActions, nestedObjs);
                    break;

                case XmlRpcType.tMultiDimArray:
                    SerializeMultiDimensionalArray(xtw, o, mappingActions, nestedObjs);
                    break;

                case XmlRpcType.tBase64:
                    SerializeBase64(xtw, o);
                    break;

                case XmlRpcType.tBoolean:
                    SerializeBoolean(xtw, o);
                    break;

                case XmlRpcType.tDateTime:
                    SerializeDateTime(xtw, o);
                    break;

                case XmlRpcType.tDouble:
                    SerializeDouble(xtw, o);
                    break;

                case XmlRpcType.tHashtable:
                    SerializeHashTable(xtw, o, mappingActions, nestedObjs);
                    break;

                case XmlRpcType.tInt32:
                    SerializeInt32(xtw, o, mappingActions);
                    break;

                case XmlRpcType.tInt64:
                    SerializeInt64(xtw, o, mappingActions);
                    break;

                case XmlRpcType.tString:
                    SerializeString(xtw, o);
                    break;

                case XmlRpcType.tStruct:
                    SerializeStruct(xtw, o, mappingActions, nestedObjs);
                    break;

                case XmlRpcType.tVoid:
                    SerializeVoid(xtw);
                    break;

                case XmlRpcType.tNil:
                    SerializeNil(xtw);
                    break;

                default:
                    throw new XmlRpcUnsupportedTypeException(o.GetType());
                }

                WriteFullEndElement(xtw);
            }
            catch (NullReferenceException)
            {
                throw new XmlRpcNullReferenceException("Attempt to serialize data " + "containing null reference");
            }
            finally
            {
                nestedObjs.RemoveAt(nestedObjs.Count - 1);
            }
        }