WaferStatusHandler.cs 4.0 KB

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