Beispiel #1
0
        private string imm_get_json_path_array(YJSONArray jsonArray, string[] paths, int ofs)
        {
            int key = Convert.ToInt32(paths[ofs]);

            if (jsonArray.Length <= key)
            {
                return("");
            }

            YJSONContent obj = jsonArray.get(key);

            if (obj != null)
            {
                if (paths.Length == ofs + 1)
                {
                    return(obj.ToString());
                }

                if (obj is YJSONArray)
                {
                    return(imm_get_json_path_array(jsonArray.getYJSONArray(key), paths, ofs + 1));
                }
                else if (obj is YJSONObject)
                {
                    return(imm_get_json_path_struct(jsonArray.getYJSONObject(key), paths, ofs + 1));
                }
            }
            return("");
        }
        private void convert(YJSONObject reference, YJSONArray newArray)
        {
            int length = newArray.Length;

            for (int i = 0; i < length; i++)
            {
                string       key            = reference.getKeyFromIdx(i);
                YJSONContent new_item       = newArray.get(i);
                YJSONContent reference_item = reference.get(key);

                if (new_item.getJSONType() == reference_item.getJSONType())
                {
                    parsed.Add(key, new_item);
                    _keys.Add(key);
                }
                else if (new_item.getJSONType() == YJSONType.ARRAY && reference_item.getJSONType() == YJSONType.OBJECT)
                {
                    YJSONObject jobj = new YJSONObject(new_item._data, new_item._data_start, reference_item._data_boundary);
                    jobj.convert((YJSONObject)reference_item, (YJSONArray)new_item);
                    parsed.Add(key, jobj);
                    _keys.Add(key);
                }
                else
                {
                    throw new System.Exception("Unable to convert " + new_item.getJSONType().ToString() + " to " + reference.getJSONType().ToString());
                }
            }
        }
        /// <summary>
        /// Builds a list of all data streams hold by the data logger (legacy method).
        /// The caller must pass by reference an empty array to hold YDataStream
        /// objects, and the function fills it with objects describing available
        /// data sequences.
        ///
        /// This is the old way to retrieve data from the DataLogger.
        /// For new applications, you should rather use get_dataSets()
        /// method, or call directly get_recordedData() on the
        /// sensor object.
        /// </summary>
        /// <param name="v"> : an array of YDataStream objects to be filled in
        /// </param>
        /// <returns> YAPI.SUCCESS if the call succeeds.
        /// </returns>
        /// <exception cref="YAPI_Exception"> on error </exception>
        public virtual async Task <int> get_dataStreams(List <YDataStream> v)
        {
            byte[] loadval = await getData(null, null);

            YJSONArray jsonAllStreams = new YJSONArray(YAPI.DefaultEncoding.GetString(loadval));

            jsonAllStreams.parse();
            if (jsonAllStreams.Length == 0)
            {
                return(YAPI.SUCCESS);
            }
            if (jsonAllStreams.get(0) is YJSONArray)
            {
                // old datalogger format: [runIdx, timerel, utc, interval]
                _throw(YAPI.NOT_SUPPORTED, "Old datalogger is no more supported. Please upgrade your device.");
                return(YAPI.NOT_SUPPORTED);
            }
            else
            {
                // new datalogger format: {"id":"...","unit":"...","streams":["...",...]}
                List <YDataSet> sets = await this.parse_dataSets(YAPI.DefaultEncoding.GetBytes(jsonAllStreams.ToString()));

                for (int j = 0; j < sets.Count; j++)
                {
                    List <YDataStream> ds = await sets[j].get_privateDataStreams();
                    for (int si = 0; si < ds.Count; si++)
                    {
                        v.Add(ds[si]);
                    }
                }
                return(YAPI.SUCCESS);
            }
        }
Beispiel #4
0
        protected internal virtual List <string> imm_json_get_array(byte[] json)
        {
            YJSONArray array = new YJSONArray(YAPI.DefaultEncoding.GetString(json));

            array.parse();
            List <string> list = new List <string>();
            int           len  = array.Length;

            for (int i = 0; i < len; i++)
            {
                YJSONContent o = array.get(i);
                list.Add(o.toJSON());
            }
            return(list);
        }