Esempio n. 1
0
        public void StopObject(string appId, Type type)
        {
            if (appId == null)
            {
                throw new ArgumentNullException("appId");
            }

            if (type == null)
            {
                throw new ArgumentNullException("type");
            }

            if (!id_to_host.ContainsKey(appId))
            {
                return;
            }

            BareApplicationHost host = id_to_host [appId];

            if (host == null)
            {
                return;
            }

            host.StopObject(type);
        }
Esempio n. 2
0
        public void ShutdownAll()
        {
            ICollection <string> coll = id_to_host.Keys;

            string [] keys = new string [coll.Count];
            coll.CopyTo(keys, 0);
            foreach (string str in keys)
            {
                BareApplicationHost host = id_to_host [str];
                host.Shutdown();
            }

            id_to_host.Clear();
        }
Esempio n. 3
0
        public void ShutdownApplication(string appId)
        {
            if (appId == null)
            {
                throw new ArgumentNullException("appId");
            }

            BareApplicationHost host = id_to_host [appId];

            if (host == null)
            {
                return;
            }

            host.Shutdown();
        }
Esempio n. 4
0
        IRegisteredObject CheckIfExists(BareApplicationHost host, Type type, bool failIfExists)
        {
            IRegisteredObject ireg = host.GetObject(type);

            if (ireg == null)
            {
                return(null);
            }

            if (failIfExists)
            {
                throw new InvalidOperationException(String.Concat("Well known object of type '", type.Name, "' already exists in this domain."));
            }

            return(ireg);
        }
Esempio n. 5
0
        public ApplicationInfo [] GetRunningApplications()
        {
            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];
                result [i++] = new ApplicationInfo(str, host.PhysicalPath, host.VirtualPath);
            }

            return(result);
        }
Esempio n. 6
0
        public IRegisteredObject GetObject(string appId, Type type)
        {
            if (appId == null)
            {
                throw new ArgumentNullException("appId");
            }

            if (type == null)
            {
                throw new ArgumentNullException("type");
            }

            BareApplicationHost host = null;

            if (!id_to_host.ContainsKey(appId))
            {
                return(null);
            }

            host = id_to_host [appId];
            return(host.GetObject(type));
        }
Esempio n. 7
0
        public IRegisteredObject CreateObject(string appId, Type type, string virtualPath,
                                              string physicalPath, bool failIfExists, bool throwOnError)
        {
            if (appId == null)
            {
                throw new ArgumentNullException("appId");
            }

            if (!VirtualPathUtility.IsAbsolute(virtualPath))
            {
                throw new ArgumentException("Relative path no allowed.", "virtualPath");
            }

            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))
            {
                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
            // in the new application domain.
            BareApplicationHost host = null;

            if (id_to_host.ContainsKey(appId))
            {
                host = id_to_host [appId];
            }

            IRegisteredObject ireg = null;

            if (host != null)
            {
                ireg = CheckIfExists(host, type, failIfExists);
                if (ireg != null)
                {
                    return(ireg);
                }
            }

            try {
                if (host == null)
                {
                    host = CreateHost(appId, virtualPath, physicalPath);
                }
                ireg = host.CreateInstance(type);
            } catch (Exception) {
                if (throwOnError)
                {
                    throw;
                }
            }

            if (ireg != null && host.GetObject(type) == null)              // If not registered from ctor...
            {
                host.RegisterObject(ireg, true);
            }

            return(ireg);
        }
		public bool Unload ()
		{
			if (host != null) {
				host.Shutdown ();
				OnAppDomainShutdown (0);
				host = null;
			}

			return true; // FIXME: may be we should do this synch. + timeout? Test!
		}
Esempio n. 9
0
		IRegisteredObject CheckIfExists (BareApplicationHost host, Type type, bool failIfExists)
		{
			IRegisteredObject ireg = host.GetObject (type);
			if (ireg == null)
				return null;

			if (failIfExists)
				throw new InvalidOperationException (String.Concat ("Well known object of type '", type.Name, "' already exists in this domain."));

			return ireg;
		}