aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Grid/NewAssetServer/Metadata.cs
diff options
context:
space:
mode:
authorMike Mazur2009-02-16 02:24:57 +0000
committerMike Mazur2009-02-16 02:24:57 +0000
commit0e09b4a08beddb3b0239a3f088ab9a230b8f3979 (patch)
tree481d1cb9a60062dea6e646e0e6c5d9d87ce40b6e /OpenSim/Grid/NewAssetServer/Metadata.cs
parentThank you, cmickeyb, for a patch to ass two string functions (diff)
downloadopensim-SC-0e09b4a08beddb3b0239a3f088ab9a230b8f3979.zip
opensim-SC-0e09b4a08beddb3b0239a3f088ab9a230b8f3979.tar.gz
opensim-SC-0e09b4a08beddb3b0239a3f088ab9a230b8f3979.tar.bz2
opensim-SC-0e09b4a08beddb3b0239a3f088ab9a230b8f3979.tar.xz
Adding
- NewAssetServer code - NewAssetServer addin manifest - example AssetServer.ini file
Diffstat (limited to 'OpenSim/Grid/NewAssetServer/Metadata.cs')
-rw-r--r--OpenSim/Grid/NewAssetServer/Metadata.cs85
1 files changed, 85 insertions, 0 deletions
diff --git a/OpenSim/Grid/NewAssetServer/Metadata.cs b/OpenSim/Grid/NewAssetServer/Metadata.cs
new file mode 100644
index 0000000..247a3e8
--- /dev/null
+++ b/OpenSim/Grid/NewAssetServer/Metadata.cs
@@ -0,0 +1,85 @@
1using System;
2using System.Collections.Generic;
3using System.Xml;
4using OpenMetaverse;
5using OpenMetaverse.StructuredData;
6
7namespace AssetServer
8{
9 public class Metadata
10 {
11 public UUID ID;
12 public string Name;
13 public string Description;
14 public DateTime CreationDate;
15 public string ContentType;
16 public byte[] SHA1;
17 public bool Temporary;
18 public Dictionary<string, Uri> Methods = new Dictionary<string, Uri>();
19 public OSDMap ExtraData;
20
21 public OSDMap SerializeToOSD()
22 {
23 OSDMap osdata = new OSDMap();
24
25 if (ID != UUID.Zero) osdata["id"] = OSD.FromUUID(ID);
26 osdata["name"] = OSD.FromString(Name);
27 osdata["description"] = OSD.FromString(Description);
28 osdata["creation_date"] = OSD.FromDate(CreationDate);
29 osdata["type"] = OSD.FromString(ContentType);
30 osdata["sha1"] = OSD.FromBinary(SHA1);
31 osdata["temporary"] = OSD.FromBoolean(Temporary);
32
33 OSDMap methods = new OSDMap(Methods.Count);
34 foreach (KeyValuePair<string, Uri> kvp in Methods)
35 methods.Add(kvp.Key, OSD.FromUri(kvp.Value));
36 osdata["methods"] = methods;
37
38 if (ExtraData != null) osdata["extra_data"] = ExtraData;
39
40 return osdata;
41 }
42
43 public byte[] SerializeToBytes()
44 {
45 LitJson.JsonData jsonData = OSDParser.SerializeJson(SerializeToOSD());
46 return System.Text.Encoding.UTF8.GetBytes(jsonData.ToJson());
47 }
48
49 public void Deserialize(byte[] data)
50 {
51 OSD osdata = OSDParser.DeserializeJson(System.Text.Encoding.UTF8.GetString(data));
52 Deserialize(osdata);
53 }
54
55 public void Deserialize(string data)
56 {
57 OSD osdata = OSDParser.DeserializeJson(data);
58 Deserialize(osdata);
59 }
60
61 public void Deserialize(OSD osdata)
62 {
63 if (osdata.Type == OSDType.Map)
64 {
65 OSDMap map = (OSDMap)osdata;
66 ID = map["id"].AsUUID();
67 Name = map["name"].AsString();
68 Description = map["description"].AsString();
69 CreationDate = map["creation_date"].AsDate();
70 ContentType = map["type"].AsString();
71 SHA1 = map["sha1"].AsBinary();
72 Temporary = map["temporary"].AsBoolean();
73
74 OSDMap methods = map["methods"] as OSDMap;
75 if (methods != null)
76 {
77 foreach (KeyValuePair<string, OSD> kvp in methods)
78 Methods.Add(kvp.Key, kvp.Value.AsUri());
79 }
80
81 ExtraData = map["extra_data"] as OSDMap;
82 }
83 }
84 }
85}