diff options
author | UbitUmarov | 2015-09-01 11:43:07 +0100 |
---|---|---|
committer | UbitUmarov | 2015-09-01 11:43:07 +0100 |
commit | fb78b182520fc9bb0f971afd0322029c70278ea6 (patch) | |
tree | b4e30d383938fdeef8c92d1d1c2f44bb61d329bd /OpenSim/Services/Base | |
parent | lixo (diff) | |
parent | Mantis #7713: fixed bug introduced by 1st MOSES patch. (diff) | |
download | opensim-SC_OLD-fb78b182520fc9bb0f971afd0322029c70278ea6.zip opensim-SC_OLD-fb78b182520fc9bb0f971afd0322029c70278ea6.tar.gz opensim-SC_OLD-fb78b182520fc9bb0f971afd0322029c70278ea6.tar.bz2 opensim-SC_OLD-fb78b182520fc9bb0f971afd0322029c70278ea6.tar.xz |
Merge remote-tracking branch 'os/master'
Diffstat (limited to 'OpenSim/Services/Base')
-rw-r--r-- | OpenSim/Services/Base/Properties/AssemblyInfo.cs | 33 | ||||
-rw-r--r-- | OpenSim/Services/Base/ServiceBase.cs | 121 |
2 files changed, 154 insertions, 0 deletions
diff --git a/OpenSim/Services/Base/Properties/AssemblyInfo.cs b/OpenSim/Services/Base/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..a3fb11b --- /dev/null +++ b/OpenSim/Services/Base/Properties/AssemblyInfo.cs | |||
@@ -0,0 +1,33 @@ | |||
1 | using System.Reflection; | ||
2 | using System.Runtime.CompilerServices; | ||
3 | using System.Runtime.InteropServices; | ||
4 | |||
5 | // General Information about an assembly is controlled through the following | ||
6 | // set of attributes. Change these attribute values to modify the information | ||
7 | // associated with an assembly. | ||
8 | [assembly: AssemblyTitle("OpenSim.Services.Base")] | ||
9 | [assembly: AssemblyDescription("")] | ||
10 | [assembly: AssemblyConfiguration("")] | ||
11 | [assembly: AssemblyCompany("http://opensimulator.org")] | ||
12 | [assembly: AssemblyProduct("OpenSim")] | ||
13 | [assembly: AssemblyCopyright("OpenSimulator developers")] | ||
14 | [assembly: AssemblyTrademark("")] | ||
15 | [assembly: AssemblyCulture("")] | ||
16 | |||
17 | // Setting ComVisible to false makes the types in this assembly not visible | ||
18 | // to COM components. If you need to access a type in this assembly from | ||
19 | // COM, set the ComVisible attribute to true on that type. | ||
20 | [assembly: ComVisible(false)] | ||
21 | |||
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM | ||
23 | [assembly: Guid("db9f6f73-3a56-497f-a465-4bea9cb86062")] | ||
24 | |||
25 | // Version information for an assembly consists of the following four values: | ||
26 | // | ||
27 | // Major Version | ||
28 | // Minor Version | ||
29 | // Build Number | ||
30 | // Revision | ||
31 | // | ||
32 | [assembly: AssemblyVersion("0.8.2.*")] | ||
33 | |||
diff --git a/OpenSim/Services/Base/ServiceBase.cs b/OpenSim/Services/Base/ServiceBase.cs new file mode 100644 index 0000000..a7eb2be --- /dev/null +++ b/OpenSim/Services/Base/ServiceBase.cs | |||
@@ -0,0 +1,121 @@ | |||
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 System.Collections.Generic; | ||
30 | using System.IO; | ||
31 | using System.Reflection; | ||
32 | using log4net; | ||
33 | using Nini.Config; | ||
34 | using OpenSim.Services.Interfaces; | ||
35 | |||
36 | namespace OpenSim.Services.Base | ||
37 | { | ||
38 | public class ServiceBase | ||
39 | { | ||
40 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
41 | |||
42 | public T LoadPlugin<T>(string dllName) where T:class | ||
43 | { | ||
44 | return LoadPlugin<T>(dllName, new Object[0]); | ||
45 | } | ||
46 | |||
47 | public T LoadPlugin<T>(string dllName, Object[] args) where T:class | ||
48 | { | ||
49 | // The path:type separator : is unfortunate because it collides | ||
50 | // with Windows paths like C:\... | ||
51 | // When the path provided includes the drive, this fails. | ||
52 | // Hence the root/noroot thing going on here. | ||
53 | string pathRoot = Path.GetPathRoot(dllName); | ||
54 | string noRoot = dllName.Substring(pathRoot.Length); | ||
55 | string[] parts = noRoot.Split(new char[] {':'}); | ||
56 | |||
57 | dllName = pathRoot + parts[0]; | ||
58 | |||
59 | string className = String.Empty; | ||
60 | |||
61 | if (parts.Length > 1) | ||
62 | className = parts[1]; | ||
63 | |||
64 | return LoadPlugin<T>(dllName, className, args); | ||
65 | } | ||
66 | |||
67 | public T LoadPlugin<T>(string dllName, string className, Object[] args) where T:class | ||
68 | { | ||
69 | string interfaceName = typeof(T).ToString(); | ||
70 | |||
71 | try | ||
72 | { | ||
73 | Assembly pluginAssembly = Assembly.LoadFrom(dllName); | ||
74 | |||
75 | // m_log.DebugFormat("[SERVICE BASE]: Found assembly {0}", dllName); | ||
76 | |||
77 | foreach (Type pluginType in pluginAssembly.GetTypes()) | ||
78 | { | ||
79 | // m_log.DebugFormat("[SERVICE BASE]: Found type {0}", pluginType); | ||
80 | |||
81 | if (pluginType.IsPublic) | ||
82 | { | ||
83 | if (className != String.Empty && | ||
84 | pluginType.ToString() != | ||
85 | pluginType.Namespace + "." + className) | ||
86 | continue; | ||
87 | |||
88 | Type typeInterface = | ||
89 | pluginType.GetInterface(interfaceName); | ||
90 | if (typeInterface != null) | ||
91 | { | ||
92 | T plug = (T)Activator.CreateInstance(pluginType, | ||
93 | args); | ||
94 | |||
95 | return plug; | ||
96 | } | ||
97 | } | ||
98 | } | ||
99 | |||
100 | return null; | ||
101 | } | ||
102 | catch (Exception e) | ||
103 | { | ||
104 | List<string> strArgs = new List<string>(); | ||
105 | foreach (Object arg in args) | ||
106 | strArgs.Add(arg.ToString()); | ||
107 | |||
108 | m_log.Error( | ||
109 | string.Format( | ||
110 | "[SERVICE BASE]: Failed to load plugin {0} from {1} with args {2}", | ||
111 | interfaceName, dllName, string.Join(", ", strArgs.ToArray())), e); | ||
112 | |||
113 | return null; | ||
114 | } | ||
115 | } | ||
116 | |||
117 | public ServiceBase(IConfigSource config) | ||
118 | { | ||
119 | } | ||
120 | } | ||
121 | } \ No newline at end of file | ||