// ----------------------------------------------------------------- /// <summary> /// /// </summary> // ----------------------------------------------------------------- private void DoJsonReadNotecard( UUID reqID, UUID hostID, UUID scriptID, UUID storeID, string path, string notecardIdentifier) { UUID assetID; if (!UUID.TryParse(notecardIdentifier, out assetID)) { SceneObjectPart part = m_scene.GetSceneObjectPart(hostID); assetID = ScriptUtils.GetAssetIdFromItemName(part, notecardIdentifier, (int)AssetType.Notecard); } AssetBase a = m_scene.AssetService.Get(assetID.ToString()); if (a == null) { GenerateRuntimeError(String.Format("Unable to find notecard asset {0}", assetID)); } if (a.Type != (sbyte)AssetType.Notecard) { GenerateRuntimeError(String.Format("Invalid notecard asset {0}", assetID)); } m_log.DebugFormat("[JsonStoreScripts]: read notecard in context {0}", storeID); try { int result; string[] data = SLUtil.ParseNotecardToArray(a.Data); if (data.Length == 0) { result = m_store.SetValue(storeID, path, string.Empty, true) ? 1 : 0; } else { StringBuilder sb = new StringBuilder(256); for (int i = 0; i < data.Length; ++i) { sb.AppendLine(data[i]); } result = m_store.SetValue(storeID, path, sb.ToString(), true) ? 1 : 0; } m_comms.DispatchReply(scriptID, result, "", reqID.ToString()); return; } catch (Exception e) { m_log.WarnFormat("[JsonStoreScripts]: Json parsing failed; {0}", e.Message); } GenerateRuntimeError(String.Format("Json parsing failed for {0}", assetID)); m_comms.DispatchReply(scriptID, 0, "", reqID.ToString()); }
// ----------------------------------------------------------------- /// <summary> /// /// </summary> // ----------------------------------------------------------------- private void DoJsonReadNotecard( UUID reqID, UUID hostID, UUID scriptID, UUID storeID, string path, string notecardIdentifier) { UUID assetID; if (!UUID.TryParse(notecardIdentifier, out assetID)) { SceneObjectPart part = m_scene.GetSceneObjectPart(hostID); assetID = ScriptUtils.GetAssetIdFromItemName(part, notecardIdentifier, (int)AssetType.Notecard); } AssetBase a = m_scene.AssetService.Get(assetID.ToString()); if (a == null) { GenerateRuntimeError(String.Format("Unable to find notecard asset {0}", assetID)); } if (a.Type != (sbyte)AssetType.Notecard) { GenerateRuntimeError(String.Format("Invalid notecard asset {0}", assetID)); } m_log.DebugFormat("[JsonStoreScripts]: read notecard in context {0}", storeID); try { string jsondata = SLUtil.ParseNotecardToString(a.Data); int result = m_store.SetValue(storeID, path, jsondata, true) ? 1 : 0; m_comms.DispatchReply(scriptID, result, "", reqID.ToString()); return; } catch (SLUtil.NotANotecardFormatException e) { m_log.WarnFormat("[JsonStoreScripts]: Notecard parsing failed; assetId {0} at line number {1}", assetID.ToString(), e.lineNumber); } catch (Exception e) { m_log.WarnFormat("[JsonStoreScripts]: Json parsing failed; {0}", e.Message); } GenerateRuntimeError(String.Format("Json parsing failed for {0}", assetID)); m_comms.DispatchReply(scriptID, 0, "", reqID.ToString()); }