PageCompiler.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. //
  2. // System.Web.Compilation.PageCompiler
  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.Web.UI;
  12. namespace System.Web.Compilation
  13. {
  14. class PageCompiler
  15. {
  16. private PageParser pageParser;
  17. internal PageCompiler (PageParser pageParser)
  18. {
  19. this.pageParser = pageParser;
  20. }
  21. public static Type CompilePageType (PageParser pageParser)
  22. {
  23. string sourceFile = GenerateSourceFile (pageParser);
  24. Console.WriteLine ("Compiling {0}", sourceFile);
  25. return TemplateFactory.GetTypeFromSource (sourceFile);
  26. }
  27. private static string GenerateSourceFile (PageParser pageParser)
  28. {
  29. string inputFile = pageParser.InputFile;
  30. Stream input = File.OpenRead (inputFile);
  31. AspParser parser = new AspParser (inputFile, input);
  32. parser.Parse ();
  33. AspGenerator generator = new AspGenerator (inputFile, parser.Elements);
  34. generator.BaseType = "System.Web.UI.Page";
  35. generator.ProcessElements ();
  36. pageParser.Text = generator.GetCode ().ReadToEnd ();
  37. //FIXME: should get Tmp dir for this application
  38. string csName = Path.GetTempFileName () + ".cs";
  39. Console.WriteLine ("Writing {0}", csName);
  40. StreamWriter output = new StreamWriter (File.OpenWrite (csName));
  41. output.Write (pageParser.Text);
  42. output.Close ();
  43. return csName;
  44. }
  45. }
  46. }