From 10875427058e68784ca6f5538a00a0cafd46a72b Mon Sep 17 00:00:00 2001
From: Justin Clarke Casey
Date: Sat, 3 May 2008 18:57:02 +0000
Subject: * Refactor: Move bulk of CreateFolder from UserProfileCacheService
into CachedUserInfo * Remove unused/superseded methods from
GridInventoryService
---
.../Communications/Cache/CachedUserInfo.cs | 100 ++++++++++++++++++++-
.../Cache/UserProfileCacheService.cs | 76 ++--------------
2 files changed, 104 insertions(+), 72 deletions(-)
(limited to 'OpenSim/Framework/Communications/Cache')
diff --git a/OpenSim/Framework/Communications/Cache/CachedUserInfo.cs b/OpenSim/Framework/Communications/Cache/CachedUserInfo.cs
index 86c24bc..f55b492 100644
--- a/OpenSim/Framework/Communications/Cache/CachedUserInfo.cs
+++ b/OpenSim/Framework/Communications/Cache/CachedUserInfo.cs
@@ -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);
+
///
/// Stores user profile and inventory data received from backend services for a particular user.
///
@@ -297,6 +302,99 @@ namespace OpenSim.Framework.Communications.Cache
}
}
}
+
+ ///
+ /// Create a folder in this agent's inventory
+ ///
+ ///
+ ///
+ 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;
+ }
///
/// Add an item to the user's inventory
@@ -360,7 +458,7 @@ namespace OpenSim.Framework.Communications.Cache
///
/// Generic inventory request
///
- public class InventoryRequest : IInventoryRequest
+ class InventoryRequest : IInventoryRequest
{
private Delegate m_delegat;
private Object[] m_args;
diff --git a/OpenSim/Framework/Communications/Cache/UserProfileCacheService.cs b/OpenSim/Framework/Communications/Cache/UserProfileCacheService.cs
index befb6c7..f1929c8 100644
--- a/OpenSim/Framework/Communications/Cache/UserProfileCacheService.cs
+++ b/OpenSim/Framework/Communications/Cache/UserProfileCacheService.cs
@@ -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
///
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);
}
}
}
--
cgit v1.1