2010-03-04 Marek Habersack <mhabersack@novell.com>
authorMarek Habersack <grendel@twistedcode.net>
Thu, 4 Mar 2010 19:04:13 +0000 (19:04 -0000)
committerMarek Habersack <grendel@twistedcode.net>
Thu, 4 Mar 2010 19:04:13 +0000 (19:04 -0000)
* BuildManager.cs: do less work in the static constructor

2010-03-04  Marek Habersack  <mhabersack@novell.com>

* RuntimeHelpers.cs: added. Contains methods moved here from
HttpRuntime, so that initialization sequence of various objects is
independent of HttpRuntime.

2010-03-04  Marek Habersack  <mhabersack@novell.com>

* HttpRuntime.cs: do less work in the static constructor. Most of
the code was moved to System.Web.Util.RuntimeHelpers. Properties
which have been moved: MonoVersion, RunningOnWindows,
CaseInsensitive, IsDebuggingEnabled

Also:
- hushed some compiler warnings
- various classes now use RuntimeHelpers instead of HttpRuntime

svn path=/trunk/mcs/; revision=153038

23 files changed:
mcs/class/System.Web/System.Web.Caching/CachedRawResponse.cs
mcs/class/System.Web/System.Web.Caching/OutputCacheProviderCollection.cs
mcs/class/System.Web/System.Web.Compilation/AppResourcesAssemblyBuilder.cs
mcs/class/System.Web/System.Web.Compilation/BuildManager.cs
mcs/class/System.Web/System.Web.Compilation/BuildManagerDirectoryBuilder.cs
mcs/class/System.Web/System.Web.Compilation/ChangeLog
mcs/class/System.Web/System.Web.Configuration_2.0/WebConfigurationManager.cs
mcs/class/System.Web/System.Web.Security/FormsAuthenticationModule.cs
mcs/class/System.Web/System.Web.SessionState_2.0/SessionSQLServerHandler.cs
mcs/class/System.Web/System.Web.UI.WebControls/TreeView.cs
mcs/class/System.Web/System.Web.UI/Page.cs
mcs/class/System.Web/System.Web.UI/SimpleWebHandlerParser.cs
mcs/class/System.Web/System.Web.Util/ChangeLog
mcs/class/System.Web/System.Web.Util/RuntimeHelpers.cs [new file with mode: 0644]
mcs/class/System.Web/System.Web.dll.sources
mcs/class/System.Web/System.Web/ChangeLog
mcs/class/System.Web/System.Web/HttpContext.cs
mcs/class/System.Web/System.Web/HttpException.cs
mcs/class/System.Web/System.Web/HttpRuntime.cs
mcs/class/System.Web/System.Web/StaticFileHandler.cs
mcs/class/System.Web/System.Web/StaticSiteMapProvider.cs
mcs/class/System.Web/System.Web/VirtualPathUtility.cs
mcs/class/System.Web/System.Web/XmlSiteMapProvider.cs

index c2003813a45eb8c92ac23aca9c4b42adf916e069..7a34c54503ff52f852d96b08c22ac548a653deba 100644 (file)
@@ -64,7 +64,6 @@ namespace System.Web.Caching
                CachedVaryBy varyby;
                int status_code;
                string status_desc;
-               int content_length;
                NameValueCollection headers;
                List <DataItem> data;
 
index 0a2f983744280a11ad70a614253c22682dd4167c..19d051dd1383a866e1ca03abf7394f6e7be90450 100644 (file)
@@ -32,7 +32,7 @@ namespace System.Web.Caching
 {
        public sealed class OutputCacheProviderCollection : ProviderCollection
        {
-               public OutputCacheProvider this [string name] {
+               public new OutputCacheProvider this [string name] {
                        get { return base [name] as OutputCacheProvider; }
                }
                
index 2589c5d8498da09f2cafc4f038616b847e752a7f..f430688bfca3df9a048d72d0ddad303a613dad4b 100644 (file)
@@ -41,6 +41,7 @@ using System.Text;
 using System.Threading;
 using System.Web;
 using System.Web.Configuration;
+using System.Web.Util;
 
 namespace System.Web.Compilation
 {
@@ -229,7 +230,7 @@ namespace System.Web.Compilation
 
                string SetAlPath (ProcessStartInfo info)
                {                       
-                       if (HttpRuntime.RunningOnWindows) {
+                       if (RuntimeHelpers.RunningOnWindows) {
                                string alPath;
                                string monoPath;
                                PropertyInfo gac = typeof (Environment).GetProperty ("GacPath", BindingFlags.Static|BindingFlags.NonPublic);
@@ -244,10 +245,18 @@ namespace System.Web.Compilation
                                                        throw new FileNotFoundException ("Windows mono path not found: " + monoPath);
                                        }
                                }
-                               
+
+#if NET_4_0
+                                alPath = Path.Combine (p, "4.0\\al.exe");
+#else
                                 alPath = Path.Combine (p, "2.0\\al.exe");
+#endif
                                 if (!File.Exists (alPath)) {
+#if NET_4_0
+                                        alPath = Path.Combine(Path.GetDirectoryName (p), "lib\\net_4_0\\al.exe");
+#else
                                         alPath = Path.Combine(Path.GetDirectoryName (p), "lib\\net_2_0\\al.exe");
+#endif
                                        if (!File.Exists (alPath))
                                                throw new FileNotFoundException ("Windows al path not found: " + alPath);
                                }
@@ -255,7 +264,11 @@ namespace System.Web.Compilation
                                info.FileName = monoPath;
                                return alPath;
                        } else {
+#if NET_4_0
+                               info.FileName = "al";
+#else
                                info.FileName = "al2";
+#endif
                                return String.Empty;
                        }
                }
index 177404c080e8a04517f042073bb3371a95d17d89..6593287ceca08dc2be5ead3953b9947228be441f 100644 (file)
@@ -57,15 +57,15 @@ namespace System.Web.Compilation
                static int BUILD_MANAGER_VIRTUAL_PATH_CACHE_PREFIX_LENGTH = BUILD_MANAGER_VIRTUAL_PATH_CACHE_PREFIX.Length;
 
                static readonly object bigCompilationLock = new object ();
+               static readonly object virtualPathsToIgnoreLock = new object ();
                static readonly char[] virtualPathsToIgnoreSplitChars = {','};
                
                static EventHandlerList events = new EventHandlerList ();
                static object buildManagerRemoveEntryEvent = new object ();
                
                static bool hosted;
-               static IEqualityComparer <string> comparer;
-               static StringComparison stringComparer;
                static Dictionary <string, bool> virtualPathsToIgnore;
+               static bool virtualPathsToIgnoreChecked;
                static bool haveVirtualPathsToIgnore;
                static List <Assembly> AppCode_Assemblies = new List<Assembly>();
                static List <Assembly> TopLevel_Assemblies = new List<Assembly>();
@@ -129,16 +129,8 @@ namespace System.Web.Compilation
                
                static BuildManager ()
                {
-                       if (HttpRuntime.CaseInsensitive) {
-                               comparer = StringComparer.CurrentCultureIgnoreCase;
-                               stringComparer = StringComparison.CurrentCultureIgnoreCase;
-                       } else {
-                               comparer = StringComparer.CurrentCulture;
-                               stringComparer = StringComparison.CurrentCulture;
-                       }
-                       
                        hosted = (AppDomain.CurrentDomain.GetData (ApplicationHost.MonoHostedDataKey) as string) == "yes";
-                       buildCache = new Dictionary <string, BuildManagerCacheItem> (comparer);
+                       buildCache = new Dictionary <string, BuildManagerCacheItem> (RuntimeHelpers.StringEqualityComparerCulture);
 #if SYSTEMCORE_DEP
                        buildCacheLock = new ReaderWriterLockSlim ();
 #else
@@ -152,7 +144,6 @@ namespace System.Web.Compilation
                        is_precompiled = String.IsNullOrEmpty (appPath) ? false : File.Exists ((precomp_name = Path.Combine (appPath, "PrecompiledApp.config")));
                        if (is_precompiled)
                                is_precompiled = LoadPrecompilationInfo (precomp_name);
-                       LoadVirtualPathsToIgnore ();
                }
 
                // Deal with precompiled sites deployed in a different virtual path
@@ -273,7 +264,7 @@ namespace System.Web.Compilation
                        }
                        if (store) {
                                if (precompiled == null)
-                                       precompiled = new Dictionary<string, PreCompilationData> (comparer);
+                                       precompiled = new Dictionary<string, PreCompilationData> (RuntimeHelpers.StringEqualityComparerCulture);
                                precompiled.Add (pc_data.VirtualPath, pc_data);
                        }
                        return pc_data;
@@ -290,7 +281,7 @@ namespace System.Web.Compilation
                static void AddPathToIgnore (string vp)
                {
                        if (virtualPathsToIgnore == null)
-                               virtualPathsToIgnore = new Dictionary <string, bool> (comparer);
+                               virtualPathsToIgnore = new Dictionary <string, bool> (RuntimeHelpers.StringEqualityComparerCulture);
                        
                        VirtualPath path = GetAbsoluteVirtualPath (vp);
                        string vpAbsolute = path.Absolute;
@@ -540,7 +531,7 @@ namespace System.Web.Compilation
                                return null;
 
                        foreach (BuildProvider bp in group) {
-                               if (String.Compare (path, req.MapPath (bp.VirtualPath), stringComparer) == 0)
+                               if (String.Compare (path, req.MapPath (bp.VirtualPath), RuntimeHelpers.StringComparison) == 0)
                                        return bp;
                        }
                        
@@ -566,6 +557,7 @@ namespace System.Web.Compilation
                        }
                        
                        List <BuildProvider> failedBuildProviders = null;
+                       StringComparison stringComparison = RuntimeHelpers.StringComparison;
                        foreach (BuildProvider bp in group) {
                                bvp = bp.VirtualPath;
                                if (HasCachedItemNoLock (bvp))
@@ -574,7 +566,7 @@ namespace System.Web.Compilation
                                try {
                                        bp.GenerateCode (abuilder);
                                } catch (Exception ex) {
-                                       if (String.Compare (bvp, vpabsolute, stringComparer) == 0) {
+                                       if (String.Compare (bvp, vpabsolute, stringComparison) == 0) {
                                                if (ex is CompilationException || ex is ParseException)
                                                        throw;
                                                
@@ -974,6 +966,14 @@ namespace System.Web.Compilation
                
                internal static bool IgnoreVirtualPath (string virtualPath)
                {
+                       if (!virtualPathsToIgnoreChecked) {
+                               lock (virtualPathsToIgnoreLock) {
+                                       if (!virtualPathsToIgnoreChecked)
+                                               LoadVirtualPathsToIgnore ();
+                                       virtualPathsToIgnoreChecked = true;
+                               }
+                       }
+                       
                        if (!haveVirtualPathsToIgnore)
                                return false;
                        
index ab1b831fb359c86022cd086ded12f68f8e4f55a7..5490059be5a6bb932aab9a8a433956f7710fed52 100644 (file)
@@ -58,8 +58,6 @@ namespace System.Web.Compilation
                readonly string virtualPathDirectory;
                CompilationSection compilationSection;
                Dictionary <string, BuildProvider> buildProviders;
-               IEqualityComparer <string> dictionaryComparer;
-               StringComparison stringComparer;
                VirtualPathProvider vpp;
                
                CompilationSection CompilationSection {
@@ -78,13 +76,6 @@ namespace System.Web.Compilation
                        this.vpp = HostingEnvironment.VirtualPathProvider;
                        this.virtualPath = virtualPath;
                        this.virtualPathDirectory = VirtualPathUtility.GetDirectory (virtualPath.Absolute);
-                       if (HttpRuntime.CaseInsensitive) {
-                               this.stringComparer = StringComparison.OrdinalIgnoreCase;
-                               this.dictionaryComparer = StringComparer.OrdinalIgnoreCase;
-                       } else {
-                               this.stringComparer = StringComparison.Ordinal;
-                               this.dictionaryComparer = StringComparer.Ordinal;
-                       }
                }
 
                public List <BuildProviderGroup> Build (bool single)
@@ -114,7 +105,7 @@ namespace System.Web.Compilation
                        if (single) {
                                AddVirtualFile (GetVirtualFile (virtualPath.Absolute), bpcoll);
                        } else {
-                               var cache = new Dictionary <string, bool> (dictionaryComparer);
+                               var cache = new Dictionary <string, bool> (RuntimeHelpers.StringEqualityComparer);
                                AddVirtualDir (GetVirtualDirectory (virtualPath.Absolute), bpcoll, cache);
                                cache = null;
                                if (buildProviders == null || buildProviders.Count == 0)
@@ -143,7 +134,7 @@ namespace System.Web.Compilation
                bool AddBuildProvider (BuildProvider buildProvider)
                {
                        if (buildProviders == null)
-                               buildProviders = new Dictionary <string, BuildProvider> (dictionaryComparer);
+                               buildProviders = new Dictionary <string, BuildProvider> (RuntimeHelpers.StringEqualityComparer);
                        
                        string bpPath = buildProvider.VirtualPath;
                        if (buildProviders.ContainsKey (bpPath))
@@ -260,6 +251,7 @@ namespace System.Web.Compilation
                        if (BuildManager.HasCachedItemNoLock (buildProvider.VirtualPath))
                                return;                 
 
+                       StringComparison stringComparison = RuntimeHelpers.StringComparison;
                        if (buildProvider is ApplicationFileBuildProvider || buildProvider is ThemeDirectoryBuildProvider) {
                                // global.asax and theme directory go into their own assemblies
                                myGroup = new BuildProviderGroup ();
@@ -284,7 +276,7 @@ namespace System.Web.Compilation
                                                }
                                        
                                                // There should be one assembly per virtual dir
-                                               if (String.Compare (bpPath, VirtualPathUtility.GetDirectory (bp.VirtualPath), stringComparer) != 0) {
+                                               if (String.Compare (bpPath, VirtualPathUtility.GetDirectory (bp.VirtualPath), stringComparison) != 0) {
                                                        canAdd = false;
                                                        break;
                                                }
@@ -315,7 +307,7 @@ namespace System.Web.Compilation
                        }
                        
                        myGroup.AddProvider (buildProvider);
-                       if (String.Compare (bpPath, virtualPathDirectory, stringComparer) == 0)
+                       if (String.Compare (bpPath, virtualPathDirectory, stringComparison) == 0)
                                myGroup.Master = true;
                }
 
index 82791a72aaacf5567459de777989fcab71ae49a1..20fa5f81828a38d25b646ed35f2310c2eec0c8d9 100644 (file)
@@ -1,3 +1,7 @@
+2010-03-04  Marek Habersack  <mhabersack@novell.com>
+
+       * BuildManager.cs: do less work in the static constructor
+
 2010-02-27  Marek Habersack  <mhabersack@novell.com>
 
        * BuildManager.cs: count only builds of updated files before
index 8b3ceb4f4cd8b417af68a836026eb89a9b30e714..c5dccf739c1a6e17a2eaa9ff7d18ad98317d596d 100644 (file)
@@ -474,8 +474,6 @@ namespace System.Web.Configuration {
                                } else
                                        relPath = path;
 
-                               _Configuration cnew;
-
                                HttpRequest req = context != null ? context.Request : null;
                                if (req != null) {
                                        string vdir = VirtualPathUtility.GetDirectory (req.Path);
index 36df0226cd97e53edc1420130505175e20667b31..cab57fea2f2ff83ab4b858d4e5947ac9b7c4d058 100644 (file)
@@ -120,7 +120,7 @@ namespace System.Web.Security
                                loginPath = context.Request.MapPath (loginPage);
                        } catch {} // ignore
 
-                       context.SkipAuthorization = String.Compare (reqPath, loginPath, HttpRuntime.CaseInsensitive, Helpers.InvariantCulture) == 0;
+                       context.SkipAuthorization = String.Compare (reqPath, loginPath, RuntimeHelpers.CaseInsensitive, Helpers.InvariantCulture) == 0;
                        
 #if NET_2_0
                        //TODO: need to check that the handler is System.Web.Handlers.AssemblyResourceLoader type
index 6120f09f7e529efae352778900a6638bf16b570e..a18cc9a25d4067eb8b25b43d8f820423c35e03eb 100644 (file)
@@ -160,8 +160,6 @@ namespace System.Web.SessionState
                {
                        DbCommand cmd;
                        DbCommand deleteCmd = null;
-                       DbParameter param;
-
                        string sessItems = Serialize((SessionStateItemCollection)item.Items);
                        DbProviderFactory factory = ProviderFactory;
                        string appName = ApplicationName;
@@ -242,7 +240,6 @@ namespace System.Web.SessionState
                        string appName = ApplicationName;
                        DbCommand cmd = null;
                        DbDataReader reader = null;
-                       DbParameter param;
                        DbParameterCollection parameters;
                        DateTime expires;
                        string serializedItems = String.Empty;
index c90dc0a510cc1bac92af1f0d52f3ccffd947c9b6..b3c005d0c8f4782cc64eb4d29e87fc8b69d2de1b 100644 (file)
@@ -1499,9 +1499,7 @@ namespace System.Web.UI.WebControls
                        bool nodeIsSelected = node == SelectedNode && selectedNodeStyle != null;
                        if (!nodeIsSelected && selectedNodeStyle != null) {
                                if (!String.IsNullOrEmpty (activeSiteMapPath))
-                                       nodeIsSelected = String.Compare (activeSiteMapPath,
-                                                                        node.NavigateUrl,
-                                                                        HttpRuntime.CaseInsensitive ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal) == 0;
+                                       nodeIsSelected = String.Compare (activeSiteMapPath, node.NavigateUrl, RuntimeHelpers.StringComparison) == 0;
                        }
                        
                        AddNodeStyle (writer, node, level, nodeIsSelected);
index 151978fe2dce618ce377049ba1a287ae12d60253..c3f86937072259630c275fe395a03f8cb376dbad 100644 (file)
@@ -1990,7 +1990,7 @@ public partial class Page : TemplateControl, IHttpHandler
                try {
                        target.RaiseCallbackEvent (callbackArgument);
                } catch (Exception ex) {
-                       callbackEventError = String.Concat ("e", HttpRuntime.IsDebuggingEnabled ? ex.ToString () : ex.Message);
+                       callbackEventError = String.Concat ("e", RuntimeHelpers.DebuggingEnabled ? ex.ToString () : ex.Message);
                }
                
        }
@@ -2001,7 +2001,7 @@ public partial class Page : TemplateControl, IHttpHandler
                try {
                        callBackResult = target.GetCallbackResult ();
                } catch (Exception ex) {
-                       return String.Concat ("e", HttpRuntime.IsDebuggingEnabled ? ex.ToString () : ex.Message);
+                       return String.Concat ("e", RuntimeHelpers.DebuggingEnabled ? ex.ToString () : ex.Message);
                }
                
                string eventValidation = ClientScript.GetEventValidationStateFormatted ();
index be84e64af035ed252a99b2d240774dd3ba5181e2..255b97288eba1c83cf568b00f0a88f7cb3d5db1c 100644 (file)
@@ -382,7 +382,7 @@ namespace System.Web.UI
                                        throw new Exception ("Error while loading " + s, e);
                                }
                                
-                               if (ex != null && HttpRuntime.IsDebuggingEnabled) {
+                               if (ex != null && RuntimeHelpers.DebuggingEnabled) {
                                        Console.WriteLine ("**** DEBUG MODE *****");
                                        Console.WriteLine ("Bad assembly found in bin/. Exception (ignored):");
                                        Console.WriteLine (ex);
index fa684200d66b44e2291144805e48bac565e44647..e7f84b083f5b442b22df3d8120f52da5230ec1f3 100644 (file)
@@ -1,3 +1,9 @@
+2010-03-04  Marek Habersack  <mhabersack@novell.com>
+
+       * RuntimeHelpers.cs: added. Contains methods moved here from
+       HttpRuntime, so that initialization sequence of various objects is
+       independent of HttpRuntime.
+
 2009-03-01 Gonzalo Paniagua Javier <gonzalo@novell.com>
 
        * WebEncoding.cs: another GetWebApplication here.
diff --git a/mcs/class/System.Web/System.Web.Util/RuntimeHelpers.cs b/mcs/class/System.Web/System.Web.Util/RuntimeHelpers.cs
new file mode 100644 (file)
index 0000000..1f06bfb
--- /dev/null
@@ -0,0 +1,144 @@
+//
+// System.Web.Util.RuntimeHelpers
+//
+// Authors:
+//      Marek Habersack (mhabersack@novell.com)
+//
+// (C) 2006-2010 Novell, Inc (http://www.novell.com)
+//
+
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Reflection;
+using System.Web.Configuration;
+
+namespace System.Web.Util
+{
+       static class RuntimeHelpers
+       {
+               public static bool CaseInsensitive {
+                       get; private set;
+               }
+
+               public static bool DebuggingEnabled {
+                       get {
+                               CompilationSection cs = WebConfigurationManager.GetSection ("system.web/compilation") as CompilationSection;
+                               if (cs != null)
+                                       return cs.Debug;
+
+                               return false;
+                       }
+               }
+
+               public static IEqualityComparer <string> StringEqualityComparer {
+                       get; private set;
+               }
+
+               public static IEqualityComparer <string> StringEqualityComparerCulture {
+                       get; private set;
+               }
+               
+               public static bool IsUncShare {
+                       get; private set;
+               }
+
+               public static string MonoVersion {
+                       get; private set;
+               }
+
+               public static bool RunningOnWindows {
+                       get; private set;
+               }
+
+               public static StringComparison StringComparison {
+                       get; private set;
+               }
+
+               public static StringComparison StringComparisonCulture {
+                       get; private set;
+               }
+               
+               static RuntimeHelpers ()
+               {
+                       PlatformID pid = Environment.OSVersion.Platform;
+                       RunningOnWindows = ((int) pid != 128 && pid != PlatformID.Unix && pid != PlatformID.MacOSX);
+
+                       if (RunningOnWindows) {
+                               CaseInsensitive = true;
+                               string appDomainAppPath = AppDomain.CurrentDomain.GetData (".appPath") as string;
+                               if (!String.IsNullOrEmpty (appDomainAppPath)) {
+                                       try {
+                                               IsUncShare = new Uri (appDomainAppPath).IsUnc;
+                                       } catch {
+                                               // ignore
+                                       }
+                               }
+                       } else {
+                               string mono_iomap = Environment.GetEnvironmentVariable ("MONO_IOMAP");
+                               if (!String.IsNullOrEmpty (mono_iomap)) {
+                                       if (mono_iomap == "all")
+                                               CaseInsensitive = true;
+                                       else {
+                                               string[] parts = mono_iomap.Split (':');
+                                               foreach (string p in parts) {
+                                                       if (p == "all" || p == "case") {
+                                                               CaseInsensitive = true;
+                                                               break;
+                                                       }
+                                               }
+                                       }
+                               }
+                       }
+
+                       if (CaseInsensitive) {
+                               StringEqualityComparer = StringComparer.OrdinalIgnoreCase;
+                               StringEqualityComparerCulture = StringComparer.CurrentCultureIgnoreCase;
+                               StringComparison = StringComparison.OrdinalIgnoreCase;
+                               StringComparisonCulture = StringComparison.CurrentCultureIgnoreCase;
+                       } else {
+                               StringEqualityComparer = StringComparer.Ordinal;
+                               StringEqualityComparerCulture = StringComparer.CurrentCulture;
+                               StringComparison = StringComparison.Ordinal;
+                               StringComparisonCulture = StringComparison.CurrentCulture;
+                       }
+                       
+                       string monoVersion = null;
+                       try {
+                               Type monoRuntime = Type.GetType ("Mono.Runtime", false);
+                               if (monoRuntime != null) {
+                                       MethodInfo mi = monoRuntime.GetMethod ("GetDisplayName", BindingFlags.Static | BindingFlags.NonPublic);
+                                       if (mi != null)
+                                               monoVersion = mi.Invoke (null, new object [0]) as string;
+                               }
+                       } catch {
+                               // ignore
+                       }
+                       
+                       if (monoVersion == null)
+                               monoVersion = Environment.Version.ToString ();
+
+                       MonoVersion = monoVersion;
+               }
+       }
+}
index 314968ba7618aa5b89147a28a5fd3997ad88eb0e..a33f91afb68a5f27b772568e8cd12987993ec370 100644 (file)
@@ -1174,6 +1174,7 @@ System.Web.Util/Helpers.cs
 System.Web.Util/ICalls.cs
 System.Web.Util/IWebObjectFactory.cs
 System.Web.Util/IWebPropertyAccessor.cs
+System.Web.Util/RuntimeHelpers.cs
 System.Web.Util/SearchPattern.cs
 System.Web.Util/SerializationHelper.cs
 System.Web.Util/StrUtils.cs
index feff6b207285686cb094e60611a1da27a551df12..9c75a9bfc22daac93c96eea1f4ebc5753db3c3c9 100644 (file)
@@ -1,3 +1,10 @@
+2010-03-04  Marek Habersack  <mhabersack@novell.com>
+
+       * HttpRuntime.cs: do less work in the static constructor. Most of
+       the code was moved to System.Web.Util.RuntimeHelpers. Properties
+       which have been moved: MonoVersion, RunningOnWindows,
+       CaseInsensitive, IsDebuggingEnabled
+
 2010-02-27  Marek Habersack  <mhabersack@novell.com>
 
        * HttpRuntime.cs: added internal property DomainUnloading.
index 0b46cddd4b44a42a0e064811b11769bae7d81774..d183afa0f4d31b816f5d2605417568a5e7fa9617 100644 (file)
@@ -228,7 +228,7 @@ namespace System.Web
                }
 #if !TARGET_JVM
                public bool IsDebuggingEnabled {
-                       get { return HttpRuntime.IsDebuggingEnabled; }
+                       get { return RuntimeHelpers.DebuggingEnabled; }
                }
 #endif
                public IDictionary Items {
@@ -475,19 +475,15 @@ namespace System.Web
                        // we should expire the entries (or just store them in InternalCache?)
                        IResourceProvider rp = null;
                        if (!resource_providers.TryGetValue (virtualPath, out rp)) {
-                               if (isLocal) {
-                                       HttpContext ctx = HttpContext.Current;
-                                       HttpRequest req = ctx != null ? ctx.Request : null;
+                               if (isLocal)
                                        rp = provider_factory.CreateLocalResourceProvider (virtualPath);
-                               else
+                               else
                                        rp = provider_factory.CreateGlobalResourceProvider (virtualPath);
                                
                                if (rp == null) {
-                                       if (isLocal) {
-                                               HttpContext ctx = HttpContext.Current;
-                                               HttpRequest req = ctx != null ? ctx.Request : null;
+                                       if (isLocal)
                                                rp = DefaultProviderFactory.CreateLocalResourceProvider (virtualPath);
-                                       else
+                                       else
                                                rp = DefaultProviderFactory.CreateGlobalResourceProvider (virtualPath);
 
                                        if (rp == null)
@@ -629,8 +625,6 @@ namespace System.Web
                        if (pathRelative || pathAbsolute) {
                                if (pathRelative)
                                        filePath = VirtualPathUtility.ToAbsolute (filePath);
-                               else
-                                       filePath = filePath;
                        } else
                                filePath = VirtualPathUtility.AppendTrailingSlash (req.BaseVirtualDir) + filePath;
                        
index 07a39f4acd1b20c495d294def9599e900838d980..7d4c541179c466ff76125f30a871906efc22648b 100644 (file)
@@ -209,7 +209,7 @@ table.sampleCode {{width: 100%; background-color: #ffffcc; }}
                        if (showTrace) {
                                builder.Append ("<hr style=\"color: silver\"/>");
                                builder.AppendFormat ("<strong>Version information: </strong> Mono Runtime Version: <tt>{0}</tt>; ASP.NET Version: <tt>{1}</tt></body></html>\r\n",
-                                                     HttpRuntime.MonoVersion, Environment.Version);
+                                                     RuntimeHelpers.MonoVersion, Environment.Version);
                        
                                string trace, message;
                                bool haveTrace;
index 4051a815ed70f5905246e3a584ae7eb91399f6a3..d2bd1447f7bd533d9b2111c36d94d7f64b6f1731 100644 (file)
@@ -59,10 +59,6 @@ namespace System.Web
        [AspNetHostingPermission (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
        public sealed class HttpRuntime
        {
-               static bool caseInsensitive;
-               static bool runningOnWindows;
-               static bool isunc;
-               static string monoVersion;
                static bool domainUnloading;
                
 #if TARGET_J2EE
@@ -131,41 +127,6 @@ namespace System.Web
 
                static HttpRuntime ()
                {
-                       PlatformID pid = Environment.OSVersion.Platform;
-                       runningOnWindows = ((int) pid != 128 && pid != PlatformID.Unix && pid != PlatformID.MacOSX);
-
-                       if (runningOnWindows) {
-                               caseInsensitive = true;
-                               if (AppDomainAppPath != null)
-                                       isunc = new Uri (AppDomainAppPath).IsUnc;
-                       } else {
-                               string mono_iomap = Environment.GetEnvironmentVariable ("MONO_IOMAP");
-                               if (mono_iomap != null) {
-                                       if (mono_iomap == "all")
-                                               caseInsensitive = true;
-                                       else {
-                                               string[] parts = mono_iomap.Split (':');
-                                               foreach (string p in parts) {
-                                                       if (p == "all" || p == "case") {
-                                                               caseInsensitive = true;
-                                                               break;
-                                                       }
-                                               }
-                                       }
-                               }
-                       }
-
-                       Type monoRuntime = Type.GetType ("Mono.Runtime", false);
-                       monoVersion = null;
-                       if (monoRuntime != null) {
-                               MethodInfo mi = monoRuntime.GetMethod ("GetDisplayName", BindingFlags.Static | BindingFlags.NonPublic);
-                               if (mi != null)
-                                       monoVersion = mi.Invoke (null, new object [0]) as string;
-                       }
-
-                       if (monoVersion == null)
-                               monoVersion = Environment.Version.ToString ();
-                       
 #if !TARGET_J2EE
                        firstRun = true;
                        try {
@@ -317,7 +278,7 @@ namespace System.Web
                public static bool IsOnUNCShare {
                        [AspNetHostingPermission (SecurityAction.Demand, Level = AspNetHostingPermissionLevel.Low)]
                        get {
-                               return isunc;
+                               return RuntimeHelpers.IsUncShare;
                        }
                }
 
@@ -736,28 +697,6 @@ namespace System.Web
                        }
                }
 #endif // #if !TARGET_J2EE
-
-               internal static string MonoVersion {
-                       get { return monoVersion; }
-               }
-               
-               internal static bool RunningOnWindows {
-                       get { return runningOnWindows; }
-               }
-
-               internal static bool CaseInsensitive {
-                       get { return caseInsensitive; }
-               }
-
-               internal static bool IsDebuggingEnabled {
-                       get {
-                               CompilationSection cs = WebConfigurationManager.GetSection ("system.web/compilation") as CompilationSection;
-                               if (cs != null)
-                                       return cs.Debug;
-
-                               return false;
-                       }
-               }
                
                internal static TraceManager TraceManager {
                        get {
index 3b0e0936c0879d980c40890521735d6717339b79..822cd68a735e8a6a4c37a687aba7e5c288ce856f 100644 (file)
@@ -41,7 +41,7 @@ namespace System.Web
        {
                static bool ValidFileName (string fileName)
                {
-                       if (!HttpRuntime.RunningOnWindows)
+                       if (!RuntimeHelpers.RunningOnWindows)
                                return true;
 
                        if (fileName == null || fileName.Length == 0)
index cde330d533e4dd6259de111f84ceff3e26ea9d96..e6765c148f86ea3480cd75b4912e0a8c3ba8f728 100644 (file)
@@ -37,8 +37,6 @@ namespace System.Web
 {
        public abstract class StaticSiteMapProvider : SiteMapProvider
        {
-               static readonly StringComparison stringComparison = HttpRuntime.CaseInsensitive ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal;
-               
                Dictionary<string, SiteMapNode> keyToNode;
                Dictionary<SiteMapNode, SiteMapNode> nodeToParent;
                Dictionary<SiteMapNode, SiteMapNodeCollection> nodeToChildren;
@@ -66,7 +64,7 @@ namespace System.Web
                                if (!String.IsNullOrEmpty (nodeUrl)) {
                                        string url = MapUrl (nodeUrl);
                                        SiteMapNode foundNode = FindSiteMapNode (url);
-                                       if (foundNode != null && String.Compare (foundNode.Url, url, stringComparison) == 0)
+                                       if (foundNode != null && String.Compare (foundNode.Url, url, RuntimeHelpers.StringComparison) == 0)
                                                throw new InvalidOperationException (String.Format (
                                                        "Multiple nodes with the same URL '{0}' were found. " + 
                                                        "StaticSiteMapProvider requires that sitemap nodes have unique URLs.",
index a5587f9107db39730169188b56e17a77a0029f49..a58a8fe2cb6d24fae10c2fa5c2d22416e9a93cf8 100644 (file)
@@ -45,7 +45,7 @@ namespace System.Web {
                static VirtualPathUtility ()
                {
                        try {
-                               runningOnWindows = HttpRuntime.RunningOnWindows;
+                               runningOnWindows = RuntimeHelpers.RunningOnWindows;
                                var monoSettings = WebConfigurationManager.GetWebApplicationSection ("system.web/monoSettings") as MonoSettingsSection;
                                if (monoSettings != null)
                                        monoSettingsVerifyCompatibility = monoSettings.VerificationCompatibility != 1;
index a0e20c35f7e4025e8ab121873fd261b7332eaf3a..40f3d797d30b2905b1a1cbf10e12826fe3c594b3 100644 (file)
@@ -48,7 +48,6 @@ namespace System.Web
        public class XmlSiteMapProvider : StaticSiteMapProvider, IDisposable
        {
                static readonly char [] seperators = { ';', ',' };
-               static readonly StringComparison stringComparison = HttpRuntime.RunningOnWindows ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal;
                
                bool initialized;
                string fileVirtualPath;
@@ -175,7 +174,7 @@ namespace System.Web
                        if (file == null)
                                throw new HttpException ("Virtual path '" + virtualPath + "' cannot be mapped to physical path.");
                        
-                       if (String.Compare (Path.GetExtension (file), ".sitemap", stringComparison) != 0)
+                       if (String.Compare (Path.GetExtension (file), ".sitemap", RuntimeHelpers.StringComparison) != 0)
                                throw new InvalidOperationException (String.Format ("The file {0} has an invalid extension, only .sitemap files are allowed in XmlSiteMapProvider.",
                                                                                    String.IsNullOrEmpty (virtualPath) ? Path.GetFileName (file) : virtualPath));