* Refactor: Move MoveFolder() and PurgeFolder() into CachedUserInfo (which arguably should be split)
parent
9485b52f97
commit
068163b14b
|
@ -35,10 +35,10 @@ using log4net;
|
|||
|
||||
namespace OpenSim.Framework.Communications.Cache
|
||||
{
|
||||
internal delegate void CreateInventoryFolderDelegate(
|
||||
string folderName, LLUUID folderID, ushort folderType, LLUUID parentID);
|
||||
internal delegate void UpdateInventoryFolderDelegate(
|
||||
string name, LLUUID folderID, ushort type, LLUUID parentID);
|
||||
internal delegate void CreateFolderDelegate(string folderName, LLUUID folderID, ushort folderType, LLUUID parentID);
|
||||
internal delegate void MoveFolderDelegate(LLUUID folderID, LLUUID parentID);
|
||||
internal delegate void PurgeFolderDelegate(LLUUID folderID);
|
||||
internal delegate void UpdateFolderDelegate(string name, LLUUID folderID, ushort type, LLUUID parentID);
|
||||
|
||||
/// <summary>
|
||||
/// Stores user profile and inventory data received from backend services for a particular user.
|
||||
|
@ -54,7 +54,7 @@ namespace OpenSim.Framework.Communications.Cache
|
|||
private readonly CommunicationsManager m_commsManager;
|
||||
|
||||
public UserProfileData UserProfile { get { return m_userProfile; } }
|
||||
private UserProfileData m_userProfile;
|
||||
private readonly UserProfileData m_userProfile;
|
||||
|
||||
/// <summary>
|
||||
/// Has we received the user's inventory from the inventory service?
|
||||
|
@ -389,7 +389,7 @@ namespace OpenSim.Framework.Communications.Cache
|
|||
{
|
||||
AddRequest(
|
||||
new InventoryRequest(
|
||||
Delegate.CreateDelegate(typeof(CreateInventoryFolderDelegate), this, "CreateFolder"),
|
||||
Delegate.CreateDelegate(typeof(CreateFolderDelegate), this, "CreateFolder"),
|
||||
new object[] { folderName, folderID, folderType, parentID }));
|
||||
|
||||
return true;
|
||||
|
@ -428,13 +428,90 @@ namespace OpenSim.Framework.Communications.Cache
|
|||
{
|
||||
AddRequest(
|
||||
new InventoryRequest(
|
||||
Delegate.CreateDelegate(typeof(UpdateInventoryFolderDelegate), this, "UpdateFolder"),
|
||||
Delegate.CreateDelegate(typeof(UpdateFolderDelegate), this, "UpdateFolder"),
|
||||
new object[] { name, folderID, type, parentID }));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handle an inventory folder move request from the client.
|
||||
/// </summary>
|
||||
/// <param name="folderID"></param>
|
||||
/// <param name="parentID"></param>
|
||||
public bool MoveFolder(LLUUID folderID, LLUUID parentID)
|
||||
{
|
||||
// m_log.DebugFormat(
|
||||
// "[AGENT INVENTORY]: Moving inventory folder {0} into folder {1} for {2} {3}",
|
||||
// parentID, remoteClient.Name, remoteClient.Name, remoteClient.AgentId);
|
||||
|
||||
if (HasInventory)
|
||||
{
|
||||
InventoryFolderBase baseFolder = new InventoryFolderBase();
|
||||
baseFolder.Owner = m_userProfile.ID;
|
||||
baseFolder.ID = folderID;
|
||||
baseFolder.ParentID = parentID;
|
||||
|
||||
m_commsManager.InventoryService.MoveFolder(baseFolder);
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
AddRequest(
|
||||
new InventoryRequest(
|
||||
Delegate.CreateDelegate(typeof(MoveFolderDelegate), this, "MoveFolder"),
|
||||
new object[] { folderID, parentID }));
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This method will delete all the items and folders in the given folder.
|
||||
/// </summary>
|
||||
/// <param name="folderID"></param>
|
||||
public bool PurgeFolder(LLUUID folderID)
|
||||
{
|
||||
// m_log.InfoFormat("[AGENT INVENTORY]: Purging folder {0} for {1} uuid {2}",
|
||||
// folderID, remoteClient.Name, remoteClient.AgentId);
|
||||
|
||||
if (HasInventory)
|
||||
{
|
||||
InventoryFolderImpl purgedFolder = RootFolder.GetDescendentFolder(folderID);
|
||||
|
||||
if (purgedFolder != null)
|
||||
{
|
||||
// XXX Nasty - have to create a new object to hold details we already have
|
||||
InventoryFolderBase purgedBaseFolder = new InventoryFolderBase();
|
||||
purgedBaseFolder.Owner = purgedFolder.Owner;
|
||||
purgedBaseFolder.ID = purgedFolder.ID;
|
||||
purgedBaseFolder.Name = purgedFolder.Name;
|
||||
purgedBaseFolder.ParentID = purgedFolder.ParentID;
|
||||
purgedBaseFolder.Type = purgedFolder.Type;
|
||||
purgedBaseFolder.Version = purgedFolder.Version;
|
||||
|
||||
m_commsManager.InventoryService.PurgeFolder(purgedBaseFolder);
|
||||
|
||||
purgedFolder.Purge();
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
AddRequest(
|
||||
new InventoryRequest(
|
||||
Delegate.CreateDelegate(typeof(PurgeFolderDelegate), this, "PurgeFolder"),
|
||||
new object[] { folderID }));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add an item to the user's inventory
|
||||
/// </summary>
|
||||
|
@ -499,18 +576,18 @@ namespace OpenSim.Framework.Communications.Cache
|
|||
/// </summary>
|
||||
class InventoryRequest : IInventoryRequest
|
||||
{
|
||||
private Delegate m_delegat;
|
||||
private Delegate m_delegate;
|
||||
private Object[] m_args;
|
||||
|
||||
internal InventoryRequest(Delegate delegat, Object[] args)
|
||||
{
|
||||
m_delegat = delegat;
|
||||
m_delegate = delegat;
|
||||
m_args = args;
|
||||
}
|
||||
|
||||
public void Execute()
|
||||
{
|
||||
m_delegat.DynamicInvoke(m_args);
|
||||
m_delegate.DynamicInvoke(m_args);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,9 +34,6 @@ using log4net;
|
|||
|
||||
namespace OpenSim.Framework.Communications.Cache
|
||||
{
|
||||
internal delegate void MoveInventoryFolderDelegate(IClientAPI remoteClient, LLUUID folderID, LLUUID parentID);
|
||||
internal delegate void PurgeInventoryDescendentsDelegate(IClientAPI remoteClient, LLUUID folderID);
|
||||
|
||||
/// <summary>
|
||||
/// Holds user profile information and retrieves it from backend services.
|
||||
/// </summary>
|
||||
|
@ -199,7 +196,7 @@ namespace OpenSim.Framework.Communications.Cache
|
|||
if (!userProfile.UpdateFolder(name, folderID, type, parentID))
|
||||
{
|
||||
m_log.ErrorFormat(
|
||||
"[AGENT INVENTORY]: Failed to create folder for user {0} {1}",
|
||||
"[AGENT INVENTORY]: Failed to update folder for user {0} {1}",
|
||||
remoteClient.Name, remoteClient.AgentId);
|
||||
}
|
||||
}
|
||||
|
@ -219,29 +216,15 @@ namespace OpenSim.Framework.Communications.Cache
|
|||
/// <param name="parentID"></param>
|
||||
public void HandleMoveInventoryFolder(IClientAPI remoteClient, LLUUID folderID, LLUUID parentID)
|
||||
{
|
||||
// m_log.DebugFormat(
|
||||
// "[AGENT INVENTORY]: Moving inventory folder {0} into folder {1} for {2} {3}",
|
||||
// parentID, remoteClient.Name, remoteClient.Name, remoteClient.AgentId);
|
||||
|
||||
CachedUserInfo userProfile;
|
||||
|
||||
if (m_userProfiles.TryGetValue(remoteClient.AgentId, out userProfile))
|
||||
{
|
||||
if (userProfile.HasInventory)
|
||||
if (!userProfile.MoveFolder(folderID, parentID))
|
||||
{
|
||||
InventoryFolderBase baseFolder = new InventoryFolderBase();
|
||||
baseFolder.Owner = remoteClient.AgentId;
|
||||
baseFolder.ID = folderID;
|
||||
baseFolder.ParentID = parentID;
|
||||
|
||||
m_commsManager.InventoryService.MoveFolder(baseFolder);
|
||||
}
|
||||
else
|
||||
{
|
||||
userProfile.AddRequest(
|
||||
new InventoryRequest(
|
||||
Delegate.CreateDelegate(typeof(MoveInventoryFolderDelegate), this, "HandleMoveInventoryFolder"),
|
||||
new object[] { remoteClient, folderID, parentID }));
|
||||
m_log.ErrorFormat(
|
||||
"[AGENT INVENTORY]: Failed to move folder for user {0} {1}",
|
||||
remoteClient.Name, remoteClient.AgentId);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -463,37 +446,15 @@ namespace OpenSim.Framework.Communications.Cache
|
|||
/// <param name="folderID"></param>
|
||||
public void HandlePurgeInventoryDescendents(IClientAPI remoteClient, LLUUID folderID)
|
||||
{
|
||||
// m_log.InfoFormat("[AGENT INVENTORY]: Purging folder {0} for {1} uuid {2}",
|
||||
// folderID, remoteClient.Name, remoteClient.AgentId);
|
||||
|
||||
CachedUserInfo userProfile;
|
||||
|
||||
if (m_userProfiles.TryGetValue(remoteClient.AgentId, out userProfile))
|
||||
{
|
||||
if (userProfile.HasInventory)
|
||||
if (!userProfile.PurgeFolder(folderID))
|
||||
{
|
||||
InventoryFolderImpl purgedFolder = userProfile.RootFolder.GetDescendentFolder(folderID);
|
||||
if (purgedFolder != null)
|
||||
{
|
||||
// XXX Nasty - have to create a new object to hold details we already have
|
||||
InventoryFolderBase purgedBaseFolder = new InventoryFolderBase();
|
||||
purgedBaseFolder.Owner = purgedFolder.Owner;
|
||||
purgedBaseFolder.ID = purgedFolder.ID;
|
||||
purgedBaseFolder.Name = purgedFolder.Name;
|
||||
purgedBaseFolder.ParentID = purgedFolder.ParentID;
|
||||
purgedBaseFolder.Type = purgedFolder.Type;
|
||||
purgedBaseFolder.Version = purgedFolder.Version;
|
||||
|
||||
m_commsManager.InventoryService.PurgeFolder(purgedBaseFolder);
|
||||
|
||||
purgedFolder.Purge();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
userProfile.AddRequest(
|
||||
new InventoryRequest(
|
||||
Delegate.CreateDelegate(typeof(PurgeInventoryDescendentsDelegate), this, "HandlePurgeInventoryDescendents"),
|
||||
new object[] { remoteClient, folderID }));
|
||||
m_log.ErrorFormat(
|
||||
"[AGENT INVENTORY]: Failed to purge folder for user {0} {1}",
|
||||
remoteClient.Name, remoteClient.AgentId);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
|
Loading…
Reference in New Issue