X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mcs%2Fclass%2FSystem.Web%2FSystem.Web.Compilation%2FAppCodeCompiler.cs;h=fef206848afe71ca028e375aeb3b6932decaa4de;hb=a01fb8227b364663dbc0a8ef50cebf8e6b9563d0;hp=283eebe98d3b85ed0e602b9d1350667b675094b3;hpb=dd5ce5833ef0d71525792a17ecb4047d844abdc5;p=mono.git diff --git a/mcs/class/System.Web/System.Web.Compilation/AppCodeCompiler.cs b/mcs/class/System.Web/System.Web.Compilation/AppCodeCompiler.cs index 283eebe98d3..fef206848af 100644 --- a/mcs/class/System.Web/System.Web.Compilation/AppCodeCompiler.cs +++ b/mcs/class/System.Web/System.Web.Compilation/AppCodeCompiler.cs @@ -27,13 +27,14 @@ // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // -#if NET_2_0 + using System; using System.CodeDom; using System.CodeDom.Compiler; using System.Configuration; using System.Collections; using System.Collections.Generic; +using System.Collections.Specialized; using System.Globalization; using System.IO; using System.Reflection; @@ -80,21 +81,22 @@ namespace System.Web.Compilation if (asm == null) throw new HttpException (String.Format ("Unable to find assembly {0}", assemblyName), error); - assemblyCache.Add (assemblyName, asm.Location); - return asm.Location; + string path = new Uri (asm.CodeBase).LocalPath; + assemblyCache.Add (assemblyName, path); + return path; } } } internal class AppCodeAssembly { - private List files; - private List units; + List files; + List units; - private string name; - private string path; - private bool validAssembly; - private string outputAssemblyName; + string name; + string path; + bool validAssembly; + string outputAssemblyName; public string OutputAssemblyName { @@ -198,16 +200,13 @@ namespace System.Web.Compilation } CodeDomProvider provider = null; - CompilationSection compilationSection = WebConfigurationManager.GetSection ("system.web/compilation") as CompilationSection; + CompilationSection compilationSection = WebConfigurationManager.GetWebApplicationSection ("system.web/compilation") as CompilationSection; if (compilerInfo == null) { if (!CodeDomProvider.IsDefinedLanguage (compilationSection.DefaultLanguage)) throw new HttpException ("Failed to retrieve default source language"); compilerInfo = CodeDomProvider.GetCompilerInfo (compilationSection.DefaultLanguage); if (compilerInfo == null || !compilerInfo.IsCodeDomProviderTypeValid) throw new HttpException ("Internal error while initializing application"); - provider = compilerInfo.CreateProvider (); - if (provider == null) - throw new HttpException ("A code provider error occurred while initializing application."); } provider = compilerInfo.CreateProvider (); @@ -224,8 +223,15 @@ namespace System.Web.Compilation CompilerParameters parameters = compilerInfo.CreateDefaultCompilerParameters (); parameters.IncludeDebugInformation = compilationSection.Debug; - if (binAssemblies != null && binAssemblies.Length > 0) - parameters.ReferencedAssemblies.AddRange (binAssemblies); + if (binAssemblies != null && binAssemblies.Length > 0) { + StringCollection parmRefAsm = parameters.ReferencedAssemblies; + foreach (string binAsm in binAssemblies) { + if (parmRefAsm.Contains (binAsm)) + continue; + + parmRefAsm.Add (binAsm); + } + } if (compilationSection != null) { foreach (AssemblyInfo ai in compilationSection.Assemblies) @@ -260,6 +266,9 @@ namespace System.Web.Compilation foreach (Assembly a in BuildManager.TopLevelAssemblies) parameters.ReferencedAssemblies.Add (a.Location); CompilerResults results = abuilder.BuildAssembly (parameters); + if (results == null) + return; + if (results.NativeCompilerReturnValue == 0) { BuildManager.CodeAssemblies.Add (results.CompiledAssembly); BuildManager.TopLevelAssemblies.Add (results.CompiledAssembly); @@ -271,17 +280,17 @@ namespace System.Web.Compilation } } - private string PhysicalToVirtual (string file) + VirtualPath PhysicalToVirtual (string file) { - return file.Replace (HttpRuntime.AppDomainAppPath, "/").Replace (Path.DirectorySeparatorChar, '/'); + return new VirtualPath (file.Replace (HttpRuntime.AppDomainAppPath, "~/").Replace (Path.DirectorySeparatorChar, '/')); } - private BuildProvider GetBuildProviderFor (string file, BuildProviderCollection buildProviders) + BuildProvider GetBuildProviderFor (string file, BuildProviderCollection buildProviders) { if (file == null || file.Length == 0 || buildProviders == null || buildProviders.Count == 0) return null; - BuildProvider ret = buildProviders.GetProviderForExtension (Path.GetExtension (file)); + BuildProvider ret = buildProviders.GetProviderInstanceForExtension (Path.GetExtension (file)); if (ret != null && IsCorrectBuilderType (ret)) { ret.SetVirtualPath (PhysicalToVirtual (file)); return ret; @@ -290,7 +299,7 @@ namespace System.Web.Compilation return null; } - private bool IsCorrectBuilderType (BuildProvider bp) + bool IsCorrectBuilderType (BuildProvider bp) { if (bp == null) return false; @@ -323,7 +332,7 @@ namespace System.Web.Compilation internal class AppCodeCompiler { - static private bool _alreadyCompiled; + static bool _alreadyCompiled; internal static string DefaultAppCodeAssemblyName; // A dictionary that contains an entry per an assembly that will @@ -348,7 +357,7 @@ namespace System.Web.Compilation // Files for which exist BuildProviders but which have no // unambiguous language assigned to them (e.g. .wsdl files), are // built using the default website compiler. - private List assemblies; + List assemblies; string providerTypeName = null; public AppCodeCompiler () @@ -359,12 +368,12 @@ namespace System.Web.Compilation bool ProcessAppCodeDir (string appCode, AppCodeAssembly defasm) { // First process the codeSubDirectories - CompilationSection cs = (CompilationSection) WebConfigurationManager.GetSection ("system.web/compilation"); + CompilationSection cs = (CompilationSection) WebConfigurationManager.GetWebApplicationSection ("system.web/compilation"); if (cs != null) { string aname; for (int i = 0; i < cs.CodeSubDirectories.Count; i++) { - aname = String.Format ("App_SubCode_{0}", cs.CodeSubDirectories[i].DirectoryName); + aname = String.Concat ("App_SubCode_", cs.CodeSubDirectories[i].DirectoryName); assemblies.Add (new AppCodeAssembly ( aname, Path.Combine (appCode, cs.CodeSubDirectories[i].DirectoryName))); @@ -416,7 +425,7 @@ namespace System.Web.Compilation void GetProfileSettingsSerializeAsAttribute (ProfileSection ps, CodeAttributeDeclarationCollection collection, SerializationMode mode) { - string parameter = String.Format ("SettingsSerializeAs.{0}", mode.ToString ()); + string parameter = String.Concat ("SettingsSerializeAs.", mode.ToString ()); collection.Add ( new CodeAttributeDeclaration ( "SettingsSerializeAs", @@ -549,7 +558,7 @@ namespace System.Web.Compilation string MakeGroupName (string name) { - return String.Format ("ProfileGroup{0}", name); + return String.Concat ("ProfileGroup", name); } // FIXME: there should be some validation of syntactic correctness of the member/class name @@ -583,12 +592,20 @@ namespace System.Web.Compilation } string baseType = ps.Inherits; - bool baseIsGlobal = false; - if (String.IsNullOrEmpty (baseType)) { + if (String.IsNullOrEmpty (baseType)) baseType = "System.Web.Profile.ProfileBase"; - baseIsGlobal = true; + else { + string[] parts = baseType.Split (new char[] {','}); + if (parts.Length > 1) + baseType = parts [0].Trim (); } + bool baseIsGlobal; + if (baseType.IndexOf ('.') != -1) + baseIsGlobal = true; + else + baseIsGlobal = false; + BuildProfileClass (ps, "ProfileCommon", props, ns, baseType, baseIsGlobal, groupProperties); return true; } @@ -606,7 +623,11 @@ namespace System.Web.Compilation { if (ps == null || !ps.Enabled) return false; - if (!String.IsNullOrEmpty (ps.Inherits) || (ps.PropertySettings != null && ps.PropertySettings.Count > 0)) + + RootProfilePropertySettingsCollection props = ps.PropertySettings; + ProfileGroupSettingsCollection groups = props != null ? props.GroupSettings : null; + + if (!String.IsNullOrEmpty (ps.Inherits) || (props != null && props.Count > 0) || (groups != null && groups.Count > 0)) return true; return false; @@ -618,7 +639,7 @@ namespace System.Web.Compilation return; string appCode = Path.Combine (HttpRuntime.AppDomainAppPath, "App_Code"); - ProfileSection ps = WebConfigurationManager.GetSection ("system.web/profile") as ProfileSection; + ProfileSection ps = WebConfigurationManager.GetWebApplicationSection ("system.web/profile") as ProfileSection; bool haveAppCodeDir = Directory.Exists (appCode); bool haveCustomProfile = HaveCustomProfile (ps); @@ -637,7 +658,7 @@ namespace System.Web.Compilation if (!haveCode) return; - + HttpRuntime.EnableAssemblyMapping (true); string[] binAssemblies = HttpApplication.BinDirectoryAssemblies; @@ -645,6 +666,8 @@ namespace System.Web.Compilation aca.Build (binAssemblies); _alreadyCompiled = true; DefaultAppCodeAssemblyName = Path.GetFileNameWithoutExtension (defasm.OutputAssemblyName); + + RunAppInitialize (); if (haveCustomProfile && providerTypeName != null) { if (Type.GetType (providerTypeName, false) == null) { @@ -658,13 +681,57 @@ namespace System.Web.Compilation } else return; - if (HttpApplication.LoadTypeFromBin (providerTypeName) == null) - throw new HttpException (String.Format ("Profile provider type not found: {0}", - providerTypeName)); + Exception noTypeException = null; + Type ptype = null; + + try { + ptype = HttpApplication.LoadTypeFromBin (providerTypeName); + } catch (Exception ex) { + noTypeException = ex; + } + + if (ptype == null) + throw new HttpException (String.Format ("Profile provider type not found: {0}", providerTypeName), noTypeException); } } - private bool CollectFiles (string dir, AppCodeAssembly aca) + // Documented (sort of...) briefly in: + // + // http://quickstarts.asp.net/QuickStartv20/aspnet/doc/extensibility.aspx + // http://msdn2.microsoft.com/en-us/library/system.web.hosting.virtualpathprovider.aspx + void RunAppInitialize () + { + MethodInfo mi = null, tmi; + Type[] types; + + foreach (Assembly asm in BuildManager.CodeAssemblies) { + types = asm.GetExportedTypes (); + if (types == null || types.Length == 0) + continue; + + foreach (Type type in types) { + tmi = type.GetMethod ("AppInitialize", + BindingFlags.Public | BindingFlags.Static | BindingFlags.IgnoreCase, + null, + Type.EmptyTypes, + null); + if (tmi == null) + continue; + + if (mi != null) + throw new HttpException ("The static AppInitialize method found in more than one type in the App_Code directory."); + + mi = tmi; + } + } + + if (mi == null) + return; + + mi.Invoke (null, null); + } + + bool CollectFiles (string dir, AppCodeAssembly aca) { bool haveFiles = false; @@ -688,4 +755,4 @@ namespace System.Web.Compilation } } } -#endif +