TestXInventoryDataPlugin.cs 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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.Mock
  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. List<XInventoryItem> origItems = Get<XInventoryItem>(fields, vals, m_allItems.Values.ToList());
  46. return origItems.Select(i => i.Clone()).ToArray();
  47. }
  48. public XInventoryFolder[] GetFolders(string[] fields, string[] vals)
  49. {
  50. // Console.WriteLine(
  51. // "Requesting folders, fields {0}, vals {1}", string.Join(",", fields), string.Join(",", vals));
  52. List<XInventoryFolder> origFolders
  53. = Get<XInventoryFolder>(fields, vals, m_allFolders.Values.ToList());
  54. return origFolders.Select(f => f.Clone()).ToArray();
  55. }
  56. public bool StoreFolder(XInventoryFolder folder)
  57. {
  58. m_allFolders[folder.folderID] = folder.Clone();
  59. // Console.WriteLine("Added folder {0} {1}", folder.folderName, folder.folderID);
  60. return true;
  61. }
  62. public bool StoreItem(XInventoryItem item)
  63. {
  64. m_allItems[item.inventoryID] = item.Clone();
  65. // Console.WriteLine("Added item {0} {1}, creator {2}, owner {3}", item.inventoryName, item.inventoryID, item.creatorID, item.avatarID);
  66. return true;
  67. }
  68. public bool DeleteFolders(string field, string val)
  69. {
  70. return DeleteFolders(new string[] { field }, new string[] { val });
  71. }
  72. public bool DeleteFolders(string[] fields, string[] vals)
  73. {
  74. XInventoryFolder[] foldersToDelete = GetFolders(fields, vals);
  75. Array.ForEach(foldersToDelete, f => m_allFolders.Remove(f.folderID));
  76. return true;
  77. }
  78. public bool DeleteItems(string field, string val)
  79. {
  80. return DeleteItems(new string[] { field }, new string[] { val });
  81. }
  82. public bool DeleteItems(string[] fields, string[] vals)
  83. {
  84. XInventoryItem[] itemsToDelete = GetItems(fields, vals);
  85. Array.ForEach(itemsToDelete, i => m_allItems.Remove(i.inventoryID));
  86. return true;
  87. }
  88. public bool MoveItem(string id, string newParent) { throw new NotImplementedException(); }
  89. public bool MoveFolder(string id, string newParent)
  90. {
  91. // Don't use GetFolders() here - it takes a clone!
  92. XInventoryFolder folder = m_allFolders[new UUID(id)];
  93. if (folder == null)
  94. return false;
  95. folder.parentFolderID = new UUID(newParent);
  96. // XInventoryFolder[] newParentFolders
  97. // = GetFolders(new string[] { "folderID" }, new string[] { folder.parentFolderID.ToString() });
  98. // Console.WriteLine(
  99. // "Moved folder {0} {1}, to {2} {3}",
  100. // folder.folderName, folder.folderID, newParentFolders[0].folderName, folder.parentFolderID);
  101. // TODO: Really need to implement folder version incrementing, though this should be common code anyway,
  102. // not reimplemented in each db plugin.
  103. return true;
  104. }
  105. public XInventoryItem[] GetActiveGestures(UUID principalID) { throw new NotImplementedException(); }
  106. public int GetAssetPermissions(UUID principalID, UUID assetID) { throw new NotImplementedException(); }
  107. }
  108. }