123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- 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<T>(Dictionary<string, object> 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<string> GetFilesNames(string path)
- {
- if (Directory.Exists(path))
- {
- return Directory.GetFiles(path, "*.rcp")?.Select(Path.GetFileNameWithoutExtension);
- }
- else
- {
- return new List<string>();
- }
- }
- /// <summary>
- /// 集合项是否包含内容
- /// </summary>
- /// <param name="list"></param>
- /// <param name="item"></param>
- /// <returns></returns>
- public static bool CheckListItemsContain(List<string> list, string item)
- {
- if (list == null)
- {
- return false;
- }
- List<string> 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;
- }
- /// <summary>
- /// 获取当前位置最后内容
- /// </summary>
- /// <param name="station"></param>
- /// <param name="moduleName"></param>
- /// <returns></returns>
- public static string GetCurrentStationLastContent(string station, string moduleName)
- {
- if (station != null)
- {
- return station.Replace($"{moduleName}.", "");
- }
- else
- {
- return "";
- }
- }
- /// <summary>
- /// 检验Routine正常结束状态
- /// </summary>
- /// <param name="routine"></param>
- /// <returns></returns>
- public static bool CheckRoutineEndState(IRoutine routine)
- {
- if(routine == null)
- {
- return false;
- }
- return routine.Monitor() == RState.End;
- }
- /// <summary>
- /// 检验Routine停止状态
- /// </summary>
- /// <param name="routine"></param>
- /// <returns></returns>
- 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;
- }
- }
- }
|