using System; using System.Collections.Generic; using System.Reflection; using libsecondlife; using OpenSim.Framework.Communications; using OpenSim.Framework.Console; using OpenSim.Framework.Types; using InventoryFolder=OpenSim.Framework.Communications.Caches.InventoryFolder; namespace OpenSim.Framework.Communications { public abstract class InventoryServiceBase : IInventoryServices { protected Dictionary m_plugins = new Dictionary(); //protected IAssetServer m_assetServer; public InventoryServiceBase() { //m_assetServer = assetServer; } /// /// Adds a new user server plugin - plugins will be requested in the order they were loaded. /// /// The filename to the user server plugin DLL public void AddPlugin(string FileName) { if (!String.IsNullOrEmpty(FileName)) { MainLog.Instance.Verbose("Inventory", "Inventorystorage: Attempting to load " + FileName); Assembly pluginAssembly = Assembly.LoadFrom(FileName); foreach (Type pluginType in pluginAssembly.GetTypes()) { if (!pluginType.IsAbstract) { Type typeInterface = pluginType.GetInterface("IInventoryData", true); if (typeInterface != null) { IInventoryData plug = (IInventoryData)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString())); plug.Initialise(); this.m_plugins.Add(plug.getName(), plug); MainLog.Instance.Verbose("Inventorystorage: Added IInventoryData Interface"); } } } } } /// /// Returns the root folder plus any folders in root (so down one level in the Inventory folders tree) /// /// /// public List RequestFirstLevelFolders(LLUUID userID) { List inventoryList = new List(); foreach (KeyValuePair plugin in m_plugins) { InventoryFolderBase rootFolder = plugin.Value.getUserRootFolder(userID); if (rootFolder != null) { inventoryList = plugin.Value.getInventoryFolders(rootFolder.folderID); inventoryList.Insert(0, rootFolder); return inventoryList; } } return inventoryList; } /// /// /// public InventoryFolderBase RequestUsersRoot(LLUUID userID) { foreach (KeyValuePair plugin in m_plugins) { return plugin.Value.getUserRootFolder(userID); } return null; } /// /// /// /// /// public List RequestSubFolders(LLUUID parentFolderID) { List inventoryList = new List(); foreach (KeyValuePair plugin in m_plugins) { return plugin.Value.getInventoryFolders(parentFolderID); } return inventoryList; } public List RequestFolderItems(LLUUID folderID) { List itemsList = new List(); foreach (KeyValuePair plugin in m_plugins) { itemsList = plugin.Value.getInventoryInFolder(folderID); return itemsList; } return itemsList; } public void AddFolder(InventoryFolderBase folder) { foreach (KeyValuePair plugin in m_plugins) { plugin.Value.addInventoryFolder(folder); } } public void AddItem(InventoryItemBase item) { foreach (KeyValuePair plugin in m_plugins) { plugin.Value.addInventoryItem(item); } } public void deleteItem(InventoryItemBase item) { foreach (KeyValuePair plugin in m_plugins) { plugin.Value.deleteInventoryItem(item); } } /// /// /// /// public void AddNewInventorySet(UsersInventory inventory) { foreach (InventoryFolderBase folder in inventory.Folders.Values) { this.AddFolder(folder); } } public void CreateNewUserInventory(LLUUID user) { UsersInventory inven = new UsersInventory(); inven.CreateNewInventorySet(user); this.AddNewInventorySet(inven); } public class UsersInventory { public Dictionary Folders = new Dictionary(); public Dictionary Items = new Dictionary(); public UsersInventory() { } public virtual void CreateNewInventorySet(LLUUID user) { InventoryFolderBase folder = new InventoryFolderBase(); folder.parentID = LLUUID.Zero; folder.agentID = user; folder.folderID = LLUUID.Random(); folder.name = "My Inventory"; folder.type = 8; folder.version = 1; Folders.Add(folder.folderID, folder); LLUUID rootFolder = folder.folderID; folder = new InventoryFolderBase(); folder.parentID = rootFolder; folder.agentID = user; folder.folderID = LLUUID.Random(); folder.name = "Textures"; folder.type = 0; folder.version = 1; Folders.Add(folder.folderID, folder); folder = new InventoryFolderBase(); folder.parentID = rootFolder; folder.agentID = user; folder.folderID = LLUUID.Random(); folder.name = "Objects"; folder.type = 6; folder.version = 1; Folders.Add(folder.folderID, folder); folder = new InventoryFolderBase(); folder.parentID = rootFolder; folder.agentID = user; folder.folderID = LLUUID.Random(); folder.name = "Clothes"; folder.type = 5; folder.version = 1; Folders.Add(folder.folderID, folder); } } public abstract void RequestInventoryForUser(LLUUID userID, InventoryFolderInfo folderCallBack, InventoryItemInfo itemCallBack); public abstract void AddNewInventoryFolder(LLUUID userID, InventoryFolder folder); public abstract void AddNewInventoryItem(LLUUID userID, InventoryItemBase item); public abstract void DeleteInventoryItem(LLUUID userID, InventoryItemBase item); } }