CompilationConfiguration.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. //
  2. // System.Web.Configuration.CompilationConfiguration
  3. //
  4. // Authors:
  5. // Gonzalo Paniagua Javier ([email protected])
  6. //
  7. // (c) Copyright 2003 Ximian, Inc (http://www.ximian.com)
  8. //
  9. using System;
  10. using System.CodeDom.Compiler;
  11. using System.Collections;
  12. using System.Configuration;
  13. using System.IO;
  14. using System.Web;
  15. using System.Xml;
  16. namespace System.Web.Configuration
  17. {
  18. sealed class CompilationConfiguration
  19. {
  20. bool debug = false;
  21. bool batch = false;
  22. int batch_timeout;
  23. string default_language = "c#";
  24. bool _explicit = true;
  25. int max_batch_size = 30;
  26. int max_batch_file_size = 3000;
  27. int num_recompiles_before_app_restart = 15;
  28. bool strict = false;
  29. string temp_directory;
  30. CompilerCollection compilers;
  31. ArrayList assemblies;
  32. bool assembliesInBin = false;
  33. /* Only the config. handler should create instances of this. Use GetInstance (context) */
  34. public CompilationConfiguration (object p)
  35. {
  36. CompilationConfiguration parent = p as CompilationConfiguration;
  37. if (parent != null)
  38. Init (parent);
  39. if (compilers == null)
  40. compilers = new CompilerCollection ();
  41. if (assemblies == null)
  42. assemblies = new ArrayList ();
  43. if (temp_directory == null)
  44. temp_directory = Path.GetTempPath ();
  45. }
  46. static public CompilationConfiguration GetInstance (HttpContext context)
  47. {
  48. CompilationConfiguration config;
  49. if (context == null)
  50. context = HttpContext.Context;
  51. config = context.GetConfig ("system.web/compilation") as CompilationConfiguration;
  52. if (config == null)
  53. throw new Exception ("Configuration error.");
  54. return config;
  55. }
  56. public CodeDomProvider GetProvider (string language)
  57. {
  58. WebCompiler compiler = Compilers [language];
  59. if (compiler == null)
  60. return null;
  61. if (compiler.Provider != null)
  62. return compiler.Provider;
  63. Type t = Type.GetType (compiler.Type);
  64. compiler.Provider = Activator.CreateInstance (t) as CodeDomProvider;
  65. return compiler.Provider;
  66. }
  67. public string GetCompilerOptions (string language)
  68. {
  69. WebCompiler compiler = Compilers [language];
  70. if (compiler == null)
  71. return null;
  72. return compiler.CompilerOptions;
  73. }
  74. public int GetWarningLevel (string language)
  75. {
  76. WebCompiler compiler = Compilers [language];
  77. if (compiler == null)
  78. return 0;
  79. return compiler.WarningLevel;
  80. }
  81. void Init (CompilationConfiguration parent)
  82. {
  83. debug = parent.debug;
  84. batch = parent.batch;
  85. batch_timeout = parent.batch_timeout;
  86. default_language = parent.default_language;
  87. _explicit = parent._explicit;
  88. max_batch_size = parent.max_batch_size;
  89. max_batch_file_size = parent.max_batch_file_size;
  90. num_recompiles_before_app_restart = parent.num_recompiles_before_app_restart;
  91. strict = parent.strict;
  92. temp_directory = parent.temp_directory;
  93. compilers = new CompilerCollection (parent.compilers);
  94. ArrayList p = parent.assemblies;
  95. assembliesInBin = parent.assembliesInBin;
  96. ICollection coll = (p == null) ? (ICollection) new object [0] : p;
  97. assemblies = new ArrayList (coll);
  98. }
  99. public bool Debug {
  100. get { return debug; }
  101. set { debug = value; }
  102. }
  103. public bool Batch {
  104. get { return batch; }
  105. set { batch = value; }
  106. }
  107. public int BatchTimeout {
  108. get { return batch_timeout; }
  109. set { batch_timeout = value; }
  110. }
  111. public string DefaultLanguage {
  112. get { return default_language; }
  113. set { default_language = value; }
  114. }
  115. public bool Explicit {
  116. get { return _explicit; }
  117. set { _explicit = value; }
  118. }
  119. public int MaxBatchSize {
  120. get { return max_batch_size; }
  121. set { max_batch_size = value; }
  122. }
  123. public int MaxBatchFileSize {
  124. get { return max_batch_file_size; }
  125. set { max_batch_file_size = value; }
  126. }
  127. public int NumRecompilesBeforeAppRestart {
  128. get { return num_recompiles_before_app_restart; }
  129. set { num_recompiles_before_app_restart = value; }
  130. }
  131. public bool Strict {
  132. get { return strict; }
  133. set { strict = value; }
  134. }
  135. public string TempDirectory {
  136. get { return temp_directory; }
  137. set {
  138. if (value != null && !Directory.Exists (value))
  139. throw new ArgumentException ("Directory does not exist");
  140. temp_directory = value;
  141. }
  142. }
  143. public CompilerCollection Compilers {
  144. get { return compilers; }
  145. }
  146. public ArrayList Assemblies {
  147. get { return assemblies; }
  148. }
  149. public bool AssembliesInBin {
  150. get { return assembliesInBin; }
  151. set { assembliesInBin = value; }
  152. }
  153. }
  154. }