Merge pull request #1896 from meum/patch-1
[mono.git] / mcs / class / System.Web / System.Web.Hosting / ApplicationManager.cs
index 0b030c4d54059c5f43805095c4c7995afdaef0f3..1f1cc9010dbcf4635fe6ea2c9455c80699580e4c 100644 (file)
@@ -5,7 +5,7 @@
 //     Gonzalo Paniagua Javier (gonzalo@novell.com)
 //
 //
-// Copyright (C) 2006 Novell, Inc (http://www.novell.com)
+// Copyright (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
@@ -26,7 +26,6 @@
 // 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.Collections.Generic;
 using System.IO;
@@ -41,7 +40,7 @@ namespace System.Web.Hosting {
                int users;
                Dictionary <string, BareApplicationHost> id_to_host;
 
-               private ApplicationManager ()
+               ApplicationManager ()
                {
                        id_to_host = new Dictionary<string, BareApplicationHost> ();
                }
@@ -52,6 +51,23 @@ namespace System.Web.Hosting {
                                ShutdownAll ();
                }
 
+               [MonoTODO ("Need to take advantage of the configuration mapping capabilities of IApplicationHost")]
+               [SecurityPermissionAttribute(SecurityAction.Demand, Unrestricted = true)]
+               public IRegisteredObject CreateObject (IApplicationHost appHost, Type type)
+               {
+                       if (appHost == null)
+                               throw new ArgumentNullException ("appHost");
+                       if (type == null)
+                               throw new ArgumentNullException ("type");
+
+                       return CreateObject (appHost.GetSiteID (),
+                                            type,
+                                            appHost.GetVirtualPath (),
+                                            appHost.GetPhysicalPath (),
+                                            true,
+                                            true);
+               }
+               
                public IRegisteredObject CreateObject (string appId, Type type, string virtualPath,
                                                        string physicalPath, bool failIfExists)
                {
@@ -67,14 +83,12 @@ namespace System.Web.Hosting {
                        if (!VirtualPathUtility.IsAbsolute (virtualPath))
                                throw new ArgumentException ("Relative path no allowed.", "virtualPath");
 
-                       if (physicalPath == null || physicalPath == "")
+                       if (String.IsNullOrEmpty (physicalPath))
                                throw new ArgumentException ("Cannot be null or empty", "physicalPath");
 
                        // 'type' is not checked. If it's null, we'll throw a NullReferenceException
-                       if (!typeof (IRegisteredObject).IsAssignableFrom (type)) {
-                               string msg = String.Format ("Type '{0}' does not implement IRegisteredObject.", type.Name);
-                               throw new ArgumentException (msg, "type");
-                       }
+                       if (!typeof (IRegisteredObject).IsAssignableFrom (type))
+                               throw new ArgumentException (String.Concat ("Type '", type.Name, "' does not implement IRegisteredObject."), "type");
 
                        //
                        // ArgumentException is thrown for the physical path from the internal object created
@@ -94,7 +108,7 @@ namespace System.Web.Hosting {
                                if (host == null)
                                        host = CreateHost (appId, virtualPath, physicalPath);
                                ireg = host.CreateInstance (type);
-                       } catch (Exception e) {
+                       } catch (Exception) {
                                if (throwOnError)
                                        throw;
                        }
@@ -135,11 +149,8 @@ namespace System.Web.Hosting {
                        if (ireg == null)
                                return null;
 
-                       if (failIfExists) {
-                               string msg = String.Format ("Well known object of type '{0}' already " +
-                                               "exists in this domain.", type.Name);
-                               throw new InvalidOperationException (msg);
-                       }
+                       if (failIfExists)
+                               throw new InvalidOperationException (String.Concat ("Well known object of type '", type.Name, "' already exists in this domain."));
 
                        return ireg;
                }
@@ -200,8 +211,6 @@ namespace System.Web.Hosting {
                        ICollection<string> coll = id_to_host.Keys;
                        string [] keys = new string [coll.Count];
                        coll.CopyTo (keys, 0);
-                       ApplicationInfo [] result = new ApplicationInfo [coll.Count];
-                       int i = 0;
                        foreach (string str in keys) {
                                BareApplicationHost host = id_to_host [str];
                                host.Shutdown ();
@@ -242,5 +251,4 @@ namespace System.Web.Hosting {
        }
 }
 
-#endif