|
@@ -14,6 +14,7 @@ using System.Web;
|
|
|
using Newtonsoft.Json.Linq;
|
|
|
using XdCxRhDW.App.CpuCgTools;
|
|
|
using static XdCxRhDW.App.WebAPI.Startup;
|
|
|
+using System.Diagnostics;
|
|
|
namespace XdCxRhDW.App.WebAPI
|
|
|
{
|
|
|
/// <summary>
|
|
@@ -22,6 +23,9 @@ namespace XdCxRhDW.App.WebAPI
|
|
|
public class DetectCgController : BaseController
|
|
|
{
|
|
|
|
|
|
+ private static readonly object thisLock = new object();
|
|
|
+ Dictionary<string, XcorrUtils> keyValues = new Dictionary<string, XcorrUtils>();
|
|
|
+
|
|
|
private string UploadFolder = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "UploadFolder");
|
|
|
private (bool, string) ValidateCalcParam(CalcDto dto)
|
|
|
{
|
|
@@ -67,6 +71,7 @@ namespace XdCxRhDW.App.WebAPI
|
|
|
[HttpPost]
|
|
|
public async Task<AjaxResult<EstimationResDto>> EstimationCalc(CalcDto dto)
|
|
|
{
|
|
|
+ var token = Request.GetCorrelationId().ToString();
|
|
|
dto.file1 = Path.Combine(UploadFolder, dto.file1);
|
|
|
dto.file2 = Path.Combine(UploadFolder, dto.file2);
|
|
|
var vpres = ValidateCalcParam(dto);
|
|
@@ -97,43 +102,92 @@ namespace XdCxRhDW.App.WebAPI
|
|
|
xItem.smpStart = dto.smpStart;
|
|
|
xItem.snrThreshold = dto.snrThreshold;
|
|
|
|
|
|
- var result = await XcorrUtils.Calc(xItem);
|
|
|
- //开始计算
|
|
|
- if (result.flag == -2)
|
|
|
- {
|
|
|
- Serilog.Log.Warning("参估计算内部错误!");
|
|
|
- return Error<EstimationResDto>("参估计算内部错误!");
|
|
|
- }
|
|
|
- else if (result.flag == -1)
|
|
|
- {
|
|
|
- Serilog.Log.Warning("参估计算所需数据超出文件范围!");
|
|
|
- return Error<EstimationResDto>("参估计算所需数据超出文件范围!");
|
|
|
- }
|
|
|
EstimationResDto resDto = new EstimationResDto();
|
|
|
- resDto.TimeMs = result.tm;
|
|
|
- resDto.Smpstart = result.smpstart;
|
|
|
- resDto.Smplen = result.smplen;
|
|
|
- resDto.File1 = result.file1;
|
|
|
- resDto.File2 = result.file2;
|
|
|
- if (result.flag == 1)
|
|
|
+ try
|
|
|
{
|
|
|
- resDto.Dt = result.dt.Value;
|
|
|
- resDto.Df = result.df.Value;
|
|
|
- resDto.Snr = result.snr.Value;
|
|
|
+ XcorrUtils xcorr = new XcorrUtils();
|
|
|
+ lock (thisLock)
|
|
|
+ {
|
|
|
+ keyValues.Add(token, xcorr);
|
|
|
+ }
|
|
|
+ var result = await xcorr.Calc(xItem);
|
|
|
+ //开始计算
|
|
|
+ if (result.flag == -2)
|
|
|
+ {
|
|
|
+ Serilog.Log.Warning("参估计算内部错误!");
|
|
|
+ return Error<EstimationResDto>("参估计算内部错误!");
|
|
|
+ }
|
|
|
+ else if (result.flag == -1)
|
|
|
+ {
|
|
|
+ Serilog.Log.Warning("参估计算所需数据超出文件范围!");
|
|
|
+ return Error<EstimationResDto>("参估计算所需数据超出文件范围!");
|
|
|
+ }
|
|
|
+ resDto.Token = token;
|
|
|
+ resDto.TimeMs = result.tm;
|
|
|
+ resDto.Smpstart = result.smpstart;
|
|
|
+ resDto.Smplen = result.smplen;
|
|
|
+ resDto.File1 = result.file1;
|
|
|
+ resDto.File2 = result.file2;
|
|
|
+ if (result.flag == 1)
|
|
|
+ {
|
|
|
+ resDto.Dt = result.dt.Value;
|
|
|
+ resDto.Df = result.df.Value;
|
|
|
+ resDto.Snr = result.snr.Value;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
- try
|
|
|
+ catch (Exception ex)
|
|
|
{
|
|
|
- //删除计算得文件
|
|
|
- File.Delete(dto.file1);
|
|
|
- File.Delete(dto.file2);
|
|
|
+ return Error<EstimationResDto>($"执行参估计算异常,{ex.Message}");
|
|
|
}
|
|
|
- catch
|
|
|
+ finally
|
|
|
{
|
|
|
+ lock (thisLock)
|
|
|
+ {
|
|
|
+ keyValues.Remove(token);
|
|
|
+ }
|
|
|
+ try
|
|
|
+ {
|
|
|
+ //删除计算得文件
|
|
|
+ File.Delete(dto.file1);
|
|
|
+ File.Delete(dto.file2);
|
|
|
+ }
|
|
|
+ catch
|
|
|
+ {
|
|
|
+ }
|
|
|
}
|
|
|
return Success(resDto);
|
|
|
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// 参估计算停止
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="token"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [HttpPost]
|
|
|
+ public async Task<AjaxResult<bool>> StopEstimationCalc(string token)
|
|
|
+ {
|
|
|
+ return await Task.Run(() =>
|
|
|
+ {
|
|
|
+ lock (thisLock)
|
|
|
+ {
|
|
|
+ if (keyValues.ContainsKey(token))
|
|
|
+ {
|
|
|
+ keyValues[token].StopCalc();
|
|
|
+ return Success(true);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return Success(false);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
|
|
|
private (bool, string) ValidateDetectParam(DetectDto dto)
|
|
|
{
|
|
@@ -166,6 +220,7 @@ namespace XdCxRhDW.App.WebAPI
|
|
|
[HttpPost]
|
|
|
public async Task<AjaxResult<IEnumerable<DetectResDto>>> DetectCalc(DetectDto dto)
|
|
|
{
|
|
|
+ var token = Request.GetCorrelationId().ToString();
|
|
|
dto.file1 = Path.Combine(UploadFolder, dto.file1);
|
|
|
var vpres = ValidateDetectParam(dto);
|
|
|
if (!vpres.Item1)
|
|
@@ -176,12 +231,18 @@ namespace XdCxRhDW.App.WebAPI
|
|
|
List<DetectResDto> list = new List<DetectResDto>();
|
|
|
try
|
|
|
{
|
|
|
- var dmcResult = await XcorrUtils.DmcCheckAsync(dto.file1,dto.fsHz, dto.dmcType);
|
|
|
+ XcorrUtils xcorr = new XcorrUtils();
|
|
|
+ lock (thisLock)
|
|
|
+ {
|
|
|
+ keyValues.Add(token, xcorr);
|
|
|
+ }
|
|
|
+ var dmcResult = await xcorr.DmcCheckAsync(dto.file1, dto.fsHz, dto.dmcType);
|
|
|
foreach (var dmcItem in dmcResult)
|
|
|
{
|
|
|
DetectResDto detectRes = new DetectResDto(dmcItem.Start, dmcItem.Length, dmcItem.UserName);
|
|
|
detectRes.File1 = dto.file1;
|
|
|
detectRes.TimeMs = dmcItem.Times;
|
|
|
+ detectRes.Token = token;
|
|
|
list.Add(detectRes);
|
|
|
|
|
|
}
|
|
@@ -192,6 +253,10 @@ namespace XdCxRhDW.App.WebAPI
|
|
|
}
|
|
|
finally
|
|
|
{
|
|
|
+ lock (thisLock)
|
|
|
+ {
|
|
|
+ //keyValues.Remove(token);
|
|
|
+ }
|
|
|
try
|
|
|
{
|
|
|
//删除检测的文件
|
|
@@ -206,6 +271,31 @@ namespace XdCxRhDW.App.WebAPI
|
|
|
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// 信号检测停止
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="token"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [HttpPost]
|
|
|
+ public async Task<AjaxResult<bool>> StopDetectCalc(string token)
|
|
|
+ {
|
|
|
+ return await Task.Run(() =>
|
|
|
+ {
|
|
|
+ lock (thisLock)
|
|
|
+ {
|
|
|
+ if (keyValues.ContainsKey(token))
|
|
|
+ {
|
|
|
+ keyValues[token].StopDm();
|
|
|
+ return Success(true);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return Success(false);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
/// <summary>
|
|
|
/// 上传文件
|
|
@@ -222,7 +312,7 @@ namespace XdCxRhDW.App.WebAPI
|
|
|
await Request.Content.ReadAsMultipartAsync(provider);
|
|
|
Directory.CreateDirectory(UploadFolder);
|
|
|
var content = provider.Contents.First();
|
|
|
- var fileName = Guid.NewGuid().ToString()+".dat";
|
|
|
+ var fileName = Guid.NewGuid().ToString() + ".dat";
|
|
|
var fileData = await content.ReadAsByteArrayAsync();
|
|
|
FileDto fileDto = new FileDto();
|
|
|
fileDto.FileName = fileName;
|