SimpleBuildProvider.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. //
  2. // System.Web.Compilation.SimpleBuildProvider
  3. //
  4. // Authors:
  5. // Marek Habersack ([email protected])
  6. //
  7. // (C) 2008 Novell, Inc
  8. //
  9. //
  10. // Permission is hereby granted, free of charge, to any person obtaining
  11. // a copy of this software and associated documentation files (the
  12. // "Software"), to deal in the Software without restriction, including
  13. // without limitation the rights to use, copy, modify, merge, publish,
  14. // distribute, sublicense, and/or sell copies of the Software, and to
  15. // permit persons to whom the Software is furnished to do so, subject to
  16. // the following conditions:
  17. //
  18. // The above copyright notice and this permission notice shall be
  19. // included in all copies or substantial portions of the Software.
  20. //
  21. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  22. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  23. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  24. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  25. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  26. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  27. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  28. //
  29. using System;
  30. using System.CodeDom;
  31. using System.CodeDom.Compiler;
  32. using System.Collections;
  33. using System.Collections.Generic;
  34. using System.IO;
  35. using System.Reflection;
  36. using System.Web;
  37. using System.Web.UI;
  38. namespace System.Web.Compilation
  39. {
  40. abstract class SimpleBuildProvider : GenericBuildProvider <SimpleWebHandlerParser>
  41. {
  42. bool _parsed;
  43. bool _needLoadFromBin;
  44. protected override SimpleWebHandlerParser Parse ()
  45. {
  46. SimpleWebHandlerParser parser = Parser;
  47. if (_parsed)
  48. return parser;
  49. _parsed = true;
  50. return parser;
  51. }
  52. protected override void GenerateCode (AssemblyBuilder assemblyBuilder, SimpleWebHandlerParser parser, BaseCompiler compiler)
  53. {
  54. if (assemblyBuilder == null || parser == null)
  55. return;
  56. string programCode = parser.Program.Trim ();
  57. if (String.IsNullOrEmpty (programCode)) {
  58. _needLoadFromBin = true;
  59. return;
  60. }
  61. _needLoadFromBin = false;
  62. using (TextWriter writer = assemblyBuilder.CreateCodeFile (this))
  63. writer.WriteLine (programCode);
  64. }
  65. protected override Type LoadTypeFromBin (BaseCompiler compiler, SimpleWebHandlerParser parser)
  66. {
  67. return parser.GetTypeFromBin (parser.ClassName);
  68. }
  69. protected override string GetClassType (BaseCompiler compiler, SimpleWebHandlerParser parser)
  70. {
  71. if (parser != null)
  72. return parser.ClassName;
  73. return null;
  74. }
  75. protected override ICollection GetParserDependencies (SimpleWebHandlerParser parser)
  76. {
  77. if (parser != null)
  78. return parser.Dependencies;
  79. return null;
  80. }
  81. protected override string GetParserLanguage (SimpleWebHandlerParser parser)
  82. {
  83. if (parser != null)
  84. return parser.Language;
  85. return null;
  86. }
  87. protected override string GetCodeBehindSource (SimpleWebHandlerParser parser)
  88. {
  89. return null;
  90. }
  91. protected override AspGenerator CreateAspGenerator (SimpleWebHandlerParser parser)
  92. {
  93. return null;
  94. }
  95. protected override BaseCompiler CreateCompiler (SimpleWebHandlerParser parser)
  96. {
  97. return new WebServiceCompiler (parser);
  98. }
  99. protected override List <string> GetReferencedAssemblies (SimpleWebHandlerParser parser)
  100. {
  101. if (parser == null)
  102. return null;
  103. ArrayList al = parser.Assemblies;
  104. if (al == null || al.Count == 0)
  105. return null;
  106. List <string> ret = new List <string> ();
  107. string loc;
  108. foreach (object o in al) {
  109. loc = o as string;
  110. if (loc == null)
  111. continue;
  112. if (ret.Contains (loc))
  113. continue;
  114. ret.Add (loc);
  115. }
  116. return ret;
  117. }
  118. protected override bool NeedsConstructType {
  119. get { return false; }
  120. }
  121. protected override bool NeedsLoadFromBin {
  122. get { return _needLoadFromBin; }
  123. }
  124. }
  125. }