using DevExpress.XtraEditors; using DxHelper; using ExtensionsDev; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Data.Entity; using System.Drawing; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Documents; using System.Windows.Forms; using XdCxRhDW.Dto; using XdCxRhDW.Entity; using XdCxRhDW.Repostory; namespace XdCxRhDW.App.CorTools { public partial class ResampleForm : DevExpress.XtraEditors.XtraForm { public SatInfo info; public ResampleForm() { InitializeComponent(); txtOutFile.Text = ""; txtFile.UseChooseWaveFile((file, fsHz) => { this.txtOutDir.Text = Path.GetDirectoryName(file); if (fsHz > 0) txtFs.Text = (fsHz / 1e3).ToString(); else this.txtFs.Text = ""; }).UseDoubleClickToSelectAll(); txtOutDir.UseChooseDir().UseDoubleClickToSelectAll(); this.txtOutFile.UseDoubleClickToSelectAll(); this.layoutControl1.UseDefault(); } private void btnCancel_Click(object sender, EventArgs e) { this.DialogResult = DialogResult.Cancel; } private async void btnOk_ClickAsync(object sender, EventArgs e) { double fsHz, outFsHz, timeout; if (!double.TryParse(txtFs.Text, out fsHz)) { DxHelper.MsgBoxHelper.ShowError($"原始采样率非数字!"); return; } if (!double.TryParse(txtOutFs.Text, out outFsHz)) { DxHelper.MsgBoxHelper.ShowError($"变换后采样率非数字!"); return; } if (!File.Exists(txtFile.Text)) { DxHelper.MsgBoxHelper.ShowError($"文件[{txtFile.Text}]不存在"); return; } if (!Directory.Exists(txtOutDir.Text)) { DxHelper.MsgBoxHelper.ShowError($"输出目录[{txtOutDir.Text}]不存在"); return; } if (!double.TryParse(txtTimeout.Text, out timeout)) { DxHelper.MsgBoxHelper.ShowError($"超时时间非数字!"); return; } if (timeout <= 0) timeout = 120; txtOutFile.Text = ""; fsHz *= 1e3; outFsHz *= 1e3; try { layoutControl1.Enabled = false; if (SysConfig.Config== null) { layoutControl1.Enabled = true; DxHelper.MsgBoxHelper.ShowWarning($"请在系统设置中配置基础信息"); return; } string file = null; try { file = await HttpHelper.UploadFileAsync(txtFile.Text, SysConfig.GetBaseUrl()); } catch (Exception ex) { layoutControl1.Enabled = true; Serilog.Log.Error(ex, ex.Message); DxHelper.MsgBoxHelper.ShowError(ex.Message); return; } ResampleRequestDto dto = new ResampleRequestDto() { File = file, FsHz = (int)fsHz, OutFsHz = (int)outFsHz, TimeoutSeconds = (int)timeout, }; var response = await HttpHelper.PostRequestAsync(SysConfig.GetUrl("DetectCg/Resample"), dto, dto.TimeoutSeconds); if (response.code == 200) { string outFile = Path.Combine(txtOutDir.Text, Path.GetFileNameWithoutExtension(txtFile.Text) + $"_Resample{txtOutFs.Text}K.dat"); if (await HttpHelper.DownloadFileAsync(SysConfig.GetBaseUrl(), response.data.File, outFile)) this.txtOutFile.Text = outFile; else { Serilog.Log.Error($"下载文件[{response.data.File}]失败"); MsgBoxHelper.ShowError($"下载文件[{response.data.File}]失败"); } } else { MsgBoxHelper.ShowError(response.msg); } } catch (TaskCanceledException) { Serilog.Log.Warning("变采样Http接口调用超时"); DxHelper.MsgBoxHelper.ShowInfo("变采样Http接口调用超时"); } catch (Exception ex) { Serilog.Log.Error(ex, "变采样出错"); DxHelper.MsgBoxHelper.ShowError("变采样出错"); } finally { layoutControl1.Enabled = true; } } } }