Welcome to mirror list, hosted at ThFree Co, Russian Federation.

PageCompiler.cs « System.Web.Compilation « System.Web « class « mcs - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 94e6cfac83bebc370bb0fdbdfcf4d273704b15b8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
//
// System.Web.Compilation.PageCompiler
//
// Authors:
//	Gonzalo Paniagua Javier (gonzalo@ximian.com)
//
// (C) 2002 Ximian, Inc (http://www.ximian.com)
//
using System;
using System.IO;
using System.Web.UI;

namespace System.Web.Compilation
{
	class PageCompiler
	{
		private PageParser pageParser;

		internal PageCompiler (PageParser pageParser)
		{
			this.pageParser = pageParser;
		}

		public static Type CompilePageType (PageParser pageParser)
		{
			string sourceFile = GenerateSourceFile (pageParser);
			Console.WriteLine ("Compiling {0}", sourceFile);
			return TemplateFactory.GetTypeFromSource (sourceFile);
		}

		private static string GenerateSourceFile (PageParser pageParser)
		{
			string inputFile = pageParser.InputFile;

			Stream input = File.OpenRead (inputFile);
			AspParser parser = new AspParser (inputFile, input);
			parser.Parse ();
			AspGenerator generator = new AspGenerator (inputFile, parser.Elements);
			generator.BaseType = "System.Web.UI.Page";
			generator.ProcessElements ();
			pageParser.Text = generator.GetCode ().ReadToEnd ();

			//FIXME: should get Tmp dir for this application
			string csName = Path.GetTempFileName () + ".cs";
			Console.WriteLine ("Writing {0}", csName);
			StreamWriter output = new StreamWriter (File.OpenWrite (csName));
			output.Write (pageParser.Text);
			output.Close ();
			return csName;
		}
	}
}