Exemplo n.º 1
0
        VPathToHost GetOrCreateApplication(string vhost, int port, string filepath, string virt)
        {
            string vdir       = Path.GetDirectoryName(virt);
            string pdir       = Path.GetDirectoryName(filepath);
            var    vinfo      = new DirectoryInfo(vdir);
            var    pinfo      = new DirectoryInfo(pdir);
            string final_pdir = null;
            string final_vdir = null;

            while (vinfo != null && pinfo != null)
            {
                if (CheckDirectory(pinfo))
                {
                    final_pdir = pinfo.ToString();
                    final_vdir = vinfo.ToString();
                    break;
                }

                if (pinfo.Name != vinfo.Name)
                {
                    final_vdir = vinfo.ToString();
                    break;
                }

                pinfo = pinfo.Parent;
                vinfo = vinfo.Parent;
            }

            if (final_pdir == null)
            {
                final_pdir = pinfo.ToString();
            }

            if (final_vdir == null)
            {
                final_vdir = vinfo.ToString();
            }


            //Logger.Write (LogLevel.Error, "final_pdir: {0} final_vdir: {1}", final_pdir, final_vdir);
            VPathToHost vapp = server.GetApplicationForPath(vhost, port, virt, false);

            if (vapp == null)
            {
                // Don't know why this breaks mod-mono-server2.exe, but not mod-mono-server.exe
                //final_pdir = "file://" + final_pdir;
                if (final_vdir [0] != '/')
                {
                    final_vdir = "/" + final_vdir;
                }
                server.AddApplication(vhost, port, final_vdir, final_pdir);
                vapp = server.GetApplicationForPath(vhost, port, virt, false);
            }

            return(vapp);
        }
Exemplo n.º 2
0
        VPathToHost GetOrCreateApplication(string vhost, int port, string filepath, string virt)
        {
            string final_vdir;
            string final_pdir;

            GetPhysicalDirectory(virt, filepath, out final_vdir, out final_pdir);

            //Logger.Write (LogLevel.Error, "final_pdir: {0} final_vdir: {1}", final_pdir, final_vdir);
            VPathToHost vapp = server.GetApplicationForPath(vhost, port, virt, false);

            if (vapp == null)
            {
                // Don't know why this breaks mod-mono-server2.exe, but not mod-mono-server.exe
                //final_pdir = "file://" + final_pdir;
                if (final_vdir [0] != '/')
                {
                    final_vdir = "/" + final_vdir;
                }
                server.AddApplication(vhost, port, final_vdir, final_pdir);
                vapp = server.GetApplicationForPath(vhost, port, virt, false);
            }

            return(vapp);
        }
        public void Start()
        {
            if (Disposed)
            {
                throw new ObjectDisposedException(GetType().FullName);
            }
            if (Running)
            {
                throw new NotSupportedException("Web service already running");
            }
            if (Starting != null)
            {
                CancelEventArgs e = new CancelEventArgs(false);
                Starting(this, e);
                if (e.Cancel)
                {
                    return;
                }
            }
            try
            {
                if (!AmIRoot())
                {
                    throw new LogbusException("In order to start Web Service the process must be run as super user");
                }

                string appPath = InstallRuntime();
#if MONO
                WebSource ws = new XSPWebSource(IPAddress.Any, HttpPort, true);

                _appserver = new ApplicationServer(ws, appPath);
                _appserver.AddApplication(null, HttpPort, "/", appPath);

                _appserver.GetSingleApp().AppHost       = new XSPApplicationHost();
                _appserver.GetSingleApp().RequestBroker = new XSPRequestBroker();
                ((VPathToHost)_appserver.GetSingleApp()).CreateHost(_appserver, ws);

                AppDomain targetDomain = _appserver.AppHost.Domain;

                targetDomain.SetData("Logbus", (_target is MarshalByRefObject) ? (MarshalByRefObject)_target : new LogBusTie(_target));
                targetDomain.SetData("CustomFilterHelper", CustomFilterHelper.Instance);

                foreach (IPlugin plugin in _target.Plugins)
                {
                    MarshalByRefObject pluginRoot = plugin.GetPluginRoot();
                    if (pluginRoot != null)
                    {
                        targetDomain.SetData(plugin.Name, pluginRoot);
                    }
                }

                _appserver.Start(true);
#else
                string[] prefixes = { string.Format(CultureInfo.InvariantCulture, "http://+:{0}/", HttpPort) };

                _ctr = new HttpListenerController(prefixes, "/", appPath);

                _ctr.Start();

                //If object is not marshalled by reference, use a wrapper, otherwise don't complicate object graph
                _ctr.Domain.SetData("Logbus", (_target is MarshalByRefObject) ? (MarshalByRefObject)_target : new LogBusTie(_target));
                _ctr.Domain.SetData("CustomFilterHelper", CustomFilterHelper.Instance);

                foreach (IPlugin plugin in _target.Plugins)
                {
                    MarshalByRefObject pluginRoot = plugin.GetPluginRoot();
                    if (pluginRoot != null)
                    {
                        _ctr.Domain.SetData(plugin.Name, pluginRoot);
                    }
                }
#endif
                Running = true;
                if (Started != null)
                {
                    Started(this, EventArgs.Empty);
                }
            }
            catch (LogbusException)
            {
                throw;
            }
            catch (Exception ex)
            {
                throw new LogbusException("Unable to start web server", ex);
            }
        }
Exemplo n.º 4
0
        public static void Start()
        {
            XSPWebSource websource = new XSPWebSource(IPAddress.Loopback, 0);

            WebAppServer = new ApplicationServer(websource);

            string basePath   = Directory.GetParent(Assembly.GetExecutingAssembly().Location).ToString();
            string serverPath = basePath;

            if (serverPath[serverPath.Length - 1] != System.IO.Path.DirectorySeparatorChar)
            {
                serverPath += System.IO.Path.DirectorySeparatorChar;
            }
            serverPath += "WebUI";
            string serverBinPath = serverPath + System.IO.Path.DirectorySeparatorChar + "bin" + System.IO.Path.DirectorySeparatorChar;

            WebAppServer.AddApplication("", -1, "/", serverPath);

            bool started = false;

            DateTime curr = DateTime.Now;

            while (!started && curr.AddMinutes(1) > DateTime.Now)
            {
                try
                {
                    WebAppServer.Start(true);
                    started = true;
                }
                catch (System.Net.Sockets.SocketException e)
                {
                    if (e.ErrorCode == 10049 || e.ErrorCode == 10022)
                    {
                        //strange error on bind, probably network still not started
                        //try to rerun server
                        System.Threading.Thread.Sleep(10000);
                        //WebAppServer.Start(true);
                    }
                    else
                    {
                        throw;
                    }
                }
            }

            if (!started)
            {
                WebAppServer.Start(true);
            }

            //copy Mono.WebServer2.dll

            /*try
             * {
             *      if (!Directory.Exists(serverBinPath))
             *              Directory.CreateDirectory(serverBinPath);
             *
             *      File.Copy(basePath + System.IO.Path.DirectorySeparatorChar+"Mono.WebServer2.dll", serverBinPath + "Mono.WebServer2.dll", true);
             * }
             *
             * catch { ;}
             */

            AppDomain ap = WebAppServer.GetApplicationForPath("", WebAppServer.Port, "/", false).AppHost.Domain;

            ap.AssemblyResolve    += new ResolveEventHandler(MyResolveEventHandler);
            ap.UnhandledException += OnUnhandledExceptionEvent;


            ap.SetData("WebUIGate", webServerGate);

            port = WebAppServer.Port;
            //uri = new Uri("http://127.0.0.1:" + port.ToString() + "/");
            uri = new Uri("http://localhost:" + port.ToString() + "/");
            Console.WriteLine("Webserver started at " + uri.ToString());
        }