DataQueryService.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  1. using Aitex.Core.RT.Event;
  2. using Aitex.Core.RT.SCCore;
  3. using Aitex.Core.UI.ControlDataContext;
  4. using Aitex.Core.Util;
  5. using MECF.Framework.Common.Communications;
  6. using MECF.Framework.Common.Equipment;
  7. using MECF.Framework.Common.Event;
  8. using MECF.Framework.Common.FAServices.E40s;
  9. using MECF.Framework.Common.FAServices.E94s;
  10. using MECF.Framework.Common.IOCore;
  11. using MECF.Framework.Common.Jobs;
  12. using MECF.Framework.Common.RecipeCenter;
  13. using MECF.Framework.Common.SubstrateTrackings;
  14. using OldWorldData.CommonData;
  15. using OldWorldData.CommonData.DeviceData;
  16. using OldWorldData.CommonData.SorterDefines;
  17. using System.Collections.Concurrent;
  18. using System.Collections.ObjectModel;
  19. using System.Data;
  20. using System.ServiceModel;
  21. namespace OldWorldDataAdaptor.Services;
  22. internal class DataQueryService : IDataQueryService, IDisposable
  23. {
  24. private ChannelFactory<IRTWcfService>? _channelFactory;
  25. private IRTWcfService? _rtService;
  26. private IQueryDataProvider? _provider;
  27. private readonly HashSet<string> _registedKeys = [];
  28. private readonly ReaderWriterLockSlim _keyRwLock = new();
  29. private readonly ConcurrentDictionary<string, object> _dataCache = [];
  30. private Timer? _updateTimer;
  31. bool IDataQueryService.Initialize(IQueryDataProvider provider)
  32. {
  33. if (this._provider is not null)
  34. return false;
  35. this._provider = provider;
  36. return true;
  37. }
  38. bool IDataQueryService.RegistDataKey(string keys)
  39. {
  40. try
  41. {
  42. _keyRwLock.EnterWriteLock();
  43. return this._registedKeys.Add(keys);
  44. }
  45. finally
  46. {
  47. _keyRwLock?.ExitWriteLock();
  48. }
  49. }
  50. bool IDataQueryService.RegistDataKey(IEnumerable<string> keys)
  51. {
  52. try
  53. {
  54. _keyRwLock.EnterWriteLock();
  55. keys.Foreach(key => this._registedKeys.Add(key));
  56. }
  57. finally
  58. {
  59. _keyRwLock?.ExitWriteLock();
  60. }
  61. return true;
  62. }
  63. bool IDataQueryService.StartService(string connectionString)
  64. {
  65. if (string.IsNullOrEmpty(connectionString))
  66. return false;
  67. if (this._updateTimer is not null)
  68. return false;
  69. EndpointAddress add = new(connectionString);
  70. NetTcpBinding binding = new(SecurityMode.None)
  71. {
  72. Name = "Aitex_netTcpBinding",
  73. MaxReceivedMessageSize = 2147483647,
  74. OpenTimeout = TimeSpan.FromSeconds(5),
  75. CloseTimeout = TimeSpan.FromMinutes(3),
  76. ReceiveTimeout = TimeSpan.FromMinutes(30)
  77. };
  78. binding.Security.Transport.ClientCredentialType = TcpClientCredentialType.None;
  79. binding.Security.Message.ClientCredentialType = MessageCredentialType.None;
  80. binding.ReaderQuotas.MaxDepth = 32;
  81. binding.ReaderQuotas.MaxArrayLength = 2147483647;
  82. binding.ReaderQuotas.MaxBytesPerRead = 4096;
  83. binding.ReaderQuotas.MaxNameTableCharCount = 16384;
  84. try
  85. {
  86. this._channelFactory = new(binding, add);
  87. this._rtService = this._channelFactory.CreateChannel();
  88. }
  89. catch
  90. {
  91. return false;
  92. }
  93. this._updateTimer = new(UpdateTimerCallback, null, 0, 1000);
  94. return true;
  95. }
  96. void UpdateTimerCallback(object? state)
  97. {
  98. try
  99. {
  100. Dictionary<string, object>? rawData = this._rtService?.PollData(this._registedKeys);
  101. if (rawData is null || rawData.Count == 0)
  102. return;
  103. Parallel.ForEach(_dataCache, data =>
  104. {
  105. this._provider?.DataChangedNotify(data.Key, data.Value);
  106. });
  107. }
  108. catch
  109. {
  110. }
  111. }
  112. public void Dispose()
  113. {
  114. }
  115. }
  116. [ServiceContract]
  117. [ServiceKnownType(typeof(SignalTowerDataItem))]
  118. [ServiceKnownType(typeof(GateValveDataItem))]
  119. [ServiceKnownType(typeof(EventItem))]
  120. [ServiceKnownType(typeof(List<EventItem>))]
  121. [ServiceKnownType(typeof(AlarmEventItem))]
  122. [ServiceKnownType(typeof(List<AlarmEventItem>))]
  123. [ServiceKnownType(typeof(List<HistoryCarrierData>))]
  124. [ServiceKnownType(typeof(List<HistoryProcessData>))]
  125. [ServiceKnownType(typeof(List<HistoryWaferData>))]
  126. [ServiceKnownType(typeof(List<HistoryMoveData>))]
  127. [ServiceKnownType(typeof(ProcessJobInfo))]
  128. [ServiceKnownType(typeof(ControlJobInfo))]
  129. [ServiceKnownType(typeof(List<ProcessJobInfo>))]
  130. [ServiceKnownType(typeof(List<ControlJobInfo>))]
  131. [ServiceKnownType(typeof(List<NotifiableIoItem>))]
  132. [ServiceKnownType(typeof(NotifiableIoItem))]
  133. [ServiceKnownType(typeof(AITChillerData))]
  134. [ServiceKnownType(typeof(AITChillerData1))]
  135. [ServiceKnownType(typeof(AITTempratureHumidityData))]
  136. [ServiceKnownType(typeof(AITValveData))]
  137. [ServiceKnownType(typeof(AITMfcData))]
  138. [ServiceKnownType(typeof(AITGasSplitterData))]
  139. [ServiceKnownType(typeof(AITHeaterData))]
  140. [ServiceKnownType(typeof(AITFFUData))]
  141. [ServiceKnownType(typeof(AITDeveloperCoupleData))]
  142. [ServiceKnownType(typeof(AITWaterFlowMeterData))]
  143. [ServiceKnownType(typeof(AITPressureMeterData))]
  144. [ServiceKnownType(typeof(AITRfData))]
  145. [ServiceKnownType(typeof(AITThrottleValveData))]
  146. [ServiceKnownType(typeof(AITAPCData))]
  147. [ServiceKnownType(typeof(AITAuxData))]
  148. [ServiceKnownType(typeof(List<AITAuxData>))]
  149. [ServiceKnownType(typeof(AITSensorData))]
  150. [ServiceKnownType(typeof(AITPumpData))]
  151. [ServiceKnownType(typeof(AITSignalTowerData))]
  152. [ServiceKnownType(typeof(AITEmoData))]
  153. [ServiceKnownType(typeof(AITStatisticsData))]
  154. [ServiceKnownType(typeof(AITBoostPumpData))]
  155. [ServiceKnownType(typeof(AITCylinderData))]
  156. [ServiceKnownType(typeof(AITWaterFlowSensorData))]
  157. [ServiceKnownType(typeof(AITServoMotorData))]
  158. [ServiceKnownType(typeof(AITLidData))]
  159. [ServiceKnownType(typeof(ServoState))]
  160. [ServiceKnownType(typeof(AITRfPowerData))]
  161. [ServiceKnownType(typeof(AITRfMatchData))]
  162. [ServiceKnownType(typeof(FlowMeterAlarmItem))]
  163. [ServiceKnownType(typeof(WaferInfo))]
  164. [ServiceKnownType(typeof(WaferInfo[]))]
  165. [ServiceKnownType(typeof(CarrierInfo))]
  166. [ServiceKnownType(typeof(CarrierInfo[]))]
  167. [ServiceKnownType(typeof(NotifiableIoItem))]
  168. [ServiceKnownType(typeof(RobotMoveInfo))]
  169. [ServiceKnownType(typeof(IndicatorState))]
  170. [ServiceKnownType(typeof(FoupClampState))]
  171. [ServiceKnownType(typeof(FoupDoorState))]
  172. [ServiceKnownType(typeof(LoadportCassetteState))]
  173. [ServiceKnownType(typeof(AITRfidReaderData))]
  174. [ServiceKnownType(typeof(AITAlignerData))]
  175. [ServiceKnownType(typeof(AITWaferIdReaderData))]
  176. [ServiceKnownType(typeof(ModuleName))]
  177. [ServiceKnownType(typeof(DeviceState))]
  178. [ServiceKnownType(typeof(SorterRecipeXml))]
  179. [ServiceKnownType(typeof(SorterRecipeType))]
  180. [ServiceKnownType(typeof(SorterRecipePlaceModeOrder))]
  181. [ServiceKnownType(typeof(SorterRecipePlaceModeTransfer1To1))]
  182. [ServiceKnownType(typeof(SorterRecipePlaceModePack))]
  183. [ServiceKnownType(typeof(ObservableCollection<SorterRecipeTransferTableItem>))]
  184. [ServiceKnownType(typeof(SorterRecipeTransferTableItem))]
  185. [ServiceKnownType(typeof(SlotTransferInfo))]
  186. [ServiceKnownType(typeof(SlotTransferInfo[]))]
  187. [ServiceKnownType(typeof(List<string>))]
  188. [ServiceKnownType(typeof(List<SCConfigItem>))]
  189. [ServiceKnownType(typeof(List<WaferTypeInfo>))]
  190. [ServiceKnownType(typeof(SerializableDictionary<string, bool>))]
  191. [ServiceKnownType(typeof(SerializableDictionary<string, string>))]
  192. [ServiceKnownType(typeof(AITWaterMappingData))]
  193. [ServiceKnownType(typeof(List<AITWaterMappingData>))]
  194. [ServiceKnownType(typeof(List<FAProcessJob>))]
  195. [ServiceKnownType(typeof(FAProcessJob))]
  196. [ServiceKnownType(typeof(List<FAControlJob>))]
  197. [ServiceKnownType(typeof(FAControlJob))]
  198. [ServiceKnownType(typeof(List<WCFProcessJobInterface>))]
  199. [ServiceKnownType(typeof(WCFProcessJobInterface))]
  200. [ServiceKnownType(typeof(List<WCFControlJobInterface>))]
  201. [ServiceKnownType(typeof(WCFControlJobInterface))]
  202. [ServiceKnownType(typeof(NotifiableConnectionItem))]
  203. [ServiceKnownType(typeof(List<NotifiableConnectionItem>))]
  204. [ServiceKnownType(typeof(WaferHistoryItemType))]
  205. [ServiceKnownType(typeof(RecipeStep))]
  206. [ServiceKnownType(typeof(List<RecipeStep>))]
  207. [ServiceKnownType(typeof(WaferHistoryItem))]
  208. [ServiceKnownType(typeof(WaferHistoryRecipe))]
  209. [ServiceKnownType(typeof(List<WaferHistoryWafer>))]
  210. [ServiceKnownType(typeof(List<WaferHistoryRecipe>))]
  211. [ServiceKnownType(typeof(List<WaferHistoryMovement>))]
  212. [ServiceKnownType(typeof(List<WaferHistoryLot>))]
  213. [ServiceKnownType(typeof(WaferSize))]
  214. [ServiceKnownType(typeof(AITDeviceData))]
  215. [ServiceKnownType(typeof(float[]))]
  216. [ServiceKnownType(typeof(bool[]))]
  217. [ServiceKnownType(typeof(int[]))]
  218. [ServiceKnownType(typeof(byte[]))]
  219. [ServiceKnownType(typeof(double[]))]
  220. [ServiceKnownType(typeof(Tuple<int, string>))]
  221. [ServiceKnownType(typeof(Tuple<int, string>[]))]
  222. [ServiceKnownType(typeof(ManualTransferTask))]
  223. [ServiceKnownType(typeof(ManualTransferTask[]))]
  224. [ServiceKnownType(typeof(Dictionary<string, string>))]
  225. [ServiceKnownType(typeof(RecipeFileNode))]
  226. [ServiceKnownType(typeof(List<RecipeFileNode>))]
  227. [ServiceKnownType(typeof(Dictionary<string, List<string>>))]
  228. [ServiceKnownType(typeof(Dictionary<string, Dictionary<string, string>>))]
  229. [ServiceKnownType(typeof(Dictionary<string, bool>))]
  230. public interface IRTWcfService
  231. {
  232. [OperationContract]
  233. object GetData(string key);
  234. [OperationContract]
  235. Dictionary<string, object> PollData(IEnumerable<string> keys);
  236. [OperationContract]
  237. Dictionary<string, object> PollConfig(IEnumerable<string> keys);
  238. [OperationContract]
  239. object GetConfig(string key);
  240. [OperationContract]
  241. List<NotifiableIoItem> GetDiList(string key);
  242. [OperationContract]
  243. List<NotifiableIoItem> GetDoList(string key);
  244. [OperationContract]
  245. List<NotifiableIoItem> GetAiList(string key);
  246. [OperationContract]
  247. List<NotifiableIoItem> GetAoList(string key);
  248. [OperationContract]
  249. string GetConfigFileContent();
  250. [OperationContract]
  251. string GetFileContent(string fileName);
  252. [OperationContract]
  253. string GetConfigFileDispenseByModule(string module);
  254. [OperationContract]
  255. List<string> GetFileListByFolderBrowser(string folderBrowser);
  256. [OperationContract]
  257. string GetConfigFileContentByModule(string module);
  258. [OperationContract]
  259. object GetConfigByModule(string module, string key);
  260. [OperationContract]
  261. List<SCConfigItem> GetConfigItemList();
  262. [OperationContract]
  263. SCConfigItem GetConfigItem(string key);
  264. [OperationContract]
  265. List<WaferTypeInfo> GetConfigWaferTypes();
  266. [OperationContract]
  267. Dictionary<string, object> PollConfigByModule(string module, IEnumerable<string> keys);
  268. [OperationContract]
  269. List<EventItem> QueryDBEvent(string sql);
  270. [OperationContract]
  271. List<HistoryCarrierData> QueryDBCarrier(string sql);
  272. [OperationContract]
  273. List<HistoryStatisticsOCRData> QueryDBOCRStatistics(string sql);
  274. [OperationContract]
  275. List<HistoryFfuDiffPressureData> QueryDBFfuDiffPressureStatistics(string sql);
  276. [OperationContract]
  277. List<StatsStatisticsData> QueryStatsDBStatistics(string sql);
  278. [OperationContract]
  279. List<HistoryOCRData> QueryDBOCRHistory(string sql);
  280. [OperationContract]
  281. List<HistoryProcessData> QueryDBProcess(string sql);
  282. [OperationContract]
  283. List<HistoryWaferData> QueryDBWafer(string sql);
  284. [OperationContract]
  285. List<HistoryMoveData> QueryDBMovement(string sql);
  286. [OperationContract]
  287. List<HistoryJobMoveData> QueryDBJobMovementByJobGuid(string jobGuid);
  288. [OperationContract]
  289. List<HistoryJobMoveData> QueryDBJobMovementByJobGuidAndStationName(string jobGuid, string stationName);
  290. [OperationContract]
  291. List<HistoryDataItem> GetHistoryData(IEnumerable<string> keys, string recipeRunGuid, string module);
  292. [OperationContract]
  293. List<HistoryDataItem> GetOneDayHistoryData(IEnumerable<string> keys, DateTime begin, string module);
  294. [OperationContract]
  295. List<HistoryDataItem> GetHistoryDataFromStartToEnd(IEnumerable<string> keys, DateTime begin, DateTime end, string module);
  296. [OperationContract]
  297. DataTable QueryData(string sql);
  298. [OperationContract]
  299. WaferHistoryRecipe GetWaferHistoryRecipe(string id);
  300. [OperationContract]
  301. List<WaferHistoryWafer> GetWaferHistoryWafers(string id);
  302. [OperationContract]
  303. List<WaferHistoryRecipe> GetWaferHistoryRecipes(string id);
  304. [OperationContract]
  305. List<WaferHistoryMovement> GetWaferHistoryMovements(string id);
  306. [OperationContract]
  307. List<WaferHistorySecquence> GetWaferHistorySecquences(string id);
  308. [OperationContract]
  309. List<WaferHistoryLot> QueryWaferHistoryLotsBySql(string sql);
  310. [OperationContract]
  311. List<WaferHistoryLot> GetWaferHistoryLots(DateTime startTime, DateTime endTime, string keyWord);
  312. [OperationContract]
  313. string GetTypedConfigContent(string type, string contentPath);
  314. [OperationContract]
  315. void SetTypedConfigContent(string type, string contentPath, string content);
  316. [OperationContract]
  317. List<string> GetExpertLayoutRecipeContent(string chamberId, string recipeFile);
  318. [OperationContract]
  319. List<string> GetLayoutRecipeContent(/*string chamberId, */string recipeFile, string slotCount, string cassetteSlotCount);
  320. [OperationContract]
  321. List<string> GetLayoutExpertRecipeContent(/*string chamberId, */string recipeFile, string slotCount, string cassetteSlotCount);
  322. [OperationContract]
  323. string GetInterlockConfigContent();
  324. [OperationContract]
  325. string GetInterlockUserDefineConfigContent();
  326. [OperationContract]
  327. void SetInterlockConfigContent(string content);
  328. [OperationContract]
  329. List<RecipeHistory> QueryByRecipePathHistory(string RecipePath, int row = 20);
  330. [OperationContract]
  331. bool ClearByRecipePathHistory(string RecipePath);
  332. [OperationContract]
  333. string GetFileXmlContent(string fileName, string diretory = "GasXml");
  334. }