aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Tests/Common/Helpers
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Tests/Common/Helpers')
-rw-r--r--OpenSim/Tests/Common/Helpers/BaseRequestHandlerHelpers.cs1
-rw-r--r--OpenSim/Tests/Common/Helpers/ClientStackHelpers.cs95
-rw-r--r--OpenSim/Tests/Common/Helpers/EntityTransferHelpers.cs123
-rw-r--r--OpenSim/Tests/Common/Helpers/SceneHelpers.cs139
-rw-r--r--OpenSim/Tests/Common/Helpers/TaskInventoryHelpers.cs121
-rw-r--r--OpenSim/Tests/Common/Helpers/UserAccountHelpers.cs2
-rw-r--r--OpenSim/Tests/Common/Helpers/UserInventoryHelpers.cs142
7 files changed, 520 insertions, 103 deletions
diff --git a/OpenSim/Tests/Common/Helpers/BaseRequestHandlerHelpers.cs b/OpenSim/Tests/Common/Helpers/BaseRequestHandlerHelpers.cs
index 49c99c5..82ecf9a 100644
--- a/OpenSim/Tests/Common/Helpers/BaseRequestHandlerHelpers.cs
+++ b/OpenSim/Tests/Common/Helpers/BaseRequestHandlerHelpers.cs
@@ -32,7 +32,6 @@ using NUnit.Framework;
32using OpenSim.Framework; 32using OpenSim.Framework;
33using OpenSim.Framework.Servers; 33using OpenSim.Framework.Servers;
34using OpenSim.Framework.Servers.HttpServer; 34using OpenSim.Framework.Servers.HttpServer;
35using OpenSim.Tests.Common.Mock;
36 35
37namespace OpenSim.Tests.Common 36namespace OpenSim.Tests.Common
38{ 37{
diff --git a/OpenSim/Tests/Common/Helpers/ClientStackHelpers.cs b/OpenSim/Tests/Common/Helpers/ClientStackHelpers.cs
new file mode 100644
index 0000000..33cd8a2
--- /dev/null
+++ b/OpenSim/Tests/Common/Helpers/ClientStackHelpers.cs
@@ -0,0 +1,95 @@
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
28using System;
29using System.Net;
30using Nini.Config;
31using OpenMetaverse;
32using OpenMetaverse.Packets;
33using OpenSim.Framework;
34using OpenSim.Region.ClientStack.LindenUDP;
35using OpenSim.Region.Framework.Scenes;
36
37namespace OpenSim.Tests.Common
38{
39 /// <summary>
40 /// This class adds full UDP client classes and associated scene presence to scene.
41 /// </summary>
42 /// <remarks>
43 /// This is used for testing client stack code. For testing other code, use SceneHelper methods instead since
44 /// they operate without the burden of setting up UDP structures which should be unnecessary for testing scene
45 /// code.
46 /// </remarks>
47 public static class ClientStackHelpers
48 {
49 public static ScenePresence AddChildClient(
50 Scene scene, LLUDPServer udpServer, UUID agentId, UUID sessionId, uint circuitCode)
51 {
52 IPEndPoint testEp = new IPEndPoint(IPAddress.Loopback, 999);
53
54 UseCircuitCodePacket uccp = new UseCircuitCodePacket();
55
56 UseCircuitCodePacket.CircuitCodeBlock uccpCcBlock
57 = new UseCircuitCodePacket.CircuitCodeBlock();
58 uccpCcBlock.Code = circuitCode;
59 uccpCcBlock.ID = agentId;
60 uccpCcBlock.SessionID = sessionId;
61 uccp.CircuitCode = uccpCcBlock;
62
63 byte[] uccpBytes = uccp.ToBytes();
64 UDPPacketBuffer upb = new UDPPacketBuffer(testEp, uccpBytes.Length);
65 upb.DataLength = uccpBytes.Length; // God knows why this isn't set by the constructor.
66 Buffer.BlockCopy(uccpBytes, 0, upb.Data, 0, uccpBytes.Length);
67
68 AgentCircuitData acd = new AgentCircuitData();
69 acd.AgentID = agentId;
70 acd.SessionID = sessionId;
71
72 scene.AuthenticateHandler.AddNewCircuit(circuitCode, acd);
73
74 udpServer.PacketReceived(upb);
75
76 return scene.GetScenePresence(agentId);
77 }
78
79 public static TestLLUDPServer AddUdpServer(Scene scene)
80 {
81 return AddUdpServer(scene, new IniConfigSource());
82 }
83
84 public static TestLLUDPServer AddUdpServer(Scene scene, IniConfigSource configSource)
85 {
86 uint port = 0;
87 AgentCircuitManager acm = scene.AuthenticateHandler;
88
89 TestLLUDPServer udpServer = new TestLLUDPServer(IPAddress.Any, ref port, 0, false, configSource, acm);
90 udpServer.AddScene(scene);
91
92 return udpServer;
93 }
94 }
95} \ No newline at end of file
diff --git a/OpenSim/Tests/Common/Helpers/EntityTransferHelpers.cs b/OpenSim/Tests/Common/Helpers/EntityTransferHelpers.cs
new file mode 100644
index 0000000..b215f1e
--- /dev/null
+++ b/OpenSim/Tests/Common/Helpers/EntityTransferHelpers.cs
@@ -0,0 +1,123 @@
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
28using System;
29using System.Collections.Generic;
30using System.IO;
31using System.Net;
32using System.Reflection;
33using System.Text;
34using System.Threading;
35using log4net;
36using Nini.Config;
37using NUnit.Framework;
38using OpenMetaverse;
39using OpenSim.Framework;
40
41using OpenSim.Framework.Servers;
42using OpenSim.Region.Framework.Interfaces;
43using OpenSim.Region.Framework.Scenes;
44using OpenSim.Region.CoreModules.Framework;
45using OpenSim.Tests.Common;
46
47namespace 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 SetupInformClientOfNeighbourTriggersNeighbourClientCreate(
63 TestClient tc, List<TestClient> neighbourTcs)
64 {
65 // XXX: Confusingly, this is also used for non-neighbour notification (as in teleports that do not use the
66 // event queue).
67
68 tc.OnTestClientInformClientOfNeighbour += (neighbourHandle, neighbourExternalEndPoint) =>
69 {
70 uint x, y;
71 Util.RegionHandleToRegionLoc(neighbourHandle, out x, out y);
72
73 m_log.DebugFormat(
74 "[TEST CLIENT]: Processing inform client of neighbour located at {0},{1} at {2}",
75 x, y, neighbourExternalEndPoint);
76
77 AgentCircuitData newAgent = tc.RequestClientInfo();
78
79 Scene neighbourScene;
80 SceneManager.Instance.TryGetScene(x, y, out neighbourScene);
81
82 TestClient neighbourTc = new TestClient(newAgent, neighbourScene);
83 neighbourTcs.Add(neighbourTc);
84 neighbourScene.AddNewAgent(neighbourTc, PresenceType.User);
85 };
86 }
87
88 /// <summary>
89 /// Set up correct handling of the InformClientOfNeighbour call from the source region that triggers the
90 /// viewer to setup a connection with the destination region.
91 /// </summary>
92 /// <param name='tc'></param>
93 /// <param name='neighbourTcs'>
94 /// A list that will be populated with any TestClients set up in response to
95 /// being informed about a destination region.
96 /// </param>
97 public static void SetupSendRegionTeleportTriggersDestinationClientCreateAndCompleteMovement(
98 TestClient client, List<TestClient> destinationClients)
99 {
100 client.OnTestClientSendRegionTeleport
101 += (regionHandle, simAccess, regionExternalEndPoint, locationID, flags, capsURL) =>
102 {
103 uint x, y;
104 Util.RegionHandleToRegionLoc(regionHandle, out x, out y);
105
106 m_log.DebugFormat(
107 "[TEST CLIENT]: Processing send region teleport for destination at {0},{1} at {2}",
108 x, y, regionExternalEndPoint);
109
110 AgentCircuitData newAgent = client.RequestClientInfo();
111
112 Scene destinationScene;
113 SceneManager.Instance.TryGetScene(x, y, out destinationScene);
114
115 TestClient destinationClient = new TestClient(newAgent, destinationScene);
116 destinationClients.Add(destinationClient);
117 destinationScene.AddNewAgent(destinationClient, PresenceType.User);
118
119 ThreadPool.UnsafeQueueUserWorkItem(o => destinationClient.CompleteMovement(), null);
120 };
121 }
122 }
123} \ No newline at end of file
diff --git a/OpenSim/Tests/Common/Helpers/SceneHelpers.cs b/OpenSim/Tests/Common/Helpers/SceneHelpers.cs
index ea3e348..df8b14c 100644
--- a/OpenSim/Tests/Common/Helpers/SceneHelpers.cs
+++ b/OpenSim/Tests/Common/Helpers/SceneHelpers.cs
@@ -30,12 +30,13 @@ using System.Net;
30using System.Collections.Generic; 30using System.Collections.Generic;
31using Nini.Config; 31using Nini.Config;
32using OpenMetaverse; 32using OpenMetaverse;
33using OpenSim.Data.Null;
33using OpenSim.Framework; 34using OpenSim.Framework;
34using OpenSim.Framework.Communications; 35
35using OpenSim.Framework.Console; 36using OpenSim.Framework.Console;
36using OpenSim.Framework.Servers; 37using OpenSim.Framework.Servers;
37using OpenSim.Framework.Servers.HttpServer; 38using OpenSim.Framework.Servers.HttpServer;
38using OpenSim.Region.Physics.Manager; 39using OpenSim.Region.PhysicsModules.SharedBase;
39using OpenSim.Region.Framework; 40using OpenSim.Region.Framework;
40using OpenSim.Region.Framework.Interfaces; 41using OpenSim.Region.Framework.Interfaces;
41using OpenSim.Region.Framework.Scenes; 42using OpenSim.Region.Framework.Scenes;
@@ -47,8 +48,8 @@ using OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory;
47using OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid; 48using OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid;
48using OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts; 49using OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts;
49using OpenSim.Region.CoreModules.ServiceConnectorsOut.Presence; 50using OpenSim.Region.CoreModules.ServiceConnectorsOut.Presence;
51using OpenSim.Region.PhysicsModule.BasicPhysics;
50using OpenSim.Services.Interfaces; 52using OpenSim.Services.Interfaces;
51using OpenSim.Tests.Common.Mock;
52using GridRegion = OpenSim.Services.Interfaces.GridRegion; 53using GridRegion = OpenSim.Services.Interfaces.GridRegion;
53 54
54namespace OpenSim.Tests.Common 55namespace OpenSim.Tests.Common
@@ -63,9 +64,9 @@ namespace OpenSim.Tests.Common
63 /// </summary> 64 /// </summary>
64 public SceneManager SceneManager { get; private set; } 65 public SceneManager SceneManager { get; private set; }
65 66
67 public ISimulationDataService SimDataService { get; private set; }
68
66 private AgentCircuitManager m_acm = new AgentCircuitManager(); 69 private AgentCircuitManager m_acm = new AgentCircuitManager();
67 private ISimulationDataService m_simDataService
68 = OpenSim.Server.Base.ServerUtils.LoadPlugin<ISimulationDataService>("OpenSim.Tests.Common.dll", null);
69 private IEstateDataService m_estateDataService = null; 70 private IEstateDataService m_estateDataService = null;
70 71
71 private LocalAssetServicesConnector m_assetService; 72 private LocalAssetServicesConnector m_assetService;
@@ -77,6 +78,8 @@ namespace OpenSim.Tests.Common
77 78
78 private CoreAssetCache m_cache; 79 private CoreAssetCache m_cache;
79 80
81 private PhysicsScene m_physicsScene;
82
80 public SceneHelpers() : this(null) {} 83 public SceneHelpers() : this(null) {}
81 84
82 public SceneHelpers(CoreAssetCache cache) 85 public SceneHelpers(CoreAssetCache cache)
@@ -96,6 +99,11 @@ namespace OpenSim.Tests.Common
96 m_presenceService.PostInitialise(); 99 m_presenceService.PostInitialise();
97 100
98 m_cache = cache; 101 m_cache = cache;
102
103 m_physicsScene = StartPhysicsScene();
104
105 SimDataService
106 = OpenSim.Server.Base.ServerUtils.LoadPlugin<ISimulationDataService>("OpenSim.Tests.Common.dll", null);
99 } 107 }
100 108
101 /// <summary> 109 /// <summary>
@@ -115,6 +123,11 @@ namespace OpenSim.Tests.Common
115 return SetupScene(name, id, x, y, new IniConfigSource()); 123 return SetupScene(name, id, x, y, new IniConfigSource());
116 } 124 }
117 125
126 public TestScene SetupScene(string name, UUID id, uint x, uint y, IConfigSource configSource)
127 {
128 return SetupScene(name, id, x, y, Constants.RegionSize, Constants.RegionSize, configSource);
129 }
130
118 /// <summary> 131 /// <summary>
119 /// Set up a scene. 132 /// Set up a scene.
120 /// </summary> 133 /// </summary>
@@ -122,10 +135,12 @@ namespace OpenSim.Tests.Common
122 /// <param name="id">ID of the region</param> 135 /// <param name="id">ID of the region</param>
123 /// <param name="x">X co-ordinate of the region</param> 136 /// <param name="x">X co-ordinate of the region</param>
124 /// <param name="y">Y co-ordinate of the region</param> 137 /// <param name="y">Y co-ordinate of the region</param>
138 /// <param name="sizeX">X size of scene</param>
139 /// <param name="sizeY">Y size of scene</param>
125 /// <param name="configSource"></param> 140 /// <param name="configSource"></param>
126 /// <returns></returns> 141 /// <returns></returns>
127 public TestScene SetupScene( 142 public TestScene SetupScene(
128 string name, UUID id, uint x, uint y, IConfigSource configSource) 143 string name, UUID id, uint x, uint y, uint sizeX, uint sizeY, IConfigSource configSource)
129 { 144 {
130 Console.WriteLine("Setting up test scene {0}", name); 145 Console.WriteLine("Setting up test scene {0}", name);
131 146
@@ -135,16 +150,20 @@ namespace OpenSim.Tests.Common
135 RegionInfo regInfo = new RegionInfo(x, y, new IPEndPoint(IPAddress.Loopback, 9000), "127.0.0.1"); 150 RegionInfo regInfo = new RegionInfo(x, y, new IPEndPoint(IPAddress.Loopback, 9000), "127.0.0.1");
136 regInfo.RegionName = name; 151 regInfo.RegionName = name;
137 regInfo.RegionID = id; 152 regInfo.RegionID = id;
138 153 regInfo.RegionSizeX = sizeX;
139 SceneCommunicationService scs = new SceneCommunicationService(); 154 regInfo.RegionSizeY = sizeY;
140 155
141 TestScene testScene = new TestScene( 156 TestScene testScene = new TestScene(
142 regInfo, m_acm, scs, m_simDataService, m_estateDataService, false, configSource, null); 157 regInfo, m_acm, SimDataService, m_estateDataService, configSource, null);
143 158
144 INonSharedRegionModule godsModule = new GodsModule(); 159 INonSharedRegionModule godsModule = new GodsModule();
145 godsModule.Initialise(new IniConfigSource()); 160 godsModule.Initialise(new IniConfigSource());
146 godsModule.AddRegion(testScene); 161 godsModule.AddRegion(testScene);
147 162
163 // Add scene to physics
164 ((INonSharedRegionModule)m_physicsScene).AddRegion(testScene);
165 ((INonSharedRegionModule)m_physicsScene).RegionLoaded(testScene);
166
148 // Add scene to services 167 // Add scene to services
149 m_assetService.AddRegion(testScene); 168 m_assetService.AddRegion(testScene);
150 169
@@ -182,12 +201,7 @@ namespace OpenSim.Tests.Common
182 testScene.SetModuleInterfaces(); 201 testScene.SetModuleInterfaces();
183 202
184 testScene.LandChannel = new TestLandChannel(testScene); 203 testScene.LandChannel = new TestLandChannel(testScene);
185 testScene.LoadWorldMap(); 204 testScene.LoadWorldMap();
186
187 PhysicsPluginManager physicsPluginManager = new PhysicsPluginManager();
188 physicsPluginManager.LoadPluginsFromAssembly("Physics/OpenSim.Region.Physics.BasicPhysicsPlugin.dll");
189 testScene.PhysicsScene
190 = physicsPluginManager.GetPhysicsScene("basicphysics", "ZeroMesher", new IniConfigSource(), "test");
191 205
192 testScene.RegionInfo.EstateSettings = new EstateSettings(); 206 testScene.RegionInfo.EstateSettings = new EstateSettings();
193 testScene.LoginsEnabled = true; 207 testScene.LoginsEnabled = true;
@@ -297,6 +311,11 @@ namespace OpenSim.Tests.Common
297 /// <param name="testScene"></param> 311 /// <param name="testScene"></param>
298 private static LocalPresenceServicesConnector StartPresenceService() 312 private static LocalPresenceServicesConnector StartPresenceService()
299 { 313 {
314 // Unfortunately, some services share data via statics, so we need to null every time to stop interference
315 // between tests.
316 // This is a massive non-obvious pita.
317 NullPresenceData.Instance = null;
318
300 IConfigSource config = new IniConfigSource(); 319 IConfigSource config = new IniConfigSource();
301 config.AddConfig("Modules"); 320 config.AddConfig("Modules");
302 config.AddConfig("PresenceService"); 321 config.AddConfig("PresenceService");
@@ -311,6 +330,19 @@ namespace OpenSim.Tests.Common
311 return presenceService; 330 return presenceService;
312 } 331 }
313 332
333 private static PhysicsScene StartPhysicsScene()
334 {
335 IConfigSource config = new IniConfigSource();
336 config.AddConfig("Startup");
337 config.Configs["Startup"].Set("physics", "basicphysics");
338
339 PhysicsScene pScene = new BasicScene();
340 INonSharedRegionModule mod = pScene as INonSharedRegionModule;
341 mod.Initialise(config);
342
343 return pScene;
344 }
345
314 /// <summary> 346 /// <summary>
315 /// Setup modules for a scene using their default settings. 347 /// Setup modules for a scene using their default settings.
316 /// </summary> 348 /// </summary>
@@ -447,9 +479,6 @@ namespace OpenSim.Tests.Common
447 /// Add a root agent where the details of the agent connection (apart from the id) are unimportant for the test 479 /// Add a root agent where the details of the agent connection (apart from the id) are unimportant for the test
448 /// </summary> 480 /// </summary>
449 /// <remarks> 481 /// <remarks>
450 /// This can be used for tests where there is only one region or where there are multiple non-neighbour regions
451 /// and teleport doesn't take place.
452 ///
453 /// XXX: Use the version of this method that takes the UserAccount structure wherever possible - this will 482 /// XXX: Use the version of this method that takes the UserAccount structure wherever possible - this will
454 /// make the agent circuit data (e.g. first, lastname) consistent with the user account data. 483 /// make the agent circuit data (e.g. first, lastname) consistent with the user account data.
455 /// </remarks> 484 /// </remarks>
@@ -462,22 +491,6 @@ namespace OpenSim.Tests.Common
462 } 491 }
463 492
464 /// <summary> 493 /// <summary>
465 /// Add a root agent where the details of the agent connection (apart from the id) are unimportant for the test
466 /// </summary>
467 /// <remarks>
468 /// XXX: Use the version of this method that takes the UserAccount structure wherever possible - this will
469 /// make the agent circuit data (e.g. first, lastname) consistent with the user account data.
470 /// </remarks>
471 /// <param name="scene"></param>
472 /// <param name="agentId"></param>
473 /// <param name="sceneManager"></param>
474 /// <returns></returns>
475 public static ScenePresence AddScenePresence(Scene scene, UUID agentId, SceneManager sceneManager)
476 {
477 return AddScenePresence(scene, GenerateAgentData(agentId), sceneManager);
478 }
479
480 /// <summary>
481 /// Add a root agent. 494 /// Add a root agent.
482 /// </summary> 495 /// </summary>
483 /// <param name="scene"></param> 496 /// <param name="scene"></param>
@@ -508,7 +521,7 @@ namespace OpenSim.Tests.Common
508 /// <returns></returns> 521 /// <returns></returns>
509 public static ScenePresence AddScenePresence(Scene scene, AgentCircuitData agentData) 522 public static ScenePresence AddScenePresence(Scene scene, AgentCircuitData agentData)
510 { 523 {
511 return AddScenePresence(scene, agentData, null); 524 return AddScenePresence(scene, new TestClient(agentData, scene), agentData);
512 } 525 }
513 526
514 /// <summary> 527 /// <summary>
@@ -528,9 +541,9 @@ namespace OpenSim.Tests.Common
528 /// </remarks> 541 /// </remarks>
529 /// <param name="scene"></param> 542 /// <param name="scene"></param>
530 /// <param name="agentData"></param> 543 /// <param name="agentData"></param>
531 /// <param name="sceneManager"></param>
532 /// <returns></returns> 544 /// <returns></returns>
533 public static ScenePresence AddScenePresence(Scene scene, AgentCircuitData agentData, SceneManager sceneManager) 545 public static ScenePresence AddScenePresence(
546 Scene scene, IClientAPI client, AgentCircuitData agentData)
534 { 547 {
535 // We emulate the proper login sequence here by doing things in four stages 548 // We emulate the proper login sequence here by doing things in four stages
536 549
@@ -541,7 +554,7 @@ namespace OpenSim.Tests.Common
541 lpsc.m_PresenceService.LoginAgent(agentData.AgentID.ToString(), agentData.SessionID, agentData.SecureSessionID); 554 lpsc.m_PresenceService.LoginAgent(agentData.AgentID.ToString(), agentData.SessionID, agentData.SecureSessionID);
542 555
543 // Stages 1 & 2 556 // Stages 1 & 2
544 ScenePresence sp = IntroduceClientToScene(scene, sceneManager, agentData, TeleportFlags.ViaLogin); 557 ScenePresence sp = IntroduceClientToScene(scene, client, agentData, TeleportFlags.ViaLogin);
545 558
546 // Stage 3: Complete the entrance into the region. This converts the child agent into a root agent. 559 // Stage 3: Complete the entrance into the region. This converts the child agent into a root agent.
547 sp.CompleteMovement(sp.ControllingClient, true); 560 sp.CompleteMovement(sp.ControllingClient, true);
@@ -553,37 +566,37 @@ namespace OpenSim.Tests.Common
553 /// Introduce an agent into the scene by adding a new client. 566 /// Introduce an agent into the scene by adding a new client.
554 /// </summary> 567 /// </summary>
555 /// <returns>The scene presence added</returns> 568 /// <returns>The scene presence added</returns>
556 /// <param name='sceneManager'>
557 /// Scene manager. Can be null if there is only one region in the test or multiple regions that are not
558 /// neighbours and where no teleporting takes place.
559 /// </param>
560 /// <param name='scene'></param> 569 /// <param name='scene'></param>
561 /// <param name='sceneManager></param> 570 /// <param name='testClient'></param>
562 /// <param name='agentData'></param> 571 /// <param name='agentData'></param>
563 /// <param name='tf'></param> 572 /// <param name='tf'></param>
564 private static ScenePresence IntroduceClientToScene( 573 private static ScenePresence IntroduceClientToScene(
565 Scene scene, SceneManager sceneManager, AgentCircuitData agentData, TeleportFlags tf) 574 Scene scene, IClientAPI client, AgentCircuitData agentData, TeleportFlags tf)
566 { 575 {
567 string reason; 576 string reason;
568 577
569 // Stage 1: tell the scene to expect a new user connection 578 // Stage 1: tell the scene to expect a new user connection
570 if (!scene.NewUserConnection(agentData, (uint)tf, out reason)) 579 if (!scene.NewUserConnection(agentData, (uint)tf, null, out reason))
571 Console.WriteLine("NewUserConnection failed: " + reason); 580 Console.WriteLine("NewUserConnection failed: " + reason);
572 581
573 // Stage 2: add the new client as a child agent to the scene 582 // Stage 2: add the new client as a child agent to the scene
574 TestClient client = new TestClient(agentData, scene, sceneManager); 583 scene.AddNewAgent(client, PresenceType.User);
575 scene.AddNewClient(client, PresenceType.User);
576 584
577 return scene.GetScenePresence(agentData.AgentID); 585 return scene.GetScenePresence(client.AgentId);
578 } 586 }
579 587
580 public static ScenePresence AddChildScenePresence(Scene scene, UUID agentId) 588 public static ScenePresence AddChildScenePresence(Scene scene, UUID agentId)
581 { 589 {
582 AgentCircuitData acd = GenerateAgentData(agentId); 590 return AddChildScenePresence(scene, GenerateAgentData(agentId));
591 }
592
593 public static ScenePresence AddChildScenePresence(Scene scene, AgentCircuitData acd)
594 {
583 acd.child = true; 595 acd.child = true;
584 596
585 // XXX: ViaLogin may not be correct for child agents 597 // XXX: ViaLogin may not be correct for child agents
586 return IntroduceClientToScene(scene, null, acd, TeleportFlags.ViaLogin); 598 TestClient client = new TestClient(acd, scene);
599 return IntroduceClientToScene(scene, client, acd, TeleportFlags.ViaLogin);
587 } 600 }
588 601
589 /// <summary> 602 /// <summary>
@@ -610,6 +623,32 @@ namespace OpenSim.Tests.Common
610 //part.UpdatePrimFlags(false, false, true); 623 //part.UpdatePrimFlags(false, false, true);
611 //part.ObjectFlags |= (uint)PrimFlags.Phantom; 624 //part.ObjectFlags |= (uint)PrimFlags.Phantom;
612 625
626 scene.AddNewSceneObject(so, true);
627
628 return so;
629 }
630
631 /// <summary>
632 /// Add a test object
633 /// </summary>
634 /// <param name="scene"></param>
635 /// <param name="parts">
636 /// The number of parts that should be in the scene object
637 /// </param>
638 /// <param name="ownerId"></param>
639 /// <param name="partNamePrefix">
640 /// The prefix to be given to part names. This will be suffixed with "Part<part no>"
641 /// (e.g. mynamePart1 for the root part)
642 /// </param>
643 /// <param name="uuidTail">
644 /// The hexadecimal last part of the UUID for parts created. A UUID of the form "00000000-0000-0000-0000-{0:XD12}"
645 /// will be given to the root part, and incremented for each part thereafter.
646 /// </param>
647 /// <returns></returns>
648 public static SceneObjectGroup AddSceneObject(Scene scene, int parts, UUID ownerId, string partNamePrefix, int uuidTail)
649 {
650 SceneObjectGroup so = CreateSceneObject(parts, ownerId, partNamePrefix, uuidTail);
651
613 scene.AddNewSceneObject(so, false); 652 scene.AddNewSceneObject(so, false);
614 653
615 return so; 654 return so;
diff --git a/OpenSim/Tests/Common/Helpers/TaskInventoryHelpers.cs b/OpenSim/Tests/Common/Helpers/TaskInventoryHelpers.cs
index 0a2b30a..3a3b33a 100644
--- a/OpenSim/Tests/Common/Helpers/TaskInventoryHelpers.cs
+++ b/OpenSim/Tests/Common/Helpers/TaskInventoryHelpers.cs
@@ -43,21 +43,40 @@ namespace OpenSim.Tests.Common
43 /// <summary> 43 /// <summary>
44 /// Add a notecard item to the given part. 44 /// Add a notecard item to the given part.
45 /// </summary> 45 /// </summary>
46 /// <param name="scene"></param> 46 /// <param name="assetService"></param>
47 /// <param name="part"></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 IAssetService assetService, SceneObjectPart part, string itemName, string itemIDStem, string assetIDStem, string text)
55 {
56 return AddNotecard(
57 assetService, 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="assetService"></param>
47 /// <param name="part"></param> 64 /// <param name="part"></param>
48 /// <param name="itemName"></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 IAssetService assetService, 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
59 = AssetHelpers.CreateAsset(assetID, AssetType.Notecard, nc.AssetData, UUID.Zero); 78 = AssetHelpers.CreateAsset(assetID, AssetType.Notecard, nc.AssetData, UUID.Zero);
60 scene.AssetService.Store(ncAsset); 79 assetService.Store(ncAsset);
61 80
62 TaskInventoryItem ncItem 81 TaskInventoryItem ncItem
63 = new TaskInventoryItem 82 = new TaskInventoryItem
@@ -75,44 +94,62 @@ namespace OpenSim.Tests.Common
75 /// TODO: Accept input for item and asset IDs to avoid mysterious script failures that try to use any of these 94 /// TODO: Accept input for item and asset IDs to avoid mysterious script failures that try to use any of these
76 /// functions more than once in a test. 95 /// functions more than once in a test.
77 /// </remarks> 96 /// </remarks>
78 /// <param name="scene"></param> 97 /// <param name="assetService"></param>
79 /// <param name="part"></param> 98 /// <param name="part"></param>
80 /// <returns>The item that was added</returns> 99 /// <returns>The item that was added</returns>
81 public static TaskInventoryItem AddScript(Scene scene, SceneObjectPart part) 100 public static TaskInventoryItem AddScript(IAssetService assetService, SceneObjectPart part)
82 { 101 {
83 return AddScript(scene, part, "scriptItem", "default { state_entry() { llSay(0, \"Hello World\"); } }"); 102 return AddScript(assetService, part, "scriptItem", "default { state_entry() { llSay(0, \"Hello World\"); } }");
84 } 103 }
85 104
86 /// <summary> 105 /// <summary>
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.
111 /// </remarks>
112 /// <param name="assetService"></param>
113 /// <param name="part"></param>
114 /// <param name="scriptName">Name of the script to add</param>
115 /// <param name="scriptSource">LSL script source</param>
116 /// <returns>The item that was added</returns>
117 public static TaskInventoryItem AddScript(
118 IAssetService assetService, SceneObjectPart part, string scriptName, string scriptSource)
119 {
120 return AddScript(assetService, part, UUID.Random(), UUID.Random(), scriptName, scriptSource);
121 }
122
123 /// <summary>
124 /// Add a simple script to the given part.
125 /// </summary>
126 /// <remarks>
127 /// TODO: Accept input for item and asset IDs so that we have completely replicatable regression tests rather
128 /// than a random component.
92 /// </remarks> 129 /// </remarks>
93 /// <param name="scene"></param> 130 /// <param name="assetService"></param>
94 /// <param name="part"></param> 131 /// <param name="part"></param>
132 /// <param name="itemId">Item UUID for the script</param>
133 /// <param name="assetId">Asset UUID for the script</param>
95 /// <param name="scriptName">Name of the script to add</param> 134 /// <param name="scriptName">Name of the script to add</param>
96 /// <param name="scriptSource">LSL script source</param> 135 /// <param name="scriptSource">LSL script source</param>
97 /// <returns>The item that was added</returns> 136 /// <returns>The item that was added</returns>
98 public static TaskInventoryItem AddScript( 137 public static TaskInventoryItem AddScript(
99 Scene scene, SceneObjectPart part, string scriptName, string scriptSource) 138 IAssetService assetService, SceneObjectPart part, UUID itemId, UUID assetId, string scriptName, string scriptSource)
100 { 139 {
101 AssetScriptText ast = new AssetScriptText(); 140 AssetScriptText ast = new AssetScriptText();
102 ast.Source = scriptSource; 141 ast.Source = scriptSource;
103 ast.Encode(); 142 ast.Encode();
104 143
105 UUID assetUuid = new UUID("00000000-0000-0000-1000-000000000000");
106 UUID itemUuid = new UUID("00000000-0000-0000-1100-000000000000");
107 AssetBase asset 144 AssetBase asset
108 = AssetHelpers.CreateAsset(assetUuid, AssetType.LSLText, ast.AssetData, UUID.Zero); 145 = AssetHelpers.CreateAsset(assetId, AssetType.LSLText, ast.AssetData, UUID.Zero);
109 scene.AssetService.Store(asset); 146 assetService.Store(asset);
110 TaskInventoryItem item 147 TaskInventoryItem item
111 = new TaskInventoryItem 148 = new TaskInventoryItem
112 { Name = scriptName, AssetID = assetUuid, ItemID = itemUuid, 149 { Name = scriptName, AssetID = assetId, ItemID = itemId,
113 Type = (int)AssetType.LSLText, InvType = (int)InventoryType.LSL }; 150 Type = (int)AssetType.LSLText, InvType = (int)InventoryType.LSL };
114 part.Inventory.AddInventoryItem(item, true); 151 part.Inventory.AddInventoryItem(item, true);
115 152
116 return item; 153 return item;
117 } 154 }
118 155
@@ -124,28 +161,50 @@ namespace OpenSim.Tests.Common
124 /// functions more than once in a test. 161 /// functions more than once in a test.
125 /// </remarks> 162 /// </remarks>
126 /// 163 ///
127 /// <param name="scene"></param> 164 /// <param name="assetService"></param>
128 /// <param name="sop"></param> 165 /// <param name="sop"></param>
129 /// <param name="itemName"></param> 166 /// <param name="itemName"></param>
130 /// <param name="id"></param> 167 /// <param name="itemId"></param>
131 /// <param name="userId"></param> 168 /// <param name="soToAdd"></param>
169 /// <param name="soAssetId"></param>
132 public static TaskInventoryItem AddSceneObject( 170 public static TaskInventoryItem AddSceneObject(
133 Scene scene, SceneObjectPart sop, string itemName, UUID id, UUID userId) 171 IAssetService assetService, SceneObjectPart sop, string itemName, UUID itemId, SceneObjectGroup soToAdd, UUID soAssetId)
134 { 172 {
135 SceneObjectGroup taskSceneObject = SceneHelpers.CreateSceneObject(1, UUID.Zero); 173 AssetBase taskSceneObjectAsset = AssetHelpers.CreateAsset(soAssetId, soToAdd);
136 AssetBase taskSceneObjectAsset = AssetHelpers.CreateAsset(0x10, taskSceneObject); 174 assetService.Store(taskSceneObjectAsset);
137 scene.AssetService.Store(taskSceneObjectAsset);
138 TaskInventoryItem taskSceneObjectItem 175 TaskInventoryItem taskSceneObjectItem
139 = new TaskInventoryItem 176 = new TaskInventoryItem
140 { Name = itemName, 177 { Name = itemName,
141 AssetID = taskSceneObjectAsset.FullID, 178 AssetID = taskSceneObjectAsset.FullID,
142 ItemID = id, 179 ItemID = itemId,
143 OwnerID = userId, 180 OwnerID = soToAdd.OwnerID,
144 Type = (int)AssetType.Object, 181 Type = (int)AssetType.Object,
145 InvType = (int)InventoryType.Object }; 182 InvType = (int)InventoryType.Object };
146 sop.Inventory.AddInventoryItem(taskSceneObjectItem, true); 183 sop.Inventory.AddInventoryItem(taskSceneObjectItem, true);
147 184
148 return taskSceneObjectItem; 185 return taskSceneObjectItem;
149 } 186 }
187
188 /// <summary>
189 /// Add a scene object item to the given part.
190 /// </summary>
191 /// <remarks>
192 /// TODO: Accept input for item and asset IDs to avoid mysterious script failures that try to use any of these
193 /// functions more than once in a test.
194 /// </remarks>
195 ///
196 /// <param name="assetService"></param>
197 /// <param name="sop"></param>
198 /// <param name="itemName"></param>
199 /// <param name="id"></param>
200 /// <param name="userId"></param>
201 public static TaskInventoryItem AddSceneObject(
202 IAssetService assetService, SceneObjectPart sop, string itemName, UUID itemId, UUID userId)
203 {
204 SceneObjectGroup taskSceneObject = SceneHelpers.CreateSceneObject(1, userId);
205
206 return TaskInventoryHelpers.AddSceneObject(
207 assetService, sop, itemName, itemId, taskSceneObject, TestHelpers.ParseTail(0x10));
208 }
150 } 209 }
151} \ No newline at end of file 210} \ No newline at end of file
diff --git a/OpenSim/Tests/Common/Helpers/UserAccountHelpers.cs b/OpenSim/Tests/Common/Helpers/UserAccountHelpers.cs
index 2fbebc4..c62b58e 100644
--- a/OpenSim/Tests/Common/Helpers/UserAccountHelpers.cs
+++ b/OpenSim/Tests/Common/Helpers/UserAccountHelpers.cs
@@ -27,7 +27,7 @@
27 27
28using System.Collections.Generic; 28using System.Collections.Generic;
29using OpenMetaverse; 29using OpenMetaverse;
30using OpenSim.Framework.Communications; 30
31using OpenSim.Region.Framework.Scenes; 31using OpenSim.Region.Framework.Scenes;
32using OpenSim.Services.Interfaces; 32using OpenSim.Services.Interfaces;
33 33
diff --git a/OpenSim/Tests/Common/Helpers/UserInventoryHelpers.cs b/OpenSim/Tests/Common/Helpers/UserInventoryHelpers.cs
index 87d9410..5a36332 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, (FolderType)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,116 @@ 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)
220 {
221 return CreateInventoryFolder(inventoryService, userId, UUID.Random(), path, useExistingFolders);
222 }
223
224 /// <summary>
225 /// Create inventory folders starting from the user's root folder.
226 /// </summary>
227 /// <param name="inventoryService"></param>
228 /// <param name="userId"></param>
229 /// <param name="folderId"></param>
230 /// <param name="path">
231 /// The folders to create. Multiple folders can be specified on a path delimited by the PATH_DELIMITER
232 /// </param>
233 /// <param name="useExistingFolders">
234 /// If true, then folders in the path which already the same name are
235 /// used. This applies to the terminal folder as well.
236 /// If false, then all folders in the path are created, even if there is already a folder at a particular
237 /// level with the same name.
238 /// </param>
239 /// <returns>
240 /// The folder created. If the path contains multiple folders then the last one created is returned.
241 /// Will return null if the root folder could not be found.
242 /// </returns>
243 public static InventoryFolderBase CreateInventoryFolder(
244 IInventoryService inventoryService, UUID userId, UUID folderId, string path, bool useExistingFolders)
173 { 245 {
174 InventoryFolderBase rootFolder = inventoryService.GetRootFolder(userId); 246 InventoryFolderBase rootFolder = inventoryService.GetRootFolder(userId);
175 247
176 if (null == rootFolder) 248 if (null == rootFolder)
177 return null; 249 return null;
178 250
179 return CreateInventoryFolder(inventoryService, rootFolder, path); 251 return CreateInventoryFolder(inventoryService, folderId, rootFolder, path, useExistingFolders);
180 } 252 }
181 253
182 /// <summary> 254 /// <summary>
183 /// Create inventory folders starting from a given parent folder 255 /// Create inventory folders starting from a given parent folder
184 /// </summary> 256 /// </summary>
185 /// 257 /// <remarks>
186 /// Ignores any existing folders with the same name 258 /// If any stem of the path names folders that already exist then these are not recreated. This includes the
187 /// 259 /// final folder.
260 /// TODO: May need to make it an option to create duplicate folders.
261 /// </remarks>
188 /// <param name="inventoryService"></param> 262 /// <param name="inventoryService"></param>
263 /// <param name="folderId">ID of the folder to create</param>
189 /// <param name="parentFolder"></param> 264 /// <param name="parentFolder"></param>
190 /// <param name="path"> 265 /// <param name="path">
191 /// The folders to create. Multiple folders can be specified on a path delimited by the PATH_DELIMITER 266 /// The folder to create.
267 /// </param>
268 /// <param name="useExistingFolders">
269 /// If true, then folders in the path which already the same name are
270 /// used. This applies to the terminal folder as well.
271 /// If false, then all folders in the path are created, even if there is already a folder at a particular
272 /// level with the same name.
192 /// </param> 273 /// </param>
193 /// <returns> 274 /// <returns>
194 /// The folder created. If the path contains multiple folders then the last one created is returned. 275 /// The folder created. If the path contains multiple folders then the last one created is returned.
195 /// </returns> 276 /// </returns>
196 public static InventoryFolderBase CreateInventoryFolder( 277 public static InventoryFolderBase CreateInventoryFolder(
197 IInventoryService inventoryService, InventoryFolderBase parentFolder, string path) 278 IInventoryService inventoryService, UUID folderId, InventoryFolderBase parentFolder, string path, bool useExistingFolders)
198 { 279 {
199 string[] components = path.Split(new string[] { PATH_DELIMITER }, 2, StringSplitOptions.None); 280 string[] components = path.Split(new string[] { PATH_DELIMITER }, 2, StringSplitOptions.None);
200 281
201 InventoryFolderBase newFolder 282 InventoryFolderBase folder = null;
202 = new InventoryFolderBase( 283
203 UUID.Random(), components[0], parentFolder.Owner, (short)AssetType.Unknown, parentFolder.ID, 0); 284 if (useExistingFolders)
204 285 folder = InventoryArchiveUtils.FindFolderByPath(inventoryService, parentFolder, components[0]);
205 inventoryService.AddFolder(newFolder); 286
287 if (folder == null)
288 {
289// Console.WriteLine("Creating folder {0} at {1}", components[0], parentFolder.Name);
290
291 UUID folderIdForCreate;
292
293 if (components.Length > 1)
294 folderIdForCreate = UUID.Random();
295 else
296 folderIdForCreate = folderId;
297
298 folder
299 = new InventoryFolderBase(
300 folderIdForCreate, components[0], parentFolder.Owner, (short)AssetType.Unknown, parentFolder.ID, 0);
301
302 inventoryService.AddFolder(folder);
303 }
304// else
305// {
306// Console.WriteLine("Found existing folder {0}", folder.Name);
307// }
206 308
207 if (components.Length > 1) 309 if (components.Length > 1)
208 return CreateInventoryFolder(inventoryService, newFolder, components[1]); 310 return CreateInventoryFolder(inventoryService, folderId, folder, components[1], useExistingFolders);
209 else 311 else
210 return newFolder; 312 return folder;
211 } 313 }
212 314
213 /// <summary> 315 /// <summary>
@@ -237,7 +339,7 @@ namespace OpenSim.Tests.Common
237 /// <returns>An empty list if no matching folders were found</returns> 339 /// <returns>An empty list if no matching folders were found</returns>
238 public static List<InventoryFolderBase> GetInventoryFolders(IInventoryService inventoryService, UUID userId, string path) 340 public static List<InventoryFolderBase> GetInventoryFolders(IInventoryService inventoryService, UUID userId, string path)
239 { 341 {
240 return InventoryArchiveUtils.FindFolderByPath(inventoryService, userId, path); 342 return InventoryArchiveUtils.FindFoldersByPath(inventoryService, userId, path);
241 } 343 }
242 344
243 /// <summary> 345 /// <summary>