/// <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 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); }