54 lines
1.9 KiB
C#
54 lines
1.9 KiB
C#
using Aurora;
|
|
using Aurora.Api;
|
|
using VisionCommon;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Reactive.Linq;
|
|
using System.Threading.Tasks;
|
|
using VisionSequence.Pattern;
|
|
|
|
namespace VisionUI.Pattern {
|
|
/// <summary>
|
|
/// 강제 OK 핸들러
|
|
/// </summary>
|
|
public static class ForceOkHandler {
|
|
private static object _lock = new object();
|
|
private static Logger _logger = new Logger(typeof(ForceOkHandler).Name);
|
|
private static Dictionary<FovInfo, IDisposable> _forceOkHandlers = new Dictionary<FovInfo, IDisposable>();
|
|
/// <summary>
|
|
/// 핸들러 추가
|
|
/// </summary>
|
|
/// <param name="fovInfo">핸들러 사전 키 (Fov 정보)</param>
|
|
public static void SetHandler(FovInfo fovInfo) {
|
|
lock (_lock) {
|
|
if (!_forceOkHandlers.ContainsKey(fovInfo)) {
|
|
_forceOkHandlers.Add(fovInfo, CreateHandler(fovInfo));
|
|
}
|
|
}
|
|
}
|
|
|
|
private static IDisposable CreateHandler(FovInfo fovInfo) {
|
|
return VisionEnv.AuroraEnv.EventObservable.AsObservable(VisionEventId.PATTERN_FORCE_OK_REQUEST)
|
|
.Where(x => x.From == fovInfo.GetKey())
|
|
.Subscribe(em => DoEvent(em));
|
|
}
|
|
|
|
private static void DoEvent(EventMessage em) {
|
|
_logger.FuncI();
|
|
|
|
Task.Run(() => {
|
|
lock (_lock) {
|
|
var forceOkReqParam = em.Param as ForceOkReqParam;
|
|
forceOkReqParam.PatternResult = ForceOkWindow.Show(
|
|
forceOkReqParam.FovInfo,
|
|
forceOkReqParam.PatternIndex,
|
|
forceOkReqParam.FindImage,
|
|
forceOkReqParam.PatternResult);
|
|
forceOkReqParam.IsDone = true;
|
|
}
|
|
});
|
|
}
|
|
}
|
|
}
|