WaferStatusHandler.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. using MECF.Framework.Common.DataCenter;
  2. using OpenSEMI.ClientBase;
  3. using OpenSEMI.Core.Msg;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading;
  9. using System.Threading.Tasks;
  10. using System.Windows;
  11. using System.Windows.Threading;
  12. namespace CyberX8_MainPages.Unity
  13. {
  14. public class WaferStatusHandler : IHandler
  15. {
  16. public static readonly List<string> ReverseModules = new List<string>() { "LLA","LLB", "LP1", "LP2", "LP3","VCE1","Dummy1", "Dummy2" };
  17. public WaferStatusHandler(Func<string, List<WaferInfo>> funcGetWaferStatus, List<string> allModules)
  18. {
  19. this.WaferStatusDic = new Dictionary<string, ModuleWaferManager>();
  20. this.looper = new MsgPool(500, Do);
  21. this.GetWaferStatusByModule = funcGetWaferStatus;
  22. //init wafer status dictionary
  23. allModules.ForEach(key => { InitWafersByModule(key); });
  24. }
  25. public void Handle()
  26. {
  27. this.looper.Run();
  28. }
  29. private void InitWafersByModule(string moduleID)
  30. {
  31. lock (lockObj)
  32. {
  33. if (!this.WaferStatusDic.ContainsKey(moduleID))
  34. {
  35. this.WaferStatusDic.Add(moduleID, new ModuleWaferManager(moduleID));
  36. List<WaferInfo> mWafers = GetWaferStatusByModule(moduleID);
  37. if (mWafers != null)
  38. {
  39. ModuleWaferManager modinfowithwafer = this.WaferStatusDic[moduleID];
  40. for (int i = 0; i < mWafers.Count; i++)
  41. {
  42. modinfowithwafer.Wafers.Add(mWafers[i]);
  43. }
  44. if (ReverseModules.Contains(moduleID))
  45. {
  46. modinfowithwafer.Wafers.Reverse();
  47. }
  48. }
  49. }
  50. }
  51. }
  52. private void Do(MsgPool pool)
  53. {
  54. lock (lockObj)
  55. {
  56. if (Application.Current == null || Application.Current.Dispatcher == null)
  57. return;
  58. foreach (KeyValuePair<string, ModuleWaferManager> pair in WaferStatusDic)
  59. {
  60. List<WaferInfo> mWafers = GetWaferStatusByModule(pair.Key);
  61. Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (ThreadStart)delegate
  62. {
  63. if (mWafers != null && mWafers.Count == pair.Value.Wafers.Count)
  64. {
  65. int index;
  66. bool isCassettePresent = true;
  67. if (pair.Key.Contains("LP")) isCassettePresent = (bool)QueryDataClient.Instance.Service.GetData($"{pair.Key}.CassettePlaced");
  68. for (int i = 0; i < mWafers.Count; i++)
  69. {
  70. //status used in UI control
  71. if (ReverseModules.Contains(pair.Key))
  72. index = mWafers.Count - i - 1;
  73. else
  74. index = i;
  75. pair.Value.Wafers[i].WaferStatus = mWafers[index].WaferStatus;
  76. pair.Value.Wafers[i].WaferID = mWafers[index].WaferID;
  77. pair.Value.Wafers[i].SourceName = mWafers[index].SourceName;
  78. if (!string.IsNullOrEmpty(mWafers[index].SequenceName) || !isCassettePresent)
  79. {
  80. pair.Value.Wafers[i].SequenceName = mWafers[index].SequenceName;
  81. }
  82. }
  83. }
  84. });
  85. }
  86. }
  87. }
  88. public Dictionary<string, ModuleWaferManager> WaferStatusDic { get; private set; }
  89. public MsgPool looper { get; private set; }
  90. private Func<string, List<WaferInfo>> GetWaferStatusByModule;
  91. private static object lockObj = new object();
  92. }
  93. }