diff options
| author | Victoria Plitt <Victoria.Plitt@twine-s.com> | 2022-01-30 14:50:12 +0200 |
|---|---|---|
| committer | Victoria Plitt <Victoria.Plitt@twine-s.com> | 2022-01-30 14:50:12 +0200 |
| commit | bfc9623f1b20c0a17e54bfbcdc59c43104afec78 (patch) | |
| tree | 4c51f8cac7e22a5e5ce7bb95d2df439deebf7056 /Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ThreadExtensions/ViewModels/TestResultViewVM.cs | |
| parent | 7baca4061db66b1c5fde1c200f0d9323ba1be23f (diff) | |
| download | Tango-bfc9623f1b20c0a17e54bfbcdc59c43104afec78.tar.gz Tango-bfc9623f1b20c0a17e54bfbcdc59c43104afec78.zip | |
Added Data grid displaying all available recorded files for download.
Related Work Items: #5820
Diffstat (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ThreadExtensions/ViewModels/TestResultViewVM.cs')
| -rw-r--r-- | Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ThreadExtensions/ViewModels/TestResultViewVM.cs | 119 |
1 files changed, 114 insertions, 5 deletions
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ThreadExtensions/ViewModels/TestResultViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ThreadExtensions/ViewModels/TestResultViewVM.cs index 41be789ed..68a886f99 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ThreadExtensions/ViewModels/TestResultViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ThreadExtensions/ViewModels/TestResultViewVM.cs @@ -1,8 +1,11 @@ using Microsoft.Win32; +using Microsoft.WindowsAPICodePack.Dialogs; using System; using System.Collections.Generic; using System.IO; using System.Linq; +using System.Data.Entity; +using System.Diagnostics; using System.Text; using System.Threading.Tasks; using Tango.BL; @@ -10,6 +13,7 @@ using Tango.BL.ActionLogs; using Tango.BL.DTO; using Tango.BL.Entities; using Tango.BL.Enumerations; +using Tango.BL.ValueObjects; using Tango.Core.Commands; using Tango.MachineStudio.Common.Notifications; using Tango.MachineStudio.ThreadExtensions.Models; @@ -21,9 +25,9 @@ namespace Tango.MachineStudio.ThreadExtensions.ViewModels { private INotificationProvider _notification; private IActionLogManager _actionLogManager; - + #region Properties - + private string _threadName; /// <summary> /// Gets or sets the name of the thread. Using in print @@ -51,7 +55,7 @@ namespace Tango.MachineStudio.ThreadExtensions.ViewModels get { return _isSelected; } set { _isSelected = value; RaisePropertyChangedAuto(); } } - + private RmlExtensionTestResult _testResult; public RmlExtensionTestResult TestResult @@ -59,19 +63,124 @@ namespace Tango.MachineStudio.ThreadExtensions.ViewModels get { return _testResult; } set { _testResult = value; RaisePropertyChangedAuto(); + RaisePropertyChanged(nameof(TestResultsFiles)); } } - - #endregion + public List<RmlExtensionTestResultsFile> TestResultsFiles + { + get + { + return TestResult.RmlExtensionTestResultsFiles.ToList(); + } + } + public RelayCommand<RmlExtensionTestResultsFile> DeleteCommand { get; set; } + public RelayCommand<RmlExtensionTestResultsFile> DownLoadFileCommand { get; set; } + public RelayCommand UploadCommand { get; set; } + public RelayCommand DownLoadAllCommand { get; set; } + #endregion + public TestResultViewVM(INotificationProvider notification, IActionLogManager actionLogManager) { _notification = notification; _actionLogManager = actionLogManager; + + UploadCommand = new RelayCommand(UploadFiles); + DownLoadFileCommand = new RelayCommand<RmlExtensionTestResultsFile>(DownLoadFile); + DeleteCommand = new RelayCommand<RmlExtensionTestResultsFile>(DeleteFile); + DownLoadAllCommand = new RelayCommand(DownLoadAllFiles); } + + #region TestResultsFiles + private async void UploadFiles(object obj) + { + OpenFileDialog dlg = new OpenFileDialog(); + dlg.Title = "Select data file"; + dlg.Filter = "CSV Files|*.csv"; + dlg.Multiselect = true; + if (dlg.ShowDialog().Value) + { + try + { + var files = dlg.FileNames.ToList(); + + using (ObservablesContext db = ObservablesContext.CreateDefault()) + { + var testResult = await db.RmlExtensionTestResults.Where(x => x.Guid == TestResult.Guid).Include(t1 => t1.RmlExtensionTestResultsFiles).FirstOrDefaultAsync(); + foreach (var strpath in files) + { + var testResultfile = new RmlExtensionTestResultsFile(); + testResultfile.FileName = Path.GetFileName(strpath); + //temporary!!! + testResultfile.FilePath = strpath; + + // TestResult.RmlExtensionTestResultsFiles.Add(testResultfile); + testResult.RmlExtensionTestResultsFiles.Add(testResultfile); + } + if (testResult != null) + { + await db.SaveChangesAsync(); + } + TestResult.RmlExtensionTestResultsFiles = testResult.RmlExtensionTestResultsFiles;///????? + RaisePropertyChanged(nameof(TestResultsFiles)); + } + _notification.ShowInfo("File successfully loaded."); + } + catch (Exception ex) + { + _notification.ShowError($"An error occurred while trying to import the file.\n{ex.FlattenMessage()}"); + } + } + + } + + private void DownLoadFile(RmlExtensionTestResultsFile file) + { + SaveFileDialog dlg = new SaveFileDialog(); + dlg.Title = "Save the csv file"; + dlg.Filter = "CSV Files|*.csv"; + dlg.DefaultExt = ".csv"; + dlg.FileName = file.FileName; + if (dlg.ShowDialog().Value) + { + /// + } + } + + private void DownLoadAllFiles() + { + CommonOpenFileDialog dlg = new CommonOpenFileDialog(); + dlg.Title = "Select folder."; + dlg.IsFolderPicker = true; + if (dlg.ShowDialog() == CommonFileDialogResult.Ok) + { + var filesPath = TestResult.RmlExtensionTestResultsFiles.Select( x=>x.FilePath).ToList(); + ///// + } + } + + private async void DeleteFile(RmlExtensionTestResultsFile file) + { + if (_notification.ShowQuestion("Are you sure you want to delete the selected file?")) + { + using (ObservablesContext db = ObservablesContext.CreateDefault()) + { + var deletefile = db.RmlExtensionTestResultsFiles.FirstOrDefault(x => x.Guid == file.Guid); + if(deletefile != null) + { + db.RmlExtensionTestResultsFiles.Remove(deletefile); + await db.SaveChangesAsync(); + } + } + TestResult.RmlExtensionTestResultsFiles.Remove(file); + RaisePropertyChanged(nameof(TestResultsFiles)); + } + } + #endregion + } } |
