using Aitex.Core.RT.Event; using Aitex.Core.RT.SCCore; using Aitex.Core.UI.ControlDataContext; using Aitex.Core.Util; using MECF.Framework.Common.Communications; using MECF.Framework.Common.Equipment; using MECF.Framework.Common.Event; using MECF.Framework.Common.FAServices.E40s; using MECF.Framework.Common.FAServices.E94s; using MECF.Framework.Common.IOCore; using MECF.Framework.Common.Jobs; using MECF.Framework.Common.RecipeCenter; using MECF.Framework.Common.SubstrateTrackings; using OldWorldData.CommonData; using OldWorldData.CommonData.DeviceData; using OldWorldData.CommonData.SorterDefines; using System.Collections.Concurrent; using System.Collections.ObjectModel; using System.Data; using System.ServiceModel; namespace OldWorldDataAdaptor.Services; internal class DataQueryService : IDataQueryService, IDisposable { private ChannelFactory? _channelFactory; private IRTWcfService? _rtService; private IQueryDataProvider? _provider; private readonly HashSet _registedKeys = []; private readonly ReaderWriterLockSlim _keyRwLock = new(); private readonly ConcurrentDictionary _dataCache = []; private Timer? _updateTimer; bool IDataQueryService.Initialize(IQueryDataProvider provider) { if (this._provider is not null) return false; this._provider = provider; return true; } bool IDataQueryService.RegistDataKey(string keys) { try { _keyRwLock.EnterWriteLock(); return this._registedKeys.Add(keys); } finally { _keyRwLock?.ExitWriteLock(); } } bool IDataQueryService.RegistDataKey(IEnumerable keys) { try { _keyRwLock.EnterWriteLock(); keys.Foreach(key => this._registedKeys.Add(key)); } finally { _keyRwLock?.ExitWriteLock(); } return true; } bool IDataQueryService.StartService(string connectionString) { if (string.IsNullOrEmpty(connectionString)) return false; if (this._updateTimer is not null) return false; EndpointAddress add = new(connectionString); NetTcpBinding binding = new(SecurityMode.None) { Name = "Aitex_netTcpBinding", MaxReceivedMessageSize = 2147483647, OpenTimeout = TimeSpan.FromSeconds(5), CloseTimeout = TimeSpan.FromMinutes(3), ReceiveTimeout = TimeSpan.FromMinutes(30) }; binding.Security.Transport.ClientCredentialType = TcpClientCredentialType.None; binding.Security.Message.ClientCredentialType = MessageCredentialType.None; binding.ReaderQuotas.MaxDepth = 32; binding.ReaderQuotas.MaxArrayLength = 2147483647; binding.ReaderQuotas.MaxBytesPerRead = 4096; binding.ReaderQuotas.MaxNameTableCharCount = 16384; try { this._channelFactory = new(binding, add); this._rtService = this._channelFactory.CreateChannel(); } catch { return false; } this._updateTimer = new(UpdateTimerCallback, null, 0, 1000); return true; } void UpdateTimerCallback(object? state) { try { Dictionary? rawData = this._rtService?.PollData(this._registedKeys); if (rawData is null || rawData.Count == 0) return; Parallel.ForEach(_dataCache, data => { this._provider?.DataChangedNotify(data.Key, data.Value); }); } catch { } } public void Dispose() { } } [ServiceContract] [ServiceKnownType(typeof(SignalTowerDataItem))] [ServiceKnownType(typeof(GateValveDataItem))] [ServiceKnownType(typeof(EventItem))] [ServiceKnownType(typeof(List))] [ServiceKnownType(typeof(AlarmEventItem))] [ServiceKnownType(typeof(List))] [ServiceKnownType(typeof(List))] [ServiceKnownType(typeof(List))] [ServiceKnownType(typeof(List))] [ServiceKnownType(typeof(List))] [ServiceKnownType(typeof(ProcessJobInfo))] [ServiceKnownType(typeof(ControlJobInfo))] [ServiceKnownType(typeof(List))] [ServiceKnownType(typeof(List))] [ServiceKnownType(typeof(List))] [ServiceKnownType(typeof(NotifiableIoItem))] [ServiceKnownType(typeof(AITChillerData))] [ServiceKnownType(typeof(AITChillerData1))] [ServiceKnownType(typeof(AITTempratureHumidityData))] [ServiceKnownType(typeof(AITValveData))] [ServiceKnownType(typeof(AITMfcData))] [ServiceKnownType(typeof(AITGasSplitterData))] [ServiceKnownType(typeof(AITHeaterData))] [ServiceKnownType(typeof(AITFFUData))] [ServiceKnownType(typeof(AITDeveloperCoupleData))] [ServiceKnownType(typeof(AITWaterFlowMeterData))] [ServiceKnownType(typeof(AITPressureMeterData))] [ServiceKnownType(typeof(AITRfData))] [ServiceKnownType(typeof(AITThrottleValveData))] [ServiceKnownType(typeof(AITAPCData))] [ServiceKnownType(typeof(AITAuxData))] [ServiceKnownType(typeof(List))] [ServiceKnownType(typeof(AITSensorData))] [ServiceKnownType(typeof(AITPumpData))] [ServiceKnownType(typeof(AITSignalTowerData))] [ServiceKnownType(typeof(AITEmoData))] [ServiceKnownType(typeof(AITStatisticsData))] [ServiceKnownType(typeof(AITBoostPumpData))] [ServiceKnownType(typeof(AITCylinderData))] [ServiceKnownType(typeof(AITWaterFlowSensorData))] [ServiceKnownType(typeof(AITServoMotorData))] [ServiceKnownType(typeof(AITLidData))] [ServiceKnownType(typeof(ServoState))] [ServiceKnownType(typeof(AITRfPowerData))] [ServiceKnownType(typeof(AITRfMatchData))] [ServiceKnownType(typeof(FlowMeterAlarmItem))] [ServiceKnownType(typeof(WaferInfo))] [ServiceKnownType(typeof(WaferInfo[]))] [ServiceKnownType(typeof(CarrierInfo))] [ServiceKnownType(typeof(CarrierInfo[]))] [ServiceKnownType(typeof(NotifiableIoItem))] [ServiceKnownType(typeof(RobotMoveInfo))] [ServiceKnownType(typeof(IndicatorState))] [ServiceKnownType(typeof(FoupClampState))] [ServiceKnownType(typeof(FoupDoorState))] [ServiceKnownType(typeof(LoadportCassetteState))] [ServiceKnownType(typeof(AITRfidReaderData))] [ServiceKnownType(typeof(AITAlignerData))] [ServiceKnownType(typeof(AITWaferIdReaderData))] [ServiceKnownType(typeof(ModuleName))] [ServiceKnownType(typeof(DeviceState))] [ServiceKnownType(typeof(SorterRecipeXml))] [ServiceKnownType(typeof(SorterRecipeType))] [ServiceKnownType(typeof(SorterRecipePlaceModeOrder))] [ServiceKnownType(typeof(SorterRecipePlaceModeTransfer1To1))] [ServiceKnownType(typeof(SorterRecipePlaceModePack))] [ServiceKnownType(typeof(ObservableCollection))] [ServiceKnownType(typeof(SorterRecipeTransferTableItem))] [ServiceKnownType(typeof(SlotTransferInfo))] [ServiceKnownType(typeof(SlotTransferInfo[]))] [ServiceKnownType(typeof(List))] [ServiceKnownType(typeof(List))] [ServiceKnownType(typeof(List))] [ServiceKnownType(typeof(SerializableDictionary))] [ServiceKnownType(typeof(SerializableDictionary))] [ServiceKnownType(typeof(AITWaterMappingData))] [ServiceKnownType(typeof(List))] [ServiceKnownType(typeof(List))] [ServiceKnownType(typeof(FAProcessJob))] [ServiceKnownType(typeof(List))] [ServiceKnownType(typeof(FAControlJob))] [ServiceKnownType(typeof(List))] [ServiceKnownType(typeof(WCFProcessJobInterface))] [ServiceKnownType(typeof(List))] [ServiceKnownType(typeof(WCFControlJobInterface))] [ServiceKnownType(typeof(NotifiableConnectionItem))] [ServiceKnownType(typeof(List))] [ServiceKnownType(typeof(WaferHistoryItemType))] [ServiceKnownType(typeof(RecipeStep))] [ServiceKnownType(typeof(List))] [ServiceKnownType(typeof(WaferHistoryItem))] [ServiceKnownType(typeof(WaferHistoryRecipe))] [ServiceKnownType(typeof(List))] [ServiceKnownType(typeof(List))] [ServiceKnownType(typeof(List))] [ServiceKnownType(typeof(List))] [ServiceKnownType(typeof(WaferSize))] [ServiceKnownType(typeof(AITDeviceData))] [ServiceKnownType(typeof(float[]))] [ServiceKnownType(typeof(bool[]))] [ServiceKnownType(typeof(int[]))] [ServiceKnownType(typeof(byte[]))] [ServiceKnownType(typeof(double[]))] [ServiceKnownType(typeof(Tuple))] [ServiceKnownType(typeof(Tuple[]))] [ServiceKnownType(typeof(ManualTransferTask))] [ServiceKnownType(typeof(ManualTransferTask[]))] [ServiceKnownType(typeof(Dictionary))] [ServiceKnownType(typeof(RecipeFileNode))] [ServiceKnownType(typeof(List))] [ServiceKnownType(typeof(Dictionary>))] [ServiceKnownType(typeof(Dictionary>))] [ServiceKnownType(typeof(Dictionary))] public interface IRTWcfService { [OperationContract] object GetData(string key); [OperationContract] Dictionary PollData(IEnumerable keys); [OperationContract] Dictionary PollConfig(IEnumerable keys); [OperationContract] object GetConfig(string key); [OperationContract] List GetDiList(string key); [OperationContract] List GetDoList(string key); [OperationContract] List GetAiList(string key); [OperationContract] List GetAoList(string key); [OperationContract] string GetConfigFileContent(); [OperationContract] string GetFileContent(string fileName); [OperationContract] string GetConfigFileDispenseByModule(string module); [OperationContract] List GetFileListByFolderBrowser(string folderBrowser); [OperationContract] string GetConfigFileContentByModule(string module); [OperationContract] object GetConfigByModule(string module, string key); [OperationContract] List GetConfigItemList(); [OperationContract] SCConfigItem GetConfigItem(string key); [OperationContract] List GetConfigWaferTypes(); [OperationContract] Dictionary PollConfigByModule(string module, IEnumerable keys); [OperationContract] List QueryDBEvent(string sql); [OperationContract] List QueryDBCarrier(string sql); [OperationContract] List QueryDBOCRStatistics(string sql); [OperationContract] List QueryDBFfuDiffPressureStatistics(string sql); [OperationContract] List QueryStatsDBStatistics(string sql); [OperationContract] List QueryDBOCRHistory(string sql); [OperationContract] List QueryDBProcess(string sql); [OperationContract] List QueryDBWafer(string sql); [OperationContract] List QueryDBMovement(string sql); [OperationContract] List QueryDBJobMovementByJobGuid(string jobGuid); [OperationContract] List QueryDBJobMovementByJobGuidAndStationName(string jobGuid, string stationName); [OperationContract] List GetHistoryData(IEnumerable keys, string recipeRunGuid, string module); [OperationContract] List GetOneDayHistoryData(IEnumerable keys, DateTime begin, string module); [OperationContract] List GetHistoryDataFromStartToEnd(IEnumerable keys, DateTime begin, DateTime end, string module); [OperationContract] DataTable QueryData(string sql); [OperationContract] WaferHistoryRecipe GetWaferHistoryRecipe(string id); [OperationContract] List GetWaferHistoryWafers(string id); [OperationContract] List GetWaferHistoryRecipes(string id); [OperationContract] List GetWaferHistoryMovements(string id); [OperationContract] List GetWaferHistorySecquences(string id); [OperationContract] List QueryWaferHistoryLotsBySql(string sql); [OperationContract] List GetWaferHistoryLots(DateTime startTime, DateTime endTime, string keyWord); [OperationContract] string GetTypedConfigContent(string type, string contentPath); [OperationContract] void SetTypedConfigContent(string type, string contentPath, string content); [OperationContract] List GetExpertLayoutRecipeContent(string chamberId, string recipeFile); [OperationContract] List GetLayoutRecipeContent(/*string chamberId, */string recipeFile, string slotCount, string cassetteSlotCount); [OperationContract] List GetLayoutExpertRecipeContent(/*string chamberId, */string recipeFile, string slotCount, string cassetteSlotCount); [OperationContract] string GetInterlockConfigContent(); [OperationContract] string GetInterlockUserDefineConfigContent(); [OperationContract] void SetInterlockConfigContent(string content); [OperationContract] List QueryByRecipePathHistory(string RecipePath, int row = 20); [OperationContract] bool ClearByRecipePathHistory(string RecipePath); [OperationContract] string GetFileXmlContent(string fileName, string diretory = "GasXml"); }