WaferStatusHandler.cs 3.6 KB

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