ApplicationHost.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. //
  2. // System.Web.Hosting.ApplicationHost
  3. //
  4. // Authors:
  5. // Patrik Torstensson ([email protected])
  6. // (class signature from Bob Smith <[email protected]> (C) )
  7. // Gonzalo Paniagua Javier ([email protected])
  8. //
  9. using System;
  10. using System.Collections;
  11. using System.IO;
  12. using System.Runtime.Remoting;
  13. namespace System.Web.Hosting
  14. {
  15. public sealed class ApplicationHost
  16. {
  17. internal class ConfigInitHelper : MarshalByRefObject
  18. {
  19. internal void InitConfig ()
  20. {
  21. }
  22. }
  23. private ApplicationHost ()
  24. {
  25. }
  26. public static object CreateApplicationHost (Type hostType,
  27. string virtualDir,
  28. string physicalDir)
  29. {
  30. if (hostType == null)
  31. throw new ArgumentException ("hostType");
  32. if (virtualDir == null || virtualDir.Length == 0)
  33. throw new ArgumentException ("virtualDir");
  34. if (physicalDir == null || physicalDir.Length == 0)
  35. throw new ArgumentException ("physicalDir");
  36. if (physicalDir [physicalDir.Length - 1] != Path.DirectorySeparatorChar)
  37. physicalDir += Path.DirectorySeparatorChar;
  38. int nowInt = DateTime.Now.ToString ().GetHashCode ();
  39. string nowHash = nowInt.ToString ("x");
  40. nowInt += physicalDir.GetHashCode ();
  41. string sum = nowInt.ToString ("x");
  42. Hashtable hTable = new Hashtable ();
  43. AppDomainSetup domainSetup = new AppDomainSetup();
  44. AppDomainFactory.PopulateDomainBindings (nowHash,
  45. sum,
  46. sum,
  47. physicalDir,
  48. virtualDir,
  49. domainSetup,
  50. hTable);
  51. AppDomain domain = AppDomain.CreateDomain (nowHash, null, domainSetup);
  52. foreach (string key in hTable.Keys) {
  53. domain.SetData (key, (string) hTable [key]);
  54. // [1] REMOVE THIS once bug #31245 is fixed
  55. AppDomain.CurrentDomain.SetData (key, (string) hTable [key]);
  56. }
  57. domain.SetData (".hostingVirtualPath", virtualDir);
  58. AppDomain.CurrentDomain.SetData (".hostingVirtualPath", virtualDir); // [1]
  59. //FIXME: this should be the directory where dlls reside.
  60. domain.SetData(".hostingInstallDir", "FIXME hostingInstallDir");
  61. AppDomain.CurrentDomain.SetData (".hostingInstallDir", "FIXME hostingInstallDir"); // [1]
  62. InitConfigInNewAppDomain (domain);
  63. ObjectHandle o = domain.CreateInstance (hostType.Assembly.FullName,
  64. hostType.FullName);
  65. return o.Unwrap();
  66. }
  67. private static void InitConfigInNewAppDomain (AppDomain appDomain)
  68. {
  69. Type t = typeof (ConfigInitHelper);
  70. ObjectHandle o = appDomain.CreateInstance (t.Assembly.FullName, t.FullName);
  71. ConfigInitHelper helper = (ConfigInitHelper) o.Unwrap();
  72. helper.InitConfig ();
  73. }
  74. }
  75. }