Example #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;
                }
            }
        }
Example #2
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);
                    }
                }
            }
        }