OpenSim
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
AssetHelpers.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.Text;
29 using OpenMetaverse;
30 using OpenMetaverse.Assets;
31 using OpenSim.Framework;
32 using OpenSim.Region.Framework.Scenes;
33 using OpenSim.Region.Framework.Scenes.Serialization;
34 using OpenSim.Services.Interfaces;
35 
36 namespace OpenSim.Tests.Common
37 {
38  public class AssetHelpers
39  {
45  {
46  return CreateNotecardAsset(UUID.Random());
47  }
48 
54  public static AssetBase CreateNotecardAsset(UUID assetId)
55  {
56  return CreateNotecardAsset(assetId, "hello");
57  }
58 
65  public static AssetBase CreateNotecardAsset(UUID assetId, string text)
66  {
67  return CreateAsset(assetId, AssetType.Notecard, text, UUID.Random());
68  }
69 
70 // /// <summary>
71 // /// Create and store a notecard asset with a random uuid and dummy text.
72 // /// </summary>
73 // /// <param name="creatorId">/param>
74 // /// <returns></returns>
75 // public static AssetBase CreateNotecardAsset(Scene scene, UUID creatorId)
76 // {
77 // AssetBase asset = CreateAsset(UUID.Random(), AssetType.Notecard, "hello", creatorId);
78 // scene.AssetService.Store(asset);
79 // return asset;
80 // }
81 
91  public static AssetBase CreateAsset(int assetUuidTail, SceneObjectGroup sog)
92  {
93  return CreateAsset(new UUID(string.Format("00000000-0000-0000-0000-{0:X12}", assetUuidTail)), sog);
94  }
95 
102  public static AssetBase CreateAsset(UUID assetUuid, SceneObjectGroup sog)
103  {
104  return CreateAsset(
105  assetUuid,
106  AssetType.Object,
107  Encoding.ASCII.GetBytes(SceneObjectSerializer.ToOriginalXmlFormat(sog)),
108  sog.OwnerID);
109  }
110 
120  public static AssetBase CreateAsset(int assetUuidTail, CoalescedSceneObjects coa)
121  {
122  return CreateAsset(new UUID(string.Format("00000000-0000-0000-0000-{0:X12}", assetUuidTail)), coa);
123  }
124 
131  public static AssetBase CreateAsset(UUID assetUuid, CoalescedSceneObjects coa)
132  {
133  return CreateAsset(
134  assetUuid,
135  AssetType.Object,
136  Encoding.ASCII.GetBytes(CoalescedSceneObjectsSerializer.ToXml(coa)),
137  coa.CreatorId);
138  }
139 
143  public static AssetBase CreateAsset(UUID assetUuid, AssetType assetType, string text, UUID creatorID)
144  {
145  AssetNotecard anc = new AssetNotecard();
146  anc.BodyText = text;
147  anc.Encode();
148 
149  return CreateAsset(assetUuid, assetType, anc.AssetData, creatorID);
150  }
151 
155  public static AssetBase CreateAsset(UUID assetUuid, AssetType assetType, byte[] data, UUID creatorID)
156  {
157  AssetBase asset = new AssetBase(assetUuid, assetUuid.ToString(), (sbyte)assetType, creatorID.ToString());
158  asset.Data = data;
159  return asset;
160  }
161 
162  public static string ReadAssetAsString(IAssetService assetService, UUID uuid)
163  {
164  byte[] assetData = assetService.GetData(uuid.ToString());
165  return Encoding.ASCII.GetString(assetData);
166  }
167  }
168 }
static AssetBase CreateNotecardAsset(UUID assetId)
Create a notecard asset with dummy text and a random owner.
Definition: AssetHelpers.cs:54
static string ReadAssetAsString(IAssetService assetService, UUID uuid)
A scene object group is conceptually an object in the scene. The object is constituted of SceneObject...
static AssetBase CreateAsset(int assetUuidTail, CoalescedSceneObjects coa)
Create an asset from the given scene object.
static AssetBase CreateAsset(UUID assetUuid, AssetType assetType, byte[] data, UUID creatorID)
Create an asset from the given data.
Asset class. All Assets are reference by this class or a class derived from this class ...
Definition: AssetBase.cs:49
static string ToOriginalXmlFormat(SceneObjectGroup sceneObject)
Serialize a scene object to the original xml format
static AssetBase CreateNotecardAsset(UUID assetId, string text)
Create a notecard asset with a random owner.
Definition: AssetHelpers.cs:65
static AssetBase CreateNotecardAsset()
Create a notecard asset with a random uuids and dummy text.
Definition: AssetHelpers.cs:44
static AssetBase CreateAsset(int assetUuidTail, SceneObjectGroup sog)
Create an asset from the given object.
Definition: AssetHelpers.cs:91
static AssetBase CreateAsset(UUID assetUuid, AssetType assetType, string text, UUID creatorID)
Create an asset from the given data.
static AssetBase CreateAsset(UUID assetUuid, CoalescedSceneObjects coa)
Create an asset from the given scene object.
static AssetBase CreateAsset(UUID assetUuid, SceneObjectGroup sog)
Create an asset from the given object.
static string ToXml(CoalescedSceneObjects coa)
Serialize coalesced objects to Xml
Represents a coalescene of scene objects. A coalescence occurs when objects that are not in the same ...
UUID CreatorId
The creator of this coalesence, though not necessarily the objects within it.