TestXInventoryDataPlugin.cs 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /*
  2. * Copyright (c) Contributors, http://opensimulator.org/
  3. * See CONTRIBUTORS.TXT for a full list of copyright holders.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of the OpenSimulator Project nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
  20. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. using System;
  28. using System.Collections.Generic;
  29. using System.Linq;
  30. using System.Reflection;
  31. using log4net;
  32. using OpenMetaverse;
  33. using OpenSim.Framework;
  34. using OpenSim.Data;
  35. using OpenSim.Data.Null;
  36. namespace OpenSim.Tests.Common
  37. {
  38. public class TestXInventoryDataPlugin : NullGenericDataHandler, IXInventoryData
  39. {
  40. private Dictionary<UUID, XInventoryFolder> m_allFolders = new Dictionary<UUID, XInventoryFolder>();
  41. private Dictionary<UUID, XInventoryItem> m_allItems = new Dictionary<UUID, XInventoryItem>();
  42. public TestXInventoryDataPlugin(string conn, string realm) {}
  43. public XInventoryItem[] GetItems(string[] fields, string[] vals)
  44. {
  45. // Console.WriteLine(
  46. // "Requesting items, fields {0}, vals {1}", string.Join(", ", fields), string.Join(", ", vals));
  47. List<XInventoryItem> origItems = Get<XInventoryItem>(fields, vals, m_allItems.Values.ToList());
  48. XInventoryItem[] items = origItems.Select(i => i.Clone()).ToArray();
  49. // Console.WriteLine("Found {0} items", items.Length);
  50. // Array.ForEach(items, i => Console.WriteLine("Found item {0} {1}", i.inventoryName, i.inventoryID));
  51. return items;
  52. }
  53. public XInventoryFolder[] GetFolders(string[] fields, string[] vals)
  54. {
  55. // Console.WriteLine(
  56. // "Requesting folders, fields {0}, vals {1}", string.Join(", ", fields), string.Join(", ", vals));
  57. List<XInventoryFolder> origFolders
  58. = Get<XInventoryFolder>(fields, vals, m_allFolders.Values.ToList());
  59. XInventoryFolder[] folders = origFolders.Select(f => f.Clone()).ToArray();
  60. // Console.WriteLine("Found {0} folders", folders.Length);
  61. // Array.ForEach(folders, f => Console.WriteLine("Found folder {0} {1}", f.folderName, f.folderID));
  62. return folders;
  63. }
  64. public bool StoreFolder(XInventoryFolder folder)
  65. {
  66. m_allFolders[folder.folderID] = folder.Clone();
  67. // Console.WriteLine("Added folder {0} {1}", folder.folderName, folder.folderID);
  68. return true;
  69. }
  70. public bool StoreItem(XInventoryItem item)
  71. {
  72. m_allItems[item.inventoryID] = item.Clone();
  73. // Console.WriteLine(
  74. // "Added item {0} {1}, folder {2}, creator {3}, owner {4}",
  75. // item.inventoryName, item.inventoryID, item.parentFolderID, item.creatorID, item.avatarID);
  76. return true;
  77. }
  78. public bool DeleteFolders(string field, string val)
  79. {
  80. return DeleteFolders(new string[] { field }, new string[] { val });
  81. }
  82. public bool DeleteFolders(string[] fields, string[] vals)
  83. {
  84. XInventoryFolder[] foldersToDelete = GetFolders(fields, vals);
  85. Array.ForEach(foldersToDelete, f => m_allFolders.Remove(f.folderID));
  86. return true;
  87. }
  88. public bool DeleteItems(string field, string val)
  89. {
  90. return DeleteItems(new string[] { field }, new string[] { val });
  91. }
  92. public bool DeleteItems(string[] fields, string[] vals)
  93. {
  94. XInventoryItem[] itemsToDelete = GetItems(fields, vals);
  95. Array.ForEach(itemsToDelete, i => m_allItems.Remove(i.inventoryID));
  96. return true;
  97. }
  98. public bool MoveItem(string id, string newParent)
  99. {
  100. UUID uid = new UUID(id);
  101. UUID upid = new UUID(newParent);
  102. m_allItems[uid].parentFolderID = upid;
  103. return true;
  104. }
  105. public bool MoveItems(string[] ids, string[] newParents)
  106. {
  107. if(ids.Length != newParents.Length)
  108. return false;
  109. for(int i =0; i< ids.Length;++i)
  110. MoveItem(ids[i], newParents[i]);
  111. return true;
  112. }
  113. public bool MoveFolder(string id, string newParent)
  114. {
  115. // Don't use GetFolders() here - it takes a clone!
  116. XInventoryFolder folder = m_allFolders[new UUID(id)];
  117. if (folder == null)
  118. return false;
  119. folder.parentFolderID = new UUID(newParent);
  120. // XInventoryFolder[] newParentFolders
  121. // = GetFolders(new string[] { "folderID" }, new string[] { folder.parentFolderID.ToString() });
  122. // Console.WriteLine(
  123. // "Moved folder {0} {1}, to {2} {3}",
  124. // folder.folderName, folder.folderID, newParentFolders[0].folderName, folder.parentFolderID);
  125. // TODO: Really need to implement folder version incrementing, though this should be common code anyway,
  126. // not reimplemented in each db plugin.
  127. return true;
  128. }
  129. public XInventoryItem[] GetActiveGestures(UUID principalID) { throw new NotImplementedException(); }
  130. public int GetAssetPermissions(UUID principalID, UUID assetID) { throw new NotImplementedException(); }
  131. }
  132. }