PageCompiler.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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.InputFile);
  24. return TemplateFactory.GetTypeFromSource (sourceFile);
  25. }
  26. private static string GenerateSourceFile (string inputFile)
  27. {
  28. Stream input = File.OpenRead (inputFile);
  29. AspParser parser = new AspParser (inputFile, input);
  30. parser.Parse ();
  31. AspGenerator generator = new AspGenerator (inputFile, parser.Elements);
  32. //FIXME: set properties here -> base type, interfaces,...
  33. generator.ProcessElements ();
  34. string code = generator.GetCode ().ReadToEnd ();
  35. //FIXME: should get Tmp dir for this application
  36. string csName = Path.GetTempFileName ();
  37. StreamWriter output = new StreamWriter (File.OpenWrite (csName));
  38. output.Write (code);
  39. output.Close ();
  40. return csName;
  41. }
  42. }
  43. }