示例#1
0
        static void Main(string[] args)
        {
            Config.Load();
            Logging.Init();

            RhinoInside.Resolver.Initialize();
#if DEBUG
            // Uncomment the following to debug with core Rhino source. This
            // tells compute to use a different RhinoCore than what RhinoInside thinks
            // should use.
            // (for McNeel devs only and only those devs who use the same path as Steve)

            /*
             * string rhinoSystemDir = @"C:\dev\github\mcneel\rhino\src4\bin\Debug";
             * if (File.Exists(rhinoSystemDir + "\\Rhino.exe"))
             *  RhinoInside.Resolver.RhinoSystemDirectory = rhinoSystemDir;
             */
#endif

            LogVersions();
            var rc = Topshelf.HostFactory.Run(x =>
            {
                x.AddCommandLineDefinition("port", port => {
                    int p       = int.Parse(port);
                    Config.Urls = new string[] { $"http://localhost:{p}" };
                });
                x.AddCommandLineDefinition("childof", parentProcessHandle =>
                {
                    int processId = int.Parse(parentProcessHandle);
                    Shutdown.RegisterParentProcess(processId);
                });
                x.AddCommandLineDefinition("parentport", port =>
                {
                    int parentPort = int.Parse(port);
                    Shutdown.RegisterParentPort(parentPort);
                });
                x.AddCommandLineDefinition("idlespan", span =>
                {
                    int spanSeconds = int.Parse(span);
                    Shutdown.RegisterIdleSpan(spanSeconds);
                });
                x.UseSerilog();
                x.ApplyCommandLine();
                x.SetStartTimeout(TimeSpan.FromMinutes(1));
                x.Service <OwinSelfHost>();
                x.RunAsPrompt(); // prompt for user to run as
                x.SetDisplayName("rhino.compute");
            });

            if (RhinoCore != null)
            {
                RhinoCore.Dispose();
            }

            Log.CloseAndFlush();

            var exitCode = (int)Convert.ChangeType(rc, rc.GetTypeCode());
            Environment.ExitCode = exitCode;
        }
        public bool Start(HostControl hctrl)
        {
            Log.Debug("Rhino system directory: {Path}", RhinoInside.Resolver.RhinoSystemDirectory);
            Log.Information("Launching RhinoCore library as {User}", Environment.UserName);
            Program.RhinoCore = new Rhino.Runtime.InProcess.RhinoCore(null, Rhino.Runtime.InProcess.WindowStyle.NoWindow);

            Environment.SetEnvironmentVariable("RHINO_TOKEN", null, EnvironmentVariableTarget.Process);

            Rhino.Runtime.HostUtils.OnExceptionReport += (source, ex) => {
                Log.Error(ex, "An exception occurred while processing request");
                if (Config.Debug)
                {
                    Logging.LogExceptionData(ex);
                }
            };

            StartOptions options = new StartOptions();

            foreach (var url in _bind)
            {
                options.Urls.Add(url);
            }

            Log.Information("Starting listener(s): {Urls}", _bind);

            // start listener and unpack HttpListenerException if thrown
            // (missing urlacl or lack of permissions)
            try
            {
                _host = WebApp.Start <Startup>(options);
            }
            catch (TargetInvocationException ex) when(ex.InnerException is HttpListenerException hle)
            {
                Log.Error("Exception: " + hle.Message);
                throw hle;
            }
            catch (Exception ex)
            {
                Log.Error("Exception: " + ex.Message);
                throw ex;
            }

            Log.Information("Listening on {Urls}", _bind);

            // when running in a console (not as a service), i.e. when launched as a child process of hops
            // update console title to differentiate windows (ports) and start parent process shutdown timer
            if (hctrl is Topshelf.Hosts.ConsoleRunHost)
            {
                Shutdown.StartTimer(hctrl);
            }

            return(true);
        }
示例#3
0
        public bool Start(HostControl hctrl)
        {
            Log.Debug("Rhino system directory: {Path}", RhinoInside.Resolver.RhinoSystemDirectory);
            Log.Information("Launching RhinoCore library as {User}", Environment.UserName);
            Program.RhinoCore = new Rhino.Runtime.InProcess.RhinoCore(null, Rhino.Runtime.InProcess.WindowStyle.NoWindow);

            Rhino.Runtime.HostUtils.OnExceptionReport += (source, ex) => {
                Log.Error(ex, "An exception occured while processing request");
                if (Config.Debug)
                {
                    Logging.LogExceptionData(ex);
                }
            };

            StartOptions options = new StartOptions();

            foreach (var url in _bind)
            {
                options.Urls.Add(url);
            }

            Log.Information("Starting listener(s): {Urls}", _bind);

            // start listener and unpack HttpListenerException if thrown
            // (missing urlacl or lack of permissions)
            try
            {
                _host = WebApp.Start <Startup>(options);
            }
            catch (TargetInvocationException ex) when(ex.InnerException is HttpListenerException hle)
            {
                throw hle;
            }
            catch
            {
                throw;
            }

            Log.Information("Listening on {Urls}", _bind);

            var chunks = _bind[0].Split(new char[] { ':' });

            Console.Title = $"rhino.compute:{chunks[chunks.Length-1]}";
            Shutdown.StartTimer(hctrl);

            return(true);
        }