123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- using OpenSEMI.Core.Msg;
- using System;
- using System.Collections.Generic;
- using System.Threading;
- using System.Windows;
- using System.Windows.Threading;
- namespace OpenSEMI.ClientBase.Handlers
- {
- public class WaferStatusHandler : IHandler
- {
- public static readonly List<string> ReverseModules = new List<string>
- {
- "LP1",
- "LP2",
- "LP3",
- "LP4"
- };
- private Func<string, List<WaferInfo>> GetWaferStatusByModule;
- private static object lockObj = new object();
- public Dictionary<string, ModuleWaferManager> WaferStatusDic
- {
- get;
- private set;
- }
- public MsgPool looper
- {
- get;
- private set;
- }
- public WaferStatusHandler(Func<string, List<WaferInfo>> funcGetWaferStatus, List<string> allModules)
- {
- WaferStatusDic = new Dictionary<string, ModuleWaferManager>();
- looper = new MsgPool(500, Do, null, false);
- GetWaferStatusByModule = funcGetWaferStatus;
- allModules.ForEach(delegate(string key)
- {
- InitWafersByModule(key);
- });
- }
- public void Handle()
- {
- looper.Run();
- }
- private void InitWafersByModule(string moduleID)
- {
- lock (lockObj)
- {
- if (!WaferStatusDic.ContainsKey(moduleID))
- {
- WaferStatusDic.Add(moduleID, new ModuleWaferManager(moduleID));
- List<WaferInfo> list = GetWaferStatusByModule(moduleID);
- if (list != null)
- {
- ModuleWaferManager moduleWaferManager = WaferStatusDic[moduleID];
- for (int i = 0; i < list.Count; i++)
- {
- moduleWaferManager.Wafers.Add(list[i]);
- }
- if (ReverseModules.Contains(moduleID))
- {
- moduleWaferManager.Wafers.Reverse();
- }
- }
- }
- }
- }
- private void Do(MsgPool pool)
- {
- lock (lockObj)
- {
- if (Application.Current != null && Application.Current.Dispatcher != null)
- {
- foreach (KeyValuePair<string, ModuleWaferManager> item in WaferStatusDic)
- {
- List<WaferInfo> mWafers = GetWaferStatusByModule(item.Key);
- Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (ThreadStart)delegate
- {
- if (mWafers != null && mWafers.Count == item.Value.Wafers.Count)
- {
- for (int i = 0; i < mWafers.Count; i++)
- {
- int index = (!ReverseModules.Contains(item.Key)) ? i : (mWafers.Count - i - 1);
- item.Value.Wafers[i].WaferStatus = mWafers[index].WaferStatus;
- item.Value.Wafers[i].WaferID = mWafers[index].WaferID;
- item.Value.Wafers[i].SourceName = mWafers[index].SourceName;
- item.Value.Wafers[i].SequenceName=mWafers[index].SequenceName;
- }
- }
- });
- }
- }
- }
- }
- }
- }
|