ApplicationHost.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. class ConfigInitHelper
  18. {
  19. public void InitConfig ()
  20. {
  21. }
  22. }
  23. public static object CreateApplicationHost (Type hostType,
  24. string virtualDir,
  25. string physicalDir)
  26. {
  27. if (hostType == null)
  28. throw new ArgumentException ("hostType");
  29. if (virtualDir == null || virtualDir.Length == 0)
  30. throw new ArgumentException ("virtualDir");
  31. if (physicalDir == null || physicalDir.Length == 0)
  32. throw new ArgumentException ("physicalDir");
  33. if (physicalDir [physicalDir.Length - 1] != Path.DirectorySeparatorChar)
  34. physicalDir += Path.DirectorySeparatorChar;
  35. int nowInt = DateTime.Now.ToString ().GetHashCode ();
  36. string nowHash = nowInt.ToString ("x");
  37. nowInt += physicalDir.GetHashCode ();
  38. string sum = nowInt.ToString ("x");
  39. Hashtable hTable = new Hashtable ();
  40. AppDomainSetup domainSetup = new AppDomainSetup();
  41. AppDomainFactory.PopulateDomainBindings (nowHash,
  42. sum,
  43. sum,
  44. physicalDir,
  45. virtualDir,
  46. domainSetup,
  47. hTable);
  48. AppDomain domain = AppDomain.CreateDomain (nowHash, null, domainSetup);
  49. foreach (string key in hTable.Keys)
  50. domain.SetData (key, (string) hTable [key]);
  51. domain.SetData (".hostingVirtualPath", virtualDir);
  52. //domain.SetData(".hostingInstallDir", ?????);
  53. InitConfigInNewAppDomain (domain);
  54. ObjectHandle o = domain.CreateInstance (hostType.Module.Assembly.FullName,
  55. hostType.FullName);
  56. return o.Unwrap();
  57. }
  58. private static void InitConfigInNewAppDomain (AppDomain appDomain)
  59. {
  60. Type t = typeof (ConfigInitHelper);
  61. ObjectHandle o = appDomain.CreateInstance (t.Module.Assembly.FullName, t.FullName);
  62. ConfigInitHelper helper = (ConfigInitHelper) o.Unwrap();
  63. helper.InitConfig ();
  64. }
  65. }
  66. }