ApplicationHost.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. domain.SetData (".hostingVirtualPath", virtualDir);
  55. //FIXME: this should be the directory where dlls reside.
  56. domain.SetData(".hostingInstallDir", "FIXME hostingInstallDir");
  57. InitConfigInNewAppDomain (domain);
  58. ObjectHandle o = domain.CreateInstance (hostType.Assembly.FullName,
  59. hostType.FullName);
  60. return o.Unwrap();
  61. }
  62. private static void InitConfigInNewAppDomain (AppDomain appDomain)
  63. {
  64. Type t = typeof (ConfigInitHelper);
  65. ObjectHandle o = appDomain.CreateInstance (t.Assembly.FullName, t.FullName);
  66. ConfigInitHelper helper = (ConfigInitHelper) o.Unwrap();
  67. helper.InitConfig ();
  68. }
  69. }
  70. }