|
@@ -30,9 +30,7 @@ namespace XdCxRhDW.App.CorTools
|
|
|
public partial class DetectToolForm : DevExpress.XtraEditors.XtraForm
|
|
|
{
|
|
|
static readonly string inifile = Path.Combine(Application.StartupPath, "par.ini");
|
|
|
- volatile bool beRunning = false;
|
|
|
- private string uploadUrL;
|
|
|
- private string token;
|
|
|
+ private string baseUrl;
|
|
|
BindingList<CafResult> gridSource = new BindingList<CafResult>();
|
|
|
|
|
|
public DetectToolForm()
|
|
@@ -102,6 +100,14 @@ namespace XdCxRhDW.App.CorTools
|
|
|
this.gridControl1.DataSource = gridSource;
|
|
|
btnCheck.Enabled = !ckKY.Checked && !ckIBS.Checked && !chkDama.Checked ? false : true;
|
|
|
ReadIni();
|
|
|
+ using (RHDWContext db = new RHDWContext())
|
|
|
+ {
|
|
|
+ var res = await db.SysSetings.FirstOrDefaultAsync();
|
|
|
+ if (res != null)
|
|
|
+ {
|
|
|
+ this.baseUrl = $"http://{IpHelper.GetLocalIp()}:{res.HttpPort}/api/";
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
|
|
@@ -135,7 +141,7 @@ namespace XdCxRhDW.App.CorTools
|
|
|
/// <param name="e"></param>
|
|
|
private void gridView1_MouseDown(object sender, MouseEventArgs e)
|
|
|
{
|
|
|
- if (e.Button == MouseButtons.Right && !beRunning)
|
|
|
+ if (e.Button == MouseButtons.Right)
|
|
|
{
|
|
|
popupMenu1.ShowPopup(Cursor.Position);
|
|
|
}
|
|
@@ -220,34 +226,22 @@ namespace XdCxRhDW.App.CorTools
|
|
|
dto.dmcType = dmcType;
|
|
|
try
|
|
|
{
|
|
|
- using (RHDWContext db = new RHDWContext())
|
|
|
- {
|
|
|
- var res = await db.SysSetings.FirstOrDefaultAsync();
|
|
|
- if (res != null)
|
|
|
- {
|
|
|
- uploadUrL = $"http://{IpHelper.GetLocalIp()}:{res.HttpPort}/api/DetectCg";
|
|
|
- }
|
|
|
- }
|
|
|
- dto.file1 = UpLoadFile(btnFile1.Text);
|
|
|
+ dto.file1 = HttpHelper.UploadFile(btnFile1.Text, baseUrl + "File/UploadFileAsync");
|
|
|
dto.fsHz = double.Parse(tefs.Text) * 1e6;
|
|
|
- // 构建上传请求的 Uri
|
|
|
- string uploadUri = $"{uploadUrL}/DetectCalc";
|
|
|
-
|
|
|
var content = new StringContent(JsonConvert.SerializeObject(dto), System.Text.Encoding.UTF8, "application/json");
|
|
|
- var dmcResult = HttpHelper.PostRequest<IEnumerable<DetectResDto>>(uploadUri, content);
|
|
|
+ var dmcResult = HttpHelper.PostRequest<IEnumerable<DetectResDto>>(baseUrl + "DetectCg/DetectCalc", content);
|
|
|
if (dmcResult != null)
|
|
|
{
|
|
|
gridSource.Clear();
|
|
|
foreach (var dmcItem in dmcResult)
|
|
|
{
|
|
|
- token = dmcItem.Token;
|
|
|
gridSource.Add(new CafResult()
|
|
|
{
|
|
|
file1 = btnFile1.Text,
|
|
|
file2 = btnFile2.Text,
|
|
|
smpstart = dmcItem.Start,
|
|
|
smplen = dmcItem.Length,
|
|
|
- tm=dmcItem.TimeMs,
|
|
|
+ tm = dmcItem.TimeMs,
|
|
|
});
|
|
|
}
|
|
|
}
|
|
@@ -316,16 +310,8 @@ namespace XdCxRhDW.App.CorTools
|
|
|
XcorrStruct xItem = new XcorrStruct();
|
|
|
try
|
|
|
{
|
|
|
- using (RHDWContext db = new RHDWContext())
|
|
|
- {
|
|
|
- var res = await db.SysSetings.FirstOrDefaultAsync();
|
|
|
- if (res != null)
|
|
|
- {
|
|
|
- uploadUrL = $"http://{IpHelper.GetLocalIp()}:{res.HttpPort}/api/DetectCg";
|
|
|
- }
|
|
|
- }
|
|
|
- xItem.file1 = UpLoadFile(btnFile1.Text);
|
|
|
- xItem.file2 = UpLoadFile(btnFile2.Text);
|
|
|
+ xItem.file1 = HttpHelper.UploadFile(btnFile1.Text, baseUrl + "File/UploadFileAsync");
|
|
|
+ xItem.file2 = HttpHelper.UploadFile(btnFile2.Text, baseUrl + "File/UploadFileAsync");
|
|
|
xItem.smpCount = int.Parse(teCount.Text);
|
|
|
xItem.samplingRate = Convert.ToInt32(double.Parse(tefs.Text) * 1e6);
|
|
|
xItem.dtCenter = int.Parse(teCenter.Text);
|
|
@@ -358,29 +344,24 @@ namespace XdCxRhDW.App.CorTools
|
|
|
|
|
|
WriteIni();
|
|
|
btnCalc.Text = "停止";
|
|
|
- beRunning = true;
|
|
|
gridSource.Clear();
|
|
|
foreach (var xcitem in xcorrs)
|
|
|
{
|
|
|
- // 构建上传请求的 Uri
|
|
|
- string uploadUri = $"{uploadUrL}/EstimationCalc";
|
|
|
-
|
|
|
var content = new StringContent(JsonConvert.SerializeObject(xcitem), System.Text.Encoding.UTF8, "application/json");
|
|
|
try
|
|
|
{
|
|
|
- var result = HttpHelper.PostRequest<EstimationResDto>(uploadUri, content);
|
|
|
+ var result = HttpHelper.PostRequest<EstimationResDto>(baseUrl+ "DetectCg/EstimationCalc", content);
|
|
|
if (result != null)
|
|
|
{
|
|
|
- token = result.Token;
|
|
|
gridSource.Add(new CafResult()
|
|
|
{
|
|
|
file1 = btnFile1.Text,
|
|
|
file2 = btnFile2.Text,
|
|
|
smpstart = result.Smpstart,
|
|
|
smplen = result.Smplen,
|
|
|
- dt=result.Dt,
|
|
|
- df= result.Df,
|
|
|
- snr= result.Snr,
|
|
|
+ dt = result.Dt,
|
|
|
+ df = result.Df,
|
|
|
+ snr = result.Snr,
|
|
|
tm = result.TimeMs,
|
|
|
});
|
|
|
gridView1.FocusedRowHandle = gridSource.Count - 1;
|
|
@@ -395,54 +376,12 @@ namespace XdCxRhDW.App.CorTools
|
|
|
}
|
|
|
|
|
|
btnCalc.Text = "计算";
|
|
|
- beRunning = false;
|
|
|
|
|
|
}
|
|
|
private void StopCalc()
|
|
|
- { // 构建上传请求的 Uri
|
|
|
- string uploadUri = $"{uploadUrL}/StopEstimationCalc?token={token}";
|
|
|
- var content = new StringContent("", System.Text.Encoding.UTF8, "application/json");
|
|
|
- try
|
|
|
- {
|
|
|
- var result = HttpHelper.PostRequest<bool>(uploadUri, content);
|
|
|
- if (result)
|
|
|
- {
|
|
|
- DxHelper.MsgBoxHelper.ShowInfo($"停止成功");
|
|
|
- }
|
|
|
- }
|
|
|
- catch (Exception)
|
|
|
- {
|
|
|
- }
|
|
|
+ {
|
|
|
}
|
|
|
- private string UpLoadFile(string filePath)
|
|
|
- {
|
|
|
- string file = string.Empty;
|
|
|
-
|
|
|
- // 构建上传请求的 Uri
|
|
|
- string uploadUri = $"{uploadUrL}/UploadFile";
|
|
|
- try
|
|
|
- {
|
|
|
- // 添加文件内容到 MultipartFormDataContent
|
|
|
- byte[] fileBytes = File.ReadAllBytes(filePath);
|
|
|
|
|
|
- // 创建 MultipartFormDataContent 用于封装文件内容
|
|
|
- MultipartFormDataContent content = new MultipartFormDataContent();
|
|
|
- ByteArrayContent fileContent = new ByteArrayContent(fileBytes);
|
|
|
- content.Add(fileContent, "file", Path.GetFileName(filePath));
|
|
|
-
|
|
|
- // 发送上传请求
|
|
|
- var filedto = HttpHelper.PostRequest<FileUploadResDto>(uploadUri, content);
|
|
|
- if (filedto != null)
|
|
|
- {
|
|
|
- file = filedto.FileName;
|
|
|
- }
|
|
|
- }
|
|
|
- catch (Exception ex)
|
|
|
- {
|
|
|
- throw new Exception($"上传文件{filePath}到{uploadUri}失败!");
|
|
|
- }
|
|
|
- return file;
|
|
|
- }
|
|
|
private async Task<CafResult> ExecuteCorAsync(XcorrStruct xItem)
|
|
|
{
|
|
|
|
|
@@ -453,20 +392,17 @@ namespace XdCxRhDW.App.CorTools
|
|
|
{
|
|
|
DxHelper.MsgBoxHelper.ShowError($"内部错误");
|
|
|
btnCalc.Text = "计算";
|
|
|
- beRunning = false;
|
|
|
return null;
|
|
|
}
|
|
|
else if (result.flag == -1)
|
|
|
{
|
|
|
DxHelper.MsgBoxHelper.ShowError($"计算所需数据超出文件范围");
|
|
|
btnCalc.Text = "计算";
|
|
|
- beRunning = false;
|
|
|
return null;
|
|
|
}
|
|
|
else if (result.flag == -3)
|
|
|
{
|
|
|
btnCalc.Text = "计算";
|
|
|
- beRunning = false;
|
|
|
return null;
|
|
|
}
|
|
|
return result;
|