ApplicationFileParser.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. //
  2. // System.Web.UI.ApplicationFileParser.cs
  3. //
  4. // Authors:
  5. // Gonzalo Paniagua Javier ([email protected])
  6. //
  7. // (C) 2002,2003 Ximian, Inc (http://www.ximian.com)
  8. // (c) 2004 Novell, Inc. (http://www.novell.com)
  9. //
  10. //
  11. // Permission is hereby granted, free of charge, to any person obtaining
  12. // a copy of this software and associated documentation files (the
  13. // "Software"), to deal in the Software without restriction, including
  14. // without limitation the rights to use, copy, modify, merge, publish,
  15. // distribute, sublicense, and/or sell copies of the Software, and to
  16. // permit persons to whom the Software is furnished to do so, subject to
  17. // the following conditions:
  18. //
  19. // The above copyright notice and this permission notice shall be
  20. // included in all copies or substantial portions of the Software.
  21. //
  22. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  23. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  24. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  25. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  26. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  27. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  28. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  29. //
  30. using System;
  31. using System.Collections;
  32. using System.IO;
  33. using System.Web;
  34. using System.Web.Compilation;
  35. namespace System.Web.UI
  36. {
  37. sealed class ApplicationFileParser : TemplateParser
  38. {
  39. static ArrayList dependencies;
  40. #if NET_2_0
  41. TextReader reader;
  42. #endif
  43. public ApplicationFileParser (string fname, HttpContext context)
  44. {
  45. InputFile = fname;
  46. Context = context;
  47. #if NET_2_0
  48. VirtualPath = new VirtualPath ("/" + Path.GetFileName (fname));
  49. #endif
  50. LoadConfigDefaults ();
  51. }
  52. #if NET_2_0
  53. internal ApplicationFileParser (VirtualPath virtualPath, TextReader reader, HttpContext context)
  54. : this (virtualPath, null, reader, context)
  55. {
  56. }
  57. internal ApplicationFileParser (VirtualPath virtualPath, string inputFile, TextReader reader, HttpContext context)
  58. {
  59. VirtualPath = virtualPath;
  60. Context = context;
  61. Reader = reader;
  62. if (String.IsNullOrEmpty (inputFile))
  63. InputFile = virtualPath.PhysicalPath;
  64. else
  65. InputFile = inputFile;
  66. SetBaseType (null);
  67. LoadConfigDefaults ();
  68. }
  69. #endif
  70. protected override Type CompileIntoType ()
  71. {
  72. return GlobalAsaxCompiler.CompileApplicationType (this);
  73. }
  74. internal static Type GetCompiledApplicationType (string inputFile, HttpContext context)
  75. {
  76. ApplicationFileParser parser = new ApplicationFileParser (inputFile, context);
  77. AspGenerator generator = new AspGenerator (parser);
  78. Type type = generator.GetCompiledType ();
  79. dependencies = parser.Dependencies;
  80. return type;
  81. }
  82. internal override void AddDirective (string directive, Hashtable atts)
  83. {
  84. if (String.Compare (directive, "application", true) != 0 &&
  85. String.Compare (directive, "Import", true) != 0 &&
  86. String.Compare (directive, "Assembly", true) != 0)
  87. ThrowParseException ("Invalid directive: " + directive);
  88. base.AddDirective (directive, atts);
  89. }
  90. internal static ArrayList FileDependencies {
  91. get { return dependencies; }
  92. }
  93. internal override string DefaultBaseTypeName {
  94. get { return "System.Web.HttpApplication"; }
  95. }
  96. internal override string DefaultDirectiveName {
  97. get { return "application"; }
  98. }
  99. internal override string BaseVirtualDir {
  100. get { return Context.Request.ApplicationPath; }
  101. }
  102. #if NET_2_0
  103. internal override TextReader Reader {
  104. get { return reader; }
  105. set { reader = value; }
  106. }
  107. #endif
  108. }
  109. }