summaryrefslogtreecommitdiffstats
path: root/win/CS
diff options
context:
space:
mode:
authorsr55 <[email protected]>2015-04-10 22:29:57 +0000
committersr55 <[email protected]>2015-04-10 22:29:57 +0000
commit01487d5277eaadf2da3a483aa1d74198050fba44 (patch)
tree71438b397683b1bb2cdc94fbc6416cbbeb744660 /win/CS
parent9c78da39f3c6947c84c039e1f16497da6020b740 (diff)
WinGui: Add a basic outline of a logging system to allow logging of the JSON and other types of messages.
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@7084 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'win/CS')
-rw-r--r--win/CS/HandBrake.ApplicationServices/HandBrake.ApplicationServices.csproj4
-rw-r--r--win/CS/HandBrake.ApplicationServices/Interop/HandBrakeInstance.cs8
-rw-r--r--win/CS/HandBrake.ApplicationServices/Interop/HandBrakeUtils.cs3
-rw-r--r--win/CS/HandBrake.ApplicationServices/Services/Logging/LogHelper.cs53
-rw-r--r--win/CS/HandBrake.ApplicationServices/Services/Logging/Model/LogLevel.cs37
-rw-r--r--win/CS/HandBrake.ApplicationServices/Services/Logging/Model/LogMessage.cs52
-rw-r--r--win/CS/HandBrake.ApplicationServices/Services/Logging/Model/LogMessageType.cs23
-rw-r--r--win/CS/HandBrakeWPF/Startup/CastleBootstrapper.cs1
8 files changed, 181 insertions, 0 deletions
diff --git a/win/CS/HandBrake.ApplicationServices/HandBrake.ApplicationServices.csproj b/win/CS/HandBrake.ApplicationServices/HandBrake.ApplicationServices.csproj
index 91b8dfea8..a8bb2a063 100644
--- a/win/CS/HandBrake.ApplicationServices/HandBrake.ApplicationServices.csproj
+++ b/win/CS/HandBrake.ApplicationServices/HandBrake.ApplicationServices.csproj
@@ -182,6 +182,10 @@
<Compile Include="Services\Encode\Model\Models\Video\VideoPreset.cs" />
<Compile Include="Services\Encode\Model\Models\Video\VideoProfile.cs" />
<Compile Include="Services\Encode\Model\Models\Video\VideoTune.cs" />
+ <Compile Include="Services\Logging\LogHelper.cs" />
+ <Compile Include="Services\Logging\Model\LogLevel.cs" />
+ <Compile Include="Services\Logging\Model\LogMessage.cs" />
+ <Compile Include="Services\Logging\Model\LogMessageType.cs" />
<Compile Include="Services\Scan\EventArgs\ScanCompletedEventArgs.cs" />
<Compile Include="Services\Scan\EventArgs\ScanProgressEventArgs.cs" />
<Compile Include="Utilities\Converters.cs" />
diff --git a/win/CS/HandBrake.ApplicationServices/Interop/HandBrakeInstance.cs b/win/CS/HandBrake.ApplicationServices/Interop/HandBrakeInstance.cs
index 97193c8dd..a97185e19 100644
--- a/win/CS/HandBrake.ApplicationServices/Interop/HandBrakeInstance.cs
+++ b/win/CS/HandBrake.ApplicationServices/Interop/HandBrakeInstance.cs
@@ -33,6 +33,8 @@ namespace HandBrake.ApplicationServices.Interop
using HandBrake.ApplicationServices.Interop.Model;
using HandBrake.ApplicationServices.Interop.Model.Encoding;
using HandBrake.ApplicationServices.Interop.Model.Preview;
+ using HandBrake.ApplicationServices.Services.Logging;
+ using HandBrake.ApplicationServices.Services.Logging.Model;
using Newtonsoft.Json;
@@ -353,6 +355,7 @@ namespace HandBrake.ApplicationServices.Interop
};
string encode = JsonConvert.SerializeObject(encodeObject, Formatting.Indented, settings);
+ LogHelper.LogMessage(new LogMessage(encode, LogMessageType.encodeJson, LogLevel.debug));
HBFunctions.hb_add_json(this.hbHandle, InteropUtilities.ToUtf8PtrFromString(encode));
HBFunctions.hb_start(this.hbHandle);
@@ -458,6 +461,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));
JsonState state = JsonConvert.DeserializeObject<JsonState>(statusJson);
if (state != null && state.State == NativeConstants.HB_STATE_SCANNING)
@@ -478,6 +482,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.titles = JsonConvert.DeserializeObject<JsonScanObject>(scanJson);
this.featureTitle = this.titles.MainFeature;
@@ -501,6 +506,9 @@ 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));
+
JsonState state = JsonConvert.DeserializeObject<JsonState>(statusJson);
if (state != null && state.State == NativeConstants.HB_STATE_WORKING)
diff --git a/win/CS/HandBrake.ApplicationServices/Interop/HandBrakeUtils.cs b/win/CS/HandBrake.ApplicationServices/Interop/HandBrakeUtils.cs
index 098646ddd..7a00bb8e9 100644
--- a/win/CS/HandBrake.ApplicationServices/Interop/HandBrakeUtils.cs
+++ b/win/CS/HandBrake.ApplicationServices/Interop/HandBrakeUtils.cs
@@ -18,6 +18,8 @@ namespace HandBrake.ApplicationServices.Interop
using HandBrake.ApplicationServices.Interop.HbLib;
using HandBrake.ApplicationServices.Interop.Json.Anamorphic;
using HandBrake.ApplicationServices.Interop.Json.Shared;
+ using HandBrake.ApplicationServices.Services.Logging;
+ using HandBrake.ApplicationServices.Services.Logging.Model;
using Newtonsoft.Json;
@@ -303,6 +305,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));
IntPtr json = HBFunctions.hb_set_anamorphic_size_json(Marshal.StringToHGlobalAnsi(encode));
string result = Marshal.PtrToStringAnsi(json);
return JsonConvert.DeserializeObject<Geometry>(result);
diff --git a/win/CS/HandBrake.ApplicationServices/Services/Logging/LogHelper.cs b/win/CS/HandBrake.ApplicationServices/Services/Logging/LogHelper.cs
new file mode 100644
index 000000000..e088acd1e
--- /dev/null
+++ b/win/CS/HandBrake.ApplicationServices/Services/Logging/LogHelper.cs
@@ -0,0 +1,53 @@
+// --------------------------------------------------------------------------------------------------------------------
+// <copyright file="LogHelper.cs" company="HandBrake Project (http://handbrake.fr)">
+// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License.
+// </copyright>
+// <summary>
+// The log service.
+// For now, this is just a simple logging service but we could provide support for a formal logging library later.
+// Also, we can consider providing the UI layer with more functional logging. (i.e levels, time/date, highlighting etc)
+// The Interop Classes are not very OO friendly, so this is going to be a static class.
+// </summary>
+// --------------------------------------------------------------------------------------------------------------------
+
+namespace HandBrake.ApplicationServices.Services.Logging
+{
+ using System.Diagnostics;
+
+ using HandBrake.ApplicationServices.Services.Logging.Model;
+
+ /// <summary>
+ /// The log helper.
+ /// </summary>
+ public static class LogHelper
+ {
+ private static LogLevel currentLogLevel = LogLevel.debug; // TODO default to Info when this class is implimented.
+
+ /// <summary>
+ /// Log message.
+ /// </summary>
+ /// <param name="message">
+ /// The message.
+ /// </param>
+ public static void LogMessage(LogMessage message)
+ {
+ if (message.LogLevel <= currentLogLevel)
+ {
+ Debug.WriteLine(message.Content);
+ }
+
+ // TODO cache logging.
+ }
+
+ /// <summary>
+ /// The set log level. Default: Info.
+ /// </summary>
+ /// <param name="level">
+ /// The level.
+ /// </param>
+ public static void SetLogLevel(LogLevel level)
+ {
+ currentLogLevel = level;
+ }
+ }
+}
diff --git a/win/CS/HandBrake.ApplicationServices/Services/Logging/Model/LogLevel.cs b/win/CS/HandBrake.ApplicationServices/Services/Logging/Model/LogLevel.cs
new file mode 100644
index 000000000..c2e2b8f0a
--- /dev/null
+++ b/win/CS/HandBrake.ApplicationServices/Services/Logging/Model/LogLevel.cs
@@ -0,0 +1,37 @@
+// --------------------------------------------------------------------------------------------------------------------
+// <copyright file="LogLevel.cs" company="HandBrake Project (http://handbrake.fr)">
+// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License.
+// </copyright>
+// <summary>
+// The log level.
+// </summary>
+// --------------------------------------------------------------------------------------------------------------------
+
+namespace HandBrake.ApplicationServices.Services.Logging.Model
+{
+ /// <summary>
+ /// The log level.
+ /// </summary>
+ public enum LogLevel
+ {
+ /// <summary>
+ /// The info.
+ /// </summary>
+ info,
+
+ /// <summary>
+ /// The warning.
+ /// </summary>
+ warning,
+
+ /// <summary>
+ /// The error.
+ /// </summary>
+ error,
+
+ /// <summary>
+ /// The debug.
+ /// </summary>
+ debug,
+ }
+}
diff --git a/win/CS/HandBrake.ApplicationServices/Services/Logging/Model/LogMessage.cs b/win/CS/HandBrake.ApplicationServices/Services/Logging/Model/LogMessage.cs
new file mode 100644
index 000000000..9179e2fa5
--- /dev/null
+++ b/win/CS/HandBrake.ApplicationServices/Services/Logging/Model/LogMessage.cs
@@ -0,0 +1,52 @@
+// --------------------------------------------------------------------------------------------------------------------
+// <copyright file="LogMessage.cs" company="HandBrake Project (http://handbrake.fr)">
+// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License.
+// </copyright>
+// <summary>
+// The message.
+// </summary>
+// --------------------------------------------------------------------------------------------------------------------
+
+namespace HandBrake.ApplicationServices.Services.Logging.Model
+{
+ /// <summary>
+ /// The json message.
+ /// </summary>
+ public class LogMessage
+ {
+ /// <summary>
+ /// Initializes a new instance of the <see cref="LogMessage"/> class.
+ /// </summary>
+ /// <param name="content">
+ /// The content.
+ /// </param>
+ /// <param name="messageType">
+ /// The message type.
+ /// </param>
+ /// <param name="logLevel">
+ /// The log level.
+ /// </param>
+ public LogMessage(string content, LogMessageType messageType, LogLevel logLevel)
+ {
+ this.Content = content;
+ this.MessageType = messageType;
+ this.LogLevel = logLevel;
+ }
+
+ /// <summary>
+ /// Gets the content.
+ /// </summary>
+ public string Content { get; private set; }
+
+ /// <summary>
+ /// Gets a value indicating whether this message was generated by the GUI.
+ /// If false, it was provided by libhb.
+ /// </summary>
+ public LogMessageType MessageType { get; private set; }
+
+ /// <summary>
+ /// Gets the log level.
+ /// </summary>
+ public LogLevel LogLevel { get; private set; }
+ }
+}
diff --git a/win/CS/HandBrake.ApplicationServices/Services/Logging/Model/LogMessageType.cs b/win/CS/HandBrake.ApplicationServices/Services/Logging/Model/LogMessageType.cs
new file mode 100644
index 000000000..df0ce0fc3
--- /dev/null
+++ b/win/CS/HandBrake.ApplicationServices/Services/Logging/Model/LogMessageType.cs
@@ -0,0 +1,23 @@
+// --------------------------------------------------------------------------------------------------------------------
+// <copyright file="LogMessageType.cs" company="HandBrake Project (http://handbrake.fr)">
+// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License.
+// </copyright>
+// <summary>
+// The log message type.
+// </summary>
+// --------------------------------------------------------------------------------------------------------------------
+
+namespace HandBrake.ApplicationServices.Services.Logging.Model
+{
+ /// <summary>
+ /// The log message type.
+ /// </summary>
+ public enum LogMessageType
+ {
+ scanJson,
+ encodeJson,
+ anamorphicJson,
+ progressJson,
+ libhb,
+ }
+}
diff --git a/win/CS/HandBrakeWPF/Startup/CastleBootstrapper.cs b/win/CS/HandBrakeWPF/Startup/CastleBootstrapper.cs
index f09696134..e51dc1707 100644
--- a/win/CS/HandBrakeWPF/Startup/CastleBootstrapper.cs
+++ b/win/CS/HandBrakeWPF/Startup/CastleBootstrapper.cs
@@ -22,6 +22,7 @@ namespace HandBrakeWPF.Startup
using HandBrake.ApplicationServices.Services.Encode;
using HandBrake.ApplicationServices.Services.Encode.Interfaces;
+ using HandBrake.ApplicationServices.Services.Logging;
using HandBrake.ApplicationServices.Services.Scan;
using HandBrake.ApplicationServices.Services.Scan.Interfaces;