Ejemplo n.º 1
0
        public void StartApplication(string path)
        {
            if (_log != null && _log.IsDebugEnabled)
            {
                _log.Debug(string.Format("Starting application from {0}", path));
            }

            lock (SyncRoot)
            {
                foreach (ApplicationInfo applicationInfo in ApplicationManager.GetApplicationManager().GetRunningApplications())
                {
                    if (applicationInfo.PhysicalPath == path)
                    {
                        throw new InvalidOperationException("Application already started");
                    }
                }
                //if (_hosts.ContainsKey(path))
                //    throw new InvalidOperationException("Application already started");
                string physicalPath = path;
                string virtualPath  = string.Empty;
                try
                {
                    DirectoryInfo directoryInfo = new DirectoryInfo(path);
                    string        appName       = directoryInfo.Name;
                    virtualPath = "/" + directoryInfo.Name;
                    if (_log != null)
                    {
                        _log.Debug("Starting application " + appName);
                    }
                    //_log.Debug("PhysicalPath = " + physicalPath);
                    //_log.Debug("VirtualPath = " + virtualPath);
                    string shadowCopyAssemblyList = string.Empty;

                    FluorineRuntimeProxy host = FluorineRuntimeProxy.Start(this, physicalPath, virtualPath, null, null, shadowCopyAssemblyList, _singleDomain);
                    host.Start();
                    //_hosts.Add(physicalPath, host);
                }
                catch (Exception exception)
                {
                    if (_log != null && _log.IsErrorEnabled)
                    {
                        _log.Error("Error starting application " + virtualPath, exception);
                    }
                    if (ApplicationError != null)
                    {
                        ApplicationError(this, new ApplicationErrorEventArgs(new ApplicationInfo(null, VirtualPath.Create(virtualPath), physicalPath), exception));
                    }
                    //throw;
                }
            }
        }
        public static FluorineRuntimeProxy Start(HostManager hostManager, string physicalPath, string virtualPath, string privateBinPath, string configFile, string shadowCopyAssemblies, bool singleDomain)
		{
			if(!StringUtil.StringEndsWith(physicalPath, Path.DirectorySeparatorChar))
				physicalPath = physicalPath + Path.DirectorySeparatorChar;

			// Copy this hosting DLL into the /bin directory of the application
			string fileName = Assembly.GetExecutingAssembly().Location;
            string binDirectory = Path.Combine(physicalPath, "Bin");
            if (!Directory.Exists(binDirectory))
                binDirectory = Path.Combine(physicalPath, "bin");
            if (!Directory.Exists(binDirectory))
                binDirectory = physicalPath; //Directory.CreateDirectory(binDirectory);
            try
			{
				string name = Path.GetFileName(fileName);
				File.Copy(fileName, Path.Combine(binDirectory, name), true);
			}
			catch{;}
			/*
			MakeShadowCopies(shadowCopyAssemblies, physicalPath);
			*/

#if NET_2_0
            TextWriter textWriter = new StreamWriter(Path.Combine(physicalPath, "web"));
            textWriter.Close();
            string configurationFile = Path.Combine(physicalPath, "web");
            System.Configuration.Configuration config = System.Configuration.ConfigurationManager.OpenExeConfiguration(configurationFile);
            System.Net.Configuration.SettingsSection section = (System.Net.Configuration.SettingsSection)config.GetSection("system.net/settings");
            section.Socket.AlwaysUseCompletionPortsForAccept = true;
            section.Socket.AlwaysUseCompletionPortsForConnect = true;
            config.Save();
#endif
            FluorineRuntimeProxy host = null;
            if (!singleDomain)
                host = ApplicationHost.CreateApplicationHost(typeof(FluorineRuntimeProxy), virtualPath, physicalPath, privateBinPath) as FluorineRuntimeProxy;
            else
                host = new FluorineRuntimeProxy();
			if( host != null )
			{
                host.HostManager = hostManager;
                host.VirtualPath = virtualPath;
				host.PhysicalDir = physicalPath;
                host.SingleDomain = singleDomain;
                host.BinDir = binDirectory;
			}
            if (singleDomain)
            {
                //AppDomain.CurrentDomain.AppendPrivatePath(binDirectory);
                AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);
            }
			return host;
		}
Ejemplo n.º 3
0
        public void Start(bool singleDomain)
        {
            if (_log != null && _log.IsDebugEnabled)
            {
                _log.Debug("Starting HostManager.");
            }

            _singleDomain = singleDomain;
            lock (SyncRoot)
            {
                try
                {
                    AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);

                    string shadowCopyAssemblyList = string.Empty;

                    /*
                     * string assemblyFolder = Path.Combine("net", Environment.Version.Major + "." + Environment.Version.Minor);
                     * string[] shadowCopyAssemblies = new string[]{"FluorineFx.Hosting.dll", "FluorineFx.dll", "log4net.dll", "ICSharpCode.SharpZipLib.dll"};
                     * for( int i = 0; i < shadowCopyAssemblies.Length; i++)
                     * {
                     *  if( i > 0 )
                     *      shadowCopyAssemblyList += ";";
                     *  shadowCopyAssemblyList += Path.Combine(assemblyFolder, shadowCopyAssemblies[i]);
                     * }
                     */
                    //string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "applications");
                    string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, ApplicationRoot);
                    if (Directory.Exists(path))
                    {
                        foreach (string dir in Directory.GetDirectories(path))
                        {
                            string physicalPath = dir;
                            string virtualPath  = string.Empty;
                            try
                            {
                                DirectoryInfo directoryInfo = new DirectoryInfo(dir);
                                string        appName       = directoryInfo.Name;
                                virtualPath = "/" + directoryInfo.Name;
                                if (_log != null)
                                {
                                    _log.Debug("Starting application " + appName);
                                }
                                //_log.Debug("PhysicalPath = " + physicalPath);
                                //_log.Debug("VirtualPath = " + virtualPath);

                                FluorineRuntimeProxy host = FluorineRuntimeProxy.Start(this, physicalPath, virtualPath, null, null, shadowCopyAssemblyList, singleDomain);
                                host.Start();
                                //_hosts.Add(physicalPath, host);
                            }
                            catch (Exception exception)
                            {
                                if (_log != null && _log.IsErrorEnabled)
                                {
                                    _log.Error("Error starting application " + virtualPath, exception);
                                }
                                if (ApplicationError != null)
                                {
                                    ApplicationError(this, new ApplicationErrorEventArgs(new ApplicationInfo(null, VirtualPath.Create(virtualPath), physicalPath), exception));
                                }
                            }
                        }
                    }
                    else
                    {
                        if (_log != null)
                        {
                            _log.Debug(string.Format("Base directory {0} was not found.", path));
                        }
                    }
                    _serverTimer.Enabled = true;
                    if (_log != null)
                    {
                        _log.Debug("HostManager started.");
                    }
                }
                catch (Exception ex)
                {
                    if (_log != null)
                    {
                        _log.Fatal("Failed to start HostManager.", ex);
                    }
                }
            }
        }
Ejemplo n.º 4
0
        public static FluorineRuntimeProxy Start(HostManager hostManager, string physicalPath, string virtualPath, string privateBinPath, string configFile, string shadowCopyAssemblies, bool singleDomain)
        {
            if (!StringUtil.StringEndsWith(physicalPath, Path.DirectorySeparatorChar))
            {
                physicalPath = physicalPath + Path.DirectorySeparatorChar;
            }

            // Copy this hosting DLL into the /bin directory of the application
            string fileName     = Assembly.GetExecutingAssembly().Location;
            string binDirectory = Path.Combine(physicalPath, "Bin");

            if (!Directory.Exists(binDirectory))
            {
                binDirectory = Path.Combine(physicalPath, "bin");
            }
            if (!Directory.Exists(binDirectory))
            {
                binDirectory = physicalPath; //Directory.CreateDirectory(binDirectory);
            }
            try
            {
                string name = Path.GetFileName(fileName);
                File.Copy(fileName, Path.Combine(binDirectory, name), true);
            }
            catch {; }

            /*
             * MakeShadowCopies(shadowCopyAssemblies, physicalPath);
             */

#if NET_2_0
            TextWriter textWriter = new StreamWriter(Path.Combine(physicalPath, "web"));
            textWriter.Close();
            string configurationFile = Path.Combine(physicalPath, "web");
            System.Configuration.Configuration       config  = System.Configuration.ConfigurationManager.OpenExeConfiguration(configurationFile);
            System.Net.Configuration.SettingsSection section = (System.Net.Configuration.SettingsSection)config.GetSection("system.net/settings");
            section.Socket.AlwaysUseCompletionPortsForAccept  = true;
            section.Socket.AlwaysUseCompletionPortsForConnect = true;
            config.Save();
#endif
            FluorineRuntimeProxy host = null;
            if (!singleDomain)
            {
                host = ApplicationHost.CreateApplicationHost(typeof(FluorineRuntimeProxy), virtualPath, physicalPath, privateBinPath) as FluorineRuntimeProxy;
            }
            else
            {
                host = new FluorineRuntimeProxy();
            }
            if (host != null)
            {
                host.HostManager  = hostManager;
                host.VirtualPath  = virtualPath;
                host.PhysicalDir  = physicalPath;
                host.SingleDomain = singleDomain;
                host.BinDir       = binDirectory;
            }
            if (singleDomain)
            {
                //AppDomain.CurrentDomain.AppendPrivatePath(binDirectory);
                AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);
            }
            return(host);
        }