using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Configuration;
using System.Data.Entity;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using XdCxRhDW.Dto;
using XdCxRhDW.Entity;
using XdCxRhDW.Framework;
using XdCxRhDW.Repostory;
namespace XdCxRhDW.App
{
///
/// 两星一地定位取参考服务
///
public class X2D1PosRefService
{
public static X2D1PosRefService Instance { get; private set; } = new X2D1PosRefService();
readonly List handles = new List();
public double TakeRefTime;
public X2D1PosRefService()
{
TakeRefTime = AppConfigHelper.Get("TakeRefTime", 10);
}
public void AddPosDto(List dtos)
{
try
{
var dto = dtos.First();
lock (this)
{
var firstDto = handles.FirstOrDefault(m => m.TaskId == dto.TaskID);
if (firstDto == null)
{
firstDto = new X2D1PosHandle(dto.TaskID.Value, TakeRefTime);
handles.Add(firstDto);
}
firstDto.Append(dtos);
}
}
catch (Exception ex)
{
LogHelper.Error($"【任务{dtos.First().TaskID}】添加取参考信号流程异常,{ex.Message}", ex).GetAwaiter();
}
}
public void Stop(int taskID)
{
try
{
lock (this)
{
var firstDto = handles.FirstOrDefault(m => m.TaskId == taskID);
if (firstDto != null)
{
firstDto.Stop();
handles.Remove(firstDto);
}
}
}
catch (Exception ex)
{
LogHelper.Error($"停止【任务{taskID}】取参考信号流程异常,{ex.Message}", ex).GetAwaiter();
}
}
}
}