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