Ejemplo n.º 1
0
        // -----------------------------------------------------------------
        /// <summary>
        ///
        /// </summary>
        // -----------------------------------------------------------------
        public void TakeValue(UUID storeID, string path, bool useJson, TakeValueCallback cback)
        {
            if (!m_enabled)
            {
                cback(String.Empty);
                return;
            }

            JsonStore map = null;

            lock (m_JsonValueStore)
            {
                if (!m_JsonValueStore.TryGetValue(storeID, out map))
                {
                    cback(String.Empty);
                    return;
                }
            }

            try
            {
                lock (map)
                {
                    map.TakeValue(path, useJson, cback);
                    return;
                }
            }
            catch (Exception e)
            {
                m_log.Error("[JsonStore] unable to retrieve value", e);
            }

            cback(String.Empty);
        }
Ejemplo n.º 2
0
        // -----------------------------------------------------------------
        /// <summary>
        ///
        /// </summary>
        // -----------------------------------------------------------------
        public bool RemoveValue(UUID storeID, string path)
        {
            if (!m_enabled)
            {
                return(false);
            }

            JsonStore map = null;

            lock (m_JsonValueStore)
            {
                if (!m_JsonValueStore.TryGetValue(storeID, out map))
                {
                    m_log.InfoFormat("[JsonStore] Missing store {0}", storeID);
                    return(false);
                }
            }

            try
            {
                lock (map)
                    return(map.RemoveValue(path));
            }
            catch (Exception e)
            {
                m_log.Error(string.Format("[JsonStore]: Unable to remove {0} in {1}", path, storeID), e);
            }

            return(false);
        }
Ejemplo n.º 3
0
        // -----------------------------------------------------------------
        /// <summary>
        ///
        /// </summary>
        // -----------------------------------------------------------------
        public JsonStoreValueType GetValueType(UUID storeID, string path)
        {
            if (!m_enabled)
            {
                return(JsonStoreValueType.Undefined);
            }

            JsonStore map = null;

            lock (m_JsonValueStore)
            {
                if (!m_JsonValueStore.TryGetValue(storeID, out map))
                {
                    m_log.InfoFormat("[JsonStore] Missing store {0}", storeID);
                    return(JsonStoreValueType.Undefined);
                }
            }

            try
            {
                lock (map)
                    return(map.GetValueType(path));
            }
            catch (Exception e)
            {
                m_log.Error(string.Format("[JsonStore]: Path test failed for {0} in {1}", path, storeID), e);
            }

            return(JsonStoreValueType.Undefined);
        }
Ejemplo n.º 4
0
        // -----------------------------------------------------------------
        /// <summary>
        ///
        /// </summary>
        // -----------------------------------------------------------------
        public bool GetValue(UUID storeID, string path, bool useJson, out string value)
        {
            value = String.Empty;

            if (!m_enabled)
            {
                return(false);
            }

            JsonStore map = null;

            lock (m_JsonValueStore)
            {
                if (!m_JsonValueStore.TryGetValue(storeID, out map))
                {
                    return(false);
                }
            }

            try
            {
                lock (map)
                {
                    return(map.GetValue(path, out value, useJson));
                }
            }
            catch (Exception e)
            {
                m_log.Error("[JsonStore]: unable to retrieve value", e);
            }

            return(false);
        }
Ejemplo n.º 5
0
        // -----------------------------------------------------------------
        /// <summary>
        ///
        /// </summary>
        // -----------------------------------------------------------------
        public int GetArrayLength(UUID storeID, string path)
        {
            if (!m_enabled)
            {
                return(-1);
            }

            JsonStore map = null;

            lock (m_JsonValueStore)
            {
                if (!m_JsonValueStore.TryGetValue(storeID, out map))
                {
                    return(-1);
                }
            }

            try
            {
                lock (map)
                {
                    return(map.ArrayLength(path));
                }
            }
            catch (Exception e)
            {
                m_log.Error("[JsonStore]: unable to retrieve value", e);
            }

            return(-1);
        }
Ejemplo n.º 6
0
        // -----------------------------------------------------------------
        /// <summary>
        ///
        /// </summary>
        // -----------------------------------------------------------------
        public bool CreateStore(string value, ref UUID result)
        {
            if (result == UUID.Zero)
            {
                result = UUID.Random();
            }

            JsonStore map = null;

            if (!m_enabled)
            {
                return(false);
            }

            try
            {
                map = new JsonStore(value);
            }
            catch (Exception)
            {
                m_log.ErrorFormat("[JsonStore]: Unable to initialize store from {0}", value);
                return(false);
            }

            lock (m_JsonValueStore)
                m_JsonValueStore.Add(result, map);

            return(true);
        }
Ejemplo n.º 7
0
        public string JsonList2Path(UUID hostID, UUID scriptID, object[] pathlist)
        {
            string ipath = ConvertList2Path(pathlist);
            string opath;

            if (JsonStore.CanonicalPathExpression(ipath, out opath))
            {
                return(opath);
            }

            // This won't parse if passed to the other routines as opposed to
            // returning an empty string which is a valid path and would overwrite
            // the entire store
            return("**INVALID**");
        }
Ejemplo n.º 8
0
        // -----------------------------------------------------------------
        /// <summary>
        ///
        /// </summary>
        // -----------------------------------------------------------------
        public bool SetValue(UUID storeID, string path, string value, bool useJson)
        {
            if (!m_enabled)
            {
                return(false);
            }

            JsonStore map = null;

            lock (m_JsonValueStore)
            {
                if (!m_JsonValueStore.TryGetValue(storeID, out map))
                {
                    m_log.InfoFormat("[JsonStore] Missing store {0}", storeID);
                    return(false);
                }
            }

            try
            {
                lock (map)
                {
                    if (map.StringSpace > m_maxStringSpace)
                    {
                        m_log.WarnFormat("[JsonStore] {0} exceeded string size; {1} bytes used of {2} limit",
                                         storeID, map.StringSpace, m_maxStringSpace);
                        return(false);
                    }

                    return(map.SetValue(path, value, useJson));
                }
            }
            catch (Exception e)
            {
                m_log.Error(string.Format("[JsonStore]: Unable to assign {0} to {1} in {2}", value, path, storeID), e);
            }

            return(false);
        }