using System; using System.Collections; using System.Diagnostics; using System.IO; using IwbZero.IwbBase; using IwbZero.IwbDataQuery; using IwbZero.Processes.StatementTypes; using IwbZero.ToolCommon.LogHelpers; using IwbZero.ToolCommon.StringModel; namespace IwbZero.Processes.Runner { public class ProcessMethods { public static bool RunProcess(string piProcessId, string pcMapping) { bool flag = false; IwbProcess poProcess = IwbProcess.LoadById(piProcessId); if (poProcess != null) { flag = new ProcessRunner().Run(poProcess, pcMapping); } return flag; } public static bool RunOneStatement(ProcessRunner poRunner, IwbXmlNode poStatement) { switch (poStatement.Name) { case PdStmtType.CreateVariables: foreach (IwbXmlNode node in poStatement.Nodes) { string childValue = node.GetChildValue("Name"); string pcVariableType = node.GetChildValue("Type"); poRunner.CreateVariable(childValue, pcVariableType); } return true; case PdStmtType.SetVariables: { string pcMapping = poStatement.GetChildValue("Content"); if (pcMapping != "") { foreach (IwbIdName name in StringHelper.MappingToArrayList(pcMapping)) { poRunner.SetValue(name.Id, name.Name, true); } } return true; } case PdStmtType.ConditionalBranching: return RunConditionalBranching(poRunner, poStatement); case PdStmtType.RunApplication: return RunApplication(poRunner, poStatement); //case "pdCreateDatasource": // return poRunner.CreateDataSource(poStatement); //case "pdDatasourceOperation": // return RunDataSourceOperation(poRunner, poStatement); //case "pdLoopQuery": // return RunLoopQuery(poRunner, poStatement); //case "pdPrintReport": // return RunPrintReport(poRunner, poStatement); //case "pdRunUpdateMethod": // return RunUpdateMethod(poRunner, poStatement); //case "pdRunServerFunction": // return RunServerFunction(poRunner, poStatement); //case "pdRecordCount": // return SetRecordCount(poRunner, poStatement); //case "pdImportMapping": // return ImportFile(poRunner, poStatement); //case "pdTransaction": // return Transaction(poRunner, poStatement); //case "pdSaveTables": // return SaveTables(poRunner, poStatement); //case "pdOutboundMapping": // return ExportFile(poRunner, poStatement); //case "pdExcelOperation": // return ExcelOperation(poRunner, poStatement); //case "pdPrintLabel": // return PrintLabel(poRunner, poStatement); } return true; } public static ArrayList ParseProcessParameter(string pcParameter) { ArrayList list = new ArrayList(); foreach (string str in pcParameter.StrToArray()) { if (str.IndexOf(":", StringComparison.Ordinal) != -1) { string pcStr = str.Substring(0, str.IndexOf(":", StringComparison.Ordinal)); ProcessParameter parameter = new ProcessParameter(str.Substring(str.IndexOf(":", StringComparison.Ordinal) + 1, (str.Length - str.IndexOf(":", StringComparison.Ordinal)) - 1), ProcessParameterTypeFromStr(pcStr)); list.Add(parameter); } } return list; } public static ProcessParameterType ProcessParameterTypeFromStr(string pcStr) { ProcessParameterType filterField = ProcessParameterType.FilterField; string str = pcStr; if (str == null) { return filterField; } str = string.IsInterned(str); if (str == "FilterField") { return ProcessParameterType.FilterField; } if (str == "File") { return ProcessParameterType.File; } if (str == "Folder") { return ProcessParameterType.Folder; } if (str != "PrinterSetting") { return filterField; } return ProcessParameterType.PrinterSetting; } private static bool RunConditionalBranching(ProcessRunner poRunner, IwbXmlNode poStatement) { string childValue = poStatement.GetChildValue("Condition"); var childNode = poStatement.GetChildNode("Yes"); var node2 = poStatement.GetChildNode("No"); if (childValue == "") { return true; } if (poRunner.EvaluateBool(childValue)) { return poRunner.RunStatements(childNode.Nodes); } return poRunner.RunStatements(node2.Nodes); } public static bool RunApplication(ProcessRunner poRunner, IwbXmlNode poStatement) { string childValue = poStatement.GetChildValue("FileName"); bool flag = poStatement.GetChildValue("WaitForResult").StrToBool(); string message = ""; if (File.Exists(childValue)) { try { Process process = new Process {EnableRaisingEvents = false, StartInfo = {FileName = childValue}}; process.Start(); if (flag) { process.WaitForExit(0x927c0); } } catch (Exception exception) { message = exception.Message; } } else { message = "File not found."; } if (message != "") { typeof(ProcessMethods).LogError($"{childValue}——{message}"); //poRunner.AbortProcessWithMessage(poRunner.UserSession.T(0x1885c, childValue, message)); } return (message == ""); } } }