From f74326c1b05237e5a9eb3fce897ed1bec3085961 Mon Sep 17 00:00:00 2001 From: Justin Clarke Casey Date: Thu, 12 Feb 2009 17:41:09 +0000 Subject: * move userinfo for inventory archiving up to module class so that it only has to be done once --- .../Archiver/InventoryArchiveReadRequest.cs | 44 ++++-------- .../Archiver/InventoryArchiveWriteRequest.cs | 47 ++++-------- .../Inventory/Archiver/InventoryArchiverModule.cs | 84 +++++++++++++++------- 3 files changed, 85 insertions(+), 90 deletions(-) (limited to 'OpenSim/Region') diff --git a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveReadRequest.cs b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveReadRequest.cs index 5ae5b4b..6f8fa3c 100644 --- a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveReadRequest.cs +++ b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveReadRequest.cs @@ -48,8 +48,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver protected TarArchiveReader archive; private static ASCIIEncoding m_asciiEncoding = new ASCIIEncoding(); - private string m_firstName; - private string m_lastName; + private CachedUserInfo m_userInfo; private string m_invPath; /// @@ -60,10 +59,9 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver CommunicationsManager commsManager; public InventoryArchiveReadRequest( - string firstName, string lastName, string invPath, string loadPath, CommunicationsManager commsManager) + CachedUserInfo userInfo, string invPath, string loadPath, CommunicationsManager commsManager) : this( - firstName, - lastName, + userInfo, invPath, new GZipStream(new FileStream(loadPath, FileMode.Open), CompressionMode.Decompress), commsManager) @@ -71,10 +69,9 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver } public InventoryArchiveReadRequest( - string firstName, string lastName, string invPath, Stream loadStream, CommunicationsManager commsManager) + CachedUserInfo userInfo, string invPath, Stream loadStream, CommunicationsManager commsManager) { - m_firstName = firstName; - m_lastName = lastName; + m_userInfo = userInfo; m_invPath = invPath; m_loadStream = loadStream; this.commsManager = commsManager; @@ -174,33 +171,16 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver int successfulItemRestores = 0; List nodesLoaded = new List(); - UserProfileData userProfile = commsManager.UserService.GetUserProfile(m_firstName, m_lastName); - if (null == userProfile) - { - m_log.ErrorFormat("[INVENTORY ARCHIVER]: Failed to find user {0} {1}", m_firstName, m_lastName); - return nodesLoaded; - } - - CachedUserInfo userInfo = commsManager.UserProfileCacheService.GetUserDetails(userProfile.ID); - if (null == userInfo) - { - m_log.ErrorFormat( - "[INVENTORY ARCHIVER]: Failed to find user info for {0} {1} {2}", - m_firstName, m_lastName, userProfile.ID); - - return nodesLoaded; - } - - if (!userInfo.HasReceivedInventory) + if (!m_userInfo.HasReceivedInventory) { m_log.ErrorFormat( - "[INVENTORY ARCHIVER]: Have not yet received inventory info for user {0} {1} {2}", - m_firstName, m_lastName, userProfile.ID); + "[INVENTORY ARCHIVER]: Have not yet received inventory info for user {0} {1}", + m_userInfo.UserProfile.Name, m_userInfo.UserProfile.ID); return nodesLoaded; } - InventoryFolderImpl inventoryFolder = userInfo.RootFolder.FindFolderByPath(m_invPath); + InventoryFolderImpl inventoryFolder = m_userInfo.RootFolder.FindFolderByPath(m_invPath); if (null == inventoryFolder) { @@ -232,15 +212,15 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver if (item != null) { - item.Creator = userProfile.ID; - item.Owner = userProfile.ID; + item.Creator = m_userInfo.UserProfile.ID; + item.Owner = m_userInfo.UserProfile.ID; // Reset folder ID to the one in which we want to load it // TODO: Properly restore entire folder structure. At the moment all items are dumped in this // single folder no matter where in the saved folder structure they are. item.Folder = inventoryFolder.ID; - userInfo.AddItem(item); + m_userInfo.AddItem(item); successfulItemRestores++; nodesLoaded.Add(item); } diff --git a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveWriteRequest.cs b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveWriteRequest.cs index da4785b..622ba86 100644 --- a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveWriteRequest.cs +++ b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveWriteRequest.cs @@ -48,8 +48,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver protected CommunicationsManager commsManager; protected Dictionary assetUuids = new Dictionary(); - private string m_firstName; - private string m_lastName; + private CachedUserInfo m_userInfo; private string m_invPath; /// @@ -61,13 +60,12 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver /// Constructor /// public InventoryArchiveWriteRequest( - string firstName, string lastName, string invPath, string savePath, CommunicationsManager commsManager) + CachedUserInfo userInfo, string invPath, string savePath, CommunicationsManager commsManager) : this( - firstName, - lastName, - invPath, - new GZipStream(new FileStream(savePath, FileMode.Create), CompressionMode.Compress), - commsManager) + userInfo, + invPath, + new GZipStream(new FileStream(savePath, FileMode.Create), CompressionMode.Compress), + commsManager) { } @@ -75,10 +73,9 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver /// Constructor /// public InventoryArchiveWriteRequest( - string firstName, string lastName, string invPath, Stream saveStream, CommunicationsManager commsManager) + CachedUserInfo userInfo, string invPath, Stream saveStream, CommunicationsManager commsManager) { - m_firstName = firstName; - m_lastName = lastName; + m_userInfo = userInfo; m_invPath = invPath; m_saveStream = saveStream; this.commsManager = commsManager; @@ -183,26 +180,10 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver public void Execute() { - UserProfileData userProfile = commsManager.UserService.GetUserProfile(m_firstName, m_lastName); - if (null == userProfile) - { - m_log.ErrorFormat("[INVENTORY ARCHIVER]: Failed to find user {0} {1}", m_firstName, m_lastName); - return; - } - - CachedUserInfo userInfo = commsManager.UserProfileCacheService.GetUserDetails(userProfile.ID); - if (null == userInfo) - { - m_log.ErrorFormat( - "[INVENTORY ARCHIVER]: Failed to find user info for {0} {1} {2}", - m_firstName, m_lastName, userProfile.ID); - return; - } - InventoryFolderImpl inventoryFolder = null; InventoryItemBase inventoryItem = null; - if (userInfo.HasReceivedInventory) + if (m_userInfo.HasReceivedInventory) { // Eliminate double slashes and any leading / on the path. This might be better done within InventoryFolderImpl // itself (possibly at a small loss in efficiency). @@ -218,25 +199,25 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver // Therefore if we still start with a / after the split, then we need the root folder if (m_invPath.Length == 0) { - inventoryFolder = userInfo.RootFolder; + inventoryFolder = m_userInfo.RootFolder; } else { m_invPath = m_invPath.Remove(m_invPath.LastIndexOf(InventoryFolderImpl.PATH_DELIMITER)); - inventoryFolder = userInfo.RootFolder.FindFolderByPath(m_invPath); + inventoryFolder = m_userInfo.RootFolder.FindFolderByPath(m_invPath); } // The path may point to an item instead if (inventoryFolder == null) { - inventoryItem = userInfo.RootFolder.FindItemByPath(m_invPath); + inventoryItem = m_userInfo.RootFolder.FindItemByPath(m_invPath); } } else { m_log.ErrorFormat( - "[INVENTORY ARCHIVER]: Have not yet received inventory info for user {0} {1} {2}", - m_firstName, m_lastName, userProfile.ID); + "[INVENTORY ARCHIVER]: Have not yet received inventory info for user {0} {1}", + m_userInfo.UserProfile.Name, m_userInfo.UserProfile.ID); return; } diff --git a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiverModule.cs b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiverModule.cs index b025a31..5684b84 100644 --- a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiverModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiverModule.cs @@ -32,7 +32,8 @@ using log4net; using Nini.Config; using OpenMetaverse; using OpenSim.Framework; -using OpenSim.Framework.Communications; +using OpenSim.Framework.Communications; +using OpenSim.Framework.Communications.Cache; using OpenSim.Region.Framework.Interfaces; using OpenSim.Region.Framework.Scenes; @@ -85,22 +86,22 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver m_scenes[scene.RegionInfo.RegionID] = scene; } - public void PostInitialise() - { - } + public void PostInitialise() {} - public void Close() - { - } + public void Close() {} public void DearchiveInventory(string firstName, string lastName, string invPath, Stream loadStream) { if (m_scenes.Count > 0) { - InventoryArchiveReadRequest request = - new InventoryArchiveReadRequest(firstName, lastName, invPath, loadStream, m_commsManager); - - UpdateClientWithLoadedNodes(firstName, lastName, request.Execute()); + CachedUserInfo userInfo = GetUserInfo(firstName, lastName); + + if (userInfo != null) + { + InventoryArchiveReadRequest request = + new InventoryArchiveReadRequest(userInfo, invPath, loadStream, m_commsManager); + UpdateClientWithLoadedNodes(userInfo, request.Execute()); + } } } @@ -108,18 +109,25 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver { if (m_scenes.Count > 0) { - new InventoryArchiveWriteRequest(firstName, lastName, invPath, saveStream, m_commsManager).Execute(); + CachedUserInfo userInfo = GetUserInfo(firstName, lastName); + + if (userInfo != null) + new InventoryArchiveWriteRequest(userInfo, invPath, saveStream, m_commsManager).Execute(); } } public void DearchiveInventory(string firstName, string lastName, string invPath, string loadPath) { if (m_scenes.Count > 0) - { - InventoryArchiveReadRequest request = - new InventoryArchiveReadRequest(firstName, lastName, invPath, loadPath, m_commsManager); + { + CachedUserInfo userInfo = GetUserInfo(firstName, lastName); - UpdateClientWithLoadedNodes(firstName, lastName, request.Execute()); + if (userInfo != null) + { + InventoryArchiveReadRequest request = + new InventoryArchiveReadRequest(userInfo, invPath, loadPath, m_commsManager); + UpdateClientWithLoadedNodes(userInfo, request.Execute()); + } } } @@ -127,9 +135,12 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver { if (m_scenes.Count > 0) { - new InventoryArchiveWriteRequest(firstName, lastName, invPath, savePath, m_commsManager).Execute(); + CachedUserInfo userInfo = GetUserInfo(firstName, lastName); + + if (userInfo != null) + new InventoryArchiveWriteRequest(userInfo, invPath, savePath, m_commsManager).Execute(); } - } + } /// /// Load inventory from an inventory file archive @@ -174,22 +185,45 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver } /// + /// Get user information for the given name. + /// + /// + /// + /// + protected CachedUserInfo GetUserInfo(string firstName, string lastName) + { + UserProfileData userProfile = m_commsManager.UserService.GetUserProfile(firstName, lastName); + + if (null == userProfile) + { + m_log.ErrorFormat("[INVENTORY ARCHIVER]: Failed to find user {0} {1}", firstName, lastName); + return null; + } + + CachedUserInfo userInfo = m_commsManager.UserProfileCacheService.GetUserDetails(userProfile.ID); + if (null == userInfo) + { + m_log.ErrorFormat( + "[INVENTORY ARCHIVER]: Failed to find user info for {0} {1} {2}", + firstName, lastName, userProfile.ID); + return null; + } + + return userInfo; + } + + /// /// Notify the client of loaded nodes if they are logged in /// /// Can be empty. In which case, nothing happens - private void UpdateClientWithLoadedNodes(string firstName, string lastName, List loadedNodes) + private void UpdateClientWithLoadedNodes(CachedUserInfo userInfo, List loadedNodes) { if (loadedNodes.Count == 0) return; - - UserProfileData userProfile = m_commsManager.UserService.GetUserProfile(firstName, lastName); - - if (null == userProfile) - return; foreach (Scene scene in m_scenes.Values) { - ScenePresence user = scene.GetScenePresence(userProfile.ID); + ScenePresence user = scene.GetScenePresence(userInfo.UserProfile.ID); if (user != null && !user.IsChildAgent) { -- cgit v1.1