diff --git a/PCUT/Http.Core/Constants/HttpConstants.cs b/PCUT/Http.Core/Constants/HttpConstants.cs index 27d3925..015904e 100644 --- a/PCUT/Http.Core/Constants/HttpConstants.cs +++ b/PCUT/Http.Core/Constants/HttpConstants.cs @@ -33,6 +33,7 @@ public const string Upload = "api/files/upload"; public const string Download = "api/files/{0}"; + public const string Cut = "api/files/{0}/cut"; public const string CdrFiles = "api/cdr-files"; public const string CdrFileById = "api/cdr-files/{0}"; diff --git a/PCUT/PCUT/Pages/DesignCenter/CutFilesDialog.xaml.cs b/PCUT/PCUT/Pages/DesignCenter/CutFilesDialog.xaml.cs index c964ee2..096290e 100644 --- a/PCUT/PCUT/Pages/DesignCenter/CutFilesDialog.xaml.cs +++ b/PCUT/PCUT/Pages/DesignCenter/CutFilesDialog.xaml.cs @@ -46,7 +46,7 @@ namespace PCUT.Pages _portName = portName; _portSettings = portSetting; _designCenterViewModel = designCenterViewModel; - //StartButton.IsEnabled = !(portName is null); + StartButton.IsEnabled = !(portName is null); ViewModels = DataContext as CutDialogViewModel; } @@ -84,12 +84,13 @@ namespace PCUT.Pages _cancellationTokenSource = new CancellationTokenSource(); ViewModels.PrintCommand = string.Empty; - //using (var serialPort = new SerialPort(_portName, _portSettings.BaudRate) - //{ - // DataBits = _portSettings.Databits, - // Parity = _portSettings.ParityList[_portSettings.SelectedParity], - // StopBits = _portSettings.StopbitsList[_portSettings.SelectedStopbits] - //}) + _ = ViewModels.CutFileAsync(_designCenterViewModel.FileId); + using (var serialPort = new SerialPort(_portName, _portSettings.BaudRate) + { + DataBits = _portSettings.Databits, + Parity = _portSettings.ParityList[_portSettings.SelectedParity], + StopBits = _portSettings.StopbitsList[_portSettings.SelectedStopbits] + }) { var errorMessage = string.Empty; try @@ -100,7 +101,7 @@ namespace PCUT.Pages (_svgData.OriginWidth.Value, _svgData.OriginHeight.Value), (_designCenterViewModel.Width, _designCenterViewModel.Height), _portSettings.Speed); - //serialPort.Open(); + serialPort.Open(); Task waitTask = Task.CompletedTask; foreach (var (path, waitTime) in data) { @@ -112,7 +113,7 @@ namespace PCUT.Pages waitTask.Wait(); try { - //serialPort.Write(path); + serialPort.Write(path); } catch { @@ -150,7 +151,7 @@ namespace PCUT.Pages { try { - //serialPort.Close(); + serialPort.Close(); Task.Delay(1000).Wait(); } catch diff --git a/PCUT/PCUT/ViewModels/CutDialogViewModel.cs b/PCUT/PCUT/ViewModels/CutDialogViewModel.cs index 540e788..dc83a68 100644 --- a/PCUT/PCUT/ViewModels/CutDialogViewModel.cs +++ b/PCUT/PCUT/ViewModels/CutDialogViewModel.cs @@ -4,6 +4,9 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Http.Core; +using Http.Core.Extensions; +using static Http.Core.Constants.HttpConstants; namespace PCUT.ViewModels { @@ -18,5 +21,19 @@ namespace PCUT.ViewModels SetProperty(ref _printCommand, value); } } + + public async Task CutFileAsync(string fileId) + { + using (var httpClient = HttpClientFactory.CreateClient(ClientNames.ApiClient)) + { + try + { + _ = await httpClient.GetAsync(Api.Cut.FormatRoute(fileId)); + } + catch + { + } + } + } } }