diff options
Diffstat (limited to 'OpenSim/Tests/Common/Helpers')
-rw-r--r-- | OpenSim/Tests/Common/Helpers/EntityTransferHelpers.cs | 91 | ||||
-rw-r--r-- | OpenSim/Tests/Common/Helpers/SceneHelpers.cs | 39 | ||||
-rw-r--r-- | OpenSim/Tests/Common/Helpers/TaskInventoryHelpers.cs | 32 | ||||
-rw-r--r-- | OpenSim/Tests/Common/Helpers/UserInventoryHelpers.cs | 109 |
4 files changed, 238 insertions, 33 deletions
diff --git a/OpenSim/Tests/Common/Helpers/EntityTransferHelpers.cs b/OpenSim/Tests/Common/Helpers/EntityTransferHelpers.cs new file mode 100644 index 0000000..6cc7ff2 --- /dev/null +++ b/OpenSim/Tests/Common/Helpers/EntityTransferHelpers.cs | |||
@@ -0,0 +1,91 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.IO; | ||
31 | using System.Net; | ||
32 | using System.Reflection; | ||
33 | using System.Text; | ||
34 | using log4net; | ||
35 | using Nini.Config; | ||
36 | using NUnit.Framework; | ||
37 | using OpenMetaverse; | ||
38 | using OpenSim.Framework; | ||
39 | using OpenSim.Framework.Communications; | ||
40 | using OpenSim.Framework.Servers; | ||
41 | using OpenSim.Region.Framework.Interfaces; | ||
42 | using OpenSim.Region.Framework.Scenes; | ||
43 | using OpenSim.Region.CoreModules.Framework; | ||
44 | using OpenSim.Tests.Common; | ||
45 | using OpenSim.Tests.Common.Mock; | ||
46 | |||
47 | namespace OpenSim.Tests.Common | ||
48 | { | ||
49 | public static class EntityTransferHelpers | ||
50 | { | ||
51 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
52 | |||
53 | /// <summary> | ||
54 | /// Set up correct handling of the InformClientOfNeighbour call from the source region that triggers the | ||
55 | /// viewer to setup a connection with the destination region. | ||
56 | /// </summary> | ||
57 | /// <param name='tc'></param> | ||
58 | /// <param name='neighbourTcs'> | ||
59 | /// A list that will be populated with any TestClients set up in response to | ||
60 | /// being informed about a destination region. | ||
61 | /// </param> | ||
62 | public static void SetUpInformClientOfNeighbour(TestClient tc, List<TestClient> neighbourTcs) | ||
63 | { | ||
64 | // XXX: Confusingly, this is also used for non-neighbour notification (as in teleports that do not use the | ||
65 | // event queue). | ||
66 | |||
67 | tc.OnTestClientInformClientOfNeighbour += (neighbourHandle, neighbourExternalEndPoint) => | ||
68 | { | ||
69 | uint x, y; | ||
70 | Utils.LongToUInts(neighbourHandle, out x, out y); | ||
71 | x /= Constants.RegionSize; | ||
72 | y /= Constants.RegionSize; | ||
73 | |||
74 | m_log.DebugFormat( | ||
75 | "[TEST CLIENT]: Processing inform client of neighbour located at {0},{1} at {2}", | ||
76 | x, y, neighbourExternalEndPoint); | ||
77 | |||
78 | // In response to this message, we are going to make a teleport to the scene we've previous been told | ||
79 | // about by test code (this needs to be improved). | ||
80 | AgentCircuitData newAgent = tc.RequestClientInfo(); | ||
81 | |||
82 | Scene neighbourScene; | ||
83 | SceneManager.Instance.TryGetScene(x, y, out neighbourScene); | ||
84 | |||
85 | TestClient neighbourTc = new TestClient(newAgent, neighbourScene, SceneManager.Instance); | ||
86 | neighbourTcs.Add(neighbourTc); | ||
87 | neighbourScene.AddNewClient(neighbourTc, PresenceType.User); | ||
88 | }; | ||
89 | } | ||
90 | } | ||
91 | } \ No newline at end of file | ||
diff --git a/OpenSim/Tests/Common/Helpers/SceneHelpers.cs b/OpenSim/Tests/Common/Helpers/SceneHelpers.cs index ea3e348..bdd9093 100644 --- a/OpenSim/Tests/Common/Helpers/SceneHelpers.cs +++ b/OpenSim/Tests/Common/Helpers/SceneHelpers.cs | |||
@@ -139,7 +139,7 @@ namespace OpenSim.Tests.Common | |||
139 | SceneCommunicationService scs = new SceneCommunicationService(); | 139 | SceneCommunicationService scs = new SceneCommunicationService(); |
140 | 140 | ||
141 | TestScene testScene = new TestScene( | 141 | TestScene testScene = new TestScene( |
142 | regInfo, m_acm, scs, m_simDataService, m_estateDataService, false, configSource, null); | 142 | regInfo, m_acm, scs, m_simDataService, m_estateDataService, configSource, null); |
143 | 143 | ||
144 | INonSharedRegionModule godsModule = new GodsModule(); | 144 | INonSharedRegionModule godsModule = new GodsModule(); |
145 | godsModule.Initialise(new IniConfigSource()); | 145 | godsModule.Initialise(new IniConfigSource()); |
@@ -532,6 +532,31 @@ namespace OpenSim.Tests.Common | |||
532 | /// <returns></returns> | 532 | /// <returns></returns> |
533 | public static ScenePresence AddScenePresence(Scene scene, AgentCircuitData agentData, SceneManager sceneManager) | 533 | public static ScenePresence AddScenePresence(Scene scene, AgentCircuitData agentData, SceneManager sceneManager) |
534 | { | 534 | { |
535 | return AddScenePresence(scene, new TestClient(agentData, scene, sceneManager), agentData, sceneManager); | ||
536 | } | ||
537 | |||
538 | /// <summary> | ||
539 | /// Add a root agent. | ||
540 | /// </summary> | ||
541 | /// <remarks> | ||
542 | /// This function | ||
543 | /// | ||
544 | /// 1) Tells the scene that an agent is coming. Normally, the login service (local if standalone, from the | ||
545 | /// userserver if grid) would give initial login data back to the client and separately tell the scene that the | ||
546 | /// agent was coming. | ||
547 | /// | ||
548 | /// 2) Connects the agent with the scene | ||
549 | /// | ||
550 | /// This function performs actions equivalent with notifying the scene that an agent is | ||
551 | /// coming and then actually connecting the agent to the scene. The one step missed out is the very first | ||
552 | /// </remarks> | ||
553 | /// <param name="scene"></param> | ||
554 | /// <param name="agentData"></param> | ||
555 | /// <param name="sceneManager"></param> | ||
556 | /// <returns></returns> | ||
557 | public static ScenePresence AddScenePresence( | ||
558 | Scene scene, IClientAPI client, AgentCircuitData agentData, SceneManager sceneManager) | ||
559 | { | ||
535 | // We emulate the proper login sequence here by doing things in four stages | 560 | // We emulate the proper login sequence here by doing things in four stages |
536 | 561 | ||
537 | // Stage 0: login | 562 | // Stage 0: login |
@@ -541,7 +566,7 @@ namespace OpenSim.Tests.Common | |||
541 | lpsc.m_PresenceService.LoginAgent(agentData.AgentID.ToString(), agentData.SessionID, agentData.SecureSessionID); | 566 | lpsc.m_PresenceService.LoginAgent(agentData.AgentID.ToString(), agentData.SessionID, agentData.SecureSessionID); |
542 | 567 | ||
543 | // Stages 1 & 2 | 568 | // Stages 1 & 2 |
544 | ScenePresence sp = IntroduceClientToScene(scene, sceneManager, agentData, TeleportFlags.ViaLogin); | 569 | ScenePresence sp = IntroduceClientToScene(scene, client, agentData, TeleportFlags.ViaLogin); |
545 | 570 | ||
546 | // Stage 3: Complete the entrance into the region. This converts the child agent into a root agent. | 571 | // Stage 3: Complete the entrance into the region. This converts the child agent into a root agent. |
547 | sp.CompleteMovement(sp.ControllingClient, true); | 572 | sp.CompleteMovement(sp.ControllingClient, true); |
@@ -558,11 +583,11 @@ namespace OpenSim.Tests.Common | |||
558 | /// neighbours and where no teleporting takes place. | 583 | /// neighbours and where no teleporting takes place. |
559 | /// </param> | 584 | /// </param> |
560 | /// <param name='scene'></param> | 585 | /// <param name='scene'></param> |
561 | /// <param name='sceneManager></param> | 586 | /// <param name='testClient'></param> |
562 | /// <param name='agentData'></param> | 587 | /// <param name='agentData'></param> |
563 | /// <param name='tf'></param> | 588 | /// <param name='tf'></param> |
564 | private static ScenePresence IntroduceClientToScene( | 589 | private static ScenePresence IntroduceClientToScene( |
565 | Scene scene, SceneManager sceneManager, AgentCircuitData agentData, TeleportFlags tf) | 590 | Scene scene, IClientAPI client, AgentCircuitData agentData, TeleportFlags tf) |
566 | { | 591 | { |
567 | string reason; | 592 | string reason; |
568 | 593 | ||
@@ -571,10 +596,9 @@ namespace OpenSim.Tests.Common | |||
571 | Console.WriteLine("NewUserConnection failed: " + reason); | 596 | Console.WriteLine("NewUserConnection failed: " + reason); |
572 | 597 | ||
573 | // Stage 2: add the new client as a child agent to the scene | 598 | // Stage 2: add the new client as a child agent to the scene |
574 | TestClient client = new TestClient(agentData, scene, sceneManager); | ||
575 | scene.AddNewClient(client, PresenceType.User); | 599 | scene.AddNewClient(client, PresenceType.User); |
576 | 600 | ||
577 | return scene.GetScenePresence(agentData.AgentID); | 601 | return scene.GetScenePresence(client.AgentId); |
578 | } | 602 | } |
579 | 603 | ||
580 | public static ScenePresence AddChildScenePresence(Scene scene, UUID agentId) | 604 | public static ScenePresence AddChildScenePresence(Scene scene, UUID agentId) |
@@ -583,7 +607,8 @@ namespace OpenSim.Tests.Common | |||
583 | acd.child = true; | 607 | acd.child = true; |
584 | 608 | ||
585 | // XXX: ViaLogin may not be correct for child agents | 609 | // XXX: ViaLogin may not be correct for child agents |
586 | return IntroduceClientToScene(scene, null, acd, TeleportFlags.ViaLogin); | 610 | TestClient client = new TestClient(acd, scene, null); |
611 | return IntroduceClientToScene(scene, client, acd, TeleportFlags.ViaLogin); | ||
587 | } | 612 | } |
588 | 613 | ||
589 | /// <summary> | 614 | /// <summary> |
diff --git a/OpenSim/Tests/Common/Helpers/TaskInventoryHelpers.cs b/OpenSim/Tests/Common/Helpers/TaskInventoryHelpers.cs index 0a2b30a..bb4b55f 100644 --- a/OpenSim/Tests/Common/Helpers/TaskInventoryHelpers.cs +++ b/OpenSim/Tests/Common/Helpers/TaskInventoryHelpers.cs | |||
@@ -46,13 +46,32 @@ namespace OpenSim.Tests.Common | |||
46 | /// <param name="scene"></param> | 46 | /// <param name="scene"></param> |
47 | /// <param name="part"></param> | 47 | /// <param name="part"></param> |
48 | /// <param name="itemName"></param> | 48 | /// <param name="itemName"></param> |
49 | /// <param name="itemIDFrag">UUID or UUID stem</param> | ||
50 | /// <param name="assetIDFrag">UUID or UUID stem</param> | ||
51 | /// <param name="text">The tex to put in the notecard.</param> | ||
52 | /// <returns>The item that was added</returns> | ||
53 | public static TaskInventoryItem AddNotecard( | ||
54 | Scene scene, SceneObjectPart part, string itemName, string itemIDStem, string assetIDStem, string text) | ||
55 | { | ||
56 | return AddNotecard( | ||
57 | scene, part, itemName, TestHelpers.ParseStem(itemIDStem), TestHelpers.ParseStem(assetIDStem), text); | ||
58 | } | ||
59 | |||
60 | /// <summary> | ||
61 | /// Add a notecard item to the given part. | ||
62 | /// </summary> | ||
63 | /// <param name="scene"></param> | ||
64 | /// <param name="part"></param> | ||
65 | /// <param name="itemName"></param> | ||
49 | /// <param name="itemID"></param> | 66 | /// <param name="itemID"></param> |
50 | /// <param name="assetID"></param> | 67 | /// <param name="assetID"></param> |
68 | /// <param name="text">The tex to put in the notecard.</param> | ||
51 | /// <returns>The item that was added</returns> | 69 | /// <returns>The item that was added</returns> |
52 | public static TaskInventoryItem AddNotecard(Scene scene, SceneObjectPart part, string itemName, UUID itemID, UUID assetID) | 70 | public static TaskInventoryItem AddNotecard( |
71 | Scene scene, SceneObjectPart part, string itemName, UUID itemID, UUID assetID, string text) | ||
53 | { | 72 | { |
54 | AssetNotecard nc = new AssetNotecard(); | 73 | AssetNotecard nc = new AssetNotecard(); |
55 | nc.BodyText = "Hello World!"; | 74 | nc.BodyText = text; |
56 | nc.Encode(); | 75 | nc.Encode(); |
57 | 76 | ||
58 | AssetBase ncAsset | 77 | AssetBase ncAsset |
@@ -87,8 +106,8 @@ namespace OpenSim.Tests.Common | |||
87 | /// Add a simple script to the given part. | 106 | /// Add a simple script to the given part. |
88 | /// </summary> | 107 | /// </summary> |
89 | /// <remarks> | 108 | /// <remarks> |
90 | /// TODO: Accept input for item and asset IDs to avoid mysterious script failures that try to use any of these | 109 | /// TODO: Accept input for item and asset IDs so that we have completely replicatable regression tests rather |
91 | /// functions more than once in a test. | 110 | /// than a random component. |
92 | /// </remarks> | 111 | /// </remarks> |
93 | /// <param name="scene"></param> | 112 | /// <param name="scene"></param> |
94 | /// <param name="part"></param> | 113 | /// <param name="part"></param> |
@@ -102,8 +121,9 @@ namespace OpenSim.Tests.Common | |||
102 | ast.Source = scriptSource; | 121 | ast.Source = scriptSource; |
103 | ast.Encode(); | 122 | ast.Encode(); |
104 | 123 | ||
105 | UUID assetUuid = new UUID("00000000-0000-0000-1000-000000000000"); | 124 | UUID assetUuid = UUID.Random(); |
106 | UUID itemUuid = new UUID("00000000-0000-0000-1100-000000000000"); | 125 | UUID itemUuid = UUID.Random(); |
126 | |||
107 | AssetBase asset | 127 | AssetBase asset |
108 | = AssetHelpers.CreateAsset(assetUuid, AssetType.LSLText, ast.AssetData, UUID.Zero); | 128 | = AssetHelpers.CreateAsset(assetUuid, AssetType.LSLText, ast.AssetData, UUID.Zero); |
109 | scene.AssetService.Store(asset); | 129 | scene.AssetService.Store(asset); |
diff --git a/OpenSim/Tests/Common/Helpers/UserInventoryHelpers.cs b/OpenSim/Tests/Common/Helpers/UserInventoryHelpers.cs index 87d9410..a1794c9 100644 --- a/OpenSim/Tests/Common/Helpers/UserInventoryHelpers.cs +++ b/OpenSim/Tests/Common/Helpers/UserInventoryHelpers.cs | |||
@@ -45,6 +45,9 @@ namespace OpenSim.Tests.Common | |||
45 | /// <summary> | 45 | /// <summary> |
46 | /// Add an existing scene object as an item in the user's inventory. | 46 | /// Add an existing scene object as an item in the user's inventory. |
47 | /// </summary> | 47 | /// </summary> |
48 | /// <remarks> | ||
49 | /// Will be added to the system Objects folder. | ||
50 | /// </remarks> | ||
48 | /// <param name='scene'></param> | 51 | /// <param name='scene'></param> |
49 | /// <param name='so'></param> | 52 | /// <param name='so'></param> |
50 | /// <param name='inventoryIdTail'></param> | 53 | /// <param name='inventoryIdTail'></param> |
@@ -63,7 +66,29 @@ namespace OpenSim.Tests.Common | |||
63 | } | 66 | } |
64 | 67 | ||
65 | /// <summary> | 68 | /// <summary> |
66 | /// Creates a notecard in the objects folder and specify an item id. | 69 | /// Add an existing scene object as an item in the user's inventory at the given path. |
70 | /// </summary> | ||
71 | /// <param name='scene'></param> | ||
72 | /// <param name='so'></param> | ||
73 | /// <param name='inventoryIdTail'></param> | ||
74 | /// <param name='assetIdTail'></param> | ||
75 | /// <returns>The inventory item created.</returns> | ||
76 | public static InventoryItemBase AddInventoryItem( | ||
77 | Scene scene, SceneObjectGroup so, int inventoryIdTail, int assetIdTail, string path) | ||
78 | { | ||
79 | return AddInventoryItem( | ||
80 | scene, | ||
81 | so.Name, | ||
82 | TestHelpers.ParseTail(inventoryIdTail), | ||
83 | InventoryType.Object, | ||
84 | AssetHelpers.CreateAsset(TestHelpers.ParseTail(assetIdTail), so), | ||
85 | so.OwnerID, | ||
86 | path); | ||
87 | } | ||
88 | |||
89 | /// <summary> | ||
90 | /// Adds the given item to the existing system folder for its type (e.g. an object will go in the "Objects" | ||
91 | /// folder). | ||
67 | /// </summary> | 92 | /// </summary> |
68 | /// <param name="scene"></param> | 93 | /// <param name="scene"></param> |
69 | /// <param name="itemName"></param> | 94 | /// <param name="itemName"></param> |
@@ -75,6 +100,25 @@ namespace OpenSim.Tests.Common | |||
75 | private static InventoryItemBase AddInventoryItem( | 100 | private static InventoryItemBase AddInventoryItem( |
76 | Scene scene, string itemName, UUID itemId, InventoryType itemType, AssetBase asset, UUID userId) | 101 | Scene scene, string itemName, UUID itemId, InventoryType itemType, AssetBase asset, UUID userId) |
77 | { | 102 | { |
103 | return AddInventoryItem( | ||
104 | scene, itemName, itemId, itemType, asset, userId, | ||
105 | scene.InventoryService.GetFolderForType(userId, (AssetType)asset.Type).Name); | ||
106 | } | ||
107 | |||
108 | /// <summary> | ||
109 | /// Adds the given item to an inventory folder | ||
110 | /// </summary> | ||
111 | /// <param name="scene"></param> | ||
112 | /// <param name="itemName"></param> | ||
113 | /// <param name="itemId"></param> | ||
114 | /// <param name="itemType"></param> | ||
115 | /// <param name="asset">The serialized asset for this item</param> | ||
116 | /// <param name="userId"></param> | ||
117 | /// <param name="path">Existing inventory path at which to add.</param> | ||
118 | /// <returns></returns> | ||
119 | private static InventoryItemBase AddInventoryItem( | ||
120 | Scene scene, string itemName, UUID itemId, InventoryType itemType, AssetBase asset, UUID userId, string path) | ||
121 | { | ||
78 | scene.AssetService.Store(asset); | 122 | scene.AssetService.Store(asset); |
79 | 123 | ||
80 | InventoryItemBase item = new InventoryItemBase(); | 124 | InventoryItemBase item = new InventoryItemBase(); |
@@ -85,7 +129,7 @@ namespace OpenSim.Tests.Common | |||
85 | item.AssetType = asset.Type; | 129 | item.AssetType = asset.Type; |
86 | item.InvType = (int)itemType; | 130 | item.InvType = (int)itemType; |
87 | 131 | ||
88 | InventoryFolderBase folder = scene.InventoryService.GetFolderForType(userId, (AssetType)asset.Type); | 132 | InventoryFolderBase folder = InventoryArchiveUtils.FindFoldersByPath(scene.InventoryService, userId, path)[0]; |
89 | 133 | ||
90 | item.Folder = folder.ID; | 134 | item.Folder = folder.ID; |
91 | scene.AddInventoryItem(item); | 135 | scene.AddInventoryItem(item); |
@@ -156,58 +200,83 @@ namespace OpenSim.Tests.Common | |||
156 | /// <summary> | 200 | /// <summary> |
157 | /// Create inventory folders starting from the user's root folder. | 201 | /// Create inventory folders starting from the user's root folder. |
158 | /// </summary> | 202 | /// </summary> |
159 | /// | ||
160 | /// Ignores any existing folders with the same name | ||
161 | /// | ||
162 | /// <param name="inventoryService"></param> | 203 | /// <param name="inventoryService"></param> |
163 | /// <param name="userId"></param> | 204 | /// <param name="userId"></param> |
164 | /// <param name="path"> | 205 | /// <param name="path"> |
165 | /// The folders to create. Multiple folders can be specified on a path delimited by the PATH_DELIMITER | 206 | /// The folders to create. Multiple folders can be specified on a path delimited by the PATH_DELIMITER |
166 | /// </param> | 207 | /// </param> |
208 | /// <param name="useExistingFolders"> | ||
209 | /// If true, then folders in the path which already the same name are | ||
210 | /// used. This applies to the terminal folder as well. | ||
211 | /// If false, then all folders in the path are created, even if there is already a folder at a particular | ||
212 | /// level with the same name. | ||
213 | /// </param> | ||
167 | /// <returns> | 214 | /// <returns> |
168 | /// The folder created. If the path contains multiple folders then the last one created is returned. | 215 | /// The folder created. If the path contains multiple folders then the last one created is returned. |
169 | /// Will return null if the root folder could not be found. | 216 | /// Will return null if the root folder could not be found. |
170 | /// </returns> | 217 | /// </returns> |
171 | public static InventoryFolderBase CreateInventoryFolder( | 218 | public static InventoryFolderBase CreateInventoryFolder( |
172 | IInventoryService inventoryService, UUID userId, string path) | 219 | IInventoryService inventoryService, UUID userId, string path, bool useExistingFolders) |
173 | { | 220 | { |
174 | InventoryFolderBase rootFolder = inventoryService.GetRootFolder(userId); | 221 | InventoryFolderBase rootFolder = inventoryService.GetRootFolder(userId); |
175 | 222 | ||
176 | if (null == rootFolder) | 223 | if (null == rootFolder) |
177 | return null; | 224 | return null; |
178 | 225 | ||
179 | return CreateInventoryFolder(inventoryService, rootFolder, path); | 226 | return CreateInventoryFolder(inventoryService, rootFolder, path, useExistingFolders); |
180 | } | 227 | } |
181 | 228 | ||
182 | /// <summary> | 229 | /// <summary> |
183 | /// Create inventory folders starting from a given parent folder | 230 | /// Create inventory folders starting from a given parent folder |
184 | /// </summary> | 231 | /// </summary> |
185 | /// | 232 | /// <remarks> |
186 | /// Ignores any existing folders with the same name | 233 | /// If any stem of the path names folders that already exist then these are not recreated. This includes the |
187 | /// | 234 | /// final folder. |
235 | /// TODO: May need to make it an option to create duplicate folders. | ||
236 | /// </remarks> | ||
188 | /// <param name="inventoryService"></param> | 237 | /// <param name="inventoryService"></param> |
189 | /// <param name="parentFolder"></param> | 238 | /// <param name="parentFolder"></param> |
190 | /// <param name="path"> | 239 | /// <param name="path"> |
191 | /// The folders to create. Multiple folders can be specified on a path delimited by the PATH_DELIMITER | 240 | /// The folder to create. |
241 | /// </param> | ||
242 | /// <param name="useExistingFolders"> | ||
243 | /// If true, then folders in the path which already the same name are | ||
244 | /// used. This applies to the terminal folder as well. | ||
245 | /// If false, then all folders in the path are created, even if there is already a folder at a particular | ||
246 | /// level with the same name. | ||
192 | /// </param> | 247 | /// </param> |
193 | /// <returns> | 248 | /// <returns> |
194 | /// The folder created. If the path contains multiple folders then the last one created is returned. | 249 | /// The folder created. If the path contains multiple folders then the last one created is returned. |
195 | /// </returns> | 250 | /// </returns> |
196 | public static InventoryFolderBase CreateInventoryFolder( | 251 | public static InventoryFolderBase CreateInventoryFolder( |
197 | IInventoryService inventoryService, InventoryFolderBase parentFolder, string path) | 252 | IInventoryService inventoryService, InventoryFolderBase parentFolder, string path, bool useExistingFolders) |
198 | { | 253 | { |
199 | string[] components = path.Split(new string[] { PATH_DELIMITER }, 2, StringSplitOptions.None); | 254 | string[] components = path.Split(new string[] { PATH_DELIMITER }, 2, StringSplitOptions.None); |
200 | 255 | ||
201 | InventoryFolderBase newFolder | 256 | InventoryFolderBase folder = null; |
202 | = new InventoryFolderBase( | 257 | |
203 | UUID.Random(), components[0], parentFolder.Owner, (short)AssetType.Unknown, parentFolder.ID, 0); | 258 | if (useExistingFolders) |
204 | 259 | folder = InventoryArchiveUtils.FindFolderByPath(inventoryService, parentFolder, components[0]); | |
205 | inventoryService.AddFolder(newFolder); | 260 | |
261 | if (folder == null) | ||
262 | { | ||
263 | // Console.WriteLine("Creating folder {0} at {1}", components[0], parentFolder.Name); | ||
264 | |||
265 | folder | ||
266 | = new InventoryFolderBase( | ||
267 | UUID.Random(), components[0], parentFolder.Owner, (short)AssetType.Unknown, parentFolder.ID, 0); | ||
268 | |||
269 | inventoryService.AddFolder(folder); | ||
270 | } | ||
271 | // else | ||
272 | // { | ||
273 | // Console.WriteLine("Found existing folder {0}", folder.Name); | ||
274 | // } | ||
206 | 275 | ||
207 | if (components.Length > 1) | 276 | if (components.Length > 1) |
208 | return CreateInventoryFolder(inventoryService, newFolder, components[1]); | 277 | return CreateInventoryFolder(inventoryService, folder, components[1], useExistingFolders); |
209 | else | 278 | else |
210 | return newFolder; | 279 | return folder; |
211 | } | 280 | } |
212 | 281 | ||
213 | /// <summary> | 282 | /// <summary> |
@@ -237,7 +306,7 @@ namespace OpenSim.Tests.Common | |||
237 | /// <returns>An empty list if no matching folders were found</returns> | 306 | /// <returns>An empty list if no matching folders were found</returns> |
238 | public static List<InventoryFolderBase> GetInventoryFolders(IInventoryService inventoryService, UUID userId, string path) | 307 | public static List<InventoryFolderBase> GetInventoryFolders(IInventoryService inventoryService, UUID userId, string path) |
239 | { | 308 | { |
240 | return InventoryArchiveUtils.FindFolderByPath(inventoryService, userId, path); | 309 | return InventoryArchiveUtils.FindFoldersByPath(inventoryService, userId, path); |
241 | } | 310 | } |
242 | 311 | ||
243 | /// <summary> | 312 | /// <summary> |