Added MoveItems, which is most useful upon viewer-delete inventory operation. Moving a batch of items is a 1-time operation. Made it async anyway, so that the viewer doesn't wait in case the DB layer is dumb (which is the case currently).

arthursv
Diva Canto 2009-08-19 10:56:08 -07:00
parent 4382f28efc
commit d519f1885f
16 changed files with 162 additions and 38 deletions

View File

@ -547,6 +547,11 @@ namespace OpenSim.Framework.Communications.Tests
return false;
}
public bool MoveItems(UUID owner, List<InventoryItemBase> items)
{
return false;
}
public bool DeleteItems(UUID owner, List<UUID> items)
{
return false;

View File

@ -254,7 +254,7 @@ namespace OpenSim.Framework
string newName);
public delegate void MoveInventoryItem(
IClientAPI remoteClient, UUID folderID, UUID itemID, int length, string newName);
IClientAPI remoteClient, List<InventoryItemBase> items);
public delegate void RemoveInventoryItem(
IClientAPI remoteClient, List<UUID> itemIDs);

View File

@ -7027,14 +7027,21 @@ namespace OpenSim.Region.ClientStack.LindenUDP
if (OnMoveInventoryItem != null)
{
handlerMoveInventoryItem = null;
InventoryItemBase itm = null;
List<InventoryItemBase> items = new List<InventoryItemBase>();
foreach (MoveInventoryItemPacket.InventoryDataBlock datablock in moveitem.InventoryData)
{
handlerMoveInventoryItem = OnMoveInventoryItem;
if (handlerMoveInventoryItem != null)
{
handlerMoveInventoryItem(this, datablock.FolderID, datablock.ItemID, datablock.Length,
Util.FieldToString(datablock.NewName));
}
itm = new InventoryItemBase(datablock.ItemID, AgentId);
itm.Folder = datablock.FolderID;
itm.Name = Util.FieldToString(datablock.NewName);
// weird, comes out as empty string
//m_log.DebugFormat("[XXX] new name: {0}", itm.Name);
items.Add(itm);
}
handlerMoveInventoryItem = OnMoveInventoryItem;
if (handlerMoveInventoryItem != null)
{
handlerMoveInventoryItem(this, items);
}
}
break;

View File

@ -181,6 +181,8 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory
/// <returns>true if the item was successfully updated</returns>
public abstract bool UpdateItem(InventoryItemBase item);
public abstract bool MoveItems(UUID ownerID, List<InventoryItemBase> items);
/// <summary>
/// Delete an item from the user's inventory
/// </summary>

View File

@ -393,6 +393,23 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory
}
}
public override bool MoveItems(UUID ownerID, List<InventoryItemBase> items)
{
if (items == null)
return false;
if (items.Count == 0)
return true;
if (IsLocalGridUser(ownerID))
return m_GridService.MoveItems(ownerID, items);
else
{
UUID sessionID = GetSessionID(ownerID);
string uri = GetUserInventoryURI(ownerID) + "/" + ownerID.ToString();
return m_HGService.MoveItems(uri, items, sessionID);
}
}
public override bool DeleteItems(UUID ownerID, List<UUID> itemIDs)
{
m_log.DebugFormat("[HG INVENTORY CONNECTOR]: Delete {0} items for user {1}", itemIDs.Count, ownerID);

View File

@ -289,6 +289,12 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory
return m_InventoryService.UpdateItem(item);
}
public override bool MoveItems(UUID ownerID, List<InventoryItemBase> items)
{
return m_InventoryService.MoveItems(ownerID, items);
}
/// <summary>
/// Delete an item from the user's inventory
/// </summary>

View File

@ -273,6 +273,16 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory
return m_RemoteConnector.UpdateItem(item.Owner.ToString(), item, sessionID);
}
public override bool MoveItems(UUID ownerID, List<InventoryItemBase> items)
{
if (items == null)
return false;
UUID sessionID = GetSessionID(ownerID);
return m_RemoteConnector.MoveItems(ownerID.ToString(), items, sessionID);
}
public override bool DeleteItems(UUID ownerID, List<UUID> itemIDs)
{
if (itemIDs == null)

View File

@ -638,36 +638,13 @@ namespace OpenSim.Region.Framework.Scenes
/// <param name="itemID"></param>
/// <param name="length"></param>
/// <param name="newName"></param>
public void MoveInventoryItem(IClientAPI remoteClient, UUID folderID, UUID itemID, int length,
string newName)
public void MoveInventoryItem(IClientAPI remoteClient, List<InventoryItemBase> items)
{
m_log.DebugFormat(
"[AGENT INVENTORY]: Moving item {0} to {1} for {2}", itemID, folderID, remoteClient.AgentId);
"[AGENT INVENTORY]: Moving {0} items for user {1}", items.Count, remoteClient.AgentId);
InventoryItemBase item = new InventoryItemBase(itemID, remoteClient.AgentId);
item = InventoryService.GetItem(item);
if (item != null)
{
if (newName != String.Empty)
{
item.Name = newName;
}
item.Folder = folderID;
// Diva comment: can't we just update?
List<UUID> uuids = new List<UUID>();
uuids.Add(item.ID);
InventoryService.DeleteItems(item.Owner, uuids);
AddInventoryItem(remoteClient, item);
}
else
{
m_log.Warn("[AGENT INVENTORY]: Failed to find item " + itemID.ToString());
return;
}
if (!InventoryService.MoveItems(remoteClient.AgentId, items))
m_log.Warn("[AGENT INVENTORY]: Failed to move items for user " + remoteClient.AgentId);
}
/// <summary>

View File

@ -125,8 +125,8 @@ namespace OpenSim.Server.Handlers.Inventory
"POST", "/NewFolder/", m_InventoryService.AddFolder, CheckAuthSession));
m_httpServer.AddStreamHandler(
new RestDeserialiseTrustedHandler<InventoryFolderBase, bool>(
"POST", "/CreateFolder/", m_InventoryService.AddFolder, CheckTrustSource));
new RestDeserialiseSecureHandler<InventoryFolderBase, bool>(
"POST", "/CreateFolder/", m_InventoryService.AddFolder, CheckAuthSession));
m_httpServer.AddStreamHandler(
new RestDeserialiseSecureHandler<InventoryItemBase, bool>(
@ -137,9 +137,13 @@ namespace OpenSim.Server.Handlers.Inventory
"POST", "/AddNewItem/", m_InventoryService.AddItem, CheckTrustSource));
m_httpServer.AddStreamHandler(
new RestDeserialiseTrustedHandler<Guid, List<InventoryItemBase>>(
"POST", "/GetItems/", GetFolderItems, CheckTrustSource));
new RestDeserialiseSecureHandler<Guid, List<InventoryItemBase>>(
"POST", "/GetItems/", GetFolderItems, CheckAuthSession));
m_httpServer.AddStreamHandler(
new RestDeserialiseSecureHandler<List<InventoryItemBase>, bool>(
"POST", "/MoveItems/", MoveItems, CheckAuthSession));
// for persistent active gestures
m_httpServer.AddStreamHandler(
new RestDeserialiseTrustedHandler<Guid, List<InventoryItemBase>>
@ -256,6 +260,15 @@ namespace OpenSim.Server.Handlers.Inventory
return m_InventoryService.DeleteItems(UUID.Zero, uuids);
}
public bool MoveItems(List<InventoryItemBase> items)
{
// oops we lost the user info here. Bad bad handlers
// let's peek at one item
UUID ownerID = UUID.Zero;
if (items.Count > 0)
ownerID = items[0].Owner;
return m_InventoryService.MoveItems(ownerID, items);
}
#endregion
/// <summary>

View File

@ -253,6 +253,19 @@ namespace OpenSim.Services.Connectors.Inventory
return false;
}
public bool MoveItems(string id, List<InventoryItemBase> items, UUID sessionID)
{
string url = string.Empty;
string userID = string.Empty;
if (StringToUrlAndUserID(id, out url, out userID))
{
ISessionAuthInventoryService connector = GetConnector(url);
return connector.MoveItems(userID, items, sessionID);
}
return false;
}
public bool DeleteItems(string id, List<UUID> itemIDs, UUID sessionID)
{
string url = string.Empty;

View File

@ -116,6 +116,8 @@ namespace OpenSim.Services.Connectors
/// <returns>true if the item was successfully updated</returns>
bool UpdateItem(string userID, InventoryItemBase item, UUID session_id);
bool MoveItems(string userID, List<InventoryItemBase> items, UUID session_id);
/// <summary>
/// Delete an item from the user's inventory
/// </summary>

View File

@ -383,6 +383,48 @@ namespace OpenSim.Services.Connectors
return false;
}
/**
* MoveItems Async group
*/
delegate void MoveItemsDelegate(string userID, List<InventoryItemBase> items, UUID sessionID);
private void MoveItemsAsync(string userID, List<InventoryItemBase> items, UUID sessionID)
{
try
{
SynchronousRestSessionObjectPoster<List<InventoryItemBase>, bool>.BeginPostObject(
"POST", m_ServerURI + "/MoveItems/", items, sessionID.ToString(), userID.ToString());
// Success
return;
}
catch (Exception e)
{
m_log.ErrorFormat("[INVENTORY CONNECTOR]: Move inventory items operation failed, {0} {1} (old server?). Trying slow way.",
e.Source, e.Message);
}
foreach (InventoryItemBase item in items)
{
InventoryItemBase itm = this.QueryItem(userID, item, sessionID);
itm.Name = item.Name;
itm.Folder = item.Folder;
this.UpdateItem(userID, itm, sessionID);
}
}
private void MoveItemsCompleted(IAsyncResult iar)
{
}
public bool MoveItems(string userID, List<InventoryItemBase> items, UUID sessionID)
{
MoveItemsDelegate d = MoveItemsAsync;
d.BeginInvoke(userID, items, sessionID, MoveItemsCompleted, d);
return true;
}
public bool DeleteItems(string userID, List<UUID> items, UUID sessionID)
{
try

View File

@ -151,6 +151,11 @@ namespace OpenSim.Services.Connectors
return false;
}
public bool MoveItems(UUID ownerID, List<InventoryItemBase> items)
{
return false;
}
public bool DeleteItems(UUID owner, List<UUID> itemIDs)
{
return false;

View File

@ -142,6 +142,8 @@ namespace OpenSim.Services.Interfaces
/// <returns>true if the item was successfully updated</returns>
bool UpdateItem(InventoryItemBase item);
bool MoveItems(UUID ownerID, List<InventoryItemBase> items);
/// <summary>
/// Delete an item from the user's inventory
/// </summary>

View File

@ -386,6 +386,24 @@ namespace OpenSim.Services.InventoryService
return true;
}
public virtual bool MoveItems(UUID ownerID, List<InventoryItemBase> items)
{
m_log.InfoFormat(
"[INVENTORY SERVICE]: Moving {0} items from user {1}", items.Count, ownerID);
InventoryItemBase itm = null;
foreach (InventoryItemBase item in items)
{
itm = GetInventoryItem(item.ID);
itm.Folder = item.Folder;
if ((item.Name != null) && !item.Name.Equals(string.Empty))
itm.Name = item.Name;
m_Database.updateInventoryItem(itm);
}
return true;
}
// See IInventoryServices
public virtual bool DeleteItems(UUID owner, List<UUID> itemIDs)
{

View File

@ -143,6 +143,11 @@ namespace OpenSim.Tests.Common.Mock
return false;
}
public bool MoveItems(UUID ownerID, List<InventoryItemBase> items)
{
return false;
}
public bool DeleteItems(UUID ownerID, List<UUID> itemIDs)
{
return false;