/// <summary> /// Runs ExecServer in server mode (waiting for connection from ExecServer clients) /// </summary> /// <param name="executablePath">Path of the executable to run from this ExecServer instance</param> private void RunServer(string executablePath) { var address = GetEndpointAddress(executablePath); // TODO: The setting of disabling caching should be done per EXE (via config file) instead of global settings for ExecServer var useAppDomainCaching = Environment.GetEnvironmentVariable(DisableExecServerAppDomainCaching) != "true"; // Start WCF pipe for communication with process var execServerApp = new ExecServerRemote(executablePath, true, useAppDomainCaching, MaxConcurrentAppDomainProcess); var host = new ServiceHost(execServerApp); host.AddServiceEndpoint(typeof(IExecServerRemote), new NetNamedPipeBinding(NetNamedPipeSecurityMode.None) { MaxReceivedMessageSize = int.MaxValue, // TODO: Check if we need to tweak timeouts }, address); host.Open(); Console.WriteLine("Server [{0}] is running", executablePath); // Register for shutdown execServerApp.ShuttingDown += (sender, args) => host.Close(); // Wait for the server to shutdown execServerApp.Wait(); }
/// <summary> /// Runs the specified arguments copy. /// </summary> /// <param name="argsCopy">The arguments copy.</param> /// <returns>System.Int32.</returns> public int Run(string[] argsCopy) { if (argsCopy.Length == 0) { Console.WriteLine("Usage ExecServer.exe [/direct|/server] executablePath [executableArguments]"); return(0); } var args = new List <string>(argsCopy); if (args[0] == "/direct") { args.RemoveAt(0); var executablePath = ExtractExePath(args); var execServerApp = new ExecServerRemote(executablePath, false, false, 1); int result = execServerApp.Run(args.ToArray()); return(result); } if (args[0] == "/server") { args.RemoveAt(0); var executablePath = ExtractExePath(args); RunServer(executablePath); return(0); } else { var executablePath = ExtractExePath(args); var result = RunClient(executablePath, args); return(result); } }
private const int RetryWait = 500; // in ms /// <summary> /// Runs the specified arguments copy. /// </summary> /// <param name="argsCopy">The arguments copy.</param> /// <returns>System.Int32.</returns> public int Run(string[] argsCopy) { if (argsCopy.Length == 0) { Console.WriteLine("Usage ExecServer.exe [/direct|/server] executablePath [executableArguments]"); return(0); } var args = new List <string>(argsCopy); if (args[0] == "/direct") { args.RemoveAt(0); var executablePath = ExtractPath(args, "executable"); var execServerApp = new ExecServerRemote(executablePath, false, false); int result = execServerApp.Run(Environment.CurrentDirectory, args.ToArray()); return(result); } if (args[0] == "/server") { args.RemoveAt(0); var executablePath = ExtractPath(args, "executable"); RunServer(executablePath); return(0); } else { var executablePath = ExtractPath(args, "executable"); var workingDirectory = ExtractPath(args, "working directory"); execServerPath = Path.Combine(Path.GetDirectoryName(executablePath), Path.GetFileNameWithoutExtension(executablePath) + "_ExecServer.exe"); var result = RunClient(executablePath, workingDirectory, args); return(result); } }
private const int RetryWait = 10; // in ms /// <summary> /// Runs the specified arguments copy. /// </summary> /// <param name="argsCopy">The arguments copy.</param> /// <returns>System.Int32.</returns> public int Run(string[] argsCopy) { if (argsCopy.Length == 0) { Console.WriteLine("Usage ExecServer.exe [/direct executablePath|/server executablePath CPUindex] [executableArguments]"); return(0); } var args = new List <string>(argsCopy); if (args[0] == "/direct") { args.RemoveAt(0); var executablePath = ExtractPath(args, "executable"); var execServerApp = new ExecServerRemote(executablePath, false, false, true); int result = execServerApp.Run(Environment.CurrentDirectory, new Dictionary <string, string>(), args.ToArray()); return(result); } if (args[0] == "/server") { args.RemoveAt(0); var executablePath = ExtractPath(args, "executable"); var cpu = int.Parse(args[0]); args.RemoveAt(0); RunServer(executablePath, cpu); return(0); } else { var executablePath = ExtractPath(args, "executable"); var workingDirectory = ExtractPath(args, "working directory"); execServerPath = Path.Combine(Path.GetDirectoryName(executablePath), Path.GetFileNameWithoutExtension(executablePath) + "_ExecServer.exe"); // Collect environment variables var environmentVariables = new Dictionary <string, string>(); foreach (DictionaryEntry environmentVariable in Environment.GetEnvironmentVariables()) { environmentVariables.Add((string)environmentVariable.Key, (string)environmentVariable.Value); } var result = RunClient(executablePath, workingDirectory, environmentVariables, args); return(result); } }
/// <summary> /// Runs ExecServer in server mode (waiting for connection from ExecServer clients) /// </summary> /// <param name="entryAssemblyPath">Path to the client assembly in case we need to start another instance of same process.</param> /// <param name="executablePath">Path of the executable to run from this ExecServer instance</param> private int RunServer(string entryAssemblyPath, string executablePath, int serverInstanceIndex) { var address = GetEndpointAddress(executablePath, serverInstanceIndex); // TODO: The setting of disabling caching should be done per EXE (via config file) instead of global settings for ExecServer var useAppDomainCaching = Environment.GetEnvironmentVariable(DisableExecServerAppDomainCaching) != "true"; // Start WCF pipe for communication with process var execServerApp = new ExecServerRemote(entryAssemblyPath, executablePath, true, useAppDomainCaching, serverInstanceIndex == 0); var host = new ServiceHost(execServerApp); host.AddServiceEndpoint(typeof(IExecServerRemote), new NetNamedPipeBinding(NetNamedPipeSecurityMode.None) { MaxReceivedMessageSize = int.MaxValue, SendTimeout = TimeSpan.FromHours(1), ReceiveTimeout = TimeSpan.FromHours(1), }, address); try { host.Open(); } catch (AddressAlreadyInUseException) { // Uncomment the following line to see which process got a ExitCodeServerAlreadyInUse // File.WriteAllText(Path.Combine(Environment.CurrentDirectory, $"test_ExecServer{Process.GetCurrentProcess().Id}.log"), $"Exit code: {ExitCodeServerAlreadyInUse}\r\n"); // Silently exit if the server is already running return(ExitCodeServerAlreadyInUse); } Console.WriteLine("Server [{0}] is running", executablePath); // Register for shutdown execServerApp.ShuttingDown += (sender, args) => host.Close(); // Wait for the server to shutdown execServerApp.Wait(); return(0); }
private const int RetryWait = 1000; // in ms /// <summary> /// Runs the specified arguments copy. /// </summary> /// <param name="argsCopy">The arguments copy.</param> /// <returns>System.Int32.</returns> public int Run(string[] argsCopy) { if (argsCopy.Length == 0) { Console.WriteLine("Usage ExecServer.exe [/direct executablePath|/server executablePath CPUindex] [executableArguments]"); return(0); } var args = new List <string>(argsCopy); if (args[0] == "/direct") { args.RemoveAt(0); var executablePath = ExtractPath(args, "executable"); var execServerApp = new ExecServerRemote(executablePath, false, false, true); int result = execServerApp.Run(Environment.CurrentDirectory, new Dictionary <string, string>(), args.ToArray()); return(result); } if (args[0] == "/server") { args.RemoveAt(0); var executablePath = ExtractPath(args, "executable"); var cpu = int.Parse(args[0]); args.RemoveAt(0); int result = 0; try { result = RunServer(executablePath, cpu); } catch (Exception ex) { try { var pid = Process.GetCurrentProcess().Id; var logPath = GetExecServerErrorLogFilePath(executablePath, pid); File.AppendAllText(logPath, $"Unexpected error while trying to run ExecServerApp [{executablePath}]. Exception: {ex}"); } catch (Exception) { // Don't try to log an error } result = 1; } return(result); } else { var executablePath = ExtractPath(args, "executable"); var workingDirectory = ExtractPath(args, "working directory"); // Collect environment variables var environmentVariables = new Dictionary <string, string>(); foreach (DictionaryEntry environmentVariable in Environment.GetEnvironmentVariables()) { environmentVariables.Add((string)environmentVariable.Key, (string)environmentVariable.Value); } var result = RunClient(executablePath, workingDirectory, environmentVariables, args); return(result); } }