OpenSim
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
TestInventoryDataPlugin.cs
Go to the documentation of this file.
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 
28 using System;
29 using System.Collections.Generic;
30 using System.Reflection;
31 using log4net;
32 using OpenMetaverse;
33 using OpenSim.Framework;
34 using OpenSim.Data;
35 
36 namespace OpenSim.Tests.Common
37 {
44  {
45 // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
46 
50  private Dictionary<UUID, InventoryFolderBase> m_folders = new Dictionary<UUID, InventoryFolderBase>();
51 
55  private Dictionary<UUID, InventoryItemBase> m_items = new Dictionary<UUID, InventoryItemBase>();
56 
60  private Dictionary<UUID, InventoryFolderBase> m_rootFolders = new Dictionary<UUID, InventoryFolderBase>();
61 
62  public string Version { get { return "0"; } }
63  public string Name { get { return "TestInventoryDataPlugin"; } }
64 
65  public void Initialise() {}
66  public void Initialise(string connect) {}
67  public void Dispose() {}
68 
69  public List<InventoryFolderBase> getFolderHierarchy(UUID parentID)
70  {
71  List<InventoryFolderBase> folders = new List<InventoryFolderBase>();
72 
73  foreach (InventoryFolderBase folder in m_folders.Values)
74  {
75  if (folder.ParentID == parentID)
76  {
77  folders.AddRange(getFolderHierarchy(folder.ID));
78  folders.Add(folder);
79  }
80  }
81 
82  return folders;
83  }
84 
85  public List<InventoryItemBase> getInventoryInFolder(UUID folderID)
86  {
87 // InventoryFolderBase folder = m_folders[folderID];
88 
89 // m_log.DebugFormat("[MOCK INV DB]: Getting items in folder {0} {1}", folder.Name, folder.ID);
90 
91  List<InventoryItemBase> items = new List<InventoryItemBase>();
92 
93  foreach (InventoryItemBase item in m_items.Values)
94  {
95  if (item.Folder == folderID)
96  {
97 // m_log.DebugFormat("[MOCK INV DB]: getInventoryInFolder() adding item {0}", item.Name);
98  items.Add(item);
99  }
100  }
101 
102  return items;
103  }
104 
105  public List<InventoryFolderBase> getUserRootFolders(UUID user) { return null; }
106 
108  {
109 // m_log.DebugFormat("[MOCK INV DB]: Looking for root folder for {0}", user);
110 
111  InventoryFolderBase folder = null;
112  m_rootFolders.TryGetValue(user, out folder);
113 
114  return folder;
115  }
116 
117  public List<InventoryFolderBase> getInventoryFolders(UUID parentID)
118  {
119 // InventoryFolderBase parentFolder = m_folders[parentID];
120 
121 // m_log.DebugFormat("[MOCK INV DB]: Getting folders in folder {0} {1}", parentFolder.Name, parentFolder.ID);
122 
123  List<InventoryFolderBase> folders = new List<InventoryFolderBase>();
124 
125  foreach (InventoryFolderBase folder in m_folders.Values)
126  {
127  if (folder.ParentID == parentID)
128  {
129 // m_log.DebugFormat(
130 // "[MOCK INV DB]: Found folder {0} {1} in {2} {3}",
131 // folder.Name, folder.ID, parentFolder.Name, parentFolder.ID);
132 
133  folders.Add(folder);
134  }
135  }
136 
137  return folders;
138  }
139 
141  {
142  InventoryFolderBase folder = null;
143  m_folders.TryGetValue(folderId, out folder);
144 
145  return folder;
146  }
147 
149  {
150  return getInventoryFolder(folderID);
151  }
152 
154  {
155 // m_log.DebugFormat(
156 // "[MOCK INV DB]: Adding inventory folder {0} {1} type {2}",
157 // folder.Name, folder.ID, (AssetType)folder.Type);
158 
159  m_folders[folder.ID] = folder;
160 
161  if (folder.ParentID == UUID.Zero)
162  {
163 // m_log.DebugFormat(
164 // "[MOCK INV DB]: Adding root folder {0} {1} for {2}", folder.Name, folder.ID, folder.Owner);
165  m_rootFolders[folder.Owner] = folder;
166  }
167  }
168 
170  {
171  m_folders[folder.ID] = folder;
172  }
173 
175  {
176  // Simple replace
177  updateInventoryFolder(folder);
178  }
179 
180  public void deleteInventoryFolder(UUID folderId)
181  {
182  if (m_folders.ContainsKey(folderId))
183  m_folders.Remove(folderId);
184  }
185 
187  {
188  InventoryFolderBase folder = m_folders[item.Folder];
189 
190 // m_log.DebugFormat(
191 // "[MOCK INV DB]: Adding inventory item {0} {1} in {2} {3}", item.Name, item.ID, folder.Name, folder.ID);
192 
193  m_items[item.ID] = item;
194  }
195 
196  public void updateInventoryItem(InventoryItemBase item) { addInventoryItem(item); }
197 
198  public void deleteInventoryItem(UUID itemId)
199  {
200  if (m_items.ContainsKey(itemId))
201  m_items.Remove(itemId);
202  }
203 
204  public InventoryItemBase getInventoryItem(UUID itemId)
205  {
206  if (m_items.ContainsKey(itemId))
207  return m_items[itemId];
208  else
209  return null;
210  }
211 
213  {
214  return null;
215  }
216 
217  public List<InventoryItemBase> fetchActiveGestures(UUID avatarID) { return null; }
218  }
219 }
List< InventoryFolderBase > getInventoryFolders(UUID parentID)
Returns a list of inventory folders contained in the folder 'parentID'
List< InventoryItemBase > fetchActiveGestures(UUID avatarID)
Returns all activated gesture-items in the inventory of the specified avatar.
void deleteInventoryFolder(UUID folderId)
Deletes a folder. Thie will delete both the folder itself and its contents (items and descendent fold...
List< InventoryFolderBase > getUserRootFolders(UUID user)
Returns a list of the root folders within a users inventory
void updateInventoryFolder(InventoryFolderBase folder)
Updates a folder based on its ID with folder
void moveInventoryFolder(InventoryFolderBase folder)
Updates a folder based on its ID with folder
void addInventoryItem(InventoryItemBase item)
Creates a new inventory item based on item
InventoryFolderBase queryInventoryFolder(UUID folderID)
InventoryFolderBase getUserRootFolder(UUID user)
Returns the users inventory root folder.
void Initialise(string connect)
Initialises the interface
In memory inventory data plugin for test purposes. Could be another dll when properly filled out and ...
List< InventoryFolderBase > getFolderHierarchy(UUID parentID)
Returns all descendent folders of this folder. Does not return the parent folder itself.
Inventory Item - contains all the properties associated with an individual inventory piece...
UUID ID
A UUID containing the ID for the inventory node itself
InventoryFolderBase getInventoryFolder(UUID folderId)
Returns a specified inventory folder by its UUID
void addInventoryFolder(InventoryFolderBase folder)
Adds a new folder specified by folder
void Initialise()
Default-initialises the plugin
void updateInventoryItem(InventoryItemBase item)
Updates an inventory item with item (updates based on ID)
List< InventoryItemBase > getInventoryInFolder(UUID folderID)
Returns a list of inventory items contained within the specified folder
InventoryItemBase getInventoryItem(UUID itemId)
Returns an inventory item by its UUID
An interface for accessing inventory data from a storage server