public ResultData ExecuteInfoWorkFlow(string workFlowName, UserProgInfo userProgInfo) { ResultData result = new ResultData(); string workingDirectory = @"C:\infa8\server\bin\"; string command = "pmcmd startworkflow -service IS_Taifex -domain Domain_Taifex -user pbusr1 -password pbusr1 -folder CI -wait " + workFlowName; ProcessStartInfo processInfo = new ProcessStartInfo("cmd.exe", "/c " + command); processInfo.WorkingDirectory = workingDirectory; processInfo.RedirectStandardOutput = true; processInfo.RedirectStandardError = true; processInfo.RedirectStandardInput = true; processInfo.UseShellExecute = false; processInfo.CreateNoWindow = true; string logStr = ""; logStr += "開始執行Workflow,指令為:" + command; Process process = Process.Start(processInfo); string myOutput = process.StandardOutput.ReadToEnd(); string myError = process.StandardError.ReadToEnd(); process.WaitForExit(); bool isError = false; logStr += "Output:" + myOutput + Environment.NewLine; if (myOutput.ToUpper().IndexOf("ERROR") != -1) { isError = true; } if (myError != "") { logStr += "Error:" + myOutput + Environment.NewLine; isError = true; } if (process.ExitCode != 0) { logStr += "ExitCode:" + process.ExitCode; isError = true; } if (isError) { result.Status = ResultStatus.Fail; } else { result.Status = ResultStatus.Success; } return(result); }
public ResultData ExecuteInfoWorkFlow(string workFlowName, UserProgInfo userProgInfo, string folder, string service, string apName, string bkFileName) { string key = "infa"; int seq = string.IsNullOrEmpty(service) ? 1 : 2; DataTable dt = daoTXFP.ListDataByKeyAndSeq(key, seq); ResultData result = new ResultData(); string workingDirectory = dt.Rows[0]["ls_exec_file"].AsString(); string domainFile = dt.Rows[0]["ls_domains_file"].AsString(); string domain = dt.Rows[0]["ls_domain"].AsString(); service = seq == 1 ? dt.Rows[0]["ls_server"].AsString() : service; string user = dt.Rows[0]["ls_str1"].AsString(); string pwd = dt.Rows[0]["ls_str2"].AsString(); string language = seq == 1 ? "" : "\nSET INFA_LANGUAGE=en"; string command = $@"SET RunUsr={user} SET RunPasswd={pwd}{language} SET INFA_DOMAINS_FILE={domainFile} {workingDirectory} startworkflow -service {service} -domain {domain} -uv RunUsr -pv RunPasswd -folder {folder} -wait {workFlowName} > {bkFileName}.log echo return status = %errorlevel% >{bkFileName}.err exit /b %errorlevel% "; string batFile = $"{bkFileName}.bat"; System.IO.File.WriteAllText(batFile, command); Process process = new Process(); process.StartInfo.FileName = batFile; process.StartInfo.CreateNoWindow = true; process.StartInfo.UseShellExecute = false; process.Start(); process.WaitForExit(); int code; code = process.ExitCode; string codeDesc = getInfaCodeDesc(code); bool isError = false; if (process.ExitCode != 0) { isError = true; } if (isError) { SystemSounds.Beep.Play(); result.returnString = $"請通知「{apName}」 Informatica 作業執行失敗!\n請查詢 {bkFileName}.err 錯誤訊息說明\nService:{service}\nFolder:{folder}\nWorkFlow:{workFlowName}\nCode Description:{code} = {codeDesc}"; result.Status = ResultStatus.Fail; } else { File.Delete(batFile); result.Status = ResultStatus.Success; } return(result); }