aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim
diff options
context:
space:
mode:
authorMic Bowman2013-01-31 14:53:16 -0800
committerMic Bowman2013-01-31 14:53:16 -0800
commit1e0420431f754ff71a97d01fae5617c1ea26cae0 (patch)
tree4d69a960e7701aa7af097b50b9259fbcc6d28021 /OpenSim
parentMerge branch 'master' of ssh://opensimulator.org/var/git/opensim (diff)
downloadopensim-SC_OLD-1e0420431f754ff71a97d01fae5617c1ea26cae0.zip
opensim-SC_OLD-1e0420431f754ff71a97d01fae5617c1ea26cae0.tar.gz
opensim-SC_OLD-1e0420431f754ff71a97d01fae5617c1ea26cae0.tar.bz2
opensim-SC_OLD-1e0420431f754ff71a97d01fae5617c1ea26cae0.tar.xz
Move the JsonStore regular expressions to static variables to avoid
recompiling on every operation. Added JsonList2Path script function to simplify array iteration.
Diffstat (limited to 'OpenSim')
-rw-r--r--OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStore.cs73
-rw-r--r--OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreScriptModule.cs204
2 files changed, 190 insertions, 87 deletions
diff --git a/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStore.cs b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStore.cs
index 34894ba..0b7b31b 100644
--- a/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStore.cs
+++ b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStore.cs
@@ -68,12 +68,46 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
68 protected List<TakeValueCallbackClass> m_TakeStore; 68 protected List<TakeValueCallbackClass> m_TakeStore;
69 protected List<TakeValueCallbackClass> m_ReadStore; 69 protected List<TakeValueCallbackClass> m_ReadStore;
70 70
71 // add separators for quoted paths
72 protected static Regex m_ParsePassOne = new Regex("{[^}]+}");
73
74 // add separators for array references
75 protected static Regex m_ParsePassTwo = new Regex("(\\[[0-9]+\\]|\\[\\+\\])");
76
77 // add quotes to bare identifiers which are limited to alphabetic characters
78 protected static Regex m_ParsePassThree = new Regex("\\.([a-zA-Z]+)");
79
80 // remove extra separator characters
81 protected static Regex m_ParsePassFour = new Regex("\\.+");
82
83 // expression used to validate the full path, this is canonical representation
84 protected static Regex m_ValidatePath = new Regex("^\\.(({[^}]+}|\\[[0-9]+\\]|\\[\\+\\])\\.)+$");
85
86 // expression used to match path components
87 protected static Regex m_PathComponent = new Regex("\\.({[^}]+}|\\[[0-9]+\\]|\\[\\+\\]+)");
88
89 // extract the internals of an array reference
90 protected static Regex m_SimpleArrayPattern = new Regex("\\[([0-9]+)\\]");
91 protected static Regex m_ArrayPattern = new Regex("\\[([0-9]+|\\+)\\]");
92
93 // extract the internals of a has reference
94 protected static Regex m_HashPattern = new Regex("{([^}]+)}");
71 95
72 // ----------------------------------------------------------------- 96 // -----------------------------------------------------------------
73 /// <summary> 97 /// <summary>
74 /// 98 ///
75 /// </summary> 99 /// </summary>
76 // ----------------------------------------------------------------- 100 // -----------------------------------------------------------------
101 public static string CanonicalPathExpression(string path)
102 {
103 return PathExpressionToKey(ParsePathExpression(path));
104 }
105
106 // -----------------------------------------------------------------
107 /// <summary>
108 ///
109 /// </summary>
110 // -----------------------------------------------------------------
77 public JsonStore() : this("") {} 111 public JsonStore() : this("") {}
78 112
79 public JsonStore(string value) 113 public JsonStore(string value)
@@ -224,9 +258,8 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
224 if (result == null) 258 if (result == null)
225 return false; 259 return false;
226 260
227 Regex aPattern = new Regex("\\[([0-9]+|\\+)\\]"); 261 // Check for and extract array references
228 MatchCollection amatches = aPattern.Matches(pkey,0); 262 MatchCollection amatches = m_ArrayPattern.Matches(pkey,0);
229
230 if (amatches.Count > 0) 263 if (amatches.Count > 0)
231 { 264 {
232 if (result.Type != OSDType.Array) 265 if (result.Type != OSDType.Array)
@@ -263,9 +296,8 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
263 return false; 296 return false;
264 } 297 }
265 298
266 Regex hPattern = new Regex("{([^}]+)}"); 299 // Check for and extract hash references
267 MatchCollection hmatches = hPattern.Matches(pkey,0); 300 MatchCollection hmatches = m_HashPattern.Matches(pkey,0);
268
269 if (hmatches.Count > 0) 301 if (hmatches.Count > 0)
270 { 302 {
271 Match match = hmatches[0]; 303 Match match = hmatches[0];
@@ -340,26 +372,21 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
340 path = "." + path + "."; 372 path = "." + path + ".";
341 373
342 // add separators for quoted paths 374 // add separators for quoted paths
343 Regex pass1 = new Regex("{[^}]+}"); 375 path = m_ParsePassOne.Replace(path,".$0.",-1,0);
344 path = pass1.Replace(path,".$0.",-1,0);
345 376
346 // add separators for array references 377 // add separators for array references
347 Regex pass2 = new Regex("(\\[[0-9]+\\]|\\[\\+\\])"); 378 path = m_ParsePassTwo.Replace(path,".$0.",-1,0);
348 path = pass2.Replace(path,".$0.",-1,0);
349 379
350 // add quotes to bare identifier 380 // add quotes to bare identifier
351 Regex pass3 = new Regex("\\.([a-zA-Z]+)"); 381 path = m_ParsePassThree.Replace(path,".{$1}",-1,0);
352 path = pass3.Replace(path,".{$1}",-1,0);
353 382
354 // remove extra separators 383 // remove extra separators
355 Regex pass4 = new Regex("\\.+"); 384 path = m_ParsePassFour.Replace(path,".",-1,0);
356 path = pass4.Replace(path,".",-1,0);
357 385
358 Regex validate = new Regex("^\\.(({[^}]+}|\\[[0-9]+\\]|\\[\\+\\])\\.)+$"); 386 // validate the results (catches extra quote characters for example)
359 if (validate.IsMatch(path)) 387 if (m_ValidatePath.IsMatch(path))
360 { 388 {
361 Regex parser = new Regex("\\.({[^}]+}|\\[[0-9]+\\]|\\[\\+\\]+)"); 389 MatchCollection matches = m_PathComponent.Matches(path,0);
362 MatchCollection matches = parser.Matches(path,0);
363 foreach (Match match in matches) 390 foreach (Match match in matches)
364 m_path.Push(match.Groups[1].Value); 391 m_path.Push(match.Groups[1].Value);
365 } 392 }
@@ -385,9 +412,8 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
385 return null; 412 return null;
386 413
387 // ---------- Check for an array index ---------- 414 // ---------- Check for an array index ----------
388 Regex aPattern = new Regex("\\[([0-9]+)\\]"); 415 MatchCollection amatches = m_SimpleArrayPattern.Matches(pkey,0);
389 MatchCollection amatches = aPattern.Matches(pkey,0); 416
390
391 if (amatches.Count > 0) 417 if (amatches.Count > 0)
392 { 418 {
393 if (rmap.Type != OSDType.Array) 419 if (rmap.Type != OSDType.Array)
@@ -410,9 +436,8 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
410 } 436 }
411 437
412 // ---------- Check for a hash index ---------- 438 // ---------- Check for a hash index ----------
413 Regex hPattern = new Regex("{([^}]+)}"); 439 MatchCollection hmatches = m_HashPattern.Matches(pkey,0);
414 MatchCollection hmatches = hPattern.Matches(pkey,0); 440
415
416 if (hmatches.Count > 0) 441 if (hmatches.Count > 0)
417 { 442 {
418 if (rmap.Type != OSDType.Map) 443 if (rmap.Type != OSDType.Map)
diff --git a/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreScriptModule.cs b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreScriptModule.cs
index 29955af..5b7a79d 100644
--- a/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreScriptModule.cs
+++ b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreScriptModule.cs
@@ -165,29 +165,32 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
165 165
166 try 166 try
167 { 167 {
168 m_comms.RegisterScriptInvocation(this, "JsonCreateStore"); 168 m_comms.RegisterScriptInvocations(this);
169 m_comms.RegisterScriptInvocation(this, "JsonDestroyStore");
170 m_comms.RegisterScriptInvocation(this, "JsonTestStore");
171 169
172 m_comms.RegisterScriptInvocation(this, "JsonReadNotecard"); 170 // m_comms.RegisterScriptInvocation(this, "JsonCreateStore");
173 m_comms.RegisterScriptInvocation(this, "JsonWriteNotecard"); 171 // m_comms.RegisterScriptInvocation(this, "JsonDestroyStore");
172 // m_comms.RegisterScriptInvocation(this, "JsonTestStore");
174 173
175 m_comms.RegisterScriptInvocation(this, "JsonTestPath"); 174 // m_comms.RegisterScriptInvocation(this, "JsonReadNotecard");
176 m_comms.RegisterScriptInvocation(this, "JsonTestPathJson"); 175 // m_comms.RegisterScriptInvocation(this, "JsonWriteNotecard");
177 176
178 m_comms.RegisterScriptInvocation(this, "JsonGetValue"); 177 // m_comms.RegisterScriptInvocation(this, "JsonTestPathList");
179 m_comms.RegisterScriptInvocation(this, "JsonGetValueJson"); 178 // m_comms.RegisterScriptInvocation(this, "JsonTestPath");
179 // m_comms.RegisterScriptInvocation(this, "JsonTestPathJson");
180 180
181 m_comms.RegisterScriptInvocation(this, "JsonTakeValue"); 181 // m_comms.RegisterScriptInvocation(this, "JsonGetValue");
182 m_comms.RegisterScriptInvocation(this, "JsonTakeValueJson"); 182 // m_comms.RegisterScriptInvocation(this, "JsonGetValueJson");
183 183
184 m_comms.RegisterScriptInvocation(this, "JsonReadValue"); 184 // m_comms.RegisterScriptInvocation(this, "JsonTakeValue");
185 m_comms.RegisterScriptInvocation(this, "JsonReadValueJson"); 185 // m_comms.RegisterScriptInvocation(this, "JsonTakeValueJson");
186 186
187 m_comms.RegisterScriptInvocation(this, "JsonSetValue"); 187 // m_comms.RegisterScriptInvocation(this, "JsonReadValue");
188 m_comms.RegisterScriptInvocation(this, "JsonSetValueJson"); 188 // m_comms.RegisterScriptInvocation(this, "JsonReadValueJson");
189 189
190 m_comms.RegisterScriptInvocation(this, "JsonRemoveValue"); 190 // m_comms.RegisterScriptInvocation(this, "JsonSetValue");
191 // m_comms.RegisterScriptInvocation(this, "JsonSetValueJson");
192
193 // m_comms.RegisterScriptInvocation(this, "JsonRemoveValue");
191 } 194 }
192 catch (Exception e) 195 catch (Exception e)
193 { 196 {
@@ -215,17 +218,8 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
215 /// 218 ///
216 /// </summary> 219 /// </summary>
217 // ----------------------------------------------------------------- 220 // -----------------------------------------------------------------
218 protected void GenerateRuntimeError(string msg) 221 [ScriptInvocation]
219 { 222 public UUID JsonCreateStore(UUID hostID, UUID scriptID, string value)
220 throw new Exception("JsonStore Runtime Error: " + msg);
221 }
222
223 // -----------------------------------------------------------------
224 /// <summary>
225 ///
226 /// </summary>
227 // -----------------------------------------------------------------
228 protected UUID JsonCreateStore(UUID hostID, UUID scriptID, string value)
229 { 223 {
230 UUID uuid = UUID.Zero; 224 UUID uuid = UUID.Zero;
231 if (! m_store.CreateStore(value, ref uuid)) 225 if (! m_store.CreateStore(value, ref uuid))
@@ -239,7 +233,8 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
239 /// 233 ///
240 /// </summary> 234 /// </summary>
241 // ----------------------------------------------------------------- 235 // -----------------------------------------------------------------
242 protected int JsonDestroyStore(UUID hostID, UUID scriptID, UUID storeID) 236 [ScriptInvocation]
237 public int JsonDestroyStore(UUID hostID, UUID scriptID, UUID storeID)
243 { 238 {
244 return m_store.DestroyStore(storeID) ? 1 : 0; 239 return m_store.DestroyStore(storeID) ? 1 : 0;
245 } 240 }
@@ -249,7 +244,8 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
249 /// 244 ///
250 /// </summary> 245 /// </summary>
251 // ----------------------------------------------------------------- 246 // -----------------------------------------------------------------
252 protected int JsonTestStore(UUID hostID, UUID scriptID, UUID storeID) 247 [ScriptInvocation]
248 public int JsonTestStore(UUID hostID, UUID scriptID, UUID storeID)
253 { 249 {
254 return m_store.TestStore(storeID) ? 1 : 0; 250 return m_store.TestStore(storeID) ? 1 : 0;
255 } 251 }
@@ -259,7 +255,8 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
259 /// 255 ///
260 /// </summary> 256 /// </summary>
261 // ----------------------------------------------------------------- 257 // -----------------------------------------------------------------
262 protected UUID JsonReadNotecard(UUID hostID, UUID scriptID, UUID storeID, string path, UUID assetID) 258 [ScriptInvocation]
259 public UUID JsonReadNotecard(UUID hostID, UUID scriptID, UUID storeID, string path, UUID assetID)
263 { 260 {
264 UUID reqID = UUID.Random(); 261 UUID reqID = UUID.Random();
265 Util.FireAndForget(delegate(object o) { DoJsonReadNotecard(reqID,hostID,scriptID,storeID,path,assetID); }); 262 Util.FireAndForget(delegate(object o) { DoJsonReadNotecard(reqID,hostID,scriptID,storeID,path,assetID); });
@@ -271,7 +268,8 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
271 /// 268 ///
272 /// </summary> 269 /// </summary>
273 // ----------------------------------------------------------------- 270 // -----------------------------------------------------------------
274 protected UUID JsonWriteNotecard(UUID hostID, UUID scriptID, UUID storeID, string path, string name) 271 [ScriptInvocation]
272 public UUID JsonWriteNotecard(UUID hostID, UUID scriptID, UUID storeID, string path, string name)
275 { 273 {
276 UUID reqID = UUID.Random(); 274 UUID reqID = UUID.Random();
277 Util.FireAndForget(delegate(object o) { DoJsonWriteNotecard(reqID,hostID,scriptID,storeID,path,name); }); 275 Util.FireAndForget(delegate(object o) { DoJsonWriteNotecard(reqID,hostID,scriptID,storeID,path,name); });
@@ -283,12 +281,25 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
283 /// 281 ///
284 /// </summary> 282 /// </summary>
285 // ----------------------------------------------------------------- 283 // -----------------------------------------------------------------
286 protected int JsonTestPath(UUID hostID, UUID scriptID, UUID storeID, string path) 284 [ScriptInvocation]
285 public string JsonList2Path(UUID hostID, UUID scriptID, object[] pathlist)
286 {
287 return JsonStore.CanonicalPathExpression(ConvertList2Path(pathlist));
288 }
289
290 // -----------------------------------------------------------------
291 /// <summary>
292 ///
293 /// </summary>
294 // -----------------------------------------------------------------
295 [ScriptInvocation]
296 public int JsonTestPath(UUID hostID, UUID scriptID, UUID storeID, string path)
287 { 297 {
288 return m_store.TestPath(storeID,path,false) ? 1 : 0; 298 return m_store.TestPath(storeID,path,false) ? 1 : 0;
289 } 299 }
290 300
291 protected int JsonTestPathJson(UUID hostID, UUID scriptID, UUID storeID, string path) 301 [ScriptInvocation]
302 public int JsonTestPathJson(UUID hostID, UUID scriptID, UUID storeID, string path)
292 { 303 {
293 return m_store.TestPath(storeID,path,true) ? 1 : 0; 304 return m_store.TestPath(storeID,path,true) ? 1 : 0;
294 } 305 }
@@ -298,12 +309,14 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
298 /// 309 ///
299 /// </summary> 310 /// </summary>
300 // ----------------------------------------------------------------- 311 // -----------------------------------------------------------------
301 protected int JsonSetValue(UUID hostID, UUID scriptID, UUID storeID, string path, string value) 312 [ScriptInvocation]
313 public int JsonSetValue(UUID hostID, UUID scriptID, UUID storeID, string path, string value)
302 { 314 {
303 return m_store.SetValue(storeID,path,value,false) ? 1 : 0; 315 return m_store.SetValue(storeID,path,value,false) ? 1 : 0;
304 } 316 }
305 317
306 protected int JsonSetValueJson(UUID hostID, UUID scriptID, UUID storeID, string path, string value) 318 [ScriptInvocation]
319 public int JsonSetValueJson(UUID hostID, UUID scriptID, UUID storeID, string path, string value)
307 { 320 {
308 return m_store.SetValue(storeID,path,value,true) ? 1 : 0; 321 return m_store.SetValue(storeID,path,value,true) ? 1 : 0;
309 } 322 }
@@ -313,7 +326,8 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
313 /// 326 ///
314 /// </summary> 327 /// </summary>
315 // ----------------------------------------------------------------- 328 // -----------------------------------------------------------------
316 protected int JsonRemoveValue(UUID hostID, UUID scriptID, UUID storeID, string path) 329 [ScriptInvocation]
330 public int JsonRemoveValue(UUID hostID, UUID scriptID, UUID storeID, string path)
317 { 331 {
318 return m_store.RemoveValue(storeID,path) ? 1 : 0; 332 return m_store.RemoveValue(storeID,path) ? 1 : 0;
319 } 333 }
@@ -323,14 +337,16 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
323 /// 337 ///
324 /// </summary> 338 /// </summary>
325 // ----------------------------------------------------------------- 339 // -----------------------------------------------------------------
326 protected string JsonGetValue(UUID hostID, UUID scriptID, UUID storeID, string path) 340 [ScriptInvocation]
341 public string JsonGetValue(UUID hostID, UUID scriptID, UUID storeID, string path)
327 { 342 {
328 string value = String.Empty; 343 string value = String.Empty;
329 m_store.GetValue(storeID,path,false,out value); 344 m_store.GetValue(storeID,path,false,out value);
330 return value; 345 return value;
331 } 346 }
332 347
333 protected string JsonGetValueJson(UUID hostID, UUID scriptID, UUID storeID, string path) 348 [ScriptInvocation]
349 public string JsonGetValueJson(UUID hostID, UUID scriptID, UUID storeID, string path)
334 { 350 {
335 string value = String.Empty; 351 string value = String.Empty;
336 m_store.GetValue(storeID,path,true, out value); 352 m_store.GetValue(storeID,path,true, out value);
@@ -342,60 +358,75 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
342 /// 358 ///
343 /// </summary> 359 /// </summary>
344 // ----------------------------------------------------------------- 360 // -----------------------------------------------------------------
345 protected UUID JsonTakeValue(UUID hostID, UUID scriptID, UUID storeID, string path) 361 [ScriptInvocation]
362 public UUID JsonTakeValue(UUID hostID, UUID scriptID, UUID storeID, string path)
346 { 363 {
347 UUID reqID = UUID.Random(); 364 UUID reqID = UUID.Random();
348 Util.FireAndForget(delegate(object o) { DoJsonTakeValue(scriptID,reqID,storeID,path,false); }); 365 Util.FireAndForget(delegate(object o) { DoJsonTakeValue(scriptID,reqID,storeID,path,false); });
349 return reqID; 366 return reqID;
350 } 367 }
351 368
352 protected UUID JsonTakeValueJson(UUID hostID, UUID scriptID, UUID storeID, string path) 369 [ScriptInvocation]
370 public UUID JsonTakeValueJson(UUID hostID, UUID scriptID, UUID storeID, string path)
353 { 371 {
354 UUID reqID = UUID.Random(); 372 UUID reqID = UUID.Random();
355 Util.FireAndForget(delegate(object o) { DoJsonTakeValue(scriptID,reqID,storeID,path,true); }); 373 Util.FireAndForget(delegate(object o) { DoJsonTakeValue(scriptID,reqID,storeID,path,true); });
356 return reqID; 374 return reqID;
357 } 375 }
358 376
359 private void DoJsonTakeValue(UUID scriptID, UUID reqID, UUID storeID, string path, bool useJson)
360 {
361 try
362 {
363 m_store.TakeValue(storeID,path,useJson,delegate(string value) { DispatchValue(scriptID,reqID,value); });
364 return;
365 }
366 catch (Exception e)
367 {
368 m_log.InfoFormat("[JsonStoreScripts]: unable to retrieve value; {0}",e.ToString());
369 }
370
371 DispatchValue(scriptID,reqID,String.Empty);
372 }
373
374
375 // ----------------------------------------------------------------- 377 // -----------------------------------------------------------------
376 /// <summary> 378 /// <summary>
377 /// 379 ///
378 /// </summary> 380 /// </summary>
379 // ----------------------------------------------------------------- 381 // -----------------------------------------------------------------
380 protected UUID JsonReadValue(UUID hostID, UUID scriptID, UUID storeID, string path) 382 [ScriptInvocation]
383 public UUID JsonReadValue(UUID hostID, UUID scriptID, UUID storeID, string path)
381 { 384 {
382 UUID reqID = UUID.Random(); 385 UUID reqID = UUID.Random();
383 Util.FireAndForget(delegate(object o) { DoJsonReadValue(scriptID,reqID,storeID,path,false); }); 386 Util.FireAndForget(delegate(object o) { DoJsonReadValue(scriptID,reqID,storeID,path,false); });
384 return reqID; 387 return reqID;
385 } 388 }
386 389
387 protected UUID JsonReadValueJson(UUID hostID, UUID scriptID, UUID storeID, string path) 390 [ScriptInvocation]
391 public UUID JsonReadValueJson(UUID hostID, UUID scriptID, UUID storeID, string path)
388 { 392 {
389 UUID reqID = UUID.Random(); 393 UUID reqID = UUID.Random();
390 Util.FireAndForget(delegate(object o) { DoJsonReadValue(scriptID,reqID,storeID,path,true); }); 394 Util.FireAndForget(delegate(object o) { DoJsonReadValue(scriptID,reqID,storeID,path,true); });
391 return reqID; 395 return reqID;
392 } 396 }
393 397
394 private void DoJsonReadValue(UUID scriptID, UUID reqID, UUID storeID, string path, bool useJson) 398#endregion
399
400 // -----------------------------------------------------------------
401 /// <summary>
402 ///
403 /// </summary>
404 // -----------------------------------------------------------------
405 protected void GenerateRuntimeError(string msg)
406 {
407 throw new Exception("JsonStore Runtime Error: " + msg);
408 }
409
410 // -----------------------------------------------------------------
411 /// <summary>
412 ///
413 /// </summary>
414 // -----------------------------------------------------------------
415 protected void DispatchValue(UUID scriptID, UUID reqID, string value)
416 {
417 m_comms.DispatchReply(scriptID,1,value,reqID.ToString());
418 }
419
420 // -----------------------------------------------------------------
421 /// <summary>
422 ///
423 /// </summary>
424 // -----------------------------------------------------------------
425 private void DoJsonTakeValue(UUID scriptID, UUID reqID, UUID storeID, string path, bool useJson)
395 { 426 {
396 try 427 try
397 { 428 {
398 m_store.ReadValue(storeID,path,useJson,delegate(string value) { DispatchValue(scriptID,reqID,value); }); 429 m_store.TakeValue(storeID,path,useJson,delegate(string value) { DispatchValue(scriptID,reqID,value); });
399 return; 430 return;
400 } 431 }
401 catch (Exception e) 432 catch (Exception e)
@@ -406,16 +437,25 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
406 DispatchValue(scriptID,reqID,String.Empty); 437 DispatchValue(scriptID,reqID,String.Empty);
407 } 438 }
408 439
409#endregion
410 440
411 // ----------------------------------------------------------------- 441 // -----------------------------------------------------------------
412 /// <summary> 442 /// <summary>
413 /// 443 ///
414 /// </summary> 444 /// </summary>
415 // ----------------------------------------------------------------- 445 // -----------------------------------------------------------------
416 protected void DispatchValue(UUID scriptID, UUID reqID, string value) 446 private void DoJsonReadValue(UUID scriptID, UUID reqID, UUID storeID, string path, bool useJson)
417 { 447 {
418 m_comms.DispatchReply(scriptID,1,value,reqID.ToString()); 448 try
449 {
450 m_store.ReadValue(storeID,path,useJson,delegate(string value) { DispatchValue(scriptID,reqID,value); });
451 return;
452 }
453 catch (Exception e)
454 {
455 m_log.InfoFormat("[JsonStoreScripts]: unable to retrieve value; {0}",e.ToString());
456 }
457
458 DispatchValue(scriptID,reqID,String.Empty);
419 } 459 }
420 460
421 // ----------------------------------------------------------------- 461 // -----------------------------------------------------------------
@@ -505,5 +545,43 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
505 545
506 m_comms.DispatchReply(scriptID,1,assetID.ToString(),reqID.ToString()); 546 m_comms.DispatchReply(scriptID,1,assetID.ToString(),reqID.ToString());
507 } 547 }
548
549 // -----------------------------------------------------------------
550 /// <summary>
551 /// Convert a list of values that are path components to a single string path
552 /// </summary>
553 // -----------------------------------------------------------------
554 protected static Regex m_ArrayPattern = new Regex("^([0-9]+|\\+)$");
555 private string ConvertList2Path(object[] pathlist)
556 {
557 string path = "";
558 for (int i = 0; i < pathlist.Length; i++)
559 {
560 string token = "";
561
562 if (pathlist[i] is string)
563 {
564 token = pathlist[i].ToString();
565
566 // Check to see if this is a bare number which would not be a valid
567 // identifier otherwise
568 if (m_ArrayPattern.IsMatch(token))
569 token = '[' + token + ']';
570 }
571 else if (pathlist[i] is int)
572 {
573 token = "[" + pathlist[i].ToString() + "]";
574 }
575 else
576 {
577 token = "." + pathlist[i].ToString() + ".";
578 }
579
580 path += token + ".";
581 }
582
583 return path;
584 }
585
508 } 586 }
509} \ No newline at end of file 587} \ No newline at end of file