public void TestCreateInventoryFolders()
        {
            TestHelpers.InMethod();
//            TestHelpers.EnableLogging();

            // For this test both folders will have the same name which is legal in SL user inventories.
            string foldersName = "f1";

            Scene       scene = new SceneHelpers().SetupScene();
            UserAccount user1 = UserAccountHelpers.CreateUserWithInventory(scene, TestHelpers.ParseTail(1001));

            UserInventoryHelpers.CreateInventoryFolder(scene.InventoryService, user1.PrincipalID, foldersName, false);

            List <InventoryFolderBase> oneFolder
                = UserInventoryHelpers.GetInventoryFolders(scene.InventoryService, user1.PrincipalID, foldersName);

            Assert.That(oneFolder.Count, Is.EqualTo(1));
            InventoryFolderBase firstRetrievedFolder = oneFolder[0];

            Assert.That(firstRetrievedFolder.Name, Is.EqualTo(foldersName));

            UserInventoryHelpers.CreateInventoryFolder(scene.InventoryService, user1.PrincipalID, foldersName, false);

            List <InventoryFolderBase> twoFolders
                = UserInventoryHelpers.GetInventoryFolders(scene.InventoryService, user1.PrincipalID, foldersName);

            Assert.That(twoFolders.Count, Is.EqualTo(2));
            Assert.That(twoFolders[0].Name, Is.EqualTo(foldersName));
            Assert.That(twoFolders[1].Name, Is.EqualTo(foldersName));
            Assert.That(twoFolders[0].ID, Is.Not.EqualTo(twoFolders[1].ID));
        }
        public void TestGiveInventoryFolder()
        {
            TestHelpers.InMethod();
//            TestHelpers.EnableLogging();

            Scene               scene = new SceneHelpers().SetupScene();
            UserAccount         user1 = UserAccountHelpers.CreateUserWithInventory(scene, TestHelpers.ParseTail(1001));
            UserAccount         user2 = UserAccountHelpers.CreateUserWithInventory(scene, TestHelpers.ParseTail(1002));
            InventoryFolderBase folder1
                = UserInventoryHelpers.CreateInventoryFolder(scene.InventoryService, user1.PrincipalID, "folder1", false);

            scene.GiveInventoryFolder(user2.PrincipalID, user1.PrincipalID, folder1.ID, UUID.Zero);

            InventoryFolderBase retrievedFolder1
                = UserInventoryHelpers.GetInventoryFolder(scene.InventoryService, user2.PrincipalID, "folder1");

            Assert.That(retrievedFolder1, Is.Not.Null);

            // Try giving back the freshly received folder
            scene.GiveInventoryFolder(user1.PrincipalID, user2.PrincipalID, retrievedFolder1.ID, UUID.Zero);

            List <InventoryFolderBase> reretrievedFolders
                = UserInventoryHelpers.GetInventoryFolders(scene.InventoryService, user1.PrincipalID, "folder1");

            Assert.That(reretrievedFolders.Count, Is.EqualTo(2));
        }
        public void TestMergeIarPath()
        {
            TestHelpers.InMethod();
            //            log4net.Config.XmlConfigurator.Configure();

            Scene scene = new SceneHelpers().SetupScene();
            UserAccount ua1 = UserAccountHelpers.CreateUserWithInventory(scene);

            string folder1ExistingName = "a";
            string folder2Name = "b";

            InventoryFolderBase folder1
                = UserInventoryHelpers.CreateInventoryFolder(
                    scene.InventoryService, ua1.PrincipalID, folder1ExistingName, false);

            string folder1ArchiveName = InventoryArchiveWriteRequest.CreateArchiveFolderName(folder1ExistingName, UUID.Random());
            string folder2ArchiveName = InventoryArchiveWriteRequest.CreateArchiveFolderName(folder2Name, UUID.Random());

            string itemArchivePath = string.Join("", new string[] { folder1ArchiveName, folder2ArchiveName });

            new InventoryArchiveReadRequest(scene.InventoryService, scene.AssetService, scene.UserAccountService, ua1, folder1ExistingName, (Stream)null, true)
                .ReplicateArchivePathToUserInventory(
                    itemArchivePath, scene.InventoryService.GetRootFolder(ua1.PrincipalID),
                    new Dictionary<string, InventoryFolderBase>(), new HashSet<InventoryNodeBase>());

            List<InventoryFolderBase> folder1PostCandidates
                = InventoryArchiveUtils.FindFoldersByPath(scene.InventoryService, ua1.PrincipalID, folder1ExistingName);
            Assert.That(folder1PostCandidates.Count, Is.EqualTo(1));
            Assert.That(folder1PostCandidates[0].ID, Is.EqualTo(folder1.ID));

            List<InventoryFolderBase> folder2PostCandidates
                = InventoryArchiveUtils.FindFoldersByPath(scene.InventoryService, folder1PostCandidates[0], "b");
            Assert.That(folder2PostCandidates.Count, Is.EqualTo(1));
        }
Exemplo n.º 4
0
        public void TestPartExistingIarPath()
        {
            TestHelpers.InMethod();
            //log4net.Config.XmlConfigurator.Configure();

            Scene       scene = new SceneHelpers().SetupScene();
            UserAccount ua1   = UserAccountHelpers.CreateUserWithInventory(scene);

            string folder1ExistingName = "a";
            string folder2Name         = "b";

            InventoryFolderBase folder1
                = UserInventoryHelpers.CreateInventoryFolder(
                      scene.InventoryService, ua1.PrincipalID, folder1ExistingName, false);

            string folder1ArchiveName = InventoryArchiveWriteRequest.CreateArchiveFolderName(folder1ExistingName, UUID.Random());
            string folder2ArchiveName = InventoryArchiveWriteRequest.CreateArchiveFolderName(folder2Name, UUID.Random());

            string itemArchivePath = string.Join("", new string[] { folder1ArchiveName, folder2ArchiveName });

            new InventoryArchiveReadRequest(UUID.Random(), null, scene.InventoryService, scene.AssetService, scene.UserAccountService, ua1, null, (Stream)null, false)
            .ReplicateArchivePathToUserInventory(
                itemArchivePath, scene.InventoryService.GetRootFolder(ua1.PrincipalID),
                new Dictionary <string, InventoryFolderBase>(), new HashSet <InventoryNodeBase>());

            List <InventoryFolderBase> folder1PostCandidates
                = InventoryArchiveUtils.FindFoldersByPath(scene.InventoryService, ua1.PrincipalID, folder1ExistingName);

            Assert.That(folder1PostCandidates.Count, Is.EqualTo(2));

            // FIXME: Temporarily, we're going to do something messy to make sure we pick up the created folder.
            InventoryFolderBase folder1Post = null;

            foreach (InventoryFolderBase folder in folder1PostCandidates)
            {
                if (folder.ID != folder1.ID)
                {
                    folder1Post = folder;
                    break;
                }
            }
//            Assert.That(folder1Post.ID, Is.EqualTo(folder1.ID));

            List <InventoryFolderBase> folder2PostCandidates
                = InventoryArchiveUtils.FindFoldersByPath(scene.InventoryService, folder1Post, "b");

            Assert.That(folder2PostCandidates.Count, Is.EqualTo(1));
        }
Exemplo n.º 5
0
        public void TestLoadIarToInventoryPaths()
        {
            TestHelpers.InMethod();
//            log4net.Config.XmlConfigurator.Configure();

            SerialiserModule        serialiserModule = new SerialiserModule();
            InventoryArchiverModule archiverModule   = new InventoryArchiverModule();

            // Annoyingly, we have to set up a scene even though inventory loading has nothing to do with a scene
            Scene scene = new SceneHelpers().SetupScene();

            SceneHelpers.SetupSceneModules(scene, serialiserModule, archiverModule);

            UserAccountHelpers.CreateUserWithInventory(scene, m_uaMT, "meowfood");
            UserAccountHelpers.CreateUserWithInventory(scene, m_uaLL1, "hampshire");

            archiverModule.DearchiveInventory(UUID.Random(), m_uaMT.FirstName, m_uaMT.LastName, "/", "meowfood", m_iarStream);
            InventoryItemBase foundItem1
                = InventoryArchiveUtils.FindItemByPath(scene.InventoryService, m_uaMT.PrincipalID, m_item1Name);

            Assert.That(foundItem1, Is.Not.Null, "Didn't find loaded item 1");

            // Now try loading to a root child folder
            UserInventoryHelpers.CreateInventoryFolder(scene.InventoryService, m_uaMT.PrincipalID, "xA", false);
            MemoryStream archiveReadStream = new MemoryStream(m_iarStream.ToArray());

            archiverModule.DearchiveInventory(UUID.Random(), m_uaMT.FirstName, m_uaMT.LastName, "xA", "meowfood", archiveReadStream);

            InventoryItemBase foundItem2
                = InventoryArchiveUtils.FindItemByPath(scene.InventoryService, m_uaMT.PrincipalID, "xA/" + m_item1Name);

            Assert.That(foundItem2, Is.Not.Null, "Didn't find loaded item 2");

            // Now try loading to a more deeply nested folder
            UserInventoryHelpers.CreateInventoryFolder(scene.InventoryService, m_uaMT.PrincipalID, "xB/xC", false);
            archiveReadStream = new MemoryStream(archiveReadStream.ToArray());
            archiverModule.DearchiveInventory(UUID.Random(), m_uaMT.FirstName, m_uaMT.LastName, "xB/xC", "meowfood", archiveReadStream);

            InventoryItemBase foundItem3
                = InventoryArchiveUtils.FindItemByPath(scene.InventoryService, m_uaMT.PrincipalID, "xB/xC/" + m_item1Name);

            Assert.That(foundItem3, Is.Not.Null, "Didn't find loaded item 3");
        }
        public void TestDeleteSceneObjectAsyncToUserInventory()
        {
            TestHelpers.InMethod();
//            TestHelpers.EnableLogging();

            UUID   agentId      = UUID.Parse("00000000-0000-0000-0000-000000000001");
            string myObjectName = "Fred";

            TestScene scene = new SceneHelpers().SetupScene();

            IConfigSource configSource = new IniConfigSource();
            IConfig       config       = configSource.AddConfig("Modules");

            config.Set("InventoryAccessModule", "BasicInventoryAccessModule");
            SceneHelpers.SetupSceneModules(
                scene, configSource, new object[] { new BasicInventoryAccessModule() });

            SceneHelpers.SetupSceneModules(scene, new object[] { });

            // Turn off the timer on the async sog deleter - we'll crank it by hand for this test.
            AsyncSceneObjectGroupDeleter sogd = scene.SceneObjectGroupDeleter;

            sogd.Enabled = false;

            SceneObjectGroup so = SceneHelpers.AddSceneObject(scene, myObjectName, agentId);

            UserAccount         ua = UserAccountHelpers.CreateUserWithInventory(scene, agentId);
            InventoryFolderBase folder1
                = UserInventoryHelpers.CreateInventoryFolder(scene.InventoryService, ua.PrincipalID, "folder1", false);

            IClientAPI client = SceneHelpers.AddScenePresence(scene, agentId).ControllingClient;

            scene.DeRezObjects(client, new List <uint>()
            {
                so.LocalId
            }, UUID.Zero, DeRezAction.Take, folder1.ID);

//            SceneObjectPart retrievedPart = scene.GetSceneObjectPart(so.LocalId);

//            Assert.That(retrievedPart, Is.Not.Null);
//            Assert.That(so.IsDeleted, Is.False);

            sogd.InventoryDeQueueAndDelete();

            Assert.That(so.IsDeleted, Is.True);

            SceneObjectPart retrievedPart2 = scene.GetSceneObjectPart(so.LocalId);

            Assert.That(retrievedPart2, Is.Null);

//            SceneSetupHelpers.DeleteSceneObjectAsync(scene, part, DeRezAction.Take, userInfo.RootFolder.ID, client);

            InventoryItemBase retrievedItem
                = UserInventoryHelpers.GetInventoryItem(
                      scene.InventoryService, ua.PrincipalID, "folder1/" + myObjectName);

            // Check that we now have the taken part in our inventory
            Assert.That(retrievedItem, Is.Not.Null);

            // Check that the taken part has actually disappeared
//            SceneObjectPart retrievedPart = scene.GetSceneObjectPart(part.LocalId);
//            Assert.That(retrievedPart, Is.Null);
        }
Exemplo n.º 7
0
        public void TestRejectGivenFolder()
        {
            TestHelpers.InMethod();
            //            TestHelpers.EnableLogging();

            UUID initialSessionId = TestHelpers.ParseTail(0x10);
            UUID folderId         = TestHelpers.ParseTail(0x100);

            UserAccount ua1
                = UserAccountHelpers.CreateUserWithInventory(m_scene, "User", "One", TestHelpers.ParseTail(0x1), "pw");
            UserAccount ua2
                = UserAccountHelpers.CreateUserWithInventory(m_scene, "User", "Two", TestHelpers.ParseTail(0x2), "pw");

            ScenePresence giverSp     = SceneHelpers.AddScenePresence(m_scene, ua1);
            TestClient    giverClient = (TestClient)giverSp.ControllingClient;

            ScenePresence receiverSp     = SceneHelpers.AddScenePresence(m_scene, ua2);
            TestClient    receiverClient = (TestClient)receiverSp.ControllingClient;

            // Create the folder to test give
            InventoryFolderBase originalFolder
                = UserInventoryHelpers.CreateInventoryFolder(
                      m_scene.InventoryService, giverSp.UUID, folderId, "f1", true);

            GridInstantMessage receivedIm = null;

            receiverClient.OnReceivedInstantMessage += im => receivedIm = im;

            byte[] giveImBinaryBucket = new byte[17];
            giveImBinaryBucket[0] = (byte)AssetType.Folder;
            byte[] itemIdBytes = folderId.GetBytes();
            Array.Copy(itemIdBytes, 0, giveImBinaryBucket, 1, itemIdBytes.Length);

            GridInstantMessage giveIm
                = new GridInstantMessage(
                      m_scene,
                      giverSp.UUID,
                      giverSp.Name,
                      receiverSp.UUID,
                      (byte)InstantMessageDialog.InventoryOffered,
                      false,
                      "inventory offered msg",
                      initialSessionId,
                      false,
                      Vector3.Zero,
                      giveImBinaryBucket,
                      true);

            giverClient.HandleImprovedInstantMessage(giveIm);

            // These details might not all be correct.
            // Session ID is now the created item ID (!)
            GridInstantMessage rejectIm
                = new GridInstantMessage(
                      m_scene,
                      receiverSp.UUID,
                      receiverSp.Name,
                      giverSp.UUID,
                      (byte)InstantMessageDialog.InventoryDeclined,
                      false,
                      "inventory declined msg",
                      new UUID(receivedIm.imSessionID),
                      false,
                      Vector3.Zero,
                      null,
                      true);

            receiverClient.HandleImprovedInstantMessage(rejectIm);

            // Test for item remaining in the giver's inventory (here we assume a copy item)
            // TODO: Test no-copy items.
            InventoryFolderBase originalFolderAfterGive
                = UserInventoryHelpers.GetInventoryFolder(m_scene.InventoryService, giverSp.UUID, "f1");

            Assert.That(originalFolderAfterGive, Is.Not.Null);
            Assert.That(originalFolderAfterGive.ID, Is.EqualTo(originalFolder.ID));

            // Test for folder successfully making it into the receiver's inventory
            InventoryFolderBase receivedFolder
                = UserInventoryHelpers.GetInventoryFolder(m_scene.InventoryService, receiverSp.UUID, "Trash/f1");

            InventoryFolderBase trashFolder
                = m_scene.InventoryService.GetFolderForType(receiverSp.UUID, FolderType.Trash);

            Assert.That(receivedFolder, Is.Not.Null);
            Assert.That(receivedFolder.ID, Is.Not.EqualTo(originalFolder.ID));
            Assert.That(receivedFolder.ParentID, Is.EqualTo(trashFolder.ID));

            // Test that on a delete, item still exists and is accessible for the giver.
            m_scene.InventoryService.PurgeFolder(trashFolder);

            InventoryFolderBase originalFolderAfterDelete
                = UserInventoryHelpers.GetInventoryFolder(m_scene.InventoryService, giverSp.UUID, "f1");

            Assert.That(originalFolderAfterDelete, Is.Not.Null);
        }
Exemplo n.º 8
0
        public void TestAcceptGivenFolder()
        {
            TestHelpers.InMethod();
            //            TestHelpers.EnableLogging();

            UUID initialSessionId = TestHelpers.ParseTail(0x10);
            UUID folderId         = TestHelpers.ParseTail(0x100);

            UserAccount ua1
                = UserAccountHelpers.CreateUserWithInventory(m_scene, "User", "One", TestHelpers.ParseTail(0x1), "pw");
            UserAccount ua2
                = UserAccountHelpers.CreateUserWithInventory(m_scene, "User", "Two", TestHelpers.ParseTail(0x2), "pw");

            ScenePresence giverSp     = SceneHelpers.AddScenePresence(m_scene, ua1);
            TestClient    giverClient = (TestClient)giverSp.ControllingClient;

            ScenePresence receiverSp     = SceneHelpers.AddScenePresence(m_scene, ua2);
            TestClient    receiverClient = (TestClient)receiverSp.ControllingClient;

            InventoryFolderBase originalFolder
                = UserInventoryHelpers.CreateInventoryFolder(
                      m_scene.InventoryService, giverSp.UUID, folderId, "f1", true);

            byte[] giveImBinaryBucket = new byte[17];
            giveImBinaryBucket[0] = (byte)AssetType.Folder;
            byte[] itemIdBytes = folderId.GetBytes();
            Array.Copy(itemIdBytes, 0, giveImBinaryBucket, 1, itemIdBytes.Length);

            GridInstantMessage giveIm
                = new GridInstantMessage(
                      m_scene,
                      giverSp.UUID,
                      giverSp.Name,
                      receiverSp.UUID,
                      (byte)InstantMessageDialog.InventoryOffered,
                      false,
                      "inventory offered msg",
                      initialSessionId,
                      false,
                      Vector3.Zero,
                      giveImBinaryBucket,
                      true);

            giverClient.HandleImprovedInstantMessage(giveIm);

            // These details might not all be correct.
            GridInstantMessage acceptIm
                = new GridInstantMessage(
                      m_scene,
                      receiverSp.UUID,
                      receiverSp.Name,
                      giverSp.UUID,
                      (byte)InstantMessageDialog.InventoryAccepted,
                      false,
                      "inventory accepted msg",
                      initialSessionId,
                      false,
                      Vector3.Zero,
                      null,
                      true);

            receiverClient.HandleImprovedInstantMessage(acceptIm);

            // Test for item remaining in the giver's inventory (here we assume a copy item)
            // TODO: Test no-copy items.
            InventoryFolderBase originalFolderAfterGive
                = UserInventoryHelpers.GetInventoryFolder(m_scene.InventoryService, giverSp.UUID, "f1");

            Assert.That(originalFolderAfterGive, Is.Not.Null);
            Assert.That(originalFolderAfterGive.ID, Is.EqualTo(originalFolder.ID));

            // Test for item successfully making it into the receiver's inventory
            InventoryFolderBase receivedFolder
                = UserInventoryHelpers.GetInventoryFolder(m_scene.InventoryService, receiverSp.UUID, "f1");

            Assert.That(receivedFolder, Is.Not.Null);
            Assert.That(receivedFolder.ID, Is.Not.EqualTo(originalFolder.ID));

            // Test that on a delete, item still exists and is accessible for the giver.
            m_scene.InventoryService.DeleteFolders(receiverSp.UUID, new List <UUID>()
            {
                receivedFolder.ID
            });

            InventoryFolderBase originalFolderAfterDelete
                = UserInventoryHelpers.GetInventoryFolder(m_scene.InventoryService, giverSp.UUID, "f1");

            Assert.That(originalFolderAfterDelete, Is.Not.Null);

            // TODO: Test scenario where giver deletes their item first.
        }
Exemplo n.º 9
0
        public void TestSaveNonRootFolderToIar()
        {
            TestHelpers.InMethod();
//            TestHelpers.EnableLogging();

            string userFirstName = "Jock";
            string userLastName  = "Stirrup";
            string userPassword  = "******";
            UUID   userId        = TestHelpers.ParseTail(0x20);

            UserAccountHelpers.CreateUserWithInventory(m_scene, userFirstName, userLastName, userId, userPassword);

            // Create base folder
            InventoryFolderBase f1
                = UserInventoryHelpers.CreateInventoryFolder(m_scene.InventoryService, userId, "f1", true);

            // Create item1
            SceneObjectGroup  so1 = SceneHelpers.CreateSceneObject(1, userId, "My Little Dog Object", 0x5);
            InventoryItemBase i1  = UserInventoryHelpers.AddInventoryItem(m_scene, so1, 0x50, 0x60, "f1");

            // Create embedded folder
            InventoryFolderBase f1_1
                = UserInventoryHelpers.CreateInventoryFolder(m_scene.InventoryService, userId, "f1/f1.1", true);

            // Create embedded item
            SceneObjectGroup  so1_1 = SceneHelpers.CreateSceneObject(1, userId, "My Little Cat Object", 0x6);
            InventoryItemBase i2    = UserInventoryHelpers.AddInventoryItem(m_scene, so1_1, 0x500, 0x600, "f1/f1.1");

            MemoryStream archiveWriteStream = new MemoryStream();

            m_archiverModule.OnInventoryArchiveSaved += SaveCompleted;

            mre.Reset();
            m_archiverModule.ArchiveInventory(
                Guid.NewGuid(), userFirstName, userLastName, "f1", userPassword, archiveWriteStream);
            mre.WaitOne(60000, false);

            // Test created iar
            byte[]           archive           = archiveWriteStream.ToArray();
            MemoryStream     archiveReadStream = new MemoryStream(archive);
            TarArchiveReader tar = new TarArchiveReader(archiveReadStream);

//            InventoryArchiveUtils.
            bool gotf1 = false, gotf1_1 = false, gotso1 = false, gotso2 = false;

            string f1FileName
                = string.Format("{0}{1}", ArchiveConstants.INVENTORY_PATH, InventoryArchiveWriteRequest.CreateArchiveFolderName(f1));
            string f1_1FileName
                = string.Format("{0}{1}", f1FileName, InventoryArchiveWriteRequest.CreateArchiveFolderName(f1_1));
            string so1FileName
                = string.Format("{0}{1}", f1FileName, InventoryArchiveWriteRequest.CreateArchiveItemName(i1));
            string so2FileName
                = string.Format("{0}{1}", f1_1FileName, InventoryArchiveWriteRequest.CreateArchiveItemName(i2));

            string filePath;

            TarArchiveReader.TarEntryType tarEntryType;

            while (tar.ReadEntry(out filePath, out tarEntryType) != null)
            {
//                Console.WriteLine("Got {0}", filePath);

                if (filePath == f1FileName)
                {
                    gotf1 = true;
                }
                else if (filePath == f1_1FileName)
                {
                    gotf1_1 = true;
                }
                else if (filePath == so1FileName)
                {
                    gotso1 = true;
                }
                else if (filePath == so2FileName)
                {
                    gotso2 = true;
                }
            }

//            Assert.That(gotControlFile, Is.True, "No control file in archive");
            Assert.That(gotf1, Is.True);
            Assert.That(gotf1_1, Is.True);
            Assert.That(gotso1, Is.True);
            Assert.That(gotso2, Is.True);

            // TODO: Test presence of more files and contents of files.
        }