opensim – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | eva | 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 | { |
||
40 | /// <summary> |
||
41 | /// Create a notecard asset with a random uuids and dummy text. |
||
42 | /// </summary> |
||
43 | /// <returns></returns> |
||
44 | public static AssetBase CreateNotecardAsset() |
||
45 | { |
||
46 | return CreateNotecardAsset(UUID.Random()); |
||
47 | } |
||
48 | |||
49 | /// <summary> |
||
50 | /// Create a notecard asset with dummy text and a random owner. |
||
51 | /// </summary> |
||
52 | /// <param name="assetId">/param> |
||
53 | /// <returns></returns> |
||
54 | public static AssetBase CreateNotecardAsset(UUID assetId) |
||
55 | { |
||
56 | return CreateNotecardAsset(assetId, "hello"); |
||
57 | } |
||
58 | |||
59 | /// <summary> |
||
60 | /// Create a notecard asset with a random owner. |
||
61 | /// </summary> |
||
62 | /// <param name="assetId">/param> |
||
63 | /// <param name="text"></param> |
||
64 | /// <returns></returns> |
||
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 | |||
82 | /// <summary> |
||
83 | /// Create an asset from the given object. |
||
84 | /// </summary> |
||
85 | /// <param name="assetUuidTail"> |
||
86 | /// The hexadecimal last part of the UUID for the asset created. A UUID of the form "00000000-0000-0000-0000-{0:XD12}" |
||
87 | /// will be used. |
||
88 | /// </param> |
||
89 | /// <param name="sog"></param> |
||
90 | /// <returns></returns> |
||
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 | |||
96 | /// <summary> |
||
97 | /// Create an asset from the given object. |
||
98 | /// </summary> |
||
99 | /// <param name="assetUuid"></param> |
||
100 | /// <param name="sog"></param> |
||
101 | /// <returns></returns> |
||
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 | |||
111 | /// <summary> |
||
112 | /// Create an asset from the given scene object. |
||
113 | /// </summary> |
||
114 | /// <param name="assetUuidTail"> |
||
115 | /// The hexadecimal last part of the UUID for the asset created. A UUID of the form "00000000-0000-0000-0000-{0:XD12}" |
||
116 | /// will be used. |
||
117 | /// </param> |
||
118 | /// <param name="coa"></param> |
||
119 | /// <returns></returns> |
||
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 | |||
125 | /// <summary> |
||
126 | /// Create an asset from the given scene object. |
||
127 | /// </summary> |
||
128 | /// <param name="assetUuid"></param> |
||
129 | /// <param name="coa"></param> |
||
130 | /// <returns></returns> |
||
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 | |||
140 | /// <summary> |
||
141 | /// Create an asset from the given data. |
||
142 | /// </summary> |
||
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 | |||
152 | /// <summary> |
||
153 | /// Create an asset from the given data. |
||
154 | /// </summary> |
||
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 | } |