Beispiel #1
0
 private void onOutputDataReceived(object sender, DataReceivedEventArgs args)
 {
     if (args?.Data != null)
     {
         OutputDataCallback?.Invoke(_currentParams, args.Data);
     }
 }
Beispiel #2
0
        public int Execute(IMigratorParams migratorParams)
        {
            _currentParams = migratorParams;

            try
            {
                using (var process = new Process())
                {
                    try
                    {
                        process.StartInfo = new ProcessStartInfo("dotnet")
                        {
                            Arguments = $"\"{Constants.MigratorAssembly}\" {migratorParams.ToArgumentString()}",
#if !DEBUG
                            WorkingDirectory = Path.GetDirectoryName(typeof(ProcessRunner).Assembly.Location),
#endif
                            CreateNoWindow         = true,
                            RedirectStandardOutput = true,
                            RedirectStandardError  = true,
                            UseShellExecute        = false
                        };

                        process.OutputDataReceived += onOutputDataReceived;
                        process.ErrorDataReceived  += onErrorDataReceived;

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

                        process.WaitForExit();
                    }
                    finally
                    {
                        process.OutputDataReceived -= onOutputDataReceived;
                        process.ErrorDataReceived  -= onErrorDataReceived;
                    }

                    return(process.ExitCode);
                }
            }
            catch (Exception ex)
            {
                OutputDataCallback?.Invoke(_currentParams, ex.Message);
                return(ExitCode.Exception);
            }
        }