Esempio n. 1
0
    //****************************************************************************************************
    //
    //****************************************************************************************************

    public override JSonEntry Resolve(string[] pathComps, int pathComp)
    {
        if (pathComps.Length <= 0)
        {
            return(null);
        }

        if (pathComp < 0)
        {
            return(null);
        }

        if (pathComp >= pathComps.Length)
        {
            return(this);
        }

        JSonEntry o = null;

        if (m_value.TryGetValue(pathComps[pathComp], out o))
        {
            if (o != null)
            {
                return(o.Resolve(pathComps, pathComp + 1));
            }
        }

        return(null);
    }
Esempio n. 2
0
 public bool       pop(ref JSonEntry entry)
 {
     if (m_count > 0)
     {
         entry = m_stack[--m_count]; return(true);
     }
     return(false);
 }
Esempio n. 3
0
 public bool       push(JSonEntry entry)
 {
     if (m_count < MAX_LVL)
     {
         m_stack[m_count++] = entry; return(true);
     }
     return(false);
 }
Esempio n. 4
0
    //****************************************************************************************************
    //
    //****************************************************************************************************

    public JSonEntry(string Name, JSonEntry Parent)
    {
        parent = Parent;

        name = (Name != null) ? Name : string.Empty;

        if (Parent != null)
        {
            Parent.Add(this);
        }
    }
Esempio n. 5
0
 public JSonObject(string Name, JSonEntry Parent) : base(Name, Parent)
 {
 }
Esempio n. 6
0
 public abstract void                            Add(JSonEntry entry);
Esempio n. 7
0
    //****************************************************************************************************
    //
    //****************************************************************************************************

    public bool Parse(string json)
    {
        if (string.IsNullOrEmpty(json))
        {
            return(false);
        }

        ControlStack ctrl = new ControlStack();

        JSonEntry cur = null;

        string name = null;

        m_root = null;


        for (int c = 0; c < json.Length; ++c)
        {
            //--------------------------------------------------------------------------------------------
            // register expression
            //--------------------------------------------------------------------------------------------

            if (char.IsWhiteSpace(json[c]) == false)
            {
                if (Semantics.hasProps(json[c], Semantics.PROP.ALL) == false)
                {
                    if (ctrl.expr.start == -1)
                    {
                        ctrl.expr.end = ctrl.expr.start = c;
                    }

                    else
                    {
                        ctrl.expr.end = c;
                    }

                    if (json[c] == QUOTE)
                    {
                        ++ctrl.expr.quotes; continue;
                    }
                }
            }
            else
            {
                continue;
            }

            //--------------------------------------------------------------------------------------------
            // register name or value
            //--------------------------------------------------------------------------------------------

            if (Semantics.hasProps(json[c], Semantics.PROP.CTRL) == true)
            {
                if ((ctrl.expr.quotes & 1) == 0)
                {
                    bool isName = (json[c] == COLON);

                    bool isValue = (isName == false);

                    bool valid = ctrl.expr.valid;

                    if ((isName) && (valid == false))
                    {
                        return(false);
                    }

                    if ((isName) && (cur is JSonObject) == false)
                    {
                        return(false);
                    }

                    if (valid)
                    {
                        string expr = json.Substring(ctrl.expr.start, ctrl.expr.end - ctrl.expr.start + 1).TrimEnd(' ', QUOTE, ' ').TrimStart(' ', QUOTE, ' ');

                        if (isName)
                        {
                            name = expr;
                        }

                        else if (isValue)
                        {
                            new JSonValue(name, cur).value = expr; name = null;
                        }
                    }

                    ctrl.expr.Reset();

                    if (Semantics.hasProps(json[c], Semantics.PROP.GRP) == false)
                    {
                        continue;
                    }
                }
            }

            //--------------------------------------------------------------------------------------------
            // register object or array
            //--------------------------------------------------------------------------------------------

            if (ctrl.expr.quotes == 0)
            {
                if (json[c] == BGN_OBJ)
                {
                    if ((cur == null) || ctrl.push(cur))
                    {
                        cur = new JSonObject(name, cur); if (m_root == null)
                        {
                            m_root = cur;
                        }
                        name = null; ctrl.expr.Reset(); continue;
                    }
                    else
                    {
                        return(false);
                    }
                }

                if (json[c] == BGN_ARR)
                {
                    if ((cur == null) || ctrl.push(cur))
                    {
                        cur = new JSonArray(name, cur); if (m_root == null)
                        {
                            m_root = cur;
                        }
                        name = null; ctrl.expr.Reset(); continue;
                    }
                    else
                    {
                        return(false);
                    }
                }

                if (json[c] == END_OBJ)
                {
                    if (cur == m_root)
                    {
                        break;
                    }
                    if ((cur is JSonObject) && ctrl.pop(ref cur))
                    {
                        ctrl.expr.Reset(); continue;
                    }
                    else
                    {
                        return(false);
                    }
                }

                if (json[c] == END_ARR)
                {
                    if (cur == m_root)
                    {
                        break;
                    }
                    if ((cur is JSonArray) && ctrl.pop(ref cur))
                    {
                        ctrl.expr.Reset(); continue;
                    }
                    else
                    {
                        return(false);
                    }
                }
            }
        }

        return((m_root != null) && (ctrl.empty));
    }
Esempio n. 8
0
 public override void      Add(JSonEntry entry)
 {
     Debug.Assert(false, "JSonValue: cannot be parent of another json elt");
 }
Esempio n. 9
0
    //****************************************************************************************************
    //
    //****************************************************************************************************

    public JSonValue(string Name, JSonEntry Parent) : base(Name, Parent)
    {
    }
Esempio n. 10
0
 public override void              Add(JSonEntry entry)
 {
     m_value.Add(entry);
 }
Esempio n. 11
0
 public JSonArray(string Name, JSonEntry Parent) : base(Name, Parent)
 {
 }
Esempio n. 12
0
    //****************************************************************************************************
    //
    //****************************************************************************************************

    private void OnItemsQueryResponse(HTTPReq query, params object[] paramsList)
    {
        if (query.result != QUERY_RESULT.SUCCESS)
        {
            End(); return;
        }


        JSon json = new JSon(query.response);

        if (json["error"] != null)
        {
            End(); return;
        }

        if ((json.root is JSonArray) == false)
        {
            End(); return;
        }

        for (int entry = 0; entry < json.count; ++entry)
        {
            JSonEntry o = json[entry];

            if ((o is JSonObject) == false)
            {
                continue;
            }

            long ID = -1L;  if (long.TryParse(o["id"].value, out ID) == false)
            {
                continue;
            }

            long siteID = -1L;  if (long.TryParse(o["site_id"].value, out siteID) == false)
            {
                continue;
            }

            float LAT = 0.0f; if (float.TryParse(o["lat"].value, out LAT) == false)
            {
                continue;
            }

            float LNG = 0.0f; if (float.TryParse(o["lng"].value, out LNG) == false)
            {
                continue;
            }

            float ALT = 0.0f; if (float.TryParse(o["alt"].value, out ALT) == false)
            {
                continue;
            }


            Item item = new Item();

            item.id = ID;

            item.parentID = siteID;

            item.name = o["name"].value;

            item.m_desc = o["dsc"].value;

            item.m_pic = o["pic"].value;

            item.m_coord.latitude.FromAngle(LAT, GPS.UNIT.DD);

            item.m_coord.longitude.FromAngle(LNG, GPS.UNIT.DD);

            item.m_coord.altitude = ALT;

            db.items.Add(item);


            if (item.m_parent == null)
            {
                item.SetParent(db.root);
            }
        }

        End();
    }