123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370 |
- using System;
- using System.Collections.Generic;
- using OpenMetaverse;
- using OpenSim.Framework;
- using OpenSim.Region.CoreModules.Avatar.Inventory.Archiver;
- using OpenSim.Region.Framework.Scenes;
- using OpenSim.Services.Interfaces;
- namespace OpenSim.Tests.Common
- {
-
-
-
- public static class UserInventoryHelpers
- {
- public static readonly string PATH_DELIMITER = "/";
-
-
-
-
-
-
-
-
-
-
-
- public static InventoryItemBase AddInventoryItem(
- Scene scene, SceneObjectGroup so, int inventoryIdTail, int assetIdTail)
- {
- return AddInventoryItem(
- scene,
- so.Name,
- TestHelpers.ParseTail(inventoryIdTail),
- InventoryType.Object,
- AssetHelpers.CreateAsset(TestHelpers.ParseTail(assetIdTail), so),
- so.OwnerID);
- }
-
-
-
-
-
-
-
-
- public static InventoryItemBase AddInventoryItem(
- Scene scene, SceneObjectGroup so, int inventoryIdTail, int assetIdTail, string path)
- {
- return AddInventoryItem(
- scene,
- so.Name,
- TestHelpers.ParseTail(inventoryIdTail),
- InventoryType.Object,
- AssetHelpers.CreateAsset(TestHelpers.ParseTail(assetIdTail), so),
- so.OwnerID,
- path);
- }
-
-
-
-
-
-
-
-
-
-
-
- private static InventoryItemBase AddInventoryItem(
- Scene scene, string itemName, UUID itemId, InventoryType itemType, AssetBase asset, UUID userId)
- {
- return AddInventoryItem(
- scene, itemName, itemId, itemType, asset, userId,
- scene.InventoryService.GetFolderForType(userId, (AssetType)asset.Type).Name);
- }
-
-
-
-
-
-
-
-
-
-
-
- private static InventoryItemBase AddInventoryItem(
- Scene scene, string itemName, UUID itemId, InventoryType itemType, AssetBase asset, UUID userId, string path)
- {
- scene.AssetService.Store(asset);
- InventoryItemBase item = new InventoryItemBase();
- item.Name = itemName;
- item.AssetID = asset.FullID;
- item.ID = itemId;
- item.Owner = userId;
- item.AssetType = asset.Type;
- item.InvType = (int)itemType;
- InventoryFolderBase folder = InventoryArchiveUtils.FindFoldersByPath(scene.InventoryService, userId, path)[0];
- item.Folder = folder.ID;
- scene.AddInventoryItem(item);
- return item;
- }
-
-
-
-
-
-
-
-
- public static InventoryItemBase CreateInventoryItem(Scene scene, string itemName, UUID userId)
- {
- return CreateInventoryItem(scene, itemName, UUID.Random(), UUID.Random(), userId, InventoryType.Notecard);
- }
-
-
-
-
-
-
-
-
-
- public static InventoryItemBase CreateInventoryItem(
- Scene scene, string itemName, UUID userId, InventoryType type)
- {
- return CreateInventoryItem(scene, itemName, UUID.Random(), UUID.Random(), userId, type);
- }
-
-
-
-
-
-
-
-
-
-
- public static InventoryItemBase CreateInventoryItem(
- Scene scene, string itemName, UUID itemId, UUID assetId, UUID userId, InventoryType itemType)
- {
- AssetBase asset = null;
- if (itemType == InventoryType.Notecard)
- {
- asset = AssetHelpers.CreateNotecardAsset();
- asset.CreatorID = userId.ToString();
- }
- else if (itemType == InventoryType.Object)
- {
- asset = AssetHelpers.CreateAsset(assetId, SceneHelpers.CreateSceneObject(1, userId));
- }
- else
- {
- throw new Exception(string.Format("Inventory type {0} not supported", itemType));
- }
- return AddInventoryItem(scene, itemName, itemId, itemType, asset, userId);
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- public static InventoryFolderBase CreateInventoryFolder(
- IInventoryService inventoryService, UUID userId, string path, bool useExistingFolders)
- {
- return CreateInventoryFolder(inventoryService, userId, UUID.Random(), path, useExistingFolders);
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- public static InventoryFolderBase CreateInventoryFolder(
- IInventoryService inventoryService, UUID userId, UUID folderId, string path, bool useExistingFolders)
- {
- InventoryFolderBase rootFolder = inventoryService.GetRootFolder(userId);
- if (null == rootFolder)
- return null;
- return CreateInventoryFolder(inventoryService, folderId, rootFolder, path, useExistingFolders);
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- public static InventoryFolderBase CreateInventoryFolder(
- IInventoryService inventoryService, UUID folderId, InventoryFolderBase parentFolder, string path, bool useExistingFolders)
- {
- string[] components = path.Split(new string[] { PATH_DELIMITER }, 2, StringSplitOptions.None);
- InventoryFolderBase folder = null;
- if (useExistingFolders)
- folder = InventoryArchiveUtils.FindFolderByPath(inventoryService, parentFolder, components[0]);
- if (folder == null)
- {
- UUID folderIdForCreate;
- if (components.Length > 1)
- folderIdForCreate = UUID.Random();
- else
- folderIdForCreate = folderId;
- folder
- = new InventoryFolderBase(
- folderIdForCreate, components[0], parentFolder.Owner, (short)AssetType.Unknown, parentFolder.ID, 0);
-
- inventoryService.AddFolder(folder);
- }
- if (components.Length > 1)
- return CreateInventoryFolder(inventoryService, folderId, folder, components[1], useExistingFolders);
- else
- return folder;
- }
-
-
-
-
-
-
-
-
- public static InventoryFolderBase GetInventoryFolder(IInventoryService inventoryService, UUID userId, string path)
- {
- List<InventoryFolderBase> folders = GetInventoryFolders(inventoryService, userId, path);
- if (folders.Count != 0)
- return folders[0];
- else
- return null;
- }
-
-
-
-
-
-
-
- public static List<InventoryFolderBase> GetInventoryFolders(IInventoryService inventoryService, UUID userId, string path)
- {
- return InventoryArchiveUtils.FindFoldersByPath(inventoryService, userId, path);
- }
-
-
-
-
-
-
-
-
- public static InventoryItemBase GetInventoryItem(IInventoryService inventoryService, UUID userId, string path)
- {
- return InventoryArchiveUtils.FindItemByPath(inventoryService, userId, path);
- }
-
-
-
-
-
-
-
- public static List<InventoryItemBase> GetInventoryItems(IInventoryService inventoryService, UUID userId, string path)
- {
- return InventoryArchiveUtils.FindItemsByPath(inventoryService, userId, path);
- }
- }
- }
|