From b4682a3abfe299c19b24752b2fb1ce2477611ec3 Mon Sep 17 00:00:00 2001 From: Roy Ben Shabat Date: Fri, 10 Apr 2020 15:06:42 +0300 Subject: Implemented FSE/PPC Logs. --- .../Tango.FSE.Common/Logging/RemoteLogFileModel.cs | 128 +++++++++++++++++++++ 1 file changed, 128 insertions(+) create mode 100644 Software/Visual_Studio/FSE/Tango.FSE.Common/Logging/RemoteLogFileModel.cs (limited to 'Software/Visual_Studio/FSE/Tango.FSE.Common/Logging/RemoteLogFileModel.cs') diff --git a/Software/Visual_Studio/FSE/Tango.FSE.Common/Logging/RemoteLogFileModel.cs b/Software/Visual_Studio/FSE/Tango.FSE.Common/Logging/RemoteLogFileModel.cs new file mode 100644 index 000000000..cf71ed270 --- /dev/null +++ b/Software/Visual_Studio/FSE/Tango.FSE.Common/Logging/RemoteLogFileModel.cs @@ -0,0 +1,128 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Data; +using Tango.Core; +using Tango.Core.Commands; +using Tango.Core.DI; +using Tango.FSE.Common.FileSystem; +using Tango.Logging; +using Tango.PPC.Shared.Logs; +using Tango.SharedUI.Components; + +namespace Tango.FSE.Common.Logging +{ + /// + /// Represents a remote log file model. + /// + /// + /// + public class RemoteLogFileModel : ExtendedObject where T : LogItemBase + { + private ILogFileParser _parser; + + /// + /// Occurs when the remote log file has downloaded successfully. + /// + public event EventHandler DownloadCompleted; + + [TangoInject] + private ILoggingProvider LoggingProvider { get; set; } + + /// + /// Gets or sets the remote log file. + /// + public RemoteLogFile RemoteLogFile { get; set; } + + /// + /// Gets the duration of the remote log file. + /// + public TimeSpan Duration + { + get { return RemoteLogFile.DateModified - RemoteLogFile.DateCreated; } + } + + private RemoteLogFileStatus _status; + /// + /// Gets or sets the remote log file status. + /// + public RemoteLogFileStatus Status + { + get { return _status; } + set { _status = value; RaisePropertyChangedAuto(); } + } + + private FileSystemHandler _handler; + /// + /// Gets or sets the remote log file download handler. + /// + public FileSystemHandler Handler + { + get { return _handler; } + set { _handler = value; RaisePropertyChangedAuto(); } + } + + /// + /// Gets or sets the temporary file (where the actual log file is stored locally). + /// + public String TemporaryFile { get; set; } + + private ObservableCollection _logItems; + /// + /// Gets or sets the log items. + /// + public ObservableCollection LogItems + { + get { return _logItems; } + set { _logItems = value; RaisePropertyChangedAuto(); } + } + + /// + /// Gets or sets the download command. + /// + public RelayCommand DownloadCommand { get; set; } + + /// + /// Initializes a new instance of the class. + /// + /// The parser. + public RemoteLogFileModel(ILogFileParser parser) + { + TangoIOC.Default.Inject(this); + _parser = parser; + LogItems = new ObservableCollection(); + DownloadCommand = new RelayCommand(DownloadLogFile); + } + + /// + /// Downloads the log file. + /// + public async void DownloadLogFile() + { + if (Status == RemoteLogFileStatus.None || Status == RemoteLogFileStatus.Failed) + { + Status = RemoteLogFileStatus.Downloading; + String tempLogFile = TemporaryManager.CreateImaginaryFile(".log"); + Handler = await LoggingProvider.DownloadLogFile(RemoteLogFile, tempLogFile); + Handler.StatusChanged += (x, status) => + { + if (status == FileSystemHandlerStatus.Completed) + { + TemporaryFile = tempLogFile; + LogItems = new ObservableCollection(_parser.Parse(tempLogFile, RemoteLogFile.DateCreated.ToLocalTime())); + Status = RemoteLogFileStatus.Downloaded; + DownloadCompleted?.Invoke(this, new EventArgs()); + } + else if (status == FileSystemHandlerStatus.Failed) + { + Status = RemoteLogFileStatus.Failed; + } + }; + } + } + } +} -- cgit v1.3.1