void p_OutputDataReceived(object sender, DataReceivedEventArgs e) { if (e.Data != null) { if (Regex.Match(e.Data, config.Default.RegexErrorFilterOracle, RegexOptions.IgnoreCase).Success) { _script.Success = false; OnStepProgress(string.Empty, e.Data); if (Regex.Match(e.Data, config.Default.RegexErrorFilterOracleCompilation, RegexOptions.IgnoreCase).Success) { string cmd = "set linesize 150\r\ncol name format a32\r\ncol line format 99999\r\ncol text format a90\r\n"; cmd = string.Format("{0}select name , line, Text\r\nfrom user_errors ue inner join user_objects uo on ue.name=uo.object_name \r\nwhere uo.last_ddl_time > sysdate - 1;\r\n", cmd); cmd = string.Format("{0}exit;", cmd); string connectionMinusPassword = string.Empty; string arguments = GetConnectionString(_currSchema, _cs.Instance, _cs.Port, _cs.Database, ref connectionMinusPassword); arguments = string.Format("-s -r 3 {0}", arguments); Process p = ScriptProcessorUtil.CreateProcess(_exe, arguments); p.OutputDataReceived += p_OutputDataReceived; p.ErrorDataReceived += p_ErrorDataReceived; p.Start(); p.StandardInput.WriteLine(cmd); p.BeginOutputReadLine(); p.BeginErrorReadLine(); p.WaitForExit(); } } else { OnStepProgress(string.Empty, e.Data); } } }
/// <summary> /// Recursively execute a list of scripts; will set section.Success /// </summary> /// <param name="scripts">The section.Scripts</param> /// <param name="section">The section itself, used to set section.Success</param> void RecurseScripts(List <Script> scripts, Section section, IConnectionSettings cs) { foreach (Script s in scripts) { OnStepProgress("RecurseScripts", string.Format("Starting Script:{0}", s.Path)); IScriptProcessor p = ScriptProcessorUtil.GetProcessorInstance(_wfp.DatabaseType); p.PathHelper = _ph; p.WorkflowParameters = _wfp; p.StepProgress += p_StepProgress; p.Start(s, cs, _wfp.AuditProcedures, _variables); OnStepProgress("RecurseScripts", string.Format("Finished Script:{0}, Success:{1}", s.Path, s.Success)); if (s.Success) { RecurseScripts(s.SuccessScripts, section, cs); } else { if (s.FailBranchOnError) { if (s.FailSectionOnError) { section.Success = false; } break; } else { RecurseScripts(s.FailScripts, section, cs); } } } }
public void RunScript(string script, string schema, bool isFile, IConnectionSettings cs) { OnStepProgress("RunScript", string.Format("On Schema {0}", schema)); _currSchema = schema; OracleConnectionSettings ocs = (OracleConnectionSettings)cs; string cmd = isFile ? string.Format(" @\"{0}\"", script) : string.Empty; string connectionMinusPassword = string.Empty; string arguments = GetConnectionString(schema, ocs.Instance, ocs.Port, ocs.Database, ref connectionMinusPassword); arguments = string.Format("{0}{1}", arguments, cmd); _p = ScriptProcessorUtil.CreateProcess(_exe, arguments); _p.StartInfo.EnvironmentVariables.Add("SQLPATH", Alphaleonis.Win32.Filesystem.Path.GetShort83Path(PathHelper.CachePath)); _p.StartInfo.EnvironmentVariables.Add("NLS_LANG", WorkflowParameters.NLS_LANG); _p.OutputDataReceived += p_OutputDataReceived; _p.ErrorDataReceived += p_ErrorDataReceived; _p.StartInfo.WorkingDirectory = Path.GetDirectoryName(Properties.Settings.Default.SqlPlusPath); if (_script.ShowSqlInOutput) { string scriptText = script; if (isFile) { scriptText = File.ReadAllText(script); } OnStepProgress(string.Empty, scriptText); } _p.Start(); if (!isFile) { _p.StandardInput.WriteLine(script); } _p.StandardInput.WriteLine("Exit"); #region read this // best practice information on accessing stdout/stderr from mdsn article: // https://msdn.microsoft.com/en-us/library/system.diagnostics.processstartinfo.redirectstandardoutput%28v=vs.110%29.aspx // Do not wait for the child process to exit before reading to the end of its redirected stream. // Do not perform a synchronous read to the end of both redirected streams. // string output = p.StandardOutput.ReadToEnd(); // string error = p.StandardError.ReadToEnd(); // p.WaitForExit(); // Use asynchronous read operations on at least one of the streams. #endregion _p.BeginOutputReadLine(); _p.BeginErrorReadLine(); _p.WaitForExit(); }
static public ConnectionValidationResult ValidateConnectionSettings(SqlServerConnectionSettings cs) { bool ok = true; string msg = "Connection ok."; string stdErr = string.Empty; string cmd = " -Q \"select getdate();\""; string arguments = string.Format("-S {0} -d {1} -E {2}", cs.Instance, cs.Database, cmd); Process p = ScriptProcessorUtil.CreateProcess(_exe, arguments); try { p.Start(); p.BeginErrorReadLine(); string stdOut = p.StandardOutput.ReadToEnd(); p.WaitForExit(); if (Regex.Match(stdOut, config.Default.RegexErrorFilterSqlServer, RegexOptions.IgnoreCase).Success) { ok = false; msg = stdOut; } } catch (Exception ex) { if (ex != null) { // msg = p.StandardError.ReadToEnd(); --This was old error information. Changed to OracleScriptProcessor version msg = stdErr; msg += ex.Message; } ok = false; } return(new ConnectionValidationResult(ok, msg)); }
public virtual void Start(Script script, IConnectionSettings cs, AuditProcedure auditProcedure, Dictionary <string, string> variables) { bool hasAudit = auditProcedure != null; if (hasAudit && auditProcedure.HasPreRun) { variables["{MetaData}"] = script.MetaData; string s = ScriptProcessorUtil.ReplaceVariablesToString(auditProcedure.PreRun, variables); RunScript(s, false, cs); } RunScript(script.Path, true, cs); variables["{Success}"] = script.Success.ToString(); if (hasAudit && auditProcedure.HasPostRun) { string s = ScriptProcessorUtil.ReplaceVariablesToString(auditProcedure.PostRun, variables); RunScript(s, false, cs); } }
static ConnectionValidationResult ValidateConnectionSettings(string arguments) { bool ok = true; string msg = "Connection ok."; string stdErr = string.Empty; string cmd = "\r\n\r\nselect * from global_name;\r\nexit;"; Process p = ScriptProcessorUtil.CreateProcess(_exe, arguments); try { p.Start(); p.StandardInput.WriteLine(cmd); //stdErr = p.StandardError.ReadToEnd(); string stdOut = p.StandardOutput.ReadToEnd(); p.WaitForExit(); if (Regex.Match(stdOut, config.Default.RegexErrorFilterOracle, RegexOptions.IgnoreCase).Success) { ok = false; msg = stdOut; } } catch (Exception ex) { if (ex != null) { msg = stdErr; msg += ex.Message; } ok = false; } return(new ConnectionValidationResult(ok, msg)); }
override public void RunScript(string script, bool isFile, IConnectionSettings cs) { string cmd = isFile ? string.Format("-i \"{0}\"", script) : string.Format("-Q \"{0}\"", script); string arguments = string.Format("-S {0} -d {1} -E {2} {3} {4} {5}", cs.Instance, cs.Database, _script.ShowSqlInOutput ? "-e" : string.Empty, _script.FailBranchOnError ? "-b" : string.Empty, _script.SetQuotedIdentifier ? "-I" : string.Empty, cmd); Process p = ScriptProcessorUtil.CreateProcess(_exe, arguments); p.OutputDataReceived += p_OutputDataReceived; p.ErrorDataReceived += p_ErrorDataReceived; p.Start(); #region read this // best practice information on accessing stdout/stderr from mdsn article: // https://msdn.microsoft.com/en-us/library/system.diagnostics.processstartinfo.redirectstandardoutput%28v=vs.110%29.aspx // Do not wait for the child process to exit before reading to the end of its redirected stream. // Do not perform a synchronous read to the end of both redirected streams. // string output = p.StandardOutput.ReadToEnd(); // string error = p.StandardError.ReadToEnd(); // p.WaitForExit(); // Use asynchronous read operations on at least one of the streams. #endregion p.BeginOutputReadLine(); string error = p.StandardError.ReadToEnd(); p.WaitForExit(); }