コード例 #1
0
    public static JSONObj Create(AddJSONContents content)
    {
        JSONObj obj = Create();

        content.Invoke(obj);
        return(obj);
    }
コード例 #2
0
    public static JSONObj Create()
    {
#if POOLING
        JSONObj result = null;
        while (result == null && releaseQueue.Count > 0)
        {
            result = releaseQueue.Dequeue();
#if DEV
            //The following cases should NEVER HAPPEN (but they do...)
            if (result == null)
            {
                Debug.WriteLine("wtf " + releaseQueue.Count);
            }
            else if (result.list != null)
            {
                Debug.WriteLine("wtflist " + result.list.Count);
            }
#endif
        }
        if (result != null)
        {
            return(result);
        }
#endif
        return(new JSONObj());
    }
コード例 #3
0
    /*
     * Vector2
     */
    public static Vector2 ToVector2(JSONObj obj)
    {
        float x = obj["x"] ? obj["x"].f : 0;
        float y = obj["y"] ? obj["y"].f : 0;

        return(new Vector2(x, y));
    }
コード例 #4
0
        public bool TryGetVector(string baseName, out Vector3 vector)
        {
            vector = new Vector3();

            if (Attributes.ContainsKey(baseName))
            {
                JSONObj Value = Attributes[baseName];

                if (Value != null && Value.IsObject)
                {
                    for (int i = 0; i < Value.list.Count; i++)
                    {
                        if (Value.list[i].IsNumber)
                        {
                            if (Value.keys[i] == "x")
                            {
                                vector.x = Value.list[i].f;
                            }
                            else if (Value.keys[i] == "y")
                            {
                                vector.y = Value.list[i].f;
                            }
                            else if (Value.keys[i] == "z")
                            {
                                vector.z = Value.list[i].f;
                            }
                        }
                    }

                    return(true);
                }
            }

            return(false);
        }
コード例 #5
0
        public static JSONObj Serialize(QueryNode node)
        {
            JSONObj masterObj = new JSONObj(JSONObj.ObjectType.OBJECT);

            masterObj.AddField("type", node.Type.ToString().ToLower());
            masterObj.AddField("op", node.Operator.ToString().ToLower());

            switch (node.Type)
            {
            case QueryNodeType.Group:
                JSONObj innerObj = new JSONObj(JSONObj.ObjectType.ARRAY);

                foreach (QueryNode Item in node.Children)
                {
                    innerObj.Add(Serialize(Item));
                }

                masterObj.AddField("children", innerObj);
                break;

            case QueryNodeType.Comparison:
                masterObj.AddField("column", node.Column);
                masterObj.AddField("value", node.Value);
                break;
            }

            string test = masterObj.ToString();

            return(masterObj);
        }
コード例 #6
0
    /// <summary>
    /// Create a JSONObj by parsing string data
    /// </summary>
    /// <param name="val">The string to be parsed</param>
    /// <param name="maxDepth">The maximum depth for the parser to search.  Set this to to 1 for the first level,
    /// 2 for the first 2 levels, etc.  It defaults to -2 because -1 is the depth value that is parsed (see below)</param>
    /// <param name="storeExcessLevels">Whether to store levels beyond maxDepth in baked JSONObjs</param>
    /// <param name="strict">Whether to be strict in the parsing. For example, non-strict parsing will successfully
    /// parse "a string" into a string-type </param>
    /// <returns></returns>
    public static JSONObj Create(string val, int maxDepth = -2, bool storeExcessLevels = false, bool strict = false)
    {
        JSONObj obj = Create();

        obj.Parse(val, maxDepth, storeExcessLevels, strict);
        return(obj);
    }
コード例 #7
0
 public void AddField(string name, JSONObj obj)
 {
     if (obj)                        //Don't do anything if the object is null
     {
         if (type != ObjectType.OBJECT)
         {
             if (keys == null)
             {
                 keys = new List <string>();
             }
             if (type == ObjectType.ARRAY)
             {
                 for (int i = 0; i < list.Count; i++)
                 {
                     keys.Add(i.ToString(CultureInfo.InvariantCulture));
                 }
             }
             else
             if (list == null)
             {
                 list = new List <JSONObj>();
             }
             type = ObjectType.OBJECT;                               //Congratulations, son, you're an OBJECT now
         }
         keys.Add(name);
         list.Add(obj);
     }
 }
コード例 #8
0
    /*
     * Layer Mask
     */
    public static JSONObj FromLayerMask(LayerMask l)
    {
        JSONObj result = JSONObj.obj;

        result.AddField("value", l.value);
        return(result);
    }
コード例 #9
0
 // Overload for grouping nodes (AND, OR)
 public QueryNode(QueryNodeType type, QueryOp op, QueryNodeList childNodes)
 {
     this.Type     = type;
     this.Operator = op;
     this.Column   = "";
     this.Value    = JSONObj.nullJO;
     this.Children = childNodes;
 }
コード例 #10
0
    public static JSONObj Create(float val)
    {
        JSONObj obj = Create();

        obj.type = ObjectType.NUMBER;
        obj.n    = val;
        return(obj);
    }
コード例 #11
0
    public static JSONObj CreateStringObject(string val)
    {
        JSONObj obj = Create();

        obj.type = ObjectType.STRING;
        obj.str  = val;
        return(obj);
    }
コード例 #12
0
 // Standard single value node
 public QueryNode(QueryNodeType type, string column, QueryOp op, JSONObj value)
 {
     this.Type     = type;
     this.Column   = column;
     this.Operator = op;
     this.Value    = value;
     this.Children = new QueryNodeList();
 }
コード例 #13
0
    public static JSONObj CreateBakedObject(string val)
    {
        JSONObj bakedObject = Create();

        bakedObject.type = ObjectType.BAKED;
        bakedObject.str  = val;
        return(bakedObject);
    }
コード例 #14
0
    public static JSONObj Create(bool val)
    {
        JSONObj obj = Create();

        obj.type = ObjectType.BOOL;
        obj.b    = val;
        return(obj);
    }
コード例 #15
0
    public static Vector3 ToVector3(JSONObj obj)
    {
        float x = obj["x"] ? obj["x"].f : 0;
        float y = obj["y"] ? obj["y"].f : 0;
        float z = obj["z"] ? obj["z"].f : 0;

        return(new Vector3(x, y, z));
    }
コード例 #16
0
    public static LayerMask ToLayerMask(JSONObj obj)
    {
        LayerMask l = new LayerMask {
            value = (int)obj["value"].n
        };

        return(l);
    }
コード例 #17
0
        public QueryEvent(JSONObj jObj)
        {
            Debug.Assert(jObj.IsObject);

            for (int i = 0; i < jObj.keys.Count; i++)
            {
                this.Attributes.Add(jObj.keys[i], jObj.list[i]);
            }
        }
コード例 #18
0
    public static Quaternion ToQuaternion(JSONObj obj)
    {
        float x = obj["x"] ? obj["x"].f : 0;
        float y = obj["y"] ? obj["y"].f : 0;
        float z = obj["z"] ? obj["z"].f : 0;
        float w = obj["w"] ? obj["w"].f : 0;

        return(new Quaternion(x, y, z, w));
    }
コード例 #19
0
    public static Vector4 ToVector4(JSONObj obj)
    {
        float x = obj["x"] ? obj["x"].f : 0;
        float y = obj["y"] ? obj["y"].f : 0;
        float z = obj["z"] ? obj["z"].f : 0;
        float w = obj["w"] ? obj["w"].f : 0;

        return(new Vector4(x, y, z, w));
    }
コード例 #20
0
 public void SetField(string name, JSONObj obj)
 {
     if (HasField(name))
     {
         list.Remove(this[name]);
         keys.Remove(name);
     }
     AddField(name, obj);
 }
コード例 #21
0
        public TelemetryBatchPayload(TelemetryProperties common)
        {
            headerObject = new JSONObj(JSONObj.ObjectType.OBJECT);
            eventList    = new System.Collections.Generic.List <JSONObj>();

            foreach (var Prop in common)
            {
                headerObject.AddField(Prop.Key, Prop.Value);
            }
        }
コード例 #22
0
    public static JSONObj Create(long val)
    {
        JSONObj obj = Create();

        obj.type   = ObjectType.NUMBER;
        obj.n      = val;
        obj.useInt = true;
        obj.i      = val;
        return(obj);
    }
コード例 #23
0
        async Task <JSONObj> GetResults(string url)
        {
            JSONObj             result   = null;
            HttpResponseMessage response = await client.GetAsync(url).ConfigureAwait(false);

            if (response.IsSuccessStatusCode)
            {
                result = await response.Content.ReadAsAsync <JSONObj>();
            }
            return(result);
        }
コード例 #24
0
        // Debug utility function for outputting telemetry to a string for printing
        public static string DumpJson(TelemetryProperties properties)
        {
            JSONObj jObject = new JSONObj(JSONObj.ObjectType.OBJECT);

            foreach (var Prop in properties)
            {
                jObject.AddField(Prop.Key, Prop.Value);
            }

            return(jObject.Print());
        }
コード例 #25
0
        public void AddTelemetry(TelemetryBuilder inEvent)
        {
            JSONObj eventObject = new JSONObj(JSONObj.ObjectType.OBJECT);

            foreach (var Prop in inEvent)
            {
                eventObject.AddField(Prop.Key, Prop.Value);
            }

            eventList.Add(eventObject);
        }
コード例 #26
0
 public void Absorb(JSONObj obj)
 {
     list.AddRange(obj.list);
     keys.AddRange(obj.keys);
     str    = obj.str;
     n      = obj.n;
     useInt = obj.useInt;
     i      = obj.i;
     b      = obj.b;
     type   = obj.type;
 }
コード例 #27
0
        public QueryEvent Parse(JSONObj jObj)
        {
            Debug.Assert(jObj.IsObject);

            QueryEvent ev = new QueryEvent();

            for (int i = 0; i < jObj.keys.Count; i++)
            {
                ev.Attributes.Add(jObj.keys[i], jObj.list[i]);
            }

            return(ev);
        }
コード例 #28
0
        // Overload for BETWEEN query nodes
        public QueryNode(QueryNodeType type, string column, QueryOp op, JSONObj value1, JSONObj value2)
        {
            // Between and In operators are the only ones that know to look at the values array
            Debug.Assert(op == QueryOp.Btwn || op == QueryOp.In);

            this.Type     = type;
            this.Column   = column;
            this.Operator = op;
            this.Children = new QueryNodeList();
            this.Value    = JSONObj.obj;
            Value.Add(value1);
            Value.Add(value2);
        }
コード例 #29
0
    public static JSONObj Create(Vector3 val)
    {
        JSONObj obj = Create(ObjectType.OBJECT);
        JSONObj x   = Create(val.x);
        JSONObj y   = Create(val.y);
        JSONObj z   = Create(val.z);

        obj.AddField("x", x);
        obj.AddField("y", y);
        obj.AddField("z", z);

        return(obj);
    }
コード例 #30
0
        async Task RunAsync(string url)
        {
            client.BaseAddress = new Uri(url);
            try
            {
                JSONObj result = await GetResults(url).ConfigureAwait(false);

                _distance = result.rows[0].Elements[0].Distance.Text;
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }