diff options
author | sr55 <[email protected]> | 2020-12-03 17:56:04 +0000 |
---|---|---|
committer | sr55 <[email protected]> | 2020-12-03 17:56:14 +0000 |
commit | 3b0bd7689579fb8012a3a6c00eae53243c61d8bd (patch) | |
tree | b80554203b4981f41da76361443f62b692445ea3 /win | |
parent | 15601f1b4aa14126ccb06ccd8041bed41aa3a7bf (diff) |
WinGui: Improvements to log handling for multi-instance
Diffstat (limited to 'win')
4 files changed, 108 insertions, 27 deletions
diff --git a/win/CS/HandBrakeWPF/Services/Encode/LibEncode.cs b/win/CS/HandBrakeWPF/Services/Encode/LibEncode.cs index 0cfd6e0f3..6754f534e 100644 --- a/win/CS/HandBrakeWPF/Services/Encode/LibEncode.cs +++ b/win/CS/HandBrakeWPF/Services/Encode/LibEncode.cs @@ -249,8 +249,6 @@ namespace HandBrakeWPF.Services.Encode this.ServiceLogMessage(completeMessage); - this.logInstanceManager.Deregister(this.GetLogFilename()); - // Handling Log Data string hbLog = this.ProcessLogs(this.currentTask.Destination); long filesize = this.GetFilesize(this.currentTask.Destination); @@ -260,6 +258,8 @@ namespace HandBrakeWPF.Services.Encode e.Error != 0 ? new EventArgs.EncodeCompletedEventArgs(false, null, e.Error.ToString(), this.currentTask.Source, this.currentTask.Destination, hbLog, filesize) : new EventArgs.EncodeCompletedEventArgs(true, null, string.Empty, this.currentTask.Source, this.currentTask.Destination, hbLog, filesize)); + + this.logInstanceManager.Deregister(this.GetLogFilename()); } private long GetFilesize(string destination) diff --git a/win/CS/HandBrakeWPF/Services/Queue/Interfaces/IQueueService.cs b/win/CS/HandBrakeWPF/Services/Queue/Interfaces/IQueueService.cs index 2cbca0439..7e50ace75 100644 --- a/win/CS/HandBrakeWPF/Services/Queue/Interfaces/IQueueService.cs +++ b/win/CS/HandBrakeWPF/Services/Queue/Interfaces/IQueueService.cs @@ -153,6 +153,12 @@ namespace HandBrakeWPF.Services.Queue.Interfaces void ClearCompleted(); /// <summary> + /// Get the log file paths for jobs still on the queue. (Including completed) + /// </summary> + /// <returns>List of filepaths</returns> + List<string> GetLogFilePaths(); + + /// <summary> /// Get the first job on the queue for processing. /// This also removes the job from the Queue and sets the LastProcessedJob /// </summary> diff --git a/win/CS/HandBrakeWPF/Services/Queue/QueueService.cs b/win/CS/HandBrakeWPF/Services/Queue/QueueService.cs index c3c65f3c3..089072136 100644 --- a/win/CS/HandBrakeWPF/Services/Queue/QueueService.cs +++ b/win/CS/HandBrakeWPF/Services/Queue/QueueService.cs @@ -349,6 +349,24 @@ namespace HandBrakeWPF.Services.Queue }); } + public List<string> GetLogFilePaths() + { + List<string> logPaths = new List<string>(); + lock (QueueLock) + { + foreach (QueueTask task in this.Queue) + { + if (!string.IsNullOrEmpty(task.Statistics.CompletedActivityLogPath)) + { + logPaths.Add(task.Statistics.CompletedActivityLogPath); + } + } + } + + return logPaths; + } + + public QueueTask GetNextJobForProcessing() { if (this.queue.Count > 0) diff --git a/win/CS/HandBrakeWPF/ViewModels/LogViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/LogViewModel.cs index 2ce7c6c5e..d98c99d48 100644 --- a/win/CS/HandBrakeWPF/ViewModels/LogViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/LogViewModel.cs @@ -10,8 +10,10 @@ namespace HandBrakeWPF.ViewModels
{
using System;
+ using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
+ using System.IO;
using System.Linq;
using System.Text;
@@ -22,6 +24,7 @@ namespace HandBrakeWPF.ViewModels using HandBrakeWPF.Properties;
using HandBrakeWPF.Services.Interfaces;
using HandBrakeWPF.Services.Logging.Interfaces;
+ using HandBrakeWPF.Services.Queue.Interfaces;
using HandBrakeWPF.Utilities;
using HandBrakeWPF.ViewModels.Interfaces;
@@ -32,8 +35,10 @@ namespace HandBrakeWPF.ViewModels public class LogViewModel : ViewModelBase, ILogViewModel
{
private readonly IErrorService errorService;
-
private readonly ILogInstanceManager logInstanceManager;
+ private readonly IQueueService queueService;
+ private readonly Dictionary<string, string> inactiveLogs = new Dictionary<string, string>();
+ private readonly object readLockObject = new object();
private ILog logService;
private StringBuilder log = new StringBuilder();
@@ -41,30 +46,19 @@ namespace HandBrakeWPF.ViewModels private string selectedLogFile;
- public LogViewModel(IErrorService errorService, ILogInstanceManager logInstanceManager)
+ public LogViewModel(IErrorService errorService, ILogInstanceManager logInstanceManager, IQueueService queueService)
{
this.errorService = errorService;
this.logInstanceManager = logInstanceManager;
+ this.queueService = queueService;
this.Title = Resources.LogViewModel_Title;
}
public event EventHandler<LogEventArgs> LogMessageReceived;
- public string ActivityLog
- {
- get
- {
- return this.log.ToString();
- }
- }
+ public string ActivityLog => this.log.ToString();
- public BindingList<string> LogFiles
- {
- get
- {
- return new BindingList<string>(this.logInstanceManager.GetLogFiles());
- }
- }
+ public BindingList<string> LogFiles { get; private set; }
public string SelectedLogFile
{
@@ -106,14 +100,10 @@ namespace HandBrakeWPF.ViewModels protected override void OnActivate()
{
this.logInstanceManager.NewLogInstanceRegistered += this.LogInstanceManager_NewLogInstanceRegistered;
+ this.queueService.QueueChanged += this.QueueService_QueueChanged;
- this.NotifyOfPropertyChange(() => this.LogFiles);
-
- if (string.IsNullOrEmpty(this.SelectedLogFile) || !this.LogFiles.Contains(this.SelectedLogFile))
- {
- this.SelectedLogFile = this.LogFiles.LastOrDefault();
- }
-
+ this.CollectLogFiles();
+
base.OnActivate();
}
@@ -127,6 +117,7 @@ namespace HandBrakeWPF.ViewModels this.SelectedLogFile = null;
this.logInstanceManager.NewLogInstanceRegistered -= this.LogInstanceManager_NewLogInstanceRegistered;
+ this.queueService.QueueChanged -= this.QueueService_QueueChanged;
base.OnDeactivate(close);
}
@@ -152,6 +143,36 @@ namespace HandBrakeWPF.ViewModels this.logService = this.logInstanceManager.GetLogInstance(this.SelectedLogFile);
+ // This is not an active log, so read from disk.
+ if (this.logService == null)
+ {
+ try
+ {
+ if (this.inactiveLogs.ContainsKey(this.SelectedLogFile) && File.Exists(this.inactiveLogs[this.selectedLogFile]))
+ {
+ this.log.Clear();
+ using (StreamReader logReader = new StreamReader(this.inactiveLogs[this.selectedLogFile]))
+ {
+ string logContent = logReader.ReadToEnd();
+ this.log.AppendLine(logContent);
+ }
+ }
+ else
+ {
+ this.log.AppendLine("Log file not found.");
+ }
+ }
+ catch (Exception exc)
+ {
+ Debug.WriteLine(exc);
+ this.log.AppendLine(exc.ToString());
+ }
+
+ this.OnLogMessageReceived(null);
+ this.NotifyOfPropertyChange(() => this.ActivityLog);
+ }
+
+ // Active in-progress log, read from the log service.
if (this.logService != null)
{
this.logService.MessageLogged += this.LogService_MessageLogged;
@@ -211,8 +232,44 @@ namespace HandBrakeWPF.ViewModels private void LogInstanceManager_NewLogInstanceRegistered(object sender, EventArgs e)
{
- this.NotifyOfPropertyChange(() => this.LogFiles);
- this.SelectedLogFile = this.LogFiles.LastOrDefault();
+ this.CollectLogFiles();
+ }
+
+ private void QueueService_QueueChanged(object sender, EventArgs e)
+ {
+ this.CollectLogFiles();
+ }
+
+ private void CollectLogFiles()
+ {
+ lock (readLockObject)
+ {
+ BindingList<string> activeLogs = new BindingList<string>(this.logInstanceManager.GetLogFiles());
+ BindingList<string> logfiles = new BindingList<string>();
+
+ // Add Inactive Logs First.
+ inactiveLogs.Clear();
+ foreach (string logFile in this.queueService.GetLogFilePaths())
+ {
+ this.inactiveLogs.Add(Path.GetFileName(logFile), logFile);
+ logfiles.Add(Path.GetFileName(logFile));
+ }
+
+ // Add active logs second.
+ foreach (var log in activeLogs)
+ {
+ logfiles.Add(log);
+ }
+
+ this.LogFiles = logfiles;
+ this.NotifyOfPropertyChange(() => this.LogFiles);
+
+ this.SelectedLogFile = this.LogFiles.LastOrDefault(c => !c.Contains("activity_log_main"));
+ if (this.SelectedLogFile == null)
+ {
+ this.SelectedLogFile = this.LogFiles.LastOrDefault();
+ }
+ }
}
}
}
\ No newline at end of file |