From 068163b14bae4f411bb3cf2b34981eb212b7639b Mon Sep 17 00:00:00 2001 From: Justin Clarke Casey Date: Sat, 3 May 2008 19:50:49 +0000 Subject: * Refactor: Move MoveFolder() and PurgeFolder() into CachedUserInfo (which arguably should be split) --- .../Communications/Cache/CachedUserInfo.cs | 97 +++++++++++++++++++--- .../Cache/UserProfileCacheService.cs | 65 +++------------ 2 files changed, 100 insertions(+), 62 deletions(-) diff --git a/OpenSim/Framework/Communications/Cache/CachedUserInfo.cs b/OpenSim/Framework/Communications/Cache/CachedUserInfo.cs index 35c2002..ceca1a4 100644 --- a/OpenSim/Framework/Communications/Cache/CachedUserInfo.cs +++ b/OpenSim/Framework/Communications/Cache/CachedUserInfo.cs @@ -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); /// /// 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; /// /// 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,11 +428,88 @@ 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; + } + + /// + /// Handle an inventory folder move request from the client. + /// + /// + /// + 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; + } + } + + /// + /// This method will delete all the items and folders in the given folder. + /// + /// + 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; } /// @@ -499,18 +576,18 @@ namespace OpenSim.Framework.Communications.Cache /// 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); } } } diff --git a/OpenSim/Framework/Communications/Cache/UserProfileCacheService.cs b/OpenSim/Framework/Communications/Cache/UserProfileCacheService.cs index f640fb8..0404477 100644 --- a/OpenSim/Framework/Communications/Cache/UserProfileCacheService.cs +++ b/OpenSim/Framework/Communications/Cache/UserProfileCacheService.cs @@ -33,10 +33,7 @@ using libsecondlife; 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); - +{ /// /// Holds user profile information and retrieves it from backend services. /// @@ -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 /// 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) - { - InventoryFolderBase baseFolder = new InventoryFolderBase(); - baseFolder.Owner = remoteClient.AgentId; - baseFolder.ID = folderID; - baseFolder.ParentID = parentID; - - m_commsManager.InventoryService.MoveFolder(baseFolder); - } - else + if (!userProfile.MoveFolder(folderID, parentID)) { - 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 @@ -249,7 +232,7 @@ namespace OpenSim.Framework.Communications.Cache m_log.ErrorFormat( "[AGENT INVENTORY]: Could not find user profile for {0} {1}", remoteClient.Name, remoteClient.AgentId); - } + } } /// @@ -463,37 +446,15 @@ namespace OpenSim.Framework.Communications.Cache /// 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 @@ -501,7 +462,7 @@ namespace OpenSim.Framework.Communications.Cache m_log.ErrorFormat( "[AGENT INVENTORY]: Could not find user profile for {0} {1}", remoteClient.Name, remoteClient.AgentId); - } + } } public void HandleFetchInventory(IClientAPI remoteClient, LLUUID itemID, LLUUID ownerID) -- cgit v1.1