Browse Source

2009-04-15 Marek Habersack <[email protected]>

	* TemplateParser.cs: use generic lists for import, namespace and
	interface caches. If a namespace is added (e.g. by parsing the
	Import directive), find the assembly in which namespace is
	defined.

2009-04-15  Marek Habersack  <[email protected]>

	* BuildManager.cs: do not add all assemblies in bin/ when serving
	a precompiled site. Fixes bug #493873
	When serving a precompiled site, check if the bin/ directory
	contains certain well-known assemblies and load them if present.

svn path=/trunk/mcs/; revision=131768
Marek Habersack 16 years ago
parent
commit
c2a841d9f8

+ 15 - 4
mcs/class/System.Web/System.Web.Compilation/BuildManager.cs

@@ -778,7 +778,7 @@ namespace System.Web.Compilation {
                         bool addAssembliesInBin = false;
                         foreach (AssemblyInfo info in compConfig.Assemblies) {
                                 if (info.Assembly == "*")
-                                        addAssembliesInBin = true;
+                                        addAssembliesInBin = is_precompiled ? false : true;
                                 else
                                         LoadAssembly (info, al);
                         }
@@ -788,8 +788,18 @@ namespace System.Web.Compilation {
 
 			foreach (string assLocation in WebConfigurationManager.ExtraAssemblies)
 				LoadAssembly (assLocation, al);
-			
-                        if (addAssembliesInBin)
+
+			if (is_precompiled) {
+				// Add well-known assemblies which need to be referenced by everyone
+				string binDir = HttpApplication.BinDirectory;
+				string asmPath;
+
+				foreach (String s in new string[] {"App_Code.dll", "App_GlobalResources.dll", "App_global.asax.dll"}) {
+					asmPath = Path.Combine (binDir, s);
+					if (File.Exists (asmPath))
+						LoadAssembly (asmPath, al);
+				}
+			} else if (addAssembliesInBin) {
 				foreach (string s in HttpApplication.BinDirectoryAssemblies) {
 					try {
 						LoadAssembly (s, al);
@@ -797,7 +807,8 @@ namespace System.Web.Compilation {
 						// ignore silently
 					}
 				}
-			
+			}
+				
 			return al;
 		}
 		

+ 7 - 0
mcs/class/System.Web/System.Web.Compilation/ChangeLog

@@ -1,3 +1,10 @@
+2009-04-15  Marek Habersack  <[email protected]>
+
+	* BuildManager.cs: do not add all assemblies in bin/ when serving
+	a precompiled site. Fixes bug #493873
+	When serving a precompiled site, check if the bin/ directory
+	contains certain well-known assemblies and load them if present.
+
 2009-04-07  Marek Habersack  <[email protected]>
 
 	* TemplateControlCompiler.cs: GenerateExpressionFromString doesn't

+ 7 - 0
mcs/class/System.Web/System.Web.UI/ChangeLog

@@ -1,3 +1,10 @@
+2009-04-15  Marek Habersack  <[email protected]>
+
+	* TemplateParser.cs: use generic lists for import, namespace and
+	interface caches. If a namespace is added (e.g. by parsing the
+	Import directive), find the assembly in which namespace is
+	defined.
+
 2009-04-07  Marek Habersack  <[email protected]>
 
 	* Control.cs: ApplyTheme - make sure Page is not null before using

+ 100 - 18
mcs/class/System.Web/System.Web.UI/TemplateParser.cs

@@ -71,9 +71,17 @@ namespace System.Web.UI {
 		ArrayList dependencies;
 		ArrayList assemblies;
 		Hashtable anames;
+#if NET_2_0
+		string[] binDirAssemblies;
+		Dictionary <string, bool> namespacesCache;
+		List <string> imports;
+		List <string> interfaces;
+		List <ServerSideScript> scripts;
+#else
 		ArrayList imports;
 		ArrayList interfaces;
 		ArrayList scripts;
+#endif
 		Type baseType;
 		bool baseTypeIsGlobal = true;
 		string className;
@@ -120,9 +128,8 @@ namespace System.Web.UI {
 		internal TemplateParser ()
 		{
 			LoadConfigDefaults ();
-			
-			imports = new ArrayList ();
 #if NET_2_0
+			imports = new List <string> ();
 			AddNamespaces (imports);
 #else
 			imports.Add ("System");
@@ -143,16 +150,10 @@ namespace System.Web.UI {
 			assemblies = new ArrayList ();
 #if NET_2_0
 			CompilationSection compConfig = CompilationConfig;
-			
-			bool addAssembliesInBin = false;
 			foreach (AssemblyInfo info in compConfig.Assemblies) {
-				if (info.Assembly == "*")
-					addAssembliesInBin = true;
-				else
+				if (info.Assembly != "*")
 					AddAssemblyByName (info.Assembly);
 			}
-			if (addAssembliesInBin)
-				AddAssembliesInBin ();
 
 			foreach (NamespaceInfo info in PagesConfig.Namespaces) {
 				imports.Add (info.Namespace);
@@ -200,7 +201,7 @@ namespace System.Web.UI {
 			generator.AddControl (type, attributes);
 		}
 		
-		void AddNamespaces (ArrayList imports)
+		void AddNamespaces (List <string> imports)
 		{
 			if (BuildManager.HaveResources)
 				imports.Add ("System.Resources");
@@ -477,8 +478,13 @@ namespace System.Web.UI {
 		
 		internal virtual void AddInterface (string iface)
 		{
-			if (interfaces == null)
+			if (interfaces == null) {
+#if NET_2_0
+				interfaces = new List <string> ();
+#else
 				interfaces = new ArrayList ();
+#endif
+			}
 
 			if (!interfaces.Contains (iface))
 				interfaces.Add (iface);
@@ -486,13 +492,70 @@ namespace System.Web.UI {
 		
 		internal virtual void AddImport (string namesp)
 		{
-			if (imports == null)
+			if (imports == null) {
+#if NET_2_0
+				imports = new List <string> ();
+#else
 				imports = new ArrayList ();
+#endif
+			}
+			
+			if (imports.Contains (namesp))
+				return;
+			
+			imports.Add (namesp);
+#if NET_2_0
+			AddAssemblyForNamespace (namesp);
+#endif
+		}
+
+#if NET_2_0
+		void AddAssemblyForNamespace (string namesp)
+		{
+			if (binDirAssemblies == null)
+				binDirAssemblies = HttpApplication.BinDirectoryAssemblies;
+			if (binDirAssemblies.Length == 0)
+				return;
+
+			if (namespacesCache == null)
+				namespacesCache = new Dictionary <string, bool> ();
+			else if (namespacesCache.ContainsKey (namesp))
+				return;
+			
+			foreach (Assembly asm in AppDomain.CurrentDomain.GetAssemblies ())
+				if (FindNamespaceInAssembly (asm, namesp))
+					return;
+			
+			IList tla = BuildManager.TopLevelAssemblies;
+			if (tla != null && tla.Count > 0) {
+				foreach (Assembly asm in tla) {
+					if (FindNamespaceInAssembly (asm, namesp))
+						return;
+				}
+			}
 
-			if (!imports.Contains (namesp))
-				imports.Add (namesp);
+			Assembly a;
+			foreach (string s in binDirAssemblies) {
+				a = Assembly.LoadFrom (s);
+				if (FindNamespaceInAssembly (a, namesp))
+					return;
+			}
 		}
 
+		bool FindNamespaceInAssembly (Assembly asm, string namesp)
+		{
+			foreach (Type type in asm.GetTypes ()) {
+				if (String.Compare (type.Namespace, namesp, StringComparison.Ordinal) == 0) {
+					namespacesCache.Add (namesp, true);
+					AddAssembly (asm, true);
+					return true;
+				}
+			}
+
+			return false;
+		}
+#endif
+		
 		internal virtual void AddSourceDependency (string filename)
 		{
 			if (dependencies != null && dependencies.Contains (filename))
@@ -1152,6 +1215,24 @@ namespace System.Web.UI {
 			}
 		}
 
+#if NET_2_0
+		internal List <ServerSideScript> Scripts {
+			get {
+				if (scripts == null)
+					scripts = new List <ServerSideScript> ();
+
+				return scripts;
+			}
+		}
+
+		internal List <string> Imports {
+			get { return imports; }
+		}
+
+		internal List <string> Interfaces {
+			get { return interfaces; }
+		}
+#else
 		internal ArrayList Scripts {
 			get {
 				if (scripts == null)
@@ -1165,6 +1246,11 @@ namespace System.Web.UI {
 			get { return imports; }
 		}
 
+		internal ArrayList Interfaces {
+			get { return interfaces; }
+		}
+#endif
+		
 		internal ArrayList Assemblies {
 			get {
 				if (appAssemblyIndex != -1) {
@@ -1178,10 +1264,6 @@ namespace System.Web.UI {
 			}
 		}
 
-		internal ArrayList Interfaces {
-			get { return interfaces; }
-		}
-
 		internal RootBuilder RootBuilder {
 			get { return rootBuilder; }
 			set { rootBuilder = value; }