public bool RunMainSql(string mainSqlPath) { using (var t = new ChangingOutput("Applying main.sql")) { using (var p = new Process()) { p.StartInfo.FileName = _mySqlPath; p.StartInfo.Arguments = _mySqlArgs; p.StartInfo.CreateNoWindow = true; p.StartInfo.RedirectStandardError = p.StartInfo.RedirectStandardInput = p.StartInfo.RedirectStandardOutput = true; p.StartInfo.UseShellExecute = false; p.StartInfo.WorkingDirectory = _mySqlDir; p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; t.PrintNumber(0); var i = 0; var ti = new Timer(1000); ti.Elapsed += (e, o) => { t.PrintNumber(++i); }; ti.Start(); p.Start(); p.StandardInput.Write(File.ReadAllText(mainSqlPath)); p.StandardInput.WriteLine(); p.StandardInput.WriteLine("exit"); p.StandardInput.Flush(); p.WaitForExit(); ti.Stop(); var success = true; if (!p.StandardError.EndOfStream) { t.FinishLine(); Console.WriteLine("MySql reports errors: {0}", p.StandardError.ReadToEnd()); success = false; } t.PrintResult(success); return success; } } }
public bool RunMainSql(string mainSqlPath) { using (var t = new ChangingOutput("Applying main.sql")) { using (var p = new Process()) { p.StartInfo.FileName = _mySqlPath; p.StartInfo.Arguments = _mySqlArgs; p.StartInfo.CreateNoWindow = true; p.StartInfo.RedirectStandardError = p.StartInfo.RedirectStandardInput = p.StartInfo.RedirectStandardOutput = true; p.StartInfo.UseShellExecute = false; p.StartInfo.WorkingDirectory = _mySqlDir; p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; t.PrintNumber(0); var i = 0; var ti = new Timer(1000); ti.Elapsed += (e, o) => { t.PrintNumber(++i); }; ti.Start(); p.Start(); p.StandardInput.Write(File.ReadAllText(mainSqlPath)); p.StandardInput.WriteLine(); p.StandardInput.WriteLine("exit"); p.StandardInput.Flush(); p.WaitForExit(); ti.Stop(); var success = true; if (!p.StandardError.EndOfStream) { t.FinishLine(); Console.WriteLine("MySql reports errors: {0}", p.StandardError.ReadToEnd()); success = false; } t.PrintResult(success); return(success); } } }
Process StartMySql() { var p = new Process { StartInfo = { FileName = _mySqlDPath, CreateNoWindow = true, UseShellExecute = false, WindowStyle = ProcessWindowStyle.Hidden, WorkingDirectory = _mySqlDir } }; using (var t = new ChangingOutput("Starting MySql server . . .")) { var success = p.Start(); t.PrintResult(success); if (!success) { p = null; } } using (var _ = new ChangingOutput("Waiting for MySql to accept connections . . .")) { var i = 0; var timer = new Timer(1000); timer.Elapsed += (e, o) => { _.PrintNumber(i++); }; timer.Start(); while (!CheckMysqlPort()) { Thread.Sleep(1000); } timer.Stop(); _.PrintResult(true); } return(p); }
Process StartMySql() { var p = new Process { StartInfo = { FileName = _mySqlDPath, CreateNoWindow = true, UseShellExecute = false, WindowStyle = ProcessWindowStyle.Hidden, WorkingDirectory = _mySqlDir } }; using (var t = new ChangingOutput("Starting MySql server . . .")) { var success = p.Start(); t.PrintResult(success); if (!success) p = null; } using (var _ = new ChangingOutput("Waiting for MySql to accept connections . . .")) { var i = 0; var timer = new Timer(1000); timer.Elapsed += (e, o) => { _.PrintNumber(i++); }; timer.Start(); while (!CheckMysqlPort()) Thread.Sleep(1000); timer.Stop(); _.PrintResult(true); } return p; }