Esempio n. 1
0
        public override byte[] Handle(string path, Stream request,
                                      OSHttpRequest httpRequest, OSHttpResponse httpResponse)
        {
            //Encoding encoding = Encoding.UTF8;
            //StreamReader streamReader = new StreamReader(request, false);

            //string requestBody = streamReader.ReadToEnd();
            //streamReader.Close();

            // OpenMetaverse.StructuredData.OSDMap hash = (OpenMetaverse.StructuredData.OSDMap)
            //    OpenMetaverse.StructuredData.LLSDParser.DeserializeXml(new XmlTextReader(request));

            Hashtable hash        = (Hashtable)LLSD.LLSDDeserialize(request);
            TRequest  llsdRequest = new TRequest();

            LLSDHelpers.DeserializeOSDMap(hash, llsdRequest);

            TResponse response = m_method(llsdRequest);

            Encoding encoding = new UTF8Encoding(false);

            return(encoding.GetBytes(LLSDHelpers.SerializeLLSDReply(response)));
        }
Esempio n. 2
0
        private static void SerializeOSDType(XmlTextWriter writer, object obj)
        {
            Type myType = obj.GetType();

            LLSDType[] llsdattributes = (LLSDType[])myType.GetCustomAttributes(typeof(LLSDType), false);
            if (llsdattributes.Length > 0)
            {
                switch (llsdattributes[0].ObjectType)
                {
                case "MAP":
                    writer.WriteStartElement(String.Empty, "map", String.Empty);
                    FieldInfo[] fields = myType.GetFields();
                    for (int i = 0; i < fields.Length; i++)
                    {
                        if (fields[i] != null && fields[i].GetValue(obj) != null)
                        {
                            object     fieldValue      = fields[i].GetValue(obj);
                            LLSDType[] fieldAttributes =
                                (LLSDType[])fieldValue.GetType().GetCustomAttributes(typeof(LLSDType), false);
                            if (fieldAttributes.Length > 0)
                            {
                                writer.WriteStartElement(String.Empty, "key", String.Empty);
                                string fieldName = fields[i].Name;
                                fieldName = fieldName.Replace("___", "-");
                                writer.WriteString(fieldName);
                                writer.WriteEndElement();
                                SerializeOSDType(writer, fieldValue);
                            }
                            else
                            {
                                writer.WriteStartElement(String.Empty, "key", String.Empty);
                                string fieldName = fields[i].Name;
                                fieldName = fieldName.Replace("___", "-");
                                writer.WriteString(fieldName);
                                writer.WriteEndElement();
                                LLSD.LLSDWriteOne(writer, fieldValue);
                                // OpenMetaverse.StructuredData.LLSDParser.SerializeXmlElement(
                                //    writer, OpenMetaverse.StructuredData.OSD.FromObject(fieldValue));
                            }
                        }
                        else
                        {
                            // TODO from ADAM: There is a nullref being caused by fields[i] being null
                            // on some computers. Unsure what is causing this, but would appreciate
                            // if sdague could take a look at this.
                        }
                    }
                    writer.WriteEndElement();
                    break;

                case "ARRAY":
                    //OSDArray arrayObject = obj as OSDArray;
                    // ArrayList a = arrayObject.Array;
                    ArrayList a = (ArrayList)obj.GetType().GetField("Array").GetValue(obj);
                    if (a != null)
                    {
                        writer.WriteStartElement(String.Empty, "array", String.Empty);
                        foreach (object item in a)
                        {
                            SerializeOSDType(writer, item);
                        }
                        writer.WriteEndElement();
                    }
                    break;
                }
            }
            else
            {
                LLSD.LLSDWriteOne(writer, obj);
                //OpenMetaverse.StructuredData.LLSDParser.SerializeXmlElement(
                //    writer, OpenMetaverse.StructuredData.OSD.FromObject(obj));
            }
        }