* Refactor: Move bulk of CreateFolder from UserProfileCacheService into CachedUserInfo

* Remove unused/superseded methods from GridInventoryService
0.6.0-stable
Justin Clarke Casey 2008-05-03 18:57:02 +00:00
parent a5dfca8958
commit 1087542705
5 changed files with 124 additions and 131 deletions

View File

@ -28,11 +28,16 @@
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Threading;
using libsecondlife;
using log4net;
namespace OpenSim.Framework.Communications.Cache
{
internal delegate void CreateInventoryFolderDelegate(
string folderName, LLUUID folderID, ushort folderType, LLUUID parentID);
/// <summary>
/// Stores user profile and inventory data received from backend services for a particular user.
/// </summary>
@ -297,6 +302,99 @@ namespace OpenSim.Framework.Communications.Cache
}
}
}
/// <summary>
/// Create a folder in this agent's inventory
/// </summary>
/// <param name="parentID"></param>
/// <returns></returns>
public bool CreateFolder(string folderName, LLUUID folderID, ushort folderType, LLUUID parentID)
{
// m_log.DebugFormat(
// "[AGENT INVENTORY]: Creating inventory folder {0} {1} for {2} {3}", folderID, folderName, remoteClient.Name, remoteClient.AgentId);
if (HasInventory)
{
if (RootFolder.ID == parentID)
{
InventoryFolderImpl createdFolder = RootFolder.CreateNewSubFolder(folderID, folderName, folderType);
if (createdFolder != null)
{
InventoryFolderBase createdBaseFolder = new InventoryFolderBase();
createdBaseFolder.Owner = createdFolder.Owner;
createdBaseFolder.ID = createdFolder.ID;
createdBaseFolder.Name = createdFolder.Name;
createdBaseFolder.ParentID = createdFolder.ParentID;
createdBaseFolder.Type = createdFolder.Type;
createdBaseFolder.Version = createdFolder.Version;
m_commsManager.InventoryService.AddFolder(createdBaseFolder);
return true;
}
else
{
m_log.WarnFormat(
"[INVENTORY CACHE]: Tried to create folder {0} {1} but the folder already exists",
folderName, folderID);
return false;
}
}
else
{
InventoryFolderImpl folder = RootFolder.GetDescendentFolder(parentID);
if (folder != null)
{
InventoryFolderImpl createdFolder = folder.CreateNewSubFolder(folderID, folderName, folderType);
if (createdFolder != null)
{
InventoryFolderBase createdBaseFolder = new InventoryFolderBase();
createdBaseFolder.Owner = createdFolder.Owner;
createdBaseFolder.ID = createdFolder.ID;
createdBaseFolder.Name = createdFolder.Name;
createdBaseFolder.ParentID = createdFolder.ParentID;
createdBaseFolder.Type = createdFolder.Type;
createdBaseFolder.Version = createdFolder.Version;
m_commsManager.InventoryService.AddFolder(createdBaseFolder);
return true;
}
else
{
m_log.WarnFormat(
"[INVENTORY CACHE]: Tried to create folder {0} {1} but the folder already exists",
folderName, folderID);
return false;
}
}
else
{
m_log.WarnFormat(
"[INVENTORY CACHE]: Could not find parent folder with id {0} in order to create folder {1} {2}",
parentID, folderName, folderID);
return false;
}
}
}
else
{
AddRequest(
new InventoryRequest(
Delegate.CreateDelegate(typeof(CreateInventoryFolderDelegate), this, "CreateFolder"),
new object[] { folderName, folderID, folderType, parentID }));
return true;
}
return false;
}
/// <summary>
/// Add an item to the user's inventory
@ -360,7 +458,7 @@ namespace OpenSim.Framework.Communications.Cache
/// <summary>
/// Generic inventory request
/// </summary>
public class InventoryRequest : IInventoryRequest
class InventoryRequest : IInventoryRequest
{
private Delegate m_delegat;
private Object[] m_args;

View File

@ -34,8 +34,6 @@ using log4net;
namespace OpenSim.Framework.Communications.Cache
{
internal delegate void CreateInventoryFolderDelegate(
IClientAPI remoteClient, LLUUID folderID, ushort folderType, string folderName, LLUUID parentID);
internal delegate void MoveInventoryFolderDelegate(IClientAPI remoteClient, LLUUID folderID, LLUUID parentID);
internal delegate void PurgeInventoryDescendentsDelegate(IClientAPI remoteClient, LLUUID folderID);
internal delegate void UpdateInventoryFolderDelegate(
@ -157,80 +155,16 @@ namespace OpenSim.Framework.Communications.Cache
/// <param name="parentID"></param>
public void HandleCreateInventoryFolder(IClientAPI remoteClient, LLUUID folderID, ushort folderType,
string folderName, LLUUID parentID)
{
// m_log.DebugFormat(
// "[AGENT INVENTORY]: Creating inventory folder {0} {1} for {2} {3}", folderID, folderName, remoteClient.Name, remoteClient.AgentId);
{
CachedUserInfo userProfile;
if (m_userProfiles.TryGetValue(remoteClient.AgentId, out userProfile))
{
if (userProfile.HasInventory)
if (!userProfile.CreateFolder(folderName, folderID, folderType, parentID))
{
if (userProfile.RootFolder.ID == parentID)
{
InventoryFolderImpl createdFolder =
userProfile.RootFolder.CreateNewSubFolder(folderID, folderName, folderType);
if (createdFolder != null)
{
InventoryFolderBase createdBaseFolder = new InventoryFolderBase();
createdBaseFolder.Owner = createdFolder.Owner;
createdBaseFolder.ID = createdFolder.ID;
createdBaseFolder.Name = createdFolder.Name;
createdBaseFolder.ParentID = createdFolder.ParentID;
createdBaseFolder.Type = createdFolder.Type;
createdBaseFolder.Version = createdFolder.Version;
m_commsManager.InventoryService.AddFolder(createdBaseFolder);
}
else
{
m_log.WarnFormat(
"[INVENTORY CACHE]: Tried to create folder {0} {1} for user {2} {3} but the folder already exists",
folderName, folderID, remoteClient.Name, remoteClient.AgentId);
}
}
else
{
InventoryFolderImpl folder = userProfile.RootFolder.GetDescendentFolder(parentID);
if (folder != null)
{
InventoryFolderImpl createdFolder = folder.CreateNewSubFolder(folderID, folderName, folderType);
if (createdFolder != null)
{
InventoryFolderBase createdBaseFolder = new InventoryFolderBase();
createdBaseFolder.Owner = createdFolder.Owner;
createdBaseFolder.ID = createdFolder.ID;
createdBaseFolder.Name = createdFolder.Name;
createdBaseFolder.ParentID = createdFolder.ParentID;
createdBaseFolder.Type = createdFolder.Type;
createdBaseFolder.Version = createdFolder.Version;
m_commsManager.InventoryService.AddFolder(createdBaseFolder);
}
else
{
m_log.WarnFormat(
"[INVENTORY CACHE]: Tried to create folder {0} {1} for user {2} {3} but the folder already exists",
folderName, folderID, remoteClient.Name, remoteClient.AgentId);
}
}
else
{
m_log.WarnFormat(
"[INVENTORY CACHE]: Could not find parent folder with id {0} in order to create folder {1} {2} for user {3} {4}",
parentID, folderName, folderID, remoteClient.Name, remoteClient.AgentId);
}
}
}
else
{
userProfile.AddRequest(
new InventoryRequest(
Delegate.CreateDelegate(typeof(CreateInventoryFolderDelegate), this, "HandleCreateInventoryFolder"),
new object[] { remoteClient, folderID, folderType, folderName, parentID }));
m_log.WarnFormat(
"[AGENT INVENTORY]: Failed to create folder for user {0} {1}",
remoteClient.Name, remoteClient.AgentId);
}
}
}

View File

@ -28,11 +28,16 @@
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Threading;
using libsecondlife;
using log4net;
namespace OpenSim.Framework.Communications
{
/// <summary>
/// Abstract base class used by local and grid implementations of an inventory service.
/// </summary>
public abstract class InventoryServiceBase : IInventoryServices
{
private static readonly ILog m_log
@ -178,10 +183,11 @@ namespace OpenSim.Framework.Communications
#endregion
// See IInventoryServices
public bool AddFolder(InventoryFolderBase folder)
{
m_log.DebugFormat(
"[AGENT INVENTORY]: Adding folder {0} {1} to folder {2}", folder.Name, folder.ID, folder.ParentID);
"[AGENT INVENTORY]: Adding folder {0} {1} to folder {2}", folder.Name, folder.ID, folder.ParentID);
foreach (KeyValuePair<string, IInventoryData> plugin in m_plugins)
{
@ -192,6 +198,7 @@ namespace OpenSim.Framework.Communications
return true;
}
// See IInventoryServices
public bool MoveFolder(InventoryFolderBase folder)
{
m_log.DebugFormat(
@ -206,6 +213,7 @@ namespace OpenSim.Framework.Communications
return true;
}
// See IInventoryServices
public bool AddItem(InventoryItemBase item)
{
m_log.DebugFormat(
@ -220,6 +228,7 @@ namespace OpenSim.Framework.Communications
return true;
}
// See IInventoryServices
public bool UpdateItem(InventoryItemBase item)
{
m_log.InfoFormat(
@ -234,6 +243,7 @@ namespace OpenSim.Framework.Communications
return true;
}
// See IInventoryServices
public bool DeleteItem(InventoryItemBase item)
{
m_log.InfoFormat(

View File

@ -28,8 +28,11 @@
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Threading;
using libsecondlife;
using log4net;
using OpenSim.Framework;
using OpenSim.Framework.Communications;
@ -47,72 +50,19 @@ namespace OpenSim.Grid.InventoryServer
{
}
/// <summary>
/// Get a user's inventory.
/// </summary>
/// <param name="userID"></param>
/// <param name="folderList"></param>
/// <param name="itemsList"></param>
/// <returns>true if the inventory was retrieved, false otherwise</returns>
private bool GetUsersInventory(LLUUID userID, out List<InventoryFolderBase> folderList,
out List<InventoryItemBase> itemsList)
{
List<InventoryFolderBase> allFolders = GetInventorySkeleton(userID);
List<InventoryItemBase> allItems = new List<InventoryItemBase>();
foreach (InventoryFolderBase folder in allFolders)
{
List<InventoryItemBase> items = RequestFolderItems(folder.ID);
if (items != null)
{
allItems.InsertRange(0, items);
}
}
folderList = allFolders;
itemsList = allItems;
if (folderList != null)
{
return true;
}
else
{
return false;
}
}
private List<InventoryFolderBase> GetAllFolders(LLUUID folder)
{
List<InventoryFolderBase> allFolders = new List<InventoryFolderBase>();
List<InventoryFolderBase> folders = RequestSubFolders(folder);
if (folders != null)
{
allFolders.InsertRange(0, folders);
foreach (InventoryFolderBase subfolder in folders)
{
List<InventoryFolderBase> subFolders = GetAllFolders(subfolder.ID);
if (subFolders != null)
{
allFolders.InsertRange(0, subFolders);
}
}
}
return allFolders;
}
/// <summary>
/// Return a user's entire inventory
/// </summary>
/// <param name="rawUserID"></param>
/// <returns>The user's inventory. If an inventory cannot be found then an empty collection is returned.</returns>
public InventoryCollection GetUserInventory(Guid rawUserID)
{
// uncomment me to simulate an overloaded inventory server
//Thread.Sleep(20000);
{
LLUUID userID = new LLUUID(rawUserID);
m_log.InfoFormat("[GRID AGENT INVENTORY]: Processing request for inventory of {0}", userID);
m_log.InfoFormat("[GRID AGENT INVENTORY]: Processing request for inventory of {0}", userID);
// uncomment me to simulate an overloaded inventory server
//Thread.Sleep(20000);
InventoryCollection invCollection = new InventoryCollection();

View File

@ -645,6 +645,7 @@ namespace OpenSim.Region.Environment.Scenes
{
CachedUserInfo userInfo
= CommsManager.UserProfileCacheService.GetUserDetails(remoteClient.AgentId);
if (userInfo == null)
{
m_log.Error("[AGENT INVENTORY]: Failed to find user " + remoteClient.AgentId.ToString());