using Aitex.Core.RT.Routine; using CyberX8_Core; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; namespace MECF.Framework.Common.Utilities { public class CommonFunction { //internal T public static T GetValue(Dictionary RtDataValues, string str) { if (RtDataValues.Keys.Contains(str)) { try { return (T)Convert.ChangeType(RtDataValues[str], typeof(T)); } catch { return default(T); } } else { return default(T); } } public static IEnumerable GetFilesNames(string path) { if (Directory.Exists(path)) { return Directory.GetFiles(path, "*.rcp")?.Select(Path.GetFileNameWithoutExtension); } else { return new List(); } } /// /// 集合项是否包含内容 /// /// /// /// public static bool CheckListItemsContain(List list, string item) { if (list == null) { return false; } List tmpList = list.ToList(); foreach (string str in tmpList) { if (!string.IsNullOrEmpty(str)) { string tmp = str.ToLower(); if (tmp.EndsWith(item.ToLower())) { return true; } } } return false; } /// /// 获取当前位置最后内容 /// /// /// /// public static string GetCurrentStationLastContent(string station, string moduleName) { if (station != null) { return station.Replace($"{moduleName}.", ""); } else { return ""; } } /// /// 检验Routine正常结束状态 /// /// /// public static bool CheckRoutineEndState(IRoutine routine) { if(routine == null) { return false; } return routine.Monitor() == RState.End; } /// /// 检验Routine停止状态 /// /// /// public static bool CheckRoutineStopState(IRoutine routine) { if(routine==null) { return false; } RState rState = routine.Monitor(); if(rState==RState.Failed||rState==RState.Timeout) { return true; } return false; } } }