aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/FSE/Tango.FSE.Common/Logging/RemoteLogFileModel.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Software/Visual_Studio/FSE/Tango.FSE.Common/Logging/RemoteLogFileModel.cs')
-rw-r--r--Software/Visual_Studio/FSE/Tango.FSE.Common/Logging/RemoteLogFileModel.cs128
1 files changed, 128 insertions, 0 deletions
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
+{
+ /// <summary>
+ /// Represents a remote log file model.
+ /// </summary>
+ /// <typeparam name="T"></typeparam>
+ /// <seealso cref="Tango.Core.ExtendedObject" />
+ public class RemoteLogFileModel<T> : ExtendedObject where T : LogItemBase
+ {
+ private ILogFileParser<T> _parser;
+
+ /// <summary>
+ /// Occurs when the remote log file has downloaded successfully.
+ /// </summary>
+ public event EventHandler DownloadCompleted;
+
+ [TangoInject]
+ private ILoggingProvider LoggingProvider { get; set; }
+
+ /// <summary>
+ /// Gets or sets the remote log file.
+ /// </summary>
+ public RemoteLogFile RemoteLogFile { get; set; }
+
+ /// <summary>
+ /// Gets the duration of the remote log file.
+ /// </summary>
+ public TimeSpan Duration
+ {
+ get { return RemoteLogFile.DateModified - RemoteLogFile.DateCreated; }
+ }
+
+ private RemoteLogFileStatus _status;
+ /// <summary>
+ /// Gets or sets the remote log file status.
+ /// </summary>
+ public RemoteLogFileStatus Status
+ {
+ get { return _status; }
+ set { _status = value; RaisePropertyChangedAuto(); }
+ }
+
+ private FileSystemHandler _handler;
+ /// <summary>
+ /// Gets or sets the remote log file download handler.
+ /// </summary>
+ public FileSystemHandler Handler
+ {
+ get { return _handler; }
+ set { _handler = value; RaisePropertyChangedAuto(); }
+ }
+
+ /// <summary>
+ /// Gets or sets the temporary file (where the actual log file is stored locally).
+ /// </summary>
+ public String TemporaryFile { get; set; }
+
+ private ObservableCollection<LogItemBase> _logItems;
+ /// <summary>
+ /// Gets or sets the log items.
+ /// </summary>
+ public ObservableCollection<LogItemBase> LogItems
+ {
+ get { return _logItems; }
+ set { _logItems = value; RaisePropertyChangedAuto(); }
+ }
+
+ /// <summary>
+ /// Gets or sets the download command.
+ /// </summary>
+ public RelayCommand DownloadCommand { get; set; }
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="RemoteLogFileModel{T}"/> class.
+ /// </summary>
+ /// <param name="parser">The parser.</param>
+ public RemoteLogFileModel(ILogFileParser<T> parser)
+ {
+ TangoIOC.Default.Inject(this);
+ _parser = parser;
+ LogItems = new ObservableCollection<LogItemBase>();
+ DownloadCommand = new RelayCommand(DownloadLogFile);
+ }
+
+ /// <summary>
+ /// Downloads the log file.
+ /// </summary>
+ 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<LogItemBase>(_parser.Parse(tempLogFile, RemoteLogFile.DateCreated.ToLocalTime()));
+ Status = RemoteLogFileStatus.Downloaded;
+ DownloadCompleted?.Invoke(this, new EventArgs());
+ }
+ else if (status == FileSystemHandlerStatus.Failed)
+ {
+ Status = RemoteLogFileStatus.Failed;
+ }
+ };
+ }
+ }
+ }
+}