WaferStatusHandler.cs 2.5 KB

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