Beispiel #1
0
        private static bool MonitorHostProcess(CommandOption host)
        {
            if (!host.HasValue())
            {
                Console.Error.WriteLine($"Option \"{host.LongName}\" is missing.");
                return false;
            }

            int hostPID;
            if (int.TryParse(host.Value(), out hostPID))
            {
                var hostProcess = Process.GetProcessById(hostPID);
                hostProcess.EnableRaisingEvents = true;
                hostProcess.Exited += (s, e) =>
                {
                    Process.GetCurrentProcess().Kill();
                };

                Reporter.Output.WriteLine($"Server will exit when process {hostPID} exits.");
                return true;
            }
            else
            {
                Reporter.Error.WriteLine($"Option \"{host.LongName}\" is not a valid Int32 value.");
                return false;
            }
        }
Beispiel #2
0
        private static int CheckPort(CommandOption port)
        {
            if (!port.HasValue())
            {
                Reporter.Error.WriteLine($"Option \"{port.LongName}\" is missing.");
            }

            int result;
            if (int.TryParse(port.Value(), out result))
            {
                return result;
            }
            else
            {
                Reporter.Error.WriteLine($"Option \"{port.LongName}\" is not a valid Int32 value.");
                return -1;
            }
        }