summaryrefslogtreecommitdiffstats
path: root/win/CS/HandBrakeWPF/ViewModels
diff options
context:
space:
mode:
authorsr55 <[email protected]>2016-03-21 00:07:04 +0000
committersr55 <[email protected]>2016-03-21 00:07:04 +0000
commit9e9167bb63f14f176913cc42521d45639512c15a (patch)
treec62ab72125805ee252ac96fdb6c78154c5c9d1fc /win/CS/HandBrakeWPF/ViewModels
parent78827728072257daadc8acb00bb24af7779c4d63 (diff)
WinGui: Add a Logging Service into the AppServices library. This does not depend on any 3rd party libraries and is off by default. It must be initialised by calling Enable() on the LogService class. Otherwise LogMessage does nothing.
Changed the Logging screen to a single panel in the WinGui. This will change back to separate Scan/Encode logs when we get libhb it's own processes. Added Auto-Scroll to the log window.
Diffstat (limited to 'win/CS/HandBrakeWPF/ViewModels')
-rw-r--r--win/CS/HandBrakeWPF/ViewModels/Interfaces/ILogViewModel.cs4
-rw-r--r--win/CS/HandBrakeWPF/ViewModels/LogViewModel.cs207
-rw-r--r--win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs8
3 files changed, 79 insertions, 140 deletions
diff --git a/win/CS/HandBrakeWPF/ViewModels/Interfaces/ILogViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/Interfaces/ILogViewModel.cs
index 6c7a7a2c8..6aa1020d4 100644
--- a/win/CS/HandBrakeWPF/ViewModels/Interfaces/ILogViewModel.cs
+++ b/win/CS/HandBrakeWPF/ViewModels/Interfaces/ILogViewModel.cs
@@ -14,9 +14,5 @@ namespace HandBrakeWPF.ViewModels.Interfaces
/// </summary>
public interface ILogViewModel
{
- /// <summary>
- /// Gets or sets the selected tab.
- /// </summary>
- int SelectedTab { get; set; }
}
} \ No newline at end of file
diff --git a/win/CS/HandBrakeWPF/ViewModels/LogViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/LogViewModel.cs
index f9a26c1ed..572d8a440 100644
--- a/win/CS/HandBrakeWPF/ViewModels/LogViewModel.cs
+++ b/win/CS/HandBrakeWPF/ViewModels/LogViewModel.cs
@@ -11,15 +11,18 @@ namespace HandBrakeWPF.ViewModels
{
using System;
using System.Diagnostics;
+ using System.Text;
using System.Windows;
- using HandBrakeWPF.Services.Scan.EventArgs;
- using HandBrakeWPF.Services.Scan.Interfaces;
+ using Caliburn.Micro;
+
+ using HandBrake.ApplicationServices.Services.Logging;
+ using HandBrake.ApplicationServices.Services.Logging.EventArgs;
+ using HandBrake.ApplicationServices.Services.Logging.Model;
+
using HandBrakeWPF.ViewModels.Interfaces;
- using EncodeCompletedEventArgs = HandBrakeWPF.Services.Encode.EventArgs.EncodeCompletedEventArgs;
- using EncodeProgressEventArgs = HandBrakeWPF.Services.Encode.EventArgs.EncodeProgressEventArgs;
- using IEncode = HandBrakeWPF.Services.Encode.Interfaces.IEncode;
+ using ILog = HandBrake.ApplicationServices.Services.Logging.Interfaces.ILog;
/// <summary>
/// The Log View Model
@@ -28,83 +31,37 @@ namespace HandBrakeWPF.ViewModels
{
#region Private Fields
- /// <summary>
- /// Backing field for the encodeService service
- /// </summary>
- private readonly IEncode encodeService;
-
- /// <summary>
- /// Backing field for the Scan Service
- /// </summary>
- private readonly IScan scanService;
-
- /// <summary>
- /// The selected tab.
- /// </summary>
- private int selectedTab;
-
- /// <summary>
- /// The encode log index.
- /// </summary>
- private int encodeLogIndex;
+ private readonly ILog logService;
+ private StringBuilder log = new StringBuilder();
+ private long lastReadIndex;
#endregion
/// <summary>
/// Initializes a new instance of the <see cref="LogViewModel"/> class.
/// </summary>
- /// <param name="encodeService">
- /// The encode service.
- /// </param>
- /// <param name="scanService">
- /// The scan service.
- /// </param>
- public LogViewModel(IEncode encodeService, IScan scanService)
+ public LogViewModel()
{
- this.encodeService = encodeService;
- this.scanService = scanService;
+ this.logService = LogService.GetLogger();
this.Title = "Log Viewer";
- this.encodeLogIndex = 0;
- }
-
- /// <summary>
- /// Gets or sets the selected tab.
- /// </summary>
- public int SelectedTab
- {
- get
- {
- return this.selectedTab;
- }
- set
- {
- this.selectedTab = value;
- this.NotifyOfPropertyChange(() => this.SelectedTab);
- }
}
/// <summary>
/// Gets Log.
/// </summary>
- public string ScanLog
+ public string ActivityLog
{
get
{
- return this.scanService.ActivityLog;
+ return this.log.ToString();
}
}
/// <summary>
- /// Gets the encodelog.
+ /// The log message received.
/// </summary>
- public string EncodeLog
- {
- get
- {
- return this.encodeService.ActivityLog;
- }
- }
-
+ public event EventHandler<LogEventArgs> LogMessageReceived;
+
/// <summary>
/// Open the Log file directory
/// </summary>
@@ -121,7 +78,7 @@ namespace HandBrakeWPF.ViewModels
/// </summary>
public void CopyLog()
{
- Clipboard.SetDataObject(this.SelectedTab == 1 ? this.ScanLog : this.EncodeLog, true);
+ Clipboard.SetDataObject(this.ActivityLog, true);
}
/// <summary>
@@ -129,49 +86,26 @@ namespace HandBrakeWPF.ViewModels
/// </summary>
protected override void OnActivate()
{
- this.scanService.ScanCompleted += ScanServiceScanCompleted;
- this.encodeService.EncodeCompleted += EncodeServiceEncodeCompleted;
- this.encodeService.EncodeStatusChanged += this.EncodeServiceEncodeStatusChanged;
- this.scanService.ScanStatusChanged += this.ScanServiceScanStatusChanged;
- this.scanService.ScanStarted += this.scanService_ScanStared;
- this.encodeService.EncodeStarted += this.encodeService_EncodeStarted;
- base.OnActivate();
-
- this.NotifyOfPropertyChange(() => this.ScanLog);
- this.NotifyOfPropertyChange(() => this.EncodeLog);
- }
-
- /// <summary>
- /// Scan Status has changed, update log window.
- /// </summary>
- /// <param name="sender">
- /// The sender.
- /// </param>
- /// <param name="e">
- /// The e.
- /// </param>
- private void ScanServiceScanStatusChanged(object sender, ScanProgressEventArgs e)
- {
- this.NotifyOfPropertyChange(() => this.ScanLog);
- }
+ this.logService.MessageLogged += this.LogService_MessageLogged;
+ this.logService.LogReset += LogService_LogReset;
- /// <summary>
- /// Encode Status has changed, update log window
- /// </summary>
- /// <param name="sender">
- /// The sender.
- /// </param>
- /// <param name="e">
- /// The e.
- /// </param>
- private void EncodeServiceEncodeStatusChanged(object sender, EncodeProgressEventArgs e)
- {
- if (encodeLogIndex != this.encodeService.LogIndex || this.encodeService.LogIndex == -1)
+ // Refresh the Log Display
+ this.log.Clear();
+ foreach (LogMessage logMessage in this.logService.LogMessages)
{
- this.NotifyOfPropertyChange(() => this.EncodeLog);
+ this.log.AppendLine(logMessage.Content);
+ this.lastReadIndex = logMessage.MessageIndex;
+
+ if (this.lastReadIndex > logMessage.MessageIndex)
+ {
+ throw new Exception("Log Message Index Error");
+ }
}
- encodeLogIndex = this.encodeService.LogIndex;
+ this.OnLogMessageReceived(null);
+ this.NotifyOfPropertyChange("ActivityLog");
+
+ base.OnActivate();
}
/// <summary>
@@ -182,18 +116,14 @@ namespace HandBrakeWPF.ViewModels
/// </param>
protected override void OnDeactivate(bool close)
{
- this.scanService.ScanCompleted -= ScanServiceScanCompleted;
- this.encodeService.EncodeCompleted -= EncodeServiceEncodeCompleted;
- this.encodeService.EncodeStatusChanged -= this.EncodeServiceEncodeStatusChanged;
- this.scanService.ScanStatusChanged -= this.ScanServiceScanStatusChanged;
- this.scanService.ScanStarted -= this.scanService_ScanStared;
- this.encodeService.EncodeStarted -= this.encodeService_EncodeStarted;
+ this.logService.MessageLogged -= this.LogService_MessageLogged;
+ this.logService.LogReset -= this.LogService_LogReset;
base.OnDeactivate(close);
}
/// <summary>
- /// Scan Completed Event Handler.
+ /// The log service_ log reset.
/// </summary>
/// <param name="sender">
/// The sender.
@@ -201,27 +131,28 @@ namespace HandBrakeWPF.ViewModels
/// <param name="e">
/// The e.
/// </param>
- private void ScanServiceScanCompleted(object sender, ScanCompletedEventArgs e)
+ private void LogService_LogReset(object sender, EventArgs e)
{
- this.NotifyOfPropertyChange(() => this.ScanLog);
- }
+ this.log.Clear();
+ this.lastReadIndex = 0;
- /// <summary>
- /// Encode Completed Event Handler.
- /// </summary>
- /// <param name="sender">
- /// The sender.
- /// </param>
- /// <param name="e">
- /// The e.
- /// </param>
- private void EncodeServiceEncodeCompleted(object sender, EncodeCompletedEventArgs e)
- {
- this.NotifyOfPropertyChange(() => this.EncodeLog);
+ foreach (LogMessage logMessage in this.logService.LogMessages)
+ {
+ this.log.AppendLine(logMessage.Content);
+ this.lastReadIndex = logMessage.MessageIndex;
+
+ if (this.lastReadIndex > logMessage.MessageIndex)
+ {
+ throw new Exception("Log Message Index Error");
+ }
+ }
+
+ this.NotifyOfPropertyChange("ActivityLog");
+ this.OnLogMessageReceived(null);
}
/// <summary>
- /// The encode service encode started.
+ /// The log service_ message logged.
/// </summary>
/// <param name="sender">
/// The sender.
@@ -229,24 +160,34 @@ namespace HandBrakeWPF.ViewModels
/// <param name="e">
/// The e.
/// </param>
- private void encodeService_EncodeStarted(object sender, EventArgs e)
+ private void LogService_MessageLogged(object sender, LogEventArgs e)
{
- this.encodeLogIndex = -1; // Reset the log index.
- this.SelectedTab = 0;
+ if (this.lastReadIndex < e.Log.MessageIndex)
+ {
+ Execute.OnUIThreadAsync(
+ () =>
+ {
+ this.lastReadIndex = e.Log.MessageIndex;
+ this.log.AppendLine(e.Log.Content);
+ this.OnLogMessageReceived(e);
+ this.NotifyOfPropertyChange("ActivityLog");
+ });
+ }
}
/// <summary>
- /// The scan service scan stared.
+ /// Trigger a faster / smoother way of updating the log window.
/// </summary>
- /// <param name="sender">
- /// The sender.
- /// </param>
/// <param name="e">
/// The e.
/// </param>
- private void scanService_ScanStared(object sender, EventArgs e)
+ protected virtual void OnLogMessageReceived(LogEventArgs e)
{
- this.SelectedTab = 1;
+ var onLogMessageReceived = this.LogMessageReceived;
+ if (onLogMessageReceived != null)
+ {
+ onLogMessageReceived.Invoke(this, e);
+ }
}
}
} \ No newline at end of file
diff --git a/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs
index 0886768e7..3f9bc7201 100644
--- a/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs
+++ b/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs
@@ -23,6 +23,8 @@ namespace HandBrakeWPF.ViewModels
using Caliburn.Micro;
using HandBrake.ApplicationServices.Interop;
+ using HandBrake.ApplicationServices.Interop.HbLib;
+ using HandBrake.ApplicationServices.Services.Logging;
using HandBrake.ApplicationServices.Utilities;
using HandBrakeWPF.Commands;
@@ -56,6 +58,8 @@ namespace HandBrakeWPF.ViewModels
using Action = System.Action;
using Execute = Caliburn.Micro.Execute;
+ using ILog = HandBrake.ApplicationServices.Services.Logging.Interfaces.ILog;
+ using LogManager = HandBrakeWPF.Helpers.LogManager;
/// <summary>
/// HandBrakes Main Window
@@ -226,6 +230,7 @@ namespace HandBrakeWPF.ViewModels
// Setup Commands
this.QueueCommand = new QueueCommands(this.QueueViewModel);
+ LogManager.Init();
HandBrakeInstanceManager.Init();
}
@@ -1277,14 +1282,11 @@ namespace HandBrakeWPF.ViewModels
if (window != null)
{
- ILogViewModel logvm = (ILogViewModel)window.DataContext;
- logvm.SelectedTab = this.IsEncoding ? 0 : 1;
window.Activate();
}
else
{
ILogViewModel logvm = IoC.Get<ILogViewModel>();
- logvm.SelectedTab = this.IsEncoding ? 0 : 1;
this.windowManager.ShowWindow(logvm);
}
}