OpenSim
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
TaskInventoryHelpers.cs
Go to the documentation of this file.
1 /*
2  * Copyright (c) Contributors, http://opensimulator.org/
3  * See CONTRIBUTORS.TXT for a full list of copyright holders.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  * * Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * * Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * * Neither the name of the OpenSimulator Project nor the
13  * names of its contributors may be used to endorse or promote products
14  * derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19  * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 using System;
29 using OpenMetaverse;
30 using OpenMetaverse.Assets;
31 using OpenSim.Framework;
32 using OpenSim.Region.Framework.Scenes;
33 using OpenSim.Services.Interfaces;
34 
35 namespace OpenSim.Tests.Common
36 {
41  public static class TaskInventoryHelpers
42  {
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 
70  public static TaskInventoryItem AddNotecard(
71  IAssetService assetService, SceneObjectPart part, string itemName, UUID itemID, UUID assetID, string text)
72  {
73  AssetNotecard nc = new AssetNotecard();
74  nc.BodyText = text;
75  nc.Encode();
76 
77  AssetBase ncAsset
78  = AssetHelpers.CreateAsset(assetID, AssetType.Notecard, nc.AssetData, UUID.Zero);
79  assetService.Store(ncAsset);
80 
81  TaskInventoryItem ncItem
82  = new TaskInventoryItem
83  { Name = itemName, AssetID = assetID, ItemID = itemID,
84  Type = (int)AssetType.Notecard, InvType = (int)InventoryType.Notecard };
85  part.Inventory.AddInventoryItem(ncItem, true);
86 
87  return ncItem;
88  }
89 
100  public static TaskInventoryItem AddScript(IAssetService assetService, SceneObjectPart part)
101  {
102  return AddScript(assetService, part, "scriptItem", "default { state_entry() { llSay(0, \"Hello World\"); } }");
103  }
104 
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 
137  public static TaskInventoryItem AddScript(
138  IAssetService assetService, SceneObjectPart part, UUID itemId, UUID assetId, string scriptName, string scriptSource)
139  {
140  AssetScriptText ast = new AssetScriptText();
141  ast.Source = scriptSource;
142  ast.Encode();
143 
144  AssetBase asset
145  = AssetHelpers.CreateAsset(assetId, AssetType.LSLText, ast.AssetData, UUID.Zero);
146  assetService.Store(asset);
147  TaskInventoryItem item
148  = new TaskInventoryItem
149  { Name = scriptName, AssetID = assetId, ItemID = itemId,
150  Type = (int)AssetType.LSLText, InvType = (int)InventoryType.LSL };
151  part.Inventory.AddInventoryItem(item, true);
152 
153  return item;
154  }
155 
170  public static TaskInventoryItem AddSceneObject(
171  IAssetService assetService, SceneObjectPart sop, string itemName, UUID itemId, SceneObjectGroup soToAdd, UUID soAssetId)
172  {
173  AssetBase taskSceneObjectAsset = AssetHelpers.CreateAsset(soAssetId, soToAdd);
174  assetService.Store(taskSceneObjectAsset);
175  TaskInventoryItem taskSceneObjectItem
176  = new TaskInventoryItem
177  { Name = itemName,
178  AssetID = taskSceneObjectAsset.FullID,
179  ItemID = itemId,
180  OwnerID = soToAdd.OwnerID,
181  Type = (int)AssetType.Object,
182  InvType = (int)InventoryType.Object };
183  sop.Inventory.AddInventoryItem(taskSceneObjectItem, true);
184 
185  return taskSceneObjectItem;
186  }
187 
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  }
209  }
210 }
A scene object group is conceptually an object in the scene. The object is constituted of SceneObject...
Represents an item in a task inventory
Asset class. All Assets are reference by this class or a class derived from this class ...
Definition: AssetBase.cs:49