aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Server/Base/ServerUtils.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Server/Base/ServerUtils.cs')
-rw-r--r--OpenSim/Server/Base/ServerUtils.cs148
1 files changed, 148 insertions, 0 deletions
diff --git a/OpenSim/Server/Base/ServerUtils.cs b/OpenSim/Server/Base/ServerUtils.cs
new file mode 100644
index 0000000..ae0c3d4
--- /dev/null
+++ b/OpenSim/Server/Base/ServerUtils.cs
@@ -0,0 +1,148 @@
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 OpenSim 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.IO;
30using System.Reflection;
31using System.Xml;
32using System.Xml.Serialization;
33using System.Text;
34
35namespace OpenSim.Server.Base
36{
37 public static class ServerUtils
38 {
39 public static string SLAssetTypeToContentType(int assetType)
40 {
41 switch (assetType)
42 {
43 case 0:
44 return "image/jp2";
45 case 1:
46 return "application/ogg";
47 case 2:
48 return "application/x-metaverse-callingcard";
49 case 3:
50 return "application/x-metaverse-landmark";
51 case 5:
52 return "application/x-metaverse-clothing";
53 case 6:
54 return "application/x-metaverse-primitive";
55 case 7:
56 return "application/x-metaverse-notecard";
57 case 8:
58 return "application/x-metaverse-folder";
59 case 10:
60 return "application/x-metaverse-lsl";
61 case 11:
62 return "application/x-metaverse-lso";
63 case 12:
64 return "image/tga";
65 case 13:
66 return "application/x-metaverse-bodypart";
67 case 17:
68 return "audio/x-wav";
69 case 19:
70 return "image/jpeg";
71 case 20:
72 return "application/x-metaverse-animation";
73 case 21:
74 return "application/x-metaverse-gesture";
75 case 22:
76 return "application/x-metaverse-simstate";
77 default:
78 return "application/octet-stream";
79 }
80 }
81
82 public static byte[] SerializeResult(XmlSerializer xs, object data)
83 {
84 MemoryStream ms = new MemoryStream();
85 XmlTextWriter xw = new XmlTextWriter(ms, Encoding.UTF8);
86 xw.Formatting = Formatting.Indented;
87 xs.Serialize(xw, data);
88 xw.Flush();
89
90 ms.Seek(0, SeekOrigin.Begin);
91 byte[] ret = ms.GetBuffer();
92 Array.Resize<byte>(ref ret, (int)ms.Length);
93
94 return ret;
95 }
96
97 public static T LoadPlugin<T>(string dllName, Object[] args) where T:class
98 {
99 string[] parts = dllName.Split(new char[] {':'});
100
101 dllName = parts[0];
102
103 string className = String.Empty;
104
105 if (parts.Length > 1)
106 className = parts[1];
107
108 return LoadPlugin<T>(dllName, className, args);
109 }
110
111 public static T LoadPlugin<T>(string dllName, string className, Object[] args) where T:class
112 {
113 string interfaceName = typeof(T).ToString();
114
115 try
116 {
117 Assembly pluginAssembly = Assembly.LoadFrom(dllName);
118
119 foreach (Type pluginType in pluginAssembly.GetTypes())
120 {
121 if (pluginType.IsPublic)
122 {
123 if (className != String.Empty &&
124 pluginType.ToString() !=
125 pluginType.Namespace + "." + className)
126 continue;
127
128 Type typeInterface =
129 pluginType.GetInterface(interfaceName, true);
130 if (typeInterface != null)
131 {
132 T plug = (T)Activator.CreateInstance(pluginType,
133 args);
134
135 return plug;
136 }
137 }
138 }
139
140 return null;
141 }
142 catch (Exception e)
143 {
144 return null;
145 }
146 }
147 }
148}