BaseCompiler.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. //
  2. // System.Web.Compilation.BaseCompiler
  3. //
  4. // Authors:
  5. // Gonzalo Paniagua Javier ([email protected])
  6. //
  7. // (C) 2002 Ximian, Inc (http://www.ximian.com)
  8. //
  9. using System;
  10. using System.IO;
  11. using System.Text;
  12. namespace System.Web.Compilation
  13. {
  14. abstract class BaseCompiler
  15. {
  16. //FIXME: configurable?
  17. static string default_assemblies = "System.Web.dll, System.Data.dll, System.Drawing.dll";
  18. static Random rnd = new Random ((int) DateTime.Now.Ticks);
  19. string randomName;
  20. protected BaseCompiler ()
  21. {
  22. }
  23. public virtual Type GetCompiledType ()
  24. {
  25. return null;
  26. }
  27. public virtual string Key {
  28. get {
  29. return null;
  30. }
  31. }
  32. public virtual string SourceFile {
  33. get {
  34. return null;
  35. }
  36. }
  37. public virtual string [] Dependencies {
  38. get {
  39. return null;
  40. }
  41. }
  42. public virtual string CompilerOptions {
  43. get {
  44. string assemblies = default_assemblies;
  45. string privatePath = AppDomain.CurrentDomain.SetupInformation.PrivateBinPath;
  46. //FIXME: remove the next line once multiple appdomains can work together
  47. if (privatePath == null) privatePath = "bin";
  48. //
  49. if (privatePath != null && Directory.Exists (privatePath)) {
  50. StringBuilder sb = new StringBuilder (assemblies);
  51. foreach (string fileName in Directory.GetFiles (privatePath, "*.dll"))
  52. sb.AppendFormat (", {0}", fileName);
  53. assemblies = sb.ToString ();
  54. sb = null;
  55. }
  56. string [] split = assemblies.Split (',');
  57. StringBuilder result = new StringBuilder ();
  58. foreach (string assembly in split)
  59. result.AppendFormat ("/r:{0} ", assembly.TrimStart ());
  60. return result.ToString ();
  61. }
  62. }
  63. static string GetRandomFileName ()
  64. {
  65. string output;
  66. do {
  67. output = "tmp" + rnd.Next () + ".dll";
  68. } while (File.Exists (output));
  69. return output;
  70. }
  71. public virtual string TargetFile {
  72. get {
  73. if (randomName == null)
  74. randomName = GetRandomFileName ();
  75. return randomName;
  76. }
  77. }
  78. }
  79. }