diff options
| author | Roy Ben-Shabat <Roy@Twine-s.com> | 2019-12-05 19:51:45 +0200 |
|---|---|---|
| committer | Roy Ben-Shabat <Roy@Twine-s.com> | 2019-12-05 19:51:45 +0200 |
| commit | cf5c35b14c3fe78874d28d3cb230adb123b1fd75 (patch) | |
| tree | 82711fcb58d8a7a309c036daaeb245af77ca08d2 /Software/Visual_Studio/PPC/Modules/Tango.PPC.Maintenance/ViewModels/MaintenanceViewVM.cs | |
| parent | d061840379f8dab9c5a47a1771ecc7e763eb8c0c (diff) | |
| download | Tango-cf5c35b14c3fe78874d28d3cb230adb123b1fd75.tar.gz Tango-cf5c35b14c3fe78874d28d3cb230adb123b1fd75.zip | |
Implemented "Export System Logs" on PPC maitenance.
Related Work Items: #1617
Diffstat (limited to 'Software/Visual_Studio/PPC/Modules/Tango.PPC.Maintenance/ViewModels/MaintenanceViewVM.cs')
| -rw-r--r-- | Software/Visual_Studio/PPC/Modules/Tango.PPC.Maintenance/ViewModels/MaintenanceViewVM.cs | 69 |
1 files changed, 68 insertions, 1 deletions
diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Maintenance/ViewModels/MaintenanceViewVM.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Maintenance/ViewModels/MaintenanceViewVM.cs index 6622bc2f4..aeb349bdc 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Maintenance/ViewModels/MaintenanceViewVM.cs +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Maintenance/ViewModels/MaintenanceViewVM.cs @@ -1,16 +1,20 @@ -using System; +using Ionic.Zip; +using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Text; using System.Threading.Tasks; using Tango.Core.Commands; +using Tango.Explorer; using Tango.Integration.Operation; +using Tango.Logging; using Tango.PMR.MachineStatus; using Tango.PPC.Common; using Tango.PPC.Maintenance.Helpers; using Tango.PPC.Maintenance.Models; using Tango.PPC.Maintenance.Views; +using Tango.PPC.Storage; namespace Tango.PPC.Maintenance.ViewModels { @@ -38,6 +42,8 @@ namespace Tango.PPC.Maintenance.ViewModels public RelayCommand CloseDyeingHeadCommand { get; set; } + public RelayCommand ExportLogsCommand { get; set; } + public MaintenanceViewVM() { Guides = new ObservableCollection<GuideBase>(GuideHelper.CreateAllGuides()); @@ -47,6 +53,7 @@ namespace Tango.PPC.Maintenance.ViewModels OpenDyeingHeadCommand = new RelayCommand(OpenDyeingHead); CloseDyeingHeadCommand = new RelayCommand(CloseDyeingHead); + ExportLogsCommand = new RelayCommand(ExportLogsToStorage); } public override void OnApplicationStarted() @@ -173,5 +180,65 @@ namespace Tango.PPC.Maintenance.ViewModels IsFree = true; } } + + private async void ExportLogsToStorage() + { + var result = await NavigationManager. + NavigateForResult<StorageModule, + Storage.Views.MainView, ExplorerFileItem, + Storage.Models.StorageNavigationRequest>( + new Storage.Models.StorageNavigationRequest() + { + Intent = Storage.Models.StorageNavigationIntent.SaveFile, + DefaultFileName = $"Tango-Logs-{DateTime.Now.ToFileName()}", + Filter = "do not display anything", + Title = "Export System Logs", + }); + + if (result != null) + { + String file = result.Path + ".zip"; + + IsFree = false; + + try + { + NotificationProvider.SetGlobalBusyMessage("Exporting system logs..."); + + var appFileLogger = LogManager.RegisteredLoggers.FirstOrDefault(x => x is FileLogger) as FileLogger; + + await Task.Factory.StartNew(() => + { + using (ZipFile zip = new ZipFile(file)) + { + zip.Password = "1Creativity"; + + if (appFileLogger != null) + { + zip.AddDirectory(appFileLogger.Folder); + } + + zip.ParallelDeflateThreshold = -1; + zip.Save(); + } + }); + + NotificationProvider.ReleaseGlobalBusyMessage(); + + await NotificationProvider.ShowSuccess("System logs exported successfully."); + } + catch (Exception ex) + { + NotificationProvider.ReleaseGlobalBusyMessage(); + LogManager.Log(ex, "Error exporting system logs."); + await NotificationProvider.ShowError($"An error occurred while trying to export the system logs.\n{ex.FlattenMessage()}"); + } + finally + { + NotificationProvider.ReleaseGlobalBusyMessage(); + IsFree = true; + } + } + } } } |
