예제 #1
0
        public async Task<bool> TryRunModule(RunModuleDto module, string serverIp)
        {
            var username = Thread.CurrentPrincipal.Identity.Name;
            var userArg = string.IsNullOrEmpty(username)  ? "" : $" --user {username}";
            var commandLineParams = $@"{module.CommandLineParameters} --serverip {serverIp} --priority {module.Priority}{userArg}";
            var processStartInfo =
                new ProcessStartInfo(_moduleService.GetModuleFilePath(module.Name), commandLineParams)
                {
                    UseShellExecute = false,
                    RedirectStandardError = true,
                    RedirectStandardOutput = true
                };

            var process = new Process
            {
                StartInfo = processStartInfo
            };

            bool isError = false;

            process.OutputDataReceived += (sender, args) => OutputReceived(args.Data, ref isError);
            process.ErrorDataReceived += (sender, args) => Error(args.Data, out isError);

            process.Start();

            process.BeginOutputReadLine();
            process.BeginErrorReadLine();

            await _semaphore.WaitAsync();
            return !isError;
        }
예제 #2
0
        public async Task<IHttpActionResult> RunModule(RunModuleDto moduleDto)
        {
            if (string.IsNullOrEmpty(moduleDto.Name))
            {
                throw new ArgumentException("Value cannot be null or empty", nameof(moduleDto.Name));
            }

            var serverIp = await _parcsService.GetServerIp();
            bool isRunSuccessfully = await _moduleRunner.TryRunModule(moduleDto, serverIp);
            if (!isRunSuccessfully)
            {
                throw new InvalidOperationException("Module didn't start successfully");
            }
            return Ok();
        }