ProcessMethods.cs 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. using System;
  2. using System.Collections;
  3. using System.Diagnostics;
  4. using System.IO;
  5. using IwbZero.IwbBase;
  6. using IwbZero.IwbDataQuery;
  7. using IwbZero.Processes.StatementTypes;
  8. using IwbZero.ToolCommon.LogHelpers;
  9. using IwbZero.ToolCommon.StringModel;
  10. namespace IwbZero.Processes.Runner
  11. {
  12. public class ProcessMethods
  13. {
  14. public static bool RunProcess(string piProcessId, string pcMapping)
  15. {
  16. bool flag = false;
  17. IwbProcess poProcess = IwbProcess.LoadById(piProcessId);
  18. if (poProcess != null)
  19. {
  20. flag = new ProcessRunner().Run(poProcess, pcMapping);
  21. }
  22. return flag;
  23. }
  24. public static bool RunOneStatement(ProcessRunner poRunner, IwbXmlNode poStatement)
  25. {
  26. switch (poStatement.Name)
  27. {
  28. case PdStmtType.CreateVariables:
  29. foreach (IwbXmlNode node in poStatement.Nodes)
  30. {
  31. string childValue = node.GetChildValue("Name");
  32. string pcVariableType = node.GetChildValue("Type");
  33. poRunner.CreateVariable(childValue, pcVariableType);
  34. }
  35. return true;
  36. case PdStmtType.SetVariables:
  37. {
  38. string pcMapping = poStatement.GetChildValue("Content");
  39. if (pcMapping != "")
  40. {
  41. foreach (IwbIdName name in StringHelper.MappingToArrayList(pcMapping))
  42. {
  43. poRunner.SetValue(name.Id, name.Name, true);
  44. }
  45. }
  46. return true;
  47. }
  48. case PdStmtType.ConditionalBranching:
  49. return RunConditionalBranching(poRunner, poStatement);
  50. case PdStmtType.RunApplication:
  51. return RunApplication(poRunner, poStatement);
  52. //case "pdCreateDatasource":
  53. // return poRunner.CreateDataSource(poStatement);
  54. //case "pdDatasourceOperation":
  55. // return RunDataSourceOperation(poRunner, poStatement);
  56. //case "pdLoopQuery":
  57. // return RunLoopQuery(poRunner, poStatement);
  58. //case "pdPrintReport":
  59. // return RunPrintReport(poRunner, poStatement);
  60. //case "pdRunUpdateMethod":
  61. // return RunUpdateMethod(poRunner, poStatement);
  62. //case "pdRunServerFunction":
  63. // return RunServerFunction(poRunner, poStatement);
  64. //case "pdRecordCount":
  65. // return SetRecordCount(poRunner, poStatement);
  66. //case "pdImportMapping":
  67. // return ImportFile(poRunner, poStatement);
  68. //case "pdTransaction":
  69. // return Transaction(poRunner, poStatement);
  70. //case "pdSaveTables":
  71. // return SaveTables(poRunner, poStatement);
  72. //case "pdOutboundMapping":
  73. // return ExportFile(poRunner, poStatement);
  74. //case "pdExcelOperation":
  75. // return ExcelOperation(poRunner, poStatement);
  76. //case "pdPrintLabel":
  77. // return PrintLabel(poRunner, poStatement);
  78. }
  79. return true;
  80. }
  81. public static ArrayList ParseProcessParameter(string pcParameter)
  82. {
  83. ArrayList list = new ArrayList();
  84. foreach (string str in pcParameter.StrToArray())
  85. {
  86. if (str.IndexOf(":", StringComparison.Ordinal) != -1)
  87. {
  88. string pcStr = str.Substring(0, str.IndexOf(":", StringComparison.Ordinal));
  89. ProcessParameter parameter = new ProcessParameter(str.Substring(str.IndexOf(":", StringComparison.Ordinal) + 1, (str.Length - str.IndexOf(":", StringComparison.Ordinal)) - 1), ProcessParameterTypeFromStr(pcStr));
  90. list.Add(parameter);
  91. }
  92. }
  93. return list;
  94. }
  95. public static ProcessParameterType ProcessParameterTypeFromStr(string pcStr)
  96. {
  97. ProcessParameterType filterField = ProcessParameterType.FilterField;
  98. string str = pcStr;
  99. if (str == null)
  100. {
  101. return filterField;
  102. }
  103. str = string.IsInterned(str);
  104. if (str == "FilterField")
  105. {
  106. return ProcessParameterType.FilterField;
  107. }
  108. if (str == "File")
  109. {
  110. return ProcessParameterType.File;
  111. }
  112. if (str == "Folder")
  113. {
  114. return ProcessParameterType.Folder;
  115. }
  116. if (str != "PrinterSetting")
  117. {
  118. return filterField;
  119. }
  120. return ProcessParameterType.PrinterSetting;
  121. }
  122. private static bool RunConditionalBranching(ProcessRunner poRunner, IwbXmlNode poStatement)
  123. {
  124. string childValue = poStatement.GetChildValue("Condition");
  125. var childNode = poStatement.GetChildNode("Yes");
  126. var node2 = poStatement.GetChildNode("No");
  127. if (childValue == "")
  128. {
  129. return true;
  130. }
  131. if (poRunner.EvaluateBool(childValue))
  132. {
  133. return poRunner.RunStatements(childNode.Nodes);
  134. }
  135. return poRunner.RunStatements(node2.Nodes);
  136. }
  137. public static bool RunApplication(ProcessRunner poRunner, IwbXmlNode poStatement)
  138. {
  139. string childValue = poStatement.GetChildValue("FileName");
  140. bool flag = poStatement.GetChildValue("WaitForResult").StrToBool();
  141. string message = "";
  142. if (File.Exists(childValue))
  143. {
  144. try
  145. {
  146. Process process = new Process { EnableRaisingEvents = false, StartInfo = { FileName = childValue } };
  147. process.Start();
  148. if (flag)
  149. {
  150. process.WaitForExit(0x927c0);
  151. }
  152. }
  153. catch (Exception exception)
  154. {
  155. message = exception.Message;
  156. }
  157. }
  158. else
  159. {
  160. message = "File not found.";
  161. }
  162. if (message != "")
  163. {
  164. typeof(ProcessMethods).LogError($"{childValue}——{message}");
  165. //poRunner.AbortProcessWithMessage(poRunner.UserSession.T(0x1885c, childValue, message));
  166. }
  167. return (message == "");
  168. }
  169. }
  170. }