CompilationConfiguration.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. //
  2. // System.Web.Configuration.CompilationConfiguration
  3. //
  4. // Authors:
  5. // Gonzalo Paniagua Javier ([email protected])
  6. //
  7. // (C) 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. //TODO: reload config when file changes.
  37. CompilationConfiguration parent = p as CompilationConfiguration;
  38. if (parent != null)
  39. Init (parent);
  40. if (compilers == null)
  41. compilers = new CompilerCollection ();
  42. if (assemblies == null)
  43. assemblies = new ArrayList ();
  44. if (temp_directory == null)
  45. temp_directory = Path.GetTempPath ();
  46. }
  47. static public CompilationConfiguration GetInstance (HttpContext context)
  48. {
  49. CompilationConfiguration config;
  50. if (context == null)
  51. context = HttpContext.Context;
  52. config = context.GetConfig ("system.web/compilation") as CompilationConfiguration;
  53. if (config == null)
  54. throw new Exception ("Configuration error.");
  55. return config;
  56. }
  57. public CodeDomProvider GetProvider (string language)
  58. {
  59. WebCompiler compiler = Compilers [language];
  60. if (compiler == null)
  61. return null;
  62. if (compiler.Provider != null)
  63. return compiler.Provider;
  64. Type t = Type.GetType (compiler.Type);
  65. compiler.Provider = Activator.CreateInstance (t) as CodeDomProvider;
  66. return compiler.Provider;
  67. }
  68. public string GetCompilerOptions (string language)
  69. {
  70. WebCompiler compiler = Compilers [language];
  71. if (compiler == null)
  72. return null;
  73. return compiler.CompilerOptions;
  74. }
  75. public int GetWarningLevel (string language)
  76. {
  77. WebCompiler compiler = Compilers [language];
  78. if (compiler == null)
  79. return 0;
  80. return compiler.WarningLevel;
  81. }
  82. void Init (CompilationConfiguration parent)
  83. {
  84. debug = parent.debug;
  85. batch = parent.batch;
  86. batch_timeout = parent.batch_timeout;
  87. default_language = parent.default_language;
  88. _explicit = parent._explicit;
  89. max_batch_size = parent.max_batch_size;
  90. max_batch_file_size = parent.max_batch_file_size;
  91. num_recompiles_before_app_restart = parent.num_recompiles_before_app_restart;
  92. strict = parent.strict;
  93. temp_directory = parent.temp_directory;
  94. compilers = new CompilerCollection (parent.compilers);
  95. ArrayList p = parent.assemblies;
  96. assembliesInBin = parent.assembliesInBin;
  97. ICollection coll = (p == null) ? (ICollection) new object [0] : p;
  98. assemblies = new ArrayList (coll);
  99. }
  100. public bool Debug {
  101. get { return debug; }
  102. set { debug = value; }
  103. }
  104. public bool Batch {
  105. get { return batch; }
  106. set { batch = value; }
  107. }
  108. public int BatchTimeout {
  109. get { return batch_timeout; }
  110. set { batch_timeout = value; }
  111. }
  112. public string DefaultLanguage {
  113. get { return default_language; }
  114. set { default_language = value; }
  115. }
  116. public bool Explicit {
  117. get { return _explicit; }
  118. set { _explicit = value; }
  119. }
  120. public int MaxBatchSize {
  121. get { return max_batch_size; }
  122. set { max_batch_size = value; }
  123. }
  124. public int MaxBatchFileSize {
  125. get { return max_batch_file_size; }
  126. set { max_batch_file_size = value; }
  127. }
  128. public int NumRecompilesBeforeAppRestart {
  129. get { return num_recompiles_before_app_restart; }
  130. set { num_recompiles_before_app_restart = value; }
  131. }
  132. public bool Strict {
  133. get { return strict; }
  134. set { strict = value; }
  135. }
  136. public string TempDirectory {
  137. get { return temp_directory; }
  138. set {
  139. if (value == null || value == "")
  140. value = Path.GetTempPath ();
  141. if (!Directory.Exists (value))
  142. throw new ArgumentException ("Directory does not exist");
  143. temp_directory = value;
  144. }
  145. }
  146. public CompilerCollection Compilers {
  147. get { return compilers; }
  148. }
  149. public ArrayList Assemblies {
  150. get { return assemblies; }
  151. }
  152. public bool AssembliesInBin {
  153. get { return assembliesInBin; }
  154. set { assembliesInBin = value; }
  155. }
  156. }
  157. }