// ----------------------------------------------------------------- /// <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); }
// ----------------------------------------------------------------- /// <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); }
// ----------------------------------------------------------------- /// <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); }
// ----------------------------------------------------------------- /// <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); }
// ----------------------------------------------------------------- /// <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); }
// ----------------------------------------------------------------- /// <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); }
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**"); }
// ----------------------------------------------------------------- /// <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); }