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/AssetHelpers.cs143
-rw-r--r--OpenSim/Tests/Common/Helpers/BaseRequestHandlerHelpers.cs76
-rw-r--r--OpenSim/Tests/Common/Helpers/SceneSetupHelpers.cs483
-rw-r--r--OpenSim/Tests/Common/Helpers/TaskInventoryHelpers.cs89
-rw-r--r--OpenSim/Tests/Common/Helpers/UserAccountHelpers.cs145
-rw-r--r--OpenSim/Tests/Common/Helpers/UserInventoryHelpers.cs115
6 files changed, 1051 insertions, 0 deletions
diff --git a/OpenSim/Tests/Common/Helpers/AssetHelpers.cs b/OpenSim/Tests/Common/Helpers/AssetHelpers.cs
new file mode 100644
index 0000000..aa55bcd
--- /dev/null
+++ b/OpenSim/Tests/Common/Helpers/AssetHelpers.cs
@@ -0,0 +1,143 @@
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.Text;
29using OpenMetaverse;
30using OpenSim.Framework;
31using OpenSim.Region.Framework.Scenes;
32using OpenSim.Region.Framework.Scenes.Serialization;
33using OpenSim.Services.Interfaces;
34
35namespace OpenSim.Tests.Common
36{
37 public class AssetHelpers
38 {
39 /// <summary>
40 /// Create a notecard asset with a random uuid and dummy text.
41 /// </summary>
42 /// <param name="creatorId">/param>
43 /// <returns></returns>
44 public static AssetBase CreateAsset(UUID creatorId)
45 {
46 return CreateAsset(UUID.Random(), AssetType.Notecard, "hello", creatorId);
47 }
48
49 /// <summary>
50 /// Create and store a notecard asset with a random uuid and dummy text.
51 /// </summary>
52 /// <param name="creatorId">/param>
53 /// <returns></returns>
54 public static AssetBase CreateAsset(Scene scene, UUID creatorId)
55 {
56 AssetBase asset = CreateAsset(UUID.Random(), AssetType.Notecard, "hello", creatorId);
57 scene.AssetService.Store(asset);
58 return asset;
59 }
60
61 /// <summary>
62 /// Create an asset from the given object.
63 /// </summary>
64 /// <param name="assetUuidTail">
65 /// The hexadecimal last part of the UUID for the asset created. A UUID of the form "00000000-0000-0000-0000-{0:XD12}"
66 /// will be used.
67 /// </param>
68 /// <param name="sog"></param>
69 /// <returns></returns>
70 public static AssetBase CreateAsset(int assetUuidTail, SceneObjectGroup sog)
71 {
72 return CreateAsset(new UUID(string.Format("00000000-0000-0000-0000-{0:X12}", assetUuidTail)), sog);
73 }
74
75 /// <summary>
76 /// Create an asset from the given object.
77 /// </summary>
78 /// <param name="assetUuid"></param>
79 /// <param name="sog"></param>
80 /// <returns></returns>
81 public static AssetBase CreateAsset(UUID assetUuid, SceneObjectGroup sog)
82 {
83 return CreateAsset(
84 assetUuid,
85 AssetType.Object,
86 Encoding.ASCII.GetBytes(SceneObjectSerializer.ToOriginalXmlFormat(sog)),
87 sog.OwnerID);
88 }
89
90 /// <summary>
91 /// Create an asset from the given scene object.
92 /// </summary>
93 /// <param name="assetUuidTail">
94 /// The hexadecimal last part of the UUID for the asset created. A UUID of the form "00000000-0000-0000-0000-{0:XD12}"
95 /// will be used.
96 /// </param>
97 /// <param name="coa"></param>
98 /// <returns></returns>
99 public static AssetBase CreateAsset(int assetUuidTail, CoalescedSceneObjects coa)
100 {
101 return CreateAsset(new UUID(string.Format("00000000-0000-0000-0000-{0:X12}", assetUuidTail)), coa);
102 }
103
104 /// <summary>
105 /// Create an asset from the given scene object.
106 /// </summary>
107 /// <param name="assetUuid"></param>
108 /// <param name="coa"></param>
109 /// <returns></returns>
110 public static AssetBase CreateAsset(UUID assetUuid, CoalescedSceneObjects coa)
111 {
112 return CreateAsset(
113 assetUuid,
114 AssetType.Object,
115 Encoding.ASCII.GetBytes(CoalescedSceneObjectsSerializer.ToXml(coa)),
116 coa.CreatorId);
117 }
118
119 /// <summary>
120 /// Create an asset from the given data.
121 /// </summary>
122 public static AssetBase CreateAsset(UUID assetUuid, AssetType assetType, string data, UUID creatorID)
123 {
124 return CreateAsset(assetUuid, assetType, Encoding.ASCII.GetBytes(data), creatorID);
125 }
126
127 /// <summary>
128 /// Create an asset from the given data.
129 /// </summary>
130 public static AssetBase CreateAsset(UUID assetUuid, AssetType assetType, byte[] data, UUID creatorID)
131 {
132 AssetBase asset = new AssetBase(assetUuid, assetUuid.ToString(), (sbyte)assetType, creatorID.ToString());
133 asset.Data = data;
134 return asset;
135 }
136
137 public static string ReadAssetAsString(IAssetService assetService, UUID uuid)
138 {
139 byte[] assetData = assetService.GetData(uuid.ToString());
140 return Encoding.ASCII.GetString(assetData);
141 }
142 }
143}
diff --git a/OpenSim/Tests/Common/Helpers/BaseRequestHandlerHelpers.cs b/OpenSim/Tests/Common/Helpers/BaseRequestHandlerHelpers.cs
new file mode 100644
index 0000000..286e6ff
--- /dev/null
+++ b/OpenSim/Tests/Common/Helpers/BaseRequestHandlerHelpers.cs
@@ -0,0 +1,76 @@
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.Text;
31using NUnit.Framework;
32using OpenSim.Framework;
33using OpenSim.Framework.Servers;
34using OpenSim.Framework.Servers.HttpServer;
35using OpenSim.Tests.Common.Mock;
36
37namespace OpenSim.Tests.Common.Setup
38{
39 public class BaseRequestHandlerHelpers
40 {
41 private static string[] m_emptyStringArray = new string[] { };
42
43 public static void BaseTestGetParams(BaseRequestHandler handler, string assetsPath)
44 {
45 Assert.AreEqual(String.Empty, handler.GetParam(null), "Failed on null path.");
46 Assert.AreEqual(String.Empty, handler.GetParam(""), "Failed on empty path.");
47 Assert.AreEqual(String.Empty, handler.GetParam("s"), "Failed on short url.");
48 Assert.AreEqual(String.Empty, handler.GetParam("corruptUrl"), "Failed on corruptUrl.");
49
50 Assert.AreEqual(String.Empty, handler.GetParam(assetsPath));
51 Assert.AreEqual("/", handler.GetParam(assetsPath + "/"));
52 Assert.AreEqual("/a", handler.GetParam(assetsPath + "/a"));
53 Assert.AreEqual("/b/", handler.GetParam(assetsPath + "/b/"));
54 Assert.AreEqual("/c/d", handler.GetParam(assetsPath + "/c/d"));
55 Assert.AreEqual("/e/f/", handler.GetParam(assetsPath + "/e/f/"));
56 }
57
58 public static void BaseTestSplitParams(BaseRequestHandler handler, string assetsPath)
59 {
60 Assert.AreEqual(m_emptyStringArray, handler.SplitParams(null), "Failed on null.");
61 Assert.AreEqual(m_emptyStringArray, handler.SplitParams(""), "Failed on empty path.");
62 Assert.AreEqual(m_emptyStringArray, handler.SplitParams("corruptUrl"), "Failed on corrupt url.");
63
64 Assert.AreEqual(m_emptyStringArray, handler.SplitParams(assetsPath), "Failed on empty params.");
65 Assert.AreEqual(m_emptyStringArray, handler.SplitParams(assetsPath + "/"), "Failed on single slash.");
66
67 Assert.AreEqual(new string[] { "a" }, handler.SplitParams(assetsPath + "/a"), "Failed on first segment.");
68 Assert.AreEqual(new string[] { "b" }, handler.SplitParams(assetsPath + "/b/"), "Failed on second slash.");
69 Assert.AreEqual(new string[] { "c", "d" }, handler.SplitParams(assetsPath + "/c/d"), "Failed on second segment.");
70 Assert.AreEqual(new string[] { "e", "f" }, handler.SplitParams(assetsPath + "/e/f/"), "Failed on trailing slash.");
71 }
72
73 public static byte[] EmptyByteArray = new byte[] {};
74
75 }
76}
diff --git a/OpenSim/Tests/Common/Helpers/SceneSetupHelpers.cs b/OpenSim/Tests/Common/Helpers/SceneSetupHelpers.cs
new file mode 100644
index 0000000..d122409
--- /dev/null
+++ b/OpenSim/Tests/Common/Helpers/SceneSetupHelpers.cs
@@ -0,0 +1,483 @@
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 System.Collections.Generic;
31using Nini.Config;
32using OpenMetaverse;
33using OpenSim.Framework;
34using OpenSim.Framework.Communications;
35using OpenSim.Framework.Console;
36using OpenSim.Framework.Servers;
37using OpenSim.Framework.Servers.HttpServer;
38using OpenSim.Region.Physics.Manager;
39using OpenSim.Region.Framework;
40using OpenSim.Region.Framework.Interfaces;
41using OpenSim.Region.Framework.Scenes;
42using OpenSim.Region.CoreModules.Avatar.Gods;
43using OpenSim.Region.CoreModules.ServiceConnectorsOut.Asset;
44using OpenSim.Region.CoreModules.ServiceConnectorsOut.Authentication;
45using OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory;
46using OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid;
47using OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts;
48using OpenSim.Region.CoreModules.ServiceConnectorsOut.Presence;
49using OpenSim.Services.Interfaces;
50using OpenSim.Tests.Common.Mock;
51
52namespace OpenSim.Tests.Common.Setup
53{
54 /// <summary>
55 /// Helpers for setting up scenes.
56 /// </summary>
57 public class SceneSetupHelpers
58 {
59 /// <summary>
60 /// Set up a test scene
61 /// </summary>
62 /// <remarks>
63 /// Automatically starts service threads, as would the normal runtime.
64 /// </remarks>
65 /// <returns></returns>
66 public static TestScene SetupScene()
67 {
68 return SetupScene("Unit test region", UUID.Random(), 1000, 1000);
69 }
70
71 /// <summary>
72 /// Set up a scene. If it's more then one scene, use the same CommunicationsManager to link regions
73 /// or a different, to get a brand new scene with new shared region modules.
74 /// </summary>
75 /// <param name="name">Name of the region</param>
76 /// <param name="id">ID of the region</param>
77 /// <param name="x">X co-ordinate of the region</param>
78 /// <param name="y">Y co-ordinate of the region</param>
79 /// <param name="cm">This should be the same if simulating two scenes within a standalone</param>
80 /// <returns></returns>
81 public static TestScene SetupScene(string name, UUID id, uint x, uint y)
82 {
83 Console.WriteLine("Setting up test scene {0}", name);
84
85 // We must set up a console otherwise setup of some modules may fail
86 MainConsole.Instance = new MockConsole("TEST PROMPT");
87
88 RegionInfo regInfo = new RegionInfo(x, y, new IPEndPoint(IPAddress.Loopback, 9000), "127.0.0.1");
89 regInfo.RegionName = name;
90 regInfo.RegionID = id;
91
92 AgentCircuitManager acm = new AgentCircuitManager();
93 SceneCommunicationService scs = new SceneCommunicationService();
94
95 ISimulationDataService simDataService = OpenSim.Server.Base.ServerUtils.LoadPlugin<ISimulationDataService>("OpenSim.Tests.Common.dll", null);
96 IEstateDataService estateDataService = null;
97 IConfigSource configSource = new IniConfigSource();
98
99 TestScene testScene = new TestScene(
100 regInfo, acm, scs, simDataService, estateDataService, null, false, false, false, configSource, null);
101
102 IRegionModule godsModule = new GodsModule();
103 godsModule.Initialise(testScene, new IniConfigSource());
104 testScene.AddModule(godsModule.Name, godsModule);
105
106 LocalAssetServicesConnector assetService = StartAssetService(testScene);
107 StartAuthenticationService(testScene);
108 LocalInventoryServicesConnector inventoryService = StartInventoryService(testScene);
109 StartGridService(testScene);
110 LocalUserAccountServicesConnector userAccountService = StartUserAccountService(testScene);
111 LocalPresenceServicesConnector presenceService = StartPresenceService(testScene);
112
113 inventoryService.PostInitialise();
114 assetService.PostInitialise();
115 userAccountService.PostInitialise();
116 presenceService.PostInitialise();
117
118 testScene.RegionInfo.EstateSettings.EstateOwner = UUID.Random();
119 testScene.SetModuleInterfaces();
120
121 testScene.LandChannel = new TestLandChannel(testScene);
122 testScene.LoadWorldMap();
123
124 PhysicsPluginManager physicsPluginManager = new PhysicsPluginManager();
125 physicsPluginManager.LoadPluginsFromAssembly("Physics/OpenSim.Region.Physics.BasicPhysicsPlugin.dll");
126 testScene.PhysicsScene
127 = physicsPluginManager.GetPhysicsScene("basicphysics", "ZeroMesher", new IniConfigSource(), "test");
128
129 testScene.RegionInfo.EstateSettings = new EstateSettings();
130 testScene.LoginsDisabled = false;
131
132 return testScene;
133 }
134
135 private static LocalAssetServicesConnector StartAssetService(Scene testScene)
136 {
137 LocalAssetServicesConnector assetService = new LocalAssetServicesConnector();
138 IConfigSource config = new IniConfigSource();
139
140 config.AddConfig("Modules");
141 config.Configs["Modules"].Set("AssetServices", "LocalAssetServicesConnector");
142 config.AddConfig("AssetService");
143 config.Configs["AssetService"].Set("LocalServiceModule", "OpenSim.Services.AssetService.dll:AssetService");
144 config.Configs["AssetService"].Set("StorageProvider", "OpenSim.Tests.Common.dll");
145
146 assetService.Initialise(config);
147 assetService.AddRegion(testScene);
148 assetService.RegionLoaded(testScene);
149 testScene.AddRegionModule(assetService.Name, assetService);
150
151 return assetService;
152 }
153
154 private static void StartAuthenticationService(Scene testScene)
155 {
156 ISharedRegionModule service = new LocalAuthenticationServicesConnector();
157 IConfigSource config = new IniConfigSource();
158
159 config.AddConfig("Modules");
160 config.AddConfig("AuthenticationService");
161 config.Configs["Modules"].Set("AuthenticationServices", "LocalAuthenticationServicesConnector");
162 config.Configs["AuthenticationService"].Set(
163 "LocalServiceModule", "OpenSim.Services.AuthenticationService.dll:PasswordAuthenticationService");
164 config.Configs["AuthenticationService"].Set("StorageProvider", "OpenSim.Data.Null.dll");
165
166 service.Initialise(config);
167 service.AddRegion(testScene);
168 service.RegionLoaded(testScene);
169 testScene.AddRegionModule(service.Name, service);
170 //m_authenticationService = service;
171 }
172
173 private static LocalInventoryServicesConnector StartInventoryService(Scene testScene)
174 {
175 LocalInventoryServicesConnector inventoryService = new LocalInventoryServicesConnector();
176
177 IConfigSource config = new IniConfigSource();
178 config.AddConfig("Modules");
179 config.AddConfig("InventoryService");
180 config.Configs["Modules"].Set("InventoryServices", "LocalInventoryServicesConnector");
181 config.Configs["InventoryService"].Set("LocalServiceModule", "OpenSim.Services.InventoryService.dll:InventoryService");
182 config.Configs["InventoryService"].Set("StorageProvider", "OpenSim.Tests.Common.dll");
183
184 inventoryService.Initialise(config);
185 inventoryService.AddRegion(testScene);
186 inventoryService.RegionLoaded(testScene);
187 testScene.AddRegionModule(inventoryService.Name, inventoryService);
188
189 return inventoryService;
190 }
191
192 private static LocalGridServicesConnector StartGridService(Scene testScene)
193 {
194 IConfigSource config = new IniConfigSource();
195 config.AddConfig("Modules");
196 config.AddConfig("GridService");
197 config.Configs["Modules"].Set("GridServices", "LocalGridServicesConnector");
198 config.Configs["GridService"].Set("StorageProvider", "OpenSim.Data.Null.dll:NullRegionData");
199 config.Configs["GridService"].Set("LocalServiceModule", "OpenSim.Services.GridService.dll:GridService");
200
201 LocalGridServicesConnector gridService = new LocalGridServicesConnector();
202 gridService.Initialise(config);
203 gridService.AddRegion(testScene);
204 gridService.RegionLoaded(testScene);
205
206 return gridService;
207 }
208
209 /// <summary>
210 /// Start a user account service
211 /// </summary>
212 /// <param name="testScene"></param>
213 /// <returns></returns>
214 private static LocalUserAccountServicesConnector StartUserAccountService(Scene testScene)
215 {
216 IConfigSource config = new IniConfigSource();
217 config.AddConfig("Modules");
218 config.AddConfig("UserAccountService");
219 config.Configs["Modules"].Set("UserAccountServices", "LocalUserAccountServicesConnector");
220 config.Configs["UserAccountService"].Set("StorageProvider", "OpenSim.Data.Null.dll");
221 config.Configs["UserAccountService"].Set(
222 "LocalServiceModule", "OpenSim.Services.UserAccountService.dll:UserAccountService");
223
224 LocalUserAccountServicesConnector userAccountService = new LocalUserAccountServicesConnector();
225 userAccountService.Initialise(config);
226
227 userAccountService.AddRegion(testScene);
228 userAccountService.RegionLoaded(testScene);
229 testScene.AddRegionModule(userAccountService.Name, userAccountService);
230
231 return userAccountService;
232 }
233
234 /// <summary>
235 /// Start a presence service
236 /// </summary>
237 /// <param name="testScene"></param>
238 private static LocalPresenceServicesConnector StartPresenceService(Scene testScene)
239 {
240 IConfigSource config = new IniConfigSource();
241 config.AddConfig("Modules");
242 config.AddConfig("PresenceService");
243 config.Configs["Modules"].Set("PresenceServices", "LocalPresenceServicesConnector");
244 config.Configs["PresenceService"].Set("StorageProvider", "OpenSim.Data.Null.dll");
245 config.Configs["PresenceService"].Set(
246 "LocalServiceModule", "OpenSim.Services.PresenceService.dll:PresenceService");
247
248 LocalPresenceServicesConnector presenceService = new LocalPresenceServicesConnector();
249 presenceService.Initialise(config);
250
251 presenceService.AddRegion(testScene);
252 presenceService.RegionLoaded(testScene);
253 testScene.AddRegionModule(presenceService.Name, presenceService);
254
255 return presenceService;
256 }
257
258 /// <summary>
259 /// Setup modules for a scene using their default settings.
260 /// </summary>
261 /// <param name="scene"></param>
262 /// <param name="modules"></param>
263 public static void SetupSceneModules(Scene scene, params object[] modules)
264 {
265 SetupSceneModules(scene, new IniConfigSource(), modules);
266 }
267
268 /// <summary>
269 /// Setup modules for a scene.
270 /// </summary>
271 /// <param name="scene"></param>
272 /// <param name="config"></param>
273 /// <param name="modules"></param>
274 public static void SetupSceneModules(Scene scene, IConfigSource config, params object[] modules)
275 {
276 List<IRegionModuleBase> newModules = new List<IRegionModuleBase>();
277 foreach (object module in modules)
278 {
279 if (module is IRegionModule)
280 {
281 IRegionModule m = (IRegionModule)module;
282 m.Initialise(scene, config);
283 scene.AddModule(m.Name, m);
284 m.PostInitialise();
285 }
286 else if (module is IRegionModuleBase)
287 {
288 // for the new system, everything has to be initialised first,
289 // shared modules have to be post-initialised, then all get an AddRegion with the scene
290 IRegionModuleBase m = (IRegionModuleBase)module;
291 m.Initialise(config);
292 newModules.Add(m);
293 }
294 }
295
296 foreach (IRegionModuleBase module in newModules)
297 {
298 if (module is ISharedRegionModule) ((ISharedRegionModule)module).PostInitialise();
299 }
300
301 foreach (IRegionModuleBase module in newModules)
302 {
303 module.AddRegion(scene);
304 scene.AddRegionModule(module.Name, module);
305 }
306
307 // RegionLoaded is fired after all modules have been appropriately added to all scenes
308 foreach (IRegionModuleBase module in newModules)
309 module.RegionLoaded(scene);
310
311 scene.SetModuleInterfaces();
312 }
313
314 /// <summary>
315 /// Generate some standard agent connection data.
316 /// </summary>
317 /// <param name="agentId"></param>
318 /// <returns></returns>
319 public static AgentCircuitData GenerateAgentData(UUID agentId)
320 {
321 string firstName = "testfirstname";
322
323 AgentCircuitData agentData = new AgentCircuitData();
324 agentData.AgentID = agentId;
325 agentData.firstname = firstName;
326 agentData.lastname = "testlastname";
327 agentData.SessionID = UUID.Zero;
328 agentData.SecureSessionID = UUID.Zero;
329 agentData.circuitcode = 123;
330 agentData.BaseFolder = UUID.Zero;
331 agentData.InventoryFolder = UUID.Zero;
332 agentData.startpos = Vector3.Zero;
333 agentData.CapsPath = "http://wibble.com";
334
335 return agentData;
336 }
337
338 /// <summary>
339 /// Add a root agent where the details of the agent connection (apart from the id) are unimportant for the test
340 /// </summary>
341 /// <param name="scene"></param>
342 /// <param name="agentId"></param>
343 /// <returns></returns>
344 public static TestClient AddRootAgent(Scene scene, UUID agentId)
345 {
346 return AddRootAgent(scene, GenerateAgentData(agentId));
347 }
348
349 /// <summary>
350 /// Add a root agent.
351 /// </summary>
352 /// <remarks>
353 /// This function
354 ///
355 /// 1) Tells the scene that an agent is coming. Normally, the login service (local if standalone, from the
356 /// userserver if grid) would give initial login data back to the client and separately tell the scene that the
357 /// agent was coming.
358 ///
359 /// 2) Connects the agent with the scene
360 ///
361 /// This function performs actions equivalent with notifying the scene that an agent is
362 /// coming and then actually connecting the agent to the scene. The one step missed out is the very first
363 /// </remarks>
364 /// <param name="scene"></param>
365 /// <param name="agentData"></param>
366 /// <returns></returns>
367 public static TestClient AddRootAgent(Scene scene, AgentCircuitData agentData)
368 {
369 string reason;
370
371 // We emulate the proper login sequence here by doing things in four stages
372
373 // Stage 0: log the presence
374 scene.PresenceService.LoginAgent(agentData.AgentID.ToString(), agentData.SessionID, agentData.SecureSessionID);
375
376 // Stage 1: simulate login by telling the scene to expect a new user connection
377 if (!scene.NewUserConnection(agentData, (uint)TeleportFlags.ViaLogin, out reason))
378 Console.WriteLine("NewUserConnection failed: " + reason);
379
380 // Stage 2: add the new client as a child agent to the scene
381 TestClient client = new TestClient(agentData, scene);
382 scene.AddNewClient(client);
383
384 // Stage 3: Complete the entrance into the region. This converts the child agent into a root agent.
385 ScenePresence scp = scene.GetScenePresence(agentData.AgentID);
386 scp.CompleteMovement(client);
387 //scp.MakeRootAgent(new Vector3(90, 90, 90), true);
388
389 return client;
390 }
391
392 /// <summary>
393 /// Add a test object
394 /// </summary>
395 /// <param name="scene"></param>
396 /// <returns></returns>
397 public static SceneObjectPart AddSceneObject(Scene scene)
398 {
399 return AddSceneObject(scene, "Test Object");
400 }
401
402 /// <summary>
403 /// Add a test object
404 /// </summary>
405 /// <param name="scene"></param>
406 /// <param name="name"></param>
407 /// <returns></returns>
408 public static SceneObjectPart AddSceneObject(Scene scene, string name)
409 {
410 SceneObjectPart part = CreateSceneObjectPart(name, UUID.Random(), UUID.Zero);
411
412 //part.UpdatePrimFlags(false, false, true);
413 //part.ObjectFlags |= (uint)PrimFlags.Phantom;
414
415 scene.AddNewSceneObject(new SceneObjectGroup(part), false);
416
417 return part;
418 }
419
420 /// <summary>
421 /// Create a scene object part.
422 /// </summary>
423 /// <param name="name"></param>
424 /// <param name="id"></param>
425 /// <param name="ownerId"></param>
426 /// <returns></returns>
427 public static SceneObjectPart CreateSceneObjectPart(string name, UUID id, UUID ownerId)
428 {
429 return new SceneObjectPart(
430 ownerId, PrimitiveBaseShape.Default, Vector3.Zero, Quaternion.Identity, Vector3.Zero)
431 { Name = name, UUID = id, Scale = new Vector3(1, 1, 1) };
432 }
433
434 /// <summary>
435 /// Create a scene object but do not add it to the scene.
436 /// </summary>
437 /// <remarks>
438 /// UUID always starts at 00000000-0000-0000-0000-000000000001
439 /// </remarks>
440 /// <param name="parts">The number of parts that should be in the scene object</param>
441 /// <param name="ownerId"></param>
442 /// <returns></returns>
443 public static SceneObjectGroup CreateSceneObject(int parts, UUID ownerId)
444 {
445 return CreateSceneObject(parts, ownerId, "", 0x1);
446 }
447
448 /// <summary>
449 /// Create a scene object but do not add it to the scene.
450 /// </summary>
451 /// <param name="parts">
452 /// The number of parts that should be in the scene object
453 /// </param>
454 /// <param name="ownerId"></param>
455 /// <param name="partNamePrefix">
456 /// The prefix to be given to part names. This will be suffixed with "Part<part no>"
457 /// (e.g. mynamePart0 for the root part)
458 /// </param>
459 /// <param name="uuidTail">
460 /// The hexadecimal last part of the UUID for parts created. A UUID of the form "00000000-0000-0000-0000-{0:XD12}"
461 /// will be given to the root part, and incremented for each part thereafter.
462 /// </param>
463 /// <returns></returns>
464 public static SceneObjectGroup CreateSceneObject(int parts, UUID ownerId, string partNamePrefix, int uuidTail)
465 {
466 string rawSogId = string.Format("00000000-0000-0000-0000-{0:X12}", uuidTail);
467
468 SceneObjectGroup sog
469 = new SceneObjectGroup(
470 CreateSceneObjectPart(string.Format("{0}Part0", partNamePrefix), new UUID(rawSogId), ownerId));
471
472 if (parts > 1)
473 for (int i = 1; i < parts; i++)
474 sog.AddPart(
475 CreateSceneObjectPart(
476 string.Format("{0}Part{1}", partNamePrefix, i),
477 new UUID(string.Format("00000000-0000-0000-0000-{0:X12}", uuidTail + i)),
478 ownerId));
479
480 return sog;
481 }
482 }
483} \ No newline at end of file
diff --git a/OpenSim/Tests/Common/Helpers/TaskInventoryHelpers.cs b/OpenSim/Tests/Common/Helpers/TaskInventoryHelpers.cs
new file mode 100644
index 0000000..fbf00d6
--- /dev/null
+++ b/OpenSim/Tests/Common/Helpers/TaskInventoryHelpers.cs
@@ -0,0 +1,89 @@
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 OpenMetaverse;
30using OpenMetaverse.Assets;
31using OpenSim.Framework;
32using OpenSim.Region.Framework.Scenes;
33using OpenSim.Services.Interfaces;
34
35namespace OpenSim.Tests.Common.Setup
36{
37 /// <summary>
38 /// Utility functions for carrying out task inventory tests.
39 /// </summary>
40 ///
41 public static class TaskInventoryHelpers
42 {
43 /// <summary>
44 /// Add a notecard item to the given part.
45 /// </summary>
46 /// <param name="scene"></param>
47 /// <param name="part"></param>
48 /// <returns>The item that was added</returns>
49 public static TaskInventoryItem AddNotecard(Scene scene, SceneObjectPart part)
50 {
51 AssetNotecard nc = new AssetNotecard();
52 nc.BodyText = "Hello World!";
53 nc.Encode();
54 UUID ncAssetUuid = new UUID("00000000-0000-0000-1000-000000000000");
55 UUID ncItemUuid = new UUID("00000000-0000-0000-1100-000000000000");
56 AssetBase ncAsset
57 = AssetHelpers.CreateAsset(ncAssetUuid, AssetType.Notecard, nc.AssetData, UUID.Zero);
58 scene.AssetService.Store(ncAsset);
59 TaskInventoryItem ncItem
60 = new TaskInventoryItem
61 { Name = "ncItem", AssetID = ncAssetUuid, ItemID = ncItemUuid,
62 Type = (int)AssetType.Notecard, InvType = (int)InventoryType.Notecard };
63 part.Inventory.AddInventoryItem(ncItem, true);
64
65 return ncItem;
66 }
67
68 /// <summary>
69 /// Add a scene object item to the given part.
70 /// </summary>
71 /// <param name="scene"></param>
72 /// <param name="sop"></param>
73 /// <param name="itemName"></param>
74 /// <param name="id"></param>
75 public static TaskInventoryItem AddSceneObject(Scene scene, SceneObjectPart sop, string itemName, UUID id)
76 {
77 SceneObjectGroup taskSceneObject = SceneSetupHelpers.CreateSceneObject(1, UUID.Zero);
78 AssetBase taskSceneObjectAsset = AssetHelpers.CreateAsset(0x10, taskSceneObject);
79 scene.AssetService.Store(taskSceneObjectAsset);
80 TaskInventoryItem taskSceneObjectItem
81 = new TaskInventoryItem
82 { Name = itemName, AssetID = taskSceneObjectAsset.FullID, ItemID = id,
83 Type = (int)AssetType.Object, InvType = (int)InventoryType.Object };
84 sop.Inventory.AddInventoryItem(taskSceneObjectItem, true);
85
86 return taskSceneObjectItem;
87 }
88 }
89} \ No newline at end of file
diff --git a/OpenSim/Tests/Common/Helpers/UserAccountHelpers.cs b/OpenSim/Tests/Common/Helpers/UserAccountHelpers.cs
new file mode 100644
index 0000000..346f78a
--- /dev/null
+++ b/OpenSim/Tests/Common/Helpers/UserAccountHelpers.cs
@@ -0,0 +1,145 @@
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.Collections.Generic;
29using OpenMetaverse;
30using OpenSim.Framework.Communications;
31using OpenSim.Region.Framework.Scenes;
32using OpenSim.Services.Interfaces;
33
34namespace OpenSim.Tests.Common.Setup
35{
36 /// <summary>
37 /// Utility functions for carrying out user profile related tests.
38 /// </summary>
39 public static class UserAccountHelpers
40 {
41// /// <summary>
42// /// Create a test user with a standard inventory
43// /// </summary>
44// /// <param name="commsManager"></param>
45// /// <param name="callback">
46// /// Callback to invoke when inventory has been loaded. This is required because
47// /// loading may be asynchronous, even on standalone
48// /// </param>
49// /// <returns></returns>
50// public static CachedUserInfo CreateUserWithInventory(
51// CommunicationsManager commsManager, OnInventoryReceivedDelegate callback)
52// {
53// UUID userId = UUID.Parse("00000000-0000-0000-0000-000000000099");
54// return CreateUserWithInventory(commsManager, userId, callback);
55// }
56//
57// /// <summary>
58// /// Create a test user with a standard inventory
59// /// </summary>
60// /// <param name="commsManager"></param>
61// /// <param name="userId">User ID</param>
62// /// <param name="callback">
63// /// Callback to invoke when inventory has been loaded. This is required because
64// /// loading may be asynchronous, even on standalone
65// /// </param>
66// /// <returns></returns>
67// public static CachedUserInfo CreateUserWithInventory(
68// CommunicationsManager commsManager, UUID userId, OnInventoryReceivedDelegate callback)
69// {
70// return CreateUserWithInventory(commsManager, "Bill", "Bailey", userId, callback);
71// }
72//
73// /// <summary>
74// /// Create a test user with a standard inventory
75// /// </summary>
76// /// <param name="commsManager"></param>
77// /// <param name="firstName">First name of user</param>
78// /// <param name="lastName">Last name of user</param>
79// /// <param name="userId">User ID</param>
80// /// <param name="callback">
81// /// Callback to invoke when inventory has been loaded. This is required because
82// /// loading may be asynchronous, even on standalone
83// /// </param>
84// /// <returns></returns>
85// public static CachedUserInfo CreateUserWithInventory(
86// CommunicationsManager commsManager, string firstName, string lastName,
87// UUID userId, OnInventoryReceivedDelegate callback)
88// {
89// return CreateUserWithInventory(commsManager, firstName, lastName, "troll", userId, callback);
90// }
91//
92// /// <summary>
93// /// Create a test user with a standard inventory
94// /// </summary>
95// /// <param name="commsManager"></param>
96// /// <param name="firstName">First name of user</param>
97// /// <param name="lastName">Last name of user</param>
98// /// <param name="password">Password</param>
99// /// <param name="userId">User ID</param>
100// /// <param name="callback">
101// /// Callback to invoke when inventory has been loaded. This is required because
102// /// loading may be asynchronous, even on standalone
103// /// </param>
104// /// <returns></returns>
105// public static CachedUserInfo CreateUserWithInventory(
106// CommunicationsManager commsManager, string firstName, string lastName, string password,
107// UUID userId, OnInventoryReceivedDelegate callback)
108// {
109// LocalUserServices lus = (LocalUserServices)commsManager.UserService;
110// lus.AddUser(firstName, lastName, password, "bill@bailey.com", 1000, 1000, userId);
111//
112// CachedUserInfo userInfo = commsManager.UserProfileCacheService.GetUserDetails(userId);
113// userInfo.OnInventoryReceived += callback;
114// userInfo.FetchInventory();
115//
116// return userInfo;
117// }
118
119 public static UserAccount CreateUserWithInventory(Scene scene)
120 {
121 return CreateUserWithInventory(
122 scene, "Bill", "Bailey", UUID.Parse("00000000-0000-0000-0000-000000000099"), "troll");
123 }
124
125 public static UserAccount CreateUserWithInventory(
126 Scene scene, string firstName, string lastName, UUID userId, string pw)
127 {
128 UserAccount ua
129 = new UserAccount(userId)
130 { FirstName = firstName, LastName = lastName };
131 CreateUserWithInventory(scene, ua, pw);
132 return ua;
133 }
134
135 public static void CreateUserWithInventory(Scene scene, UserAccount ua, string pw)
136 {
137 // FIXME: This should really be set up by UserAccount itself
138 ua.ServiceURLs = new Dictionary<string, object>();
139
140 scene.UserAccountService.StoreUserAccount(ua);
141 scene.InventoryService.CreateUserInventory(ua.PrincipalID);
142 scene.AuthenticationService.SetPassword(ua.PrincipalID, pw);
143 }
144 }
145} \ No newline at end of file
diff --git a/OpenSim/Tests/Common/Helpers/UserInventoryHelpers.cs b/OpenSim/Tests/Common/Helpers/UserInventoryHelpers.cs
new file mode 100644
index 0000000..0419134
--- /dev/null
+++ b/OpenSim/Tests/Common/Helpers/UserInventoryHelpers.cs
@@ -0,0 +1,115 @@
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 OpenMetaverse;
30using OpenSim.Framework;
31using OpenSim.Region.Framework.Scenes;
32using OpenSim.Services.Interfaces;
33
34namespace OpenSim.Tests.Common
35{
36 /// <summary>
37 /// Utility functions for carrying out user inventory tests.
38 /// </summary>
39 public static class UserInventoryHelpers
40 {
41 public static readonly string PATH_DELIMITER = "/";
42
43 public static InventoryItemBase CreateInventoryItem(
44 Scene scene, string itemName, UUID itemId, string folderPath, UUID userId)
45 {
46 InventoryItemBase item = new InventoryItemBase();
47 item.Name = itemName;
48 item.AssetID = AssetHelpers.CreateAsset(scene, userId).FullID;
49 item.ID = itemId;
50
51 // Really quite bad since the objs folder could be moved in the future and confuse the tests
52 InventoryFolderBase objsFolder = scene.InventoryService.GetFolderForType(userId, AssetType.Object);
53
54 item.Folder = objsFolder.ID;
55 scene.AddInventoryItem(item);
56
57 return item;
58 }
59
60 /// <summary>
61 /// Create inventory folders starting from the user's root folder.
62 /// </summary>
63 ///
64 /// Ignores any existing folders with the same name
65 ///
66 /// <param name="inventoryService"></param>
67 /// <param name="userId"></param>
68 /// <param name="path">
69 /// The folders to create. Multiple folders can be specified on a path delimited by the PATH_DELIMITER
70 /// </param>
71 /// <returns>
72 /// The folder created. If the path contains multiple folders then the last one created is returned.
73 /// Will return null if the root folder could not be found.
74 /// </returns>
75 public static InventoryFolderBase CreateInventoryFolder(
76 IInventoryService inventoryService, UUID userId, string path)
77 {
78 InventoryFolderBase rootFolder = inventoryService.GetRootFolder(userId);
79
80 if (null == rootFolder)
81 return null;
82
83 return CreateInventoryFolder(inventoryService, rootFolder, path);
84 }
85
86 /// <summary>
87 /// Create inventory folders starting from a given parent folder
88 /// </summary>
89 ///
90 /// Ignores any existing folders with the same name
91 ///
92 /// <param name="inventoryService"></param>
93 /// <param name="parentFolder"></param>
94 /// <param name="path">
95 /// The folders to create. Multiple folders can be specified on a path delimited by the PATH_DELIMITER
96 /// </param>
97 /// <returns>
98 /// The folder created. If the path contains multiple folders then the last one created is returned.
99 /// </returns>
100 public static InventoryFolderBase CreateInventoryFolder(
101 IInventoryService inventoryService, InventoryFolderBase parentFolder, string path)
102 {
103 string[] components = path.Split(new string[] { PATH_DELIMITER }, 2, StringSplitOptions.None);
104
105 InventoryFolderBase newFolder
106 = new InventoryFolderBase(UUID.Random(), components[0], parentFolder.Owner, parentFolder.ID);
107 inventoryService.AddFolder(newFolder);
108
109 if (components.Length > 1)
110 return CreateInventoryFolder(inventoryService, newFolder, components[1]);
111 else
112 return newFolder;
113 }
114 }
115} \ No newline at end of file