CommonFunction.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. using Aitex.Core.RT.Routine;
  2. using CyberX8_Core;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.IO;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. namespace MECF.Framework.Common.Utilities
  10. {
  11. public class CommonFunction
  12. {
  13. //internal T
  14. public static T GetValue<T>(Dictionary<string, object> RtDataValues, string str)
  15. {
  16. if (RtDataValues.Keys.Contains(str))
  17. {
  18. try
  19. {
  20. return (T)Convert.ChangeType(RtDataValues[str], typeof(T));
  21. }
  22. catch
  23. {
  24. return default(T);
  25. }
  26. }
  27. else
  28. {
  29. return default(T);
  30. }
  31. }
  32. public static IEnumerable<string> GetFilesNames(string path)
  33. {
  34. if (Directory.Exists(path))
  35. {
  36. return Directory.GetFiles(path, "*.rcp")?.Select(Path.GetFileNameWithoutExtension);
  37. }
  38. else
  39. {
  40. return new List<string>();
  41. }
  42. }
  43. /// <summary>
  44. /// 集合项是否包含内容
  45. /// </summary>
  46. /// <param name="list"></param>
  47. /// <param name="item"></param>
  48. /// <returns></returns>
  49. public static bool CheckListItemsContain(List<string> list, string item)
  50. {
  51. if (list == null)
  52. {
  53. return false;
  54. }
  55. List<string> tmpList = list.ToList();
  56. foreach (string str in tmpList)
  57. {
  58. if (!string.IsNullOrEmpty(str))
  59. {
  60. string tmp = str.ToLower();
  61. if (tmp.EndsWith(item.ToLower()))
  62. {
  63. return true;
  64. }
  65. }
  66. }
  67. return false;
  68. }
  69. /// <summary>
  70. /// 获取当前位置最后内容
  71. /// </summary>
  72. /// <param name="station"></param>
  73. /// <param name="moduleName"></param>
  74. /// <returns></returns>
  75. public static string GetCurrentStationLastContent(string station, string moduleName)
  76. {
  77. if (station != null)
  78. {
  79. return station.Replace($"{moduleName}.", "");
  80. }
  81. else
  82. {
  83. return "";
  84. }
  85. }
  86. /// <summary>
  87. /// 检验Routine正常结束状态
  88. /// </summary>
  89. /// <param name="routine"></param>
  90. /// <returns></returns>
  91. public static bool CheckRoutineEndState(IRoutine routine)
  92. {
  93. if(routine == null)
  94. {
  95. return false;
  96. }
  97. return routine.Monitor() == RState.End;
  98. }
  99. /// <summary>
  100. /// 检验Routine停止状态
  101. /// </summary>
  102. /// <param name="routine"></param>
  103. /// <returns></returns>
  104. public static bool CheckRoutineStopState(IRoutine routine)
  105. {
  106. if(routine==null)
  107. {
  108. return false;
  109. }
  110. RState rState = routine.Monitor();
  111. if(rState==RState.Failed||rState==RState.Timeout)
  112. {
  113. return true;
  114. }
  115. return false;
  116. }
  117. }
  118. }