示例#1
0
    public static ResultSetErrorDetails CreateFromXML(string xml)
    {
        ResultSetErrorDetails details = new ResultSetErrorDetails();

        XmlReader reader = XmlReader.Create(new StringReader(xml));

        // XmlDeclaration
        reader.Read();
        // Whitespace
        reader.Read();

        //Table-name
        reader.Read();

        reader.ReadToFollowing("error-type-id");
        details._errorId = reader.ReadElementContentAsInt();

        reader.ReadToFollowing("name");
        details._errorName = reader.ReadElementContentAsString();

        reader.ReadToFollowing("description");
        details._errorDescription = reader.ReadElementContentAsString();

        reader.ReadToFollowing("created-at");
        details._createdAt = reader.ReadElementContentAsDateTime();

        reader.Close();

        return(details);
    }
示例#2
0
 public WebOperationException(ResultSetErrorDetails details)
 {
     ErrorDetails = details;
 }
示例#3
0
    private static ResultSet ParseResponse(WWW response)
    {
        ResultSet.Builder builder = ResultSet.Builder.Create();
        if (!string.IsNullOrEmpty(response.error))
        {
            return(builder.Status(ResultSetStatus.ConnectionError).ConnectionErrorMessage(response.error).Build());
        }

        // TODO need to rewrite this parser: broken for GetGroups

        //ResultSet resultSet;

        //ResultSetArray array = resultSet.GetArray("game-user-groups");

        //array.GetStructure("

        // Unable to parse xml like following:

        //<?xml version="1.0" encoding="UTF-8"?>
        //<game-user-groups type="array">
        //  <game-user-group>
        //    <id type="integer">1298</id>
        //    <game-user-id type="integer">1225</game-user-id>
        //    <group-id type="integer">10</group-id>
        //    <created-at type="datetime">2013-08-03T03:30:40Z</created-at>
        //    <updated-at type="datetime">2013-08-03T03:30:40Z</updated-at>
        //    <state>accepted</state>
        //    <game-role-id type="integer">2</game-role-id>
        //    <inviter-id type="integer" nil="true"/>
        //    <group>
        //      <id type="integer">10</id>
        //      <name>Meta!Blast</name>
        //      <owner-id type="integer">18</owner-id>
        //      <deleted-at type="datetime" nil="true"/>
        //      <created-at type="datetime">2011-02-28T11:41:09Z</created-at>
        //      <updated-at type="datetime">2011-02-28T11:41:10Z</updated-at>
        //      <collections type="array">
        //        <collection>
        //          <id type="integer">11</id>
        //          <description>Meta!Blast Basic</description>
        //          <group-id type="integer">10</group-id>
        //          <creator-id type="integer">18</creator-id>
        //          <created-at type="datetime">2011-09-13T19:32:53Z</created-at>
        //          <updated-at type="datetime">2012-09-29T04:49:24Z</updated-at>
        //          <name>Meta!Blast Basic</name>
        //        </collection>
        //        <collection>
        //          <id type="integer">210</id>
        //          <description>Meta!Blast Best Bio Questions</description>
        //          <group-id type="integer">10</group-id>
        //          <creator-id type="integer">440</creator-id>
        //          <created-at type="datetime" nil="true"/>
        //          <updated-at type="datetime" nil="true"/>
        //          <name>Meta!Blast Best Bio Questions</name>
        //        </collection>
        //      </collections>
        //    </group>
        //  </game-user-group>
        //</game-user-groups>

        // Need new ResultSet type: Structure
        // Need new ResultSet type: Array
        //  the <group> tag will be parsed into a structure.
        //  The group structure will contain:
        //      int id
        //      string name
        //      int owner-id
        //      datetime deleted-at,created-at,updated-at
        //      array collections

        // where collections is an array of structures, each element with:
        //  int id
        //  string description
        //  int group-id
        //  int creator-id
        //  datetime created-at
        //  datetime updated-at
        //  string name

        Debug.Log(response.text);

        XmlReader reader = XmlReader.Create(new StringReader(response.text));

        // XmlDeclaration
        reader.Read();
        // Whitespace
        reader.Read();

        //Table-name
        reader.Read();

        string tableName = reader.Name;

        if (tableName == "error")
        {
            reader.Close();
            return(builder.Status(ResultSetStatus.InvalidFormError).InvalidFormErrorDetails(ResultSetErrorDetails.CreateFromXML(response.text)).Build());
        }

        builder.TableName(reader.Name);

        while (reader.Read())
        {
            switch (reader.NodeType)
            {
            case (XmlNodeType.Element):
                string name          = reader.Name;
                string typeAttribute = reader.GetAttribute("type");
                string nilAttribute  = reader.GetAttribute("nil");

                bool isNull = false;

                if (nilAttribute != null)
                {
                    isNull = bool.Parse(nilAttribute);
                }

                object content = null;

                if (!isNull)
                {
                    switch (typeAttribute)
                    {
                    case "integer":
                        content = reader.ReadElementContentAsInt();
                        break;

                    case "datetime":
                        string dateTimeString = reader.ReadElementContentAsString();
                        content = DateTime.Parse(dateTimeString);
                        break;

                    case "array":
                        // TODO handle this:
                        // if an array is encountered,
                        //      Must create child ResultSet sort of object that has accessors for fields of whatever object is in the array.
                        //
                        break;

                    default:
                        content = reader.ReadElementContentAsString();
                        break;
                    }
                }

                builder.Field(name, content);
                break;

            default:
                break;
            }
        }

        return(builder.Build());
    }
示例#4
0
 public Builder InvalidFormErrorDetails(ResultSetErrorDetails resultSetErrorDetails)
 {
     _resultSet._invalidFormErrorDetails = resultSetErrorDetails;
     return(this);
 }