30 using System.Collections.Generic;
31 using System.Reflection;
34 using OpenSim.Services.Interfaces;
40 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
42 public T LoadPlugin<T>(
string dllName) where T:
class
44 return LoadPlugin<T>(dllName,
new Object[0]);
47 public T LoadPlugin<T>(
string dllName, Object[] args) where T:
class
53 string pathRoot = Path.GetPathRoot(dllName);
54 string noRoot = dllName.Substring(pathRoot.Length);
55 string[] parts = noRoot.Split(
new char[] {
':'});
58 dllName = pathRoot + parts[0];
60 string className = String.Empty;
65 return LoadPlugin<T>(dllName, className, args);
68 public T LoadPlugin<T>(
string dllName,
string className, Object[] args) where T:
class
70 string interfaceName = typeof(T).ToString();
74 Assembly pluginAssembly = Assembly.LoadFrom(dllName);
78 foreach (Type pluginType
in pluginAssembly.GetTypes())
82 if (pluginType.IsPublic)
84 if (className != String.Empty &&
85 pluginType.ToString() !=
86 pluginType.Namespace +
"." + className)
90 pluginType.GetInterface(interfaceName);
91 if (typeInterface != null)
93 T plug = (T)Activator.CreateInstance(pluginType,
105 List<string> strArgs =
new List<string>();
106 foreach (Object arg
in args)
107 strArgs.Add(arg.ToString());
111 "[SERVICE BASE]: Failed to load plugin {0} from {1} with args {2}",
112 interfaceName, dllName, string.Join(
", ", strArgs.ToArray())), e);
ServiceBase(IConfigSource config)
Interactive OpenSim region server