diff --git a/ExtensionLoader/ExtensionLoader.cs b/ExtensionLoader/ExtensionLoader.cs
new file mode 100644
index 00000000..e9ae9c58
--- /dev/null
+++ b/ExtensionLoader/ExtensionLoader.cs
@@ -0,0 +1,191 @@
+using System;
+using System.Collections.Generic;
+using System.Reflection;
+using System.CodeDom.Compiler;
+using System.IO;
+
+namespace ExtensionLoader
+{
+ ///
+ /// Exception thrown when there is a problem with an extension
+ ///
+ public class ExtensionException : Exception
+ {
+ public ExtensionException(string message)
+ : base(message)
+ {
+ }
+
+ public ExtensionException(string message, Exception innerException)
+ : base(message, innerException)
+ {
+ }
+ }
+
+ public static class ExtensionLoader
+ {
+ /// Currently loaded extensions
+ public static List Extensions;
+ ///
+ public static CodeDomProvider CSCompiler;
+ ///
+ public static CompilerParameters CSCompilerParams;
+
+ static ExtensionLoader()
+ {
+ Extensions = new List();
+
+ CSCompiler = CodeDomProvider.CreateProvider("C#");
+
+ CSCompilerParams = new CompilerParameters();
+ CSCompilerParams.GenerateExecutable = false;
+ CSCompilerParams.GenerateInMemory = true;
+ if (System.Diagnostics.Debugger.IsAttached)
+ CSCompilerParams.IncludeDebugInformation = true;
+ else
+ CSCompilerParams.IncludeDebugInformation = false;
+ }
+
+ ///
+ /// Load extensions within the current assembly, from assembly files in
+ /// a given directory, or from source code files in a given directory
+ ///
+ /// Main assembly to load extensions from
+ /// Directory to load assembly and source code
+ /// extensions from
+ /// Object that owns the extensions. A reference to
+ /// this is passed to the constructor of each extension
+ /// List of assemblies the
+ /// extensions need references to
+ /// Search pattern for extension
+ /// dlls, for example MyApp.Extension.*.dll
+ /// Search pattern for extension
+ /// source code files, for example MyApp.Extension.*.cs
+ /// The object containing the
+ /// assignable interfaces
+ /// A list of interface types and
+ /// interface references to assign extensions to
+ public static void LoadAllExtensions(Assembly assembly, string path, TOwner owner,
+ List referencedAssemblies, string assemblySearchPattern, string sourceSearchPattern,
+ object assignablesParent, Dictionary assignableInterfaces)
+ {
+ // Add referenced assemblies to the C# compiler
+ CSCompilerParams.ReferencedAssemblies.Clear();
+ if (referencedAssemblies != null)
+ {
+ for (int i = 0; i < referencedAssemblies.Count; i++)
+ CSCompilerParams.ReferencedAssemblies.Add(referencedAssemblies[i]);
+ }
+
+ // Load internal extensions
+ LoadAssemblyExtensions(assembly, owner);
+
+ // Load extensions from external assemblies
+ List extensionNames = ListExtensionAssemblies(path, assemblySearchPattern);
+ foreach (string name in extensionNames)
+ LoadAssemblyExtensions(Assembly.LoadFile(name), owner);
+
+ // Load extensions from external code files
+ extensionNames = ListExtensionSourceFiles(path, sourceSearchPattern);
+ foreach (string name in extensionNames)
+ {
+ CompilerResults results = CSCompiler.CompileAssemblyFromFile(CSCompilerParams, name);
+ if (results.Errors.Count == 0)
+ LoadAssemblyExtensions(results.CompiledAssembly, owner);
+ else
+ throw new ExtensionException("Error(s) compiling " + name);
+ }
+
+ if (assignableInterfaces != null)
+ {
+ // Assign extensions to interfaces
+ foreach (KeyValuePair kvp in assignableInterfaces)
+ {
+ Type type = kvp.Key;
+ FieldInfo assignable = kvp.Value;
+
+ for (int i = 0; i < Extensions.Count; i++)
+ {
+ IExtension extension = Extensions[i];
+
+ if (extension.GetType().GetInterface(type.Name) != null)
+ assignable.SetValue(assignablesParent, extension);
+ }
+ }
+
+ // Check for unassigned interfaces
+ foreach (KeyValuePair kvp in assignableInterfaces)
+ {
+ if (kvp.Value == null)
+ throw new ExtensionException("Unassigned interface " + kvp.Key.Name);
+ }
+ }
+ }
+
+ public static List ListExtensionAssemblies(string path, string searchPattern)
+ {
+ List plugins = new List();
+ string[] files = Directory.GetFiles(path, searchPattern);
+
+ foreach (string f in files)
+ {
+ try
+ {
+ Assembly a = Assembly.LoadFrom(f);
+ System.Type[] types = a.GetTypes();
+ foreach (System.Type type in types)
+ {
+ if (type.GetInterface("IExtension") != null)
+ {
+ plugins.Add(f);
+ break;
+ }
+ }
+ }
+ catch (Exception e)
+ {
+ throw new ExtensionException("Unrecognized extension " + f, e);
+ }
+ }
+
+ return plugins;
+ }
+
+ public static List ListExtensionSourceFiles(string path, string searchPattern)
+ {
+ List plugins = new List();
+ string[] files = Directory.GetFiles(path, searchPattern);
+
+ foreach (string f in files)
+ {
+ if (File.ReadAllText(f).Contains("IExtension"))
+ plugins.Add(f);
+ }
+
+ return plugins;
+ }
+
+ public static void LoadAssemblyExtensions(Assembly assembly, TOwner owner)
+ {
+ Type[] constructorParams = new Type[] { typeof(TOwner) };
+
+ foreach (Type t in assembly.GetTypes())
+ {
+ try
+ {
+ if (t.GetInterface("IExtension") != null)
+ {
+ ConstructorInfo info = t.GetConstructor(constructorParams);
+ IExtension extension = (IExtension)info.Invoke(new object[] { owner });
+ Extensions.Add(extension);
+ }
+ }
+ catch (Exception e)
+ {
+ throw new ExtensionException(String.Format(
+ "Failed to load IExtension {0} from assembly {1}", t.FullName, assembly.FullName), e);
+ }
+ }
+ }
+ }
+}
diff --git a/ExtensionLoader/IExtension.cs b/ExtensionLoader/IExtension.cs
new file mode 100644
index 00000000..fa509e61
--- /dev/null
+++ b/ExtensionLoader/IExtension.cs
@@ -0,0 +1,20 @@
+using System;
+
+namespace ExtensionLoader
+{
+ ///
+ /// Abstract base for extensions
+ ///
+ public interface IExtension
+ {
+ ///
+ /// Called when the extension is starting
+ ///
+ void Start();
+
+ ///
+ /// Called when the extension is stopping
+ ///
+ void Stop();
+ }
+}
diff --git a/Programs/Simian/ExtensionLoader.cs b/Programs/Simian/ExtensionLoader.cs
deleted file mode 100644
index 3be3b7ff..00000000
--- a/Programs/Simian/ExtensionLoader.cs
+++ /dev/null
@@ -1,150 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Reflection;
-using System.CodeDom.Compiler;
-using System.IO;
-using OpenMetaverse;
-
-namespace Simian
-{
- public static class ExtensionLoader
- {
- ///
- /// Exception thrown when there is a problem with an extension
- ///
- public class ExtensionException : Exception
- {
- public ExtensionException(string message)
- : base(message)
- {
- }
-
- public ExtensionException(string message, Exception innerException)
- : base(message, innerException)
- {
- }
- }
-
- /// Currently loaded extensions
- public static List Extensions;
- ///
- public static CodeDomProvider CSCompiler;
- ///
- public static CompilerParameters CSCompilerParams;
-
- static ExtensionLoader()
- {
- Extensions = new List();
-
- CSCompiler = CodeDomProvider.CreateProvider("C#");
-
- CSCompilerParams = new CompilerParameters();
- CSCompilerParams.GenerateExecutable = false;
- CSCompilerParams.GenerateInMemory = true;
- if (System.Diagnostics.Debugger.IsAttached)
- CSCompilerParams.IncludeDebugInformation = true;
- else
- CSCompilerParams.IncludeDebugInformation = false;
- CSCompilerParams.ReferencedAssemblies.Add("OpenMetaverseTypes.dll");
- CSCompilerParams.ReferencedAssemblies.Add("OpenMetaverse.dll");
- CSCompilerParams.ReferencedAssemblies.Add("Simian.exe");
- }
-
- ///
- ///
- ///
- ///
- /// server that these extensions belong to
- public static void LoadAllExtensions(string path, Simian owner)
- {
- // Load internal extensions
- LoadAssemblyExtensions(Assembly.GetExecutingAssembly(), owner);
-
- // Load extensions from external assemblies
- List extensionNames = ListExtensionAssemblies(path);
- foreach (string name in extensionNames)
- LoadAssemblyExtensions(Assembly.LoadFile(name), owner);
-
- // Load extensions from external code files
- extensionNames = ListExtensionSourceFiles(path);
- foreach (string name in extensionNames)
- {
- CompilerResults results = CSCompiler.CompileAssemblyFromFile(CSCompilerParams, name);
- if (results.Errors.Count == 0)
- {
- LoadAssemblyExtensions(results.CompiledAssembly, owner);
- }
- else
- {
- Logger.Log("Error(s) compiling " + name, Helpers.LogLevel.Error);
- foreach (CompilerError error in results.Errors)
- Logger.Log(error.ToString(), Helpers.LogLevel.Error);
- }
- }
- }
-
- public static List ListExtensionAssemblies(string path)
- {
- List plugins = new List();
- string[] files = Directory.GetFiles(path, "Simian.*.dll");
-
- foreach (string f in files)
- {
- try
- {
- Assembly a = Assembly.LoadFrom(f);
- System.Type[] types = a.GetTypes();
- foreach (System.Type type in types)
- {
- if (type.GetInterface("ISimianExtension") != null)
- {
- plugins.Add(f);
- break;
- }
- }
- }
- catch (Exception e)
- {
- Logger.Log(String.Format("Unrecognized extension {0}: {1}", f, e.Message),
- Helpers.LogLevel.Warning, e);
- }
- }
-
- return plugins;
- }
-
- public static List ListExtensionSourceFiles(string path)
- {
- List plugins = new List();
- string[] files = Directory.GetFiles(path, "Simian.*.cs");
-
- foreach (string f in files)
- {
- if (File.ReadAllText(f).Contains("ISimianExtension"))
- plugins.Add(f);
- }
-
- return plugins;
- }
-
- public static void LoadAssemblyExtensions(Assembly assembly, Simian owner)
- {
- foreach (Type t in assembly.GetTypes())
- {
- try
- {
- if (t.GetInterface("ISimianExtension") != null)
- {
- ConstructorInfo info = t.GetConstructor(new Type[] { typeof(Simian) });
- ISimianExtension extension = (ISimianExtension)info.Invoke(new object[] { owner });
- Extensions.Add(extension);
- }
- }
- catch (Exception e)
- {
- Logger.Log("LoadAssemblyExtensions(): " + e.Message, Helpers.LogLevel.Warning);
- }
- }
- }
- }
-}
diff --git a/Programs/Simian/Extensions/AccountManager.cs b/Programs/Simian/Extensions/AccountManager.cs
index 8e07e7c5..f77a9696 100644
--- a/Programs/Simian/Extensions/AccountManager.cs
+++ b/Programs/Simian/Extensions/AccountManager.cs
@@ -1,11 +1,12 @@
using System;
using System.Collections.Generic;
+using ExtensionLoader;
using OpenMetaverse;
using OpenMetaverse.StructuredData;
namespace Simian.Extensions
{
- public class AccountManager : ISimianExtension, IAccountProvider, IPersistable
+ public class AccountManager : IExtension, IAccountProvider, IPersistable
{
public string StoreName { get { return "Accounts"; } }
diff --git a/Programs/Simian/Extensions/AssetManager.cs b/Programs/Simian/Extensions/AssetManager.cs
index d9529c84..4318cba6 100644
--- a/Programs/Simian/Extensions/AssetManager.cs
+++ b/Programs/Simian/Extensions/AssetManager.cs
@@ -1,13 +1,14 @@
using System;
using System.Collections.Generic;
using System.IO;
+using ExtensionLoader;
using OpenMetaverse;
using OpenMetaverse.Imaging;
using OpenMetaverse.Packets;
namespace Simian.Extensions
{
- public class AssetManager : ISimianExtension, IAssetProvider
+ public class AssetManager : IExtension, IAssetProvider
{
Simian Server;
Dictionary AssetStore = new Dictionary();
diff --git a/Programs/Simian/Extensions/AuthFreeForAll.cs b/Programs/Simian/Extensions/AuthFreeForAll.cs
index 0d8625f5..31266765 100644
--- a/Programs/Simian/Extensions/AuthFreeForAll.cs
+++ b/Programs/Simian/Extensions/AuthFreeForAll.cs
@@ -1,9 +1,10 @@
using System;
+using ExtensionLoader;
using OpenMetaverse;
namespace Simian.Extensions
{
- public class AuthFreeForAll : ISimianExtension, IAuthenticationProvider
+ public class AuthFreeForAll : IExtension, IAuthenticationProvider
{
Simian server;
diff --git a/Programs/Simian/Extensions/AvatarManager.cs b/Programs/Simian/Extensions/AvatarManager.cs
index c7151bd1..ad72ee69 100644
--- a/Programs/Simian/Extensions/AvatarManager.cs
+++ b/Programs/Simian/Extensions/AvatarManager.cs
@@ -1,13 +1,14 @@
using System;
using System.Collections.Generic;
using System.Threading;
+using ExtensionLoader;
using OpenMetaverse;
using OpenMetaverse.StructuredData;
using OpenMetaverse.Packets;
namespace Simian.Extensions
{
- class AvatarManager : ISimianExtension, IAvatarProvider
+ class AvatarManager : IExtension, IAvatarProvider
{
Simian Server;
int currentWearablesSerialNum = -1;
diff --git a/Programs/Simian/Extensions/CoarseLocationUpdates.cs b/Programs/Simian/Extensions/CoarseLocationUpdates.cs
index f883125a..300e8578 100644
--- a/Programs/Simian/Extensions/CoarseLocationUpdates.cs
+++ b/Programs/Simian/Extensions/CoarseLocationUpdates.cs
@@ -1,5 +1,6 @@
using OpenMetaverse;
using OpenMetaverse.Packets;
+using ExtensionLoader;
using System;
using System.Collections.Generic;
using System.Text;
@@ -7,7 +8,7 @@ using System.Threading;
namespace Simian.Extensions
{
- public class CoarseLocationUpdates : ISimianExtension
+ public class CoarseLocationUpdates : IExtension
{
Simian Server;
Timer CoarseLocationTimer;
diff --git a/Programs/Simian/Extensions/ConnectionManagement.cs b/Programs/Simian/Extensions/ConnectionManagement.cs
index a8b7b92d..d538ab72 100644
--- a/Programs/Simian/Extensions/ConnectionManagement.cs
+++ b/Programs/Simian/Extensions/ConnectionManagement.cs
@@ -1,10 +1,11 @@
using System;
+using ExtensionLoader;
using OpenMetaverse;
using OpenMetaverse.Packets;
namespace Simian.Extensions
{
- public class ConnectionManagement : ISimianExtension
+ public class ConnectionManagement : IExtension
{
Simian server;
diff --git a/Programs/Simian/Extensions/FriendManager.cs b/Programs/Simian/Extensions/FriendManager.cs
index 61b5a145..3c1c4119 100644
--- a/Programs/Simian/Extensions/FriendManager.cs
+++ b/Programs/Simian/Extensions/FriendManager.cs
@@ -1,12 +1,12 @@
-using OpenMetaverse;
-using OpenMetaverse.Packets;
using System;
using System.Collections.Generic;
-using System.Text;
+using ExtensionLoader;
+using OpenMetaverse;
+using OpenMetaverse.Packets;
namespace Simian.Extensions
{
- public class FriendManager : ISimianExtension
+ public class FriendManager : IExtension
{
Simian Server;
diff --git a/Programs/Simian/Extensions/ImageDelivery.cs b/Programs/Simian/Extensions/ImageDelivery.cs
index 9868f2d9..ff7d19b9 100644
--- a/Programs/Simian/Extensions/ImageDelivery.cs
+++ b/Programs/Simian/Extensions/ImageDelivery.cs
@@ -2,6 +2,7 @@ using System;
using System.Collections.Generic;
using System.Drawing;
using System.Threading;
+using ExtensionLoader;
using OpenMetaverse;
using OpenMetaverse.Imaging;
using OpenMetaverse.Packets;
@@ -81,7 +82,7 @@ namespace Simian.Extensions
}
}
- public class ImageDelivery : ISimianExtension
+ public class ImageDelivery : IExtension
{
Simian Server;
AssetTexture defaultJP2;
diff --git a/Programs/Simian/Extensions/InventoryManager.cs b/Programs/Simian/Extensions/InventoryManager.cs
index 0542f5b0..68348a44 100644
--- a/Programs/Simian/Extensions/InventoryManager.cs
+++ b/Programs/Simian/Extensions/InventoryManager.cs
@@ -1,11 +1,12 @@
using System;
using System.Collections.Generic;
+using ExtensionLoader;
using OpenMetaverse;
using OpenMetaverse.Packets;
namespace Simian.Extensions
{
- public class InventoryManager : ISimianExtension, IInventoryProvider
+ public class InventoryManager : IExtension, IInventoryProvider
{
Simian Server;
diff --git a/Programs/Simian/Extensions/Messaging.cs b/Programs/Simian/Extensions/Messaging.cs
index d45ee7e4..cc804af6 100644
--- a/Programs/Simian/Extensions/Messaging.cs
+++ b/Programs/Simian/Extensions/Messaging.cs
@@ -1,12 +1,12 @@
-using OpenMetaverse;
-using OpenMetaverse.Packets;
using System;
using System.Collections.Generic;
-using System.Text;
+using ExtensionLoader;
+using OpenMetaverse;
+using OpenMetaverse.Packets;
namespace Simian.Extensions
{
- public class Messaging : ISimianExtension
+ public class Messaging : IExtension
{
Simian Server;
diff --git a/Programs/Simian/Extensions/Money.cs b/Programs/Simian/Extensions/Money.cs
index 9f6381c3..f1a46141 100644
--- a/Programs/Simian/Extensions/Money.cs
+++ b/Programs/Simian/Extensions/Money.cs
@@ -1,12 +1,12 @@
-using OpenMetaverse;
-using OpenMetaverse.Packets;
using System;
using System.Collections.Generic;
-using System.Text;
+using ExtensionLoader;
+using OpenMetaverse;
+using OpenMetaverse.Packets;
namespace Simian.Extensions
{
- class Money : ISimianExtension
+ class Money : IExtension
{
Simian Server;
diff --git a/Programs/Simian/Extensions/Movement.cs b/Programs/Simian/Extensions/Movement.cs
index 0436478b..dc374678 100644
--- a/Programs/Simian/Extensions/Movement.cs
+++ b/Programs/Simian/Extensions/Movement.cs
@@ -1,13 +1,13 @@
-using OpenMetaverse;
-using OpenMetaverse.Packets;
using System;
using System.Collections.Generic;
-using System.Text;
using System.Threading;
+using ExtensionLoader;
+using OpenMetaverse;
+using OpenMetaverse.Packets;
namespace Simian.Extensions
{
- public class Movement : ISimianExtension
+ public class Movement : IExtension
{
const int UPDATE_ITERATION = 100; //rate in milliseconds to send ObjectUpdate
const bool ENVIRONMENT_SOUNDS = true; //collision sounds, splashing, etc
diff --git a/Programs/Simian/Extensions/ObjectManager.cs b/Programs/Simian/Extensions/ObjectManager.cs
index ca199677..25940f3d 100644
--- a/Programs/Simian/Extensions/ObjectManager.cs
+++ b/Programs/Simian/Extensions/ObjectManager.cs
@@ -1,13 +1,14 @@
using System;
using System.Collections.Generic;
using System.Threading;
+using ExtensionLoader;
using OpenMetaverse;
using OpenMetaverse.Rendering;
using OpenMetaverse.Packets;
namespace Simian.Extensions
{
- public class ObjectManager : ISimianExtension
+ public class ObjectManager : IExtension
{
Simian Server;
diff --git a/Programs/Simian/Extensions/ParcelManager.cs b/Programs/Simian/Extensions/ParcelManager.cs
index 79c39da9..29601a23 100644
--- a/Programs/Simian/Extensions/ParcelManager.cs
+++ b/Programs/Simian/Extensions/ParcelManager.cs
@@ -1,11 +1,12 @@
using System;
using System.Collections.Generic;
+using ExtensionLoader;
using OpenMetaverse;
using OpenMetaverse.Packets;
namespace Simian.Extensions
{
- public class ParcelManager : ISimianExtension, IParcelProvider
+ public class ParcelManager : IExtension, IParcelProvider
{
Simian server;
Dictionary parcels = new Dictionary();
diff --git a/Programs/Simian/Extensions/RenderingPluginMesher.cs b/Programs/Simian/Extensions/RenderingPluginMesher.cs
index 126d3182..356e8131 100644
--- a/Programs/Simian/Extensions/RenderingPluginMesher.cs
+++ b/Programs/Simian/Extensions/RenderingPluginMesher.cs
@@ -1,11 +1,12 @@
using System;
using System.Collections.Generic;
+using ExtensionLoader;
using OpenMetaverse;
using OpenMetaverse.Rendering;
namespace Simian.Extensions
{
- public class RenderingPluginMesher : ISimianExtension, IMeshingProvider
+ public class RenderingPluginMesher : IExtension, IMeshingProvider
{
Simian Server;
IRendering Renderer;
diff --git a/Programs/Simian/Extensions/SceneManager.cs b/Programs/Simian/Extensions/SceneManager.cs
index f460d58e..4754b7e4 100644
--- a/Programs/Simian/Extensions/SceneManager.cs
+++ b/Programs/Simian/Extensions/SceneManager.cs
@@ -5,13 +5,14 @@ using System.Drawing.Imaging;
using System.IO;
using System.Runtime.InteropServices;
using System.Threading;
+using ExtensionLoader;
using OpenMetaverse;
using OpenMetaverse.Imaging;
using OpenMetaverse.Packets;
namespace Simian.Extensions
{
- public class SceneManager : ISimianExtension, ISceneProvider
+ public class SceneManager : IExtension, ISceneProvider
{
Simian server;
DoubleDictionary sceneObjects = new DoubleDictionary();
diff --git a/Programs/Simian/Extensions/UDPServer.cs b/Programs/Simian/Extensions/UDPServer.cs
index 34269e01..dd8b10a3 100644
--- a/Programs/Simian/Extensions/UDPServer.cs
+++ b/Programs/Simian/Extensions/UDPServer.cs
@@ -3,6 +3,7 @@ using System.Collections;
using System.Collections.Generic;
using System.Net;
using System.Threading;
+using ExtensionLoader;
using OpenMetaverse;
using OpenMetaverse.Packets;
@@ -67,7 +68,7 @@ namespace Simian
}
}
- public class UDPManager : ISimianExtension, IUDPProvider
+ public class UDPManager : IExtension, IUDPProvider
{
Simian Server;
UDPServer udpServer;
diff --git a/Programs/Simian/Extensions/XMLPersistence.cs b/Programs/Simian/Extensions/XMLPersistence.cs
index bd878ced..e9bb883c 100644
--- a/Programs/Simian/Extensions/XMLPersistence.cs
+++ b/Programs/Simian/Extensions/XMLPersistence.cs
@@ -2,12 +2,13 @@ using System;
using System.Collections.Generic;
using System.IO;
using System.Xml;
+using ExtensionLoader;
using OpenMetaverse;
using OpenMetaverse.StructuredData;
namespace Simian.Extensions
{
- public class XMLPersistence : ISimianExtension, IPersistenceProvider
+ public class XMLPersistence : IExtension, IPersistenceProvider
{
Simian server;
diff --git a/Programs/Simian/ISimianExtension.cs b/Programs/Simian/ISimianExtension.cs
deleted file mode 100644
index 72338740..00000000
--- a/Programs/Simian/ISimianExtension.cs
+++ /dev/null
@@ -1,18 +0,0 @@
-namespace Simian
-{
- ///
- /// Abstract base for rendering plugins
- ///
- public interface ISimianExtension
- {
- ///
- /// Called when the simulator is initializing
- ///
- void Start();
-
- ///
- /// Called when the simulator is shutting down
- ///
- void Stop();
- }
-}
diff --git a/Programs/Simian/Simian.cs b/Programs/Simian/Simian.cs
index bace95da..362400c5 100644
--- a/Programs/Simian/Simian.cs
+++ b/Programs/Simian/Simian.cs
@@ -5,6 +5,8 @@ using System.IO;
using System.Text;
using System.Xml;
using System.Threading;
+using System.Reflection;
+using ExtensionLoader;
using OpenMetaverse;
using OpenMetaverse.Capabilities;
using OpenMetaverse.Packets;
@@ -54,16 +56,35 @@ namespace Simian
RegionHandle = Helpers.UIntsToLong(REGION_X, REGION_Y);
- // Load all of the extensions
- ExtensionLoader.LoadAllExtensions(AppDomain.CurrentDomain.BaseDirectory, this);
-
- foreach (ISimianExtension extension in ExtensionLoader.Extensions)
+ try
{
- // Assign to an interface if possible
- TryAssignToInterface(extension);
+ // Load all of the extensions
+ List references = new List();
+ references.Add("OpenMetaverseTypes.dll");
+ references.Add("OpenMetaverse.dll");
+ references.Add("Simian.exe");
+
+ Dictionary assignables = GetInterfaces();
+
+ ExtensionLoader.LoadAllExtensions(Assembly.GetExecutingAssembly(),
+ AppDomain.CurrentDomain.BaseDirectory, this, references,
+ "Simian.*.dll", "Simian.*.cs", this, assignables);
+ }
+ catch (ExtensionException ex)
+ {
+ Logger.Log("Interface loading failed, shutting down: " + ex.Message, Helpers.LogLevel.Error);
+ Stop();
+ return false;
}
- foreach (ISimianExtension extension in ExtensionLoader.Extensions)
+ foreach (IExtension extension in ExtensionLoader.Extensions)
+ {
+ // Track all of the extensions with persistence
+ if (extension is IPersistable)
+ PersistentExtensions.Add((IPersistable)extension);
+ }
+
+ foreach (IExtension extension in ExtensionLoader.Extensions)
{
// Start persistance providers after all other extensions
if (!(extension is IPersistenceProvider))
@@ -73,7 +94,7 @@ namespace Simian
}
}
- foreach (ISimianExtension extension in ExtensionLoader.Extensions)
+ foreach (IExtension extension in ExtensionLoader.Extensions)
{
// Start the persistance provider(s)
if (extension is IPersistenceProvider)
@@ -83,28 +104,19 @@ namespace Simian
}
}
- if (!CheckInterfaces())
- {
- Logger.Log("Missing interfaces, shutting down", Helpers.LogLevel.Error);
- Stop();
- return false;
- }
- else
- {
- return true;
- }
+ return true;
}
public void Stop()
{
- foreach (ISimianExtension extension in ExtensionLoader.Extensions)
+ foreach (IExtension extension in ExtensionLoader.Extensions)
{
// Stop persistance providers first
if (extension is IPersistenceProvider)
extension.Stop();
}
- foreach (ISimianExtension extension in ExtensionLoader.Extensions)
+ foreach (IExtension extension in ExtensionLoader.Extensions)
{
// Stop all other extensions
if (!(extension is IPersistenceProvider))
@@ -134,56 +146,17 @@ namespace Simian
UDP.BroadcastPacket(offline, PacketCategory.State);
}
- void TryAssignToInterface(ISimianExtension extension)
+ Dictionary GetInterfaces()
{
- if (extension is IAuthenticationProvider)
- Authentication = (IAuthenticationProvider)extension;
- else if (extension is IAccountProvider)
- Accounts = (IAccountProvider)extension;
- else if (extension is IUDPProvider)
- UDP = (IUDPProvider)extension;
- else if (extension is ISceneProvider)
- Scene = (ISceneProvider)extension;
- else if (extension is IAssetProvider)
- Assets = (IAssetProvider)extension;
- else if (extension is IAvatarProvider)
- Avatars = (IAvatarProvider)extension;
- else if (extension is IInventoryProvider)
- Inventory = (IInventoryProvider)extension;
- else if (extension is IParcelProvider)
- Parcels = (IParcelProvider)extension;
- else if (extension is IMeshingProvider)
- Mesher = (IMeshingProvider)extension;
+ Dictionary interfaces = new Dictionary();
- // Track all of the extensions with persistence
- if (extension is IPersistable)
- PersistentExtensions.Add((IPersistable)extension);
- }
+ foreach (FieldInfo field in this.GetType().GetFields())
+ {
+ if (field.FieldType.IsInterface)
+ interfaces.Add(field.FieldType, field);
+ }
- bool CheckInterfaces()
- {
- if (Authentication == null)
- Logger.Log("No IAuthenticationProvider interface loaded", Helpers.LogLevel.Error);
- else if (Accounts == null)
- Logger.Log("No IAccountProvider interface loaded", Helpers.LogLevel.Error);
- else if (UDP == null)
- Logger.Log("No IUDPProvider interface loaded", Helpers.LogLevel.Error);
- else if (Scene == null)
- Logger.Log("No ISceneProvider interface loaded", Helpers.LogLevel.Error);
- else if (Assets == null)
- Logger.Log("No IAssetProvider interface loaded", Helpers.LogLevel.Error);
- else if (Avatars == null)
- Logger.Log("No IAvatarProvider interface loaded", Helpers.LogLevel.Error);
- else if (Inventory == null)
- Logger.Log("No IInventoryProvider interface loaded", Helpers.LogLevel.Error);
- else if (Parcels == null)
- Logger.Log("No IParcelProvider interface loaded", Helpers.LogLevel.Error);
- else if (Mesher == null)
- Logger.Log("No IMeshingProvider interface loaded", Helpers.LogLevel.Error);
- else
- return true;
-
- return false;
+ return interfaces;
}
void InitHttpServer(int port, bool ssl)
diff --git a/prebuild.xml b/prebuild.xml
index 8dd845fb..70dde08e 100644
--- a/prebuild.xml
+++ b/prebuild.xml
@@ -137,6 +137,25 @@
+
+
+
+
+ ../bin/
+
+
+
+
+ ../bin/
+
+
+
+ ../bin/
+
+
+
+
+
@@ -680,6 +699,7 @@
+