Grid.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Reflection;
  5. using OpenSim.Framework.Interfaces;
  6. using OpenSim.UserServer;
  7. namespace OpenSim
  8. {
  9. public class Grid
  10. {
  11. public IAssetServer AssetServer;
  12. public IGridServer GridServer;
  13. public IUserServer UserServer;
  14. public string AssetDll = "";
  15. public string GridDll = "";
  16. public Grid()
  17. {
  18. }
  19. public virtual void Initialise()
  20. {
  21. //load the dlls
  22. this.AssetServer = this.LoadAssetDll(this.AssetDll);
  23. this.GridServer = this.LoadGridDll(this.GridDll);
  24. }
  25. public virtual void Close()
  26. {
  27. this.AssetServer.Close();
  28. this.GridServer.Close();
  29. }
  30. private IAssetServer LoadAssetDll(string dllName)
  31. {
  32. Assembly pluginAssembly = Assembly.LoadFrom(dllName);
  33. IAssetServer server = null;
  34. foreach (Type pluginType in pluginAssembly.GetTypes())
  35. {
  36. if (pluginType.IsPublic)
  37. {
  38. if (!pluginType.IsAbstract)
  39. {
  40. Type typeInterface = pluginType.GetInterface("IAssetPlugin", true);
  41. if (typeInterface != null)
  42. {
  43. IAssetPlugin plug = (IAssetPlugin)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString()));
  44. server = plug.GetAssetServer();
  45. break;
  46. }
  47. typeInterface = null;
  48. }
  49. }
  50. }
  51. pluginAssembly = null;
  52. return server;
  53. }
  54. private IGridServer LoadGridDll(string dllName)
  55. {
  56. Assembly pluginAssembly = Assembly.LoadFrom(dllName);
  57. IGridServer server = null;
  58. foreach (Type pluginType in pluginAssembly.GetTypes())
  59. {
  60. if (pluginType.IsPublic)
  61. {
  62. if (!pluginType.IsAbstract)
  63. {
  64. Type typeInterface = pluginType.GetInterface("IGridPlugin", true);
  65. if (typeInterface != null)
  66. {
  67. IGridPlugin plug = (IGridPlugin)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString()));
  68. server = plug.GetGridServer();
  69. break;
  70. }
  71. typeInterface = null;
  72. }
  73. }
  74. }
  75. pluginAssembly = null;
  76. return server;
  77. }
  78. }
  79. }