From 9e9167bb63f14f176913cc42521d45639512c15a Mon Sep 17 00:00:00 2001 From: sr55 Date: Mon, 21 Mar 2016 00:07:04 +0000 Subject: 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. --- .../Interop/HandBrakeInstance.cs | 9 ++++++--- .../Interop/HandBrakePresetService.cs | 7 +++++-- .../HandBrake.ApplicationServices/Interop/HandBrakeUtils.cs | 12 ++++++------ 3 files changed, 17 insertions(+), 11 deletions(-) (limited to 'win/CS/HandBrake.ApplicationServices/Interop') diff --git a/win/CS/HandBrake.ApplicationServices/Interop/HandBrakeInstance.cs b/win/CS/HandBrake.ApplicationServices/Interop/HandBrakeInstance.cs index a862dc1e6..633c4e1fb 100644 --- a/win/CS/HandBrake.ApplicationServices/Interop/HandBrakeInstance.cs +++ b/win/CS/HandBrake.ApplicationServices/Interop/HandBrakeInstance.cs @@ -34,6 +34,7 @@ namespace HandBrake.ApplicationServices.Interop using HandBrake.ApplicationServices.Interop.Model.Encoding; using HandBrake.ApplicationServices.Interop.Model.Preview; using HandBrake.ApplicationServices.Services.Logging; + using HandBrake.ApplicationServices.Services.Logging.Interfaces; using HandBrake.ApplicationServices.Services.Logging.Model; using Newtonsoft.Json; @@ -55,6 +56,8 @@ namespace HandBrake.ApplicationServices.Interop /// private const double EncodePollIntervalMs = 250; + private readonly ILog log = LogService.GetLogger(); + /// /// The native handle to the HandBrake instance. /// @@ -502,7 +505,7 @@ namespace HandBrake.ApplicationServices.Interop { IntPtr json = HBFunctions.hb_get_state_json(this.hbHandle); string statusJson = Marshal.PtrToStringAnsi(json); - LogHelper.LogMessage(new LogMessage(statusJson, LogMessageType.progressJson, LogLevel.debug)); + this.log.LogMessage(statusJson, LogMessageType.Progress, LogLevel.Trace); JsonState state = JsonConvert.DeserializeObject(statusJson); if (state != null && state.State == NativeConstants.HB_STATE_SCANNING) @@ -516,7 +519,7 @@ namespace HandBrake.ApplicationServices.Interop { var jsonMsg = HBFunctions.hb_get_title_set_json(this.hbHandle); string scanJson = InteropUtilities.ToStringFromUtf8Ptr(jsonMsg); - LogHelper.LogMessage(new LogMessage(scanJson, LogMessageType.scanJson, LogLevel.debug)); + this.log.LogMessage(scanJson, LogMessageType.Progress, LogLevel.Trace); this.titles = JsonConvert.DeserializeObject(scanJson); this.featureTitle = this.titles.MainFeature; @@ -541,7 +544,7 @@ namespace HandBrake.ApplicationServices.Interop IntPtr json = HBFunctions.hb_get_state_json(this.hbHandle); string statusJson = Marshal.PtrToStringAnsi(json); - LogHelper.LogMessage(new LogMessage(statusJson, LogMessageType.progressJson, LogLevel.debug)); + this.log.LogMessage(statusJson, LogMessageType.Progress, LogLevel.Trace); JsonState state = JsonConvert.DeserializeObject(statusJson); diff --git a/win/CS/HandBrake.ApplicationServices/Interop/HandBrakePresetService.cs b/win/CS/HandBrake.ApplicationServices/Interop/HandBrakePresetService.cs index fcc6d61da..7e1f95d3e 100644 --- a/win/CS/HandBrake.ApplicationServices/Interop/HandBrakePresetService.cs +++ b/win/CS/HandBrake.ApplicationServices/Interop/HandBrakePresetService.cs @@ -18,6 +18,7 @@ namespace HandBrake.ApplicationServices.Interop using HandBrake.ApplicationServices.Interop.Helpers; using HandBrake.ApplicationServices.Interop.Json.Presets; using HandBrake.ApplicationServices.Services.Logging; + using HandBrake.ApplicationServices.Services.Logging.Interfaces; using HandBrake.ApplicationServices.Services.Logging.Model; using Newtonsoft.Json; @@ -27,6 +28,8 @@ namespace HandBrake.ApplicationServices.Interop /// public class HandBrakePresetService { + private static readonly ILog log = LogService.GetLogger(); + /// /// The get built in presets. /// Requires an hb_init to have been invoked. @@ -39,7 +42,7 @@ namespace HandBrake.ApplicationServices.Interop IntPtr presets = HBFunctions.hb_presets_builtin_get_json(); string presetJson = Marshal.PtrToStringAnsi(presets); - LogHelper.LogMessage(new LogMessage(presetJson, LogMessageType.progressJson, LogLevel.debug)); + log.LogMessage(presetJson, LogMessageType.API, LogLevel.Debug); IList presetList = JsonConvert.DeserializeObject>(presetJson); @@ -60,7 +63,7 @@ namespace HandBrake.ApplicationServices.Interop IntPtr presetStringPointer = HBFunctions.hb_presets_read_file_json(InteropUtilities.ToUtf8PtrFromString(filename)); string presetJson = Marshal.PtrToStringAnsi(presetStringPointer); - LogHelper.LogMessage(new LogMessage(presetJson, LogMessageType.libhb, LogLevel.debug)); + log.LogMessage(presetJson, LogMessageType.API, LogLevel.Debug); PresetTransportContainer preset = JsonConvert.DeserializeObject(presetJson); diff --git a/win/CS/HandBrake.ApplicationServices/Interop/HandBrakeUtils.cs b/win/CS/HandBrake.ApplicationServices/Interop/HandBrakeUtils.cs index 3540bb368..ef98f3f86 100644 --- a/win/CS/HandBrake.ApplicationServices/Interop/HandBrakeUtils.cs +++ b/win/CS/HandBrake.ApplicationServices/Interop/HandBrakeUtils.cs @@ -11,7 +11,6 @@ namespace HandBrake.ApplicationServices.Interop { using System; using System.Collections.Generic; - using System.Diagnostics; using System.Runtime.InteropServices; using HandBrake.ApplicationServices.Interop.EventArgs; @@ -19,6 +18,7 @@ namespace HandBrake.ApplicationServices.Interop using HandBrake.ApplicationServices.Interop.Json.Anamorphic; using HandBrake.ApplicationServices.Interop.Json.Shared; using HandBrake.ApplicationServices.Services.Logging; + using HandBrake.ApplicationServices.Services.Logging.Interfaces; using HandBrake.ApplicationServices.Services.Logging.Model; using Newtonsoft.Json; @@ -28,6 +28,8 @@ namespace HandBrake.ApplicationServices.Interop /// public static class HandBrakeUtils { + private static readonly ILog log = LogService.GetLogger(); + /// /// The callback for log messages from HandBrake. /// @@ -301,7 +303,7 @@ namespace HandBrake.ApplicationServices.Interop public static Geometry GetAnamorphicSize(AnamorphicGeometry anamorphicGeometry) { string encode = JsonConvert.SerializeObject(anamorphicGeometry, Formatting.Indented, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }); - LogHelper.LogMessage(new LogMessage(encode, LogMessageType.encodeJson, LogLevel.debug)); + log.LogMessage(encode, LogMessageType.API, LogLevel.Debug); IntPtr json = HBFunctions.hb_set_anamorphic_size_json(Marshal.StringToHGlobalAnsi(encode)); string result = Marshal.PtrToStringAnsi(json); return JsonConvert.DeserializeObject(result); @@ -317,10 +319,9 @@ namespace HandBrake.ApplicationServices.Interop { if (MessageLogged != null) { + log.LogMessage(message, LogMessageType.ScanOrEncode, LogLevel.Info); MessageLogged(null, new MessageLoggedEventArgs(message)); } - - Debug.WriteLine(message); } /// @@ -333,10 +334,9 @@ namespace HandBrake.ApplicationServices.Interop { if (ErrorLogged != null) { + log.LogMessage(message, LogMessageType.ScanOrEncode, LogLevel.Error); ErrorLogged(null, new MessageLoggedEventArgs(message)); } - - Debug.WriteLine("ERROR: " + message); } } } -- cgit v1.2.3