]> granicus.if.org Git - handbrake/commitdiff
WinGui: Add a basic outline of a logging system to allow logging of the JSON and...
authorsr55 <sr55.hb@outlook.com>
Fri, 10 Apr 2015 22:29:57 +0000 (22:29 +0000)
committersr55 <sr55.hb@outlook.com>
Fri, 10 Apr 2015 22:29:57 +0000 (22:29 +0000)
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@7084 b64f7644-9d1e-0410-96f1-a4d463321fa5

win/CS/HandBrake.ApplicationServices/HandBrake.ApplicationServices.csproj
win/CS/HandBrake.ApplicationServices/Interop/HandBrakeInstance.cs
win/CS/HandBrake.ApplicationServices/Interop/HandBrakeUtils.cs
win/CS/HandBrake.ApplicationServices/Services/Logging/LogHelper.cs [new file with mode: 0644]
win/CS/HandBrake.ApplicationServices/Services/Logging/Model/LogLevel.cs [new file with mode: 0644]
win/CS/HandBrake.ApplicationServices/Services/Logging/Model/LogMessage.cs [new file with mode: 0644]
win/CS/HandBrake.ApplicationServices/Services/Logging/Model/LogMessageType.cs [new file with mode: 0644]
win/CS/HandBrakeWPF/Startup/CastleBootstrapper.cs

index 91b8dfea8aa2087a48277a3e4e456697f1d9b260..a8bb2a0634cd2623a00defd2a98431cf94cd9dc4 100644 (file)
     <Compile Include="Services\Encode\Model\Models\Video\VideoPreset.cs" />\r
     <Compile Include="Services\Encode\Model\Models\Video\VideoProfile.cs" />\r
     <Compile Include="Services\Encode\Model\Models\Video\VideoTune.cs" />\r
+    <Compile Include="Services\Logging\LogHelper.cs" />\r
+    <Compile Include="Services\Logging\Model\LogLevel.cs" />\r
+    <Compile Include="Services\Logging\Model\LogMessage.cs" />\r
+    <Compile Include="Services\Logging\Model\LogMessageType.cs" />\r
     <Compile Include="Services\Scan\EventArgs\ScanCompletedEventArgs.cs" />\r
     <Compile Include="Services\Scan\EventArgs\ScanProgressEventArgs.cs" />\r
     <Compile Include="Utilities\Converters.cs" />\r
index 97193c8ddd2d39237c282f8aa394883200f45f13..a97185e19b0ac961f2f20d08255094407ac35b56 100644 (file)
@@ -33,6 +33,8 @@ namespace HandBrake.ApplicationServices.Interop
     using HandBrake.ApplicationServices.Interop.Model;\r
     using HandBrake.ApplicationServices.Interop.Model.Encoding;\r
     using HandBrake.ApplicationServices.Interop.Model.Preview;\r
+    using HandBrake.ApplicationServices.Services.Logging;\r
+    using HandBrake.ApplicationServices.Services.Logging.Model;\r
 \r
     using Newtonsoft.Json;\r
 \r
@@ -353,6 +355,7 @@ namespace HandBrake.ApplicationServices.Interop
             };\r
 \r
             string encode = JsonConvert.SerializeObject(encodeObject, Formatting.Indented, settings);\r
+            LogHelper.LogMessage(new LogMessage(encode, LogMessageType.encodeJson, LogLevel.debug));\r
             HBFunctions.hb_add_json(this.hbHandle, InteropUtilities.ToUtf8PtrFromString(encode));\r
             HBFunctions.hb_start(this.hbHandle);\r
 \r
@@ -458,6 +461,7 @@ namespace HandBrake.ApplicationServices.Interop
         {\r
             IntPtr json = HBFunctions.hb_get_state_json(this.hbHandle);\r
             string statusJson = Marshal.PtrToStringAnsi(json);\r
+            LogHelper.LogMessage(new LogMessage(statusJson, LogMessageType.progressJson, LogLevel.debug));\r
             JsonState state = JsonConvert.DeserializeObject<JsonState>(statusJson);\r
 \r
             if (state != null && state.State == NativeConstants.HB_STATE_SCANNING)\r
@@ -478,6 +482,7 @@ namespace HandBrake.ApplicationServices.Interop
             {\r
                 var jsonMsg = HBFunctions.hb_get_title_set_json(this.hbHandle);\r
                 string scanJson = InteropUtilities.ToStringFromUtf8Ptr(jsonMsg);\r
+                LogHelper.LogMessage(new LogMessage(scanJson, LogMessageType.scanJson, LogLevel.debug));\r
                 this.titles = JsonConvert.DeserializeObject<JsonScanObject>(scanJson);\r
                 this.featureTitle = this.titles.MainFeature;\r
 \r
@@ -501,6 +506,9 @@ namespace HandBrake.ApplicationServices.Interop
         {\r
             IntPtr json = HBFunctions.hb_get_state_json(this.hbHandle);\r
             string statusJson = Marshal.PtrToStringAnsi(json);\r
+\r
+            LogHelper.LogMessage(new LogMessage(statusJson, LogMessageType.progressJson, LogLevel.debug));\r
+\r
             JsonState state = JsonConvert.DeserializeObject<JsonState>(statusJson);\r
 \r
             if (state != null && state.State == NativeConstants.HB_STATE_WORKING)\r
index 098646ddda9a0eb98739dae37f04df32153b579d..7a00bb8e9dfb1cc63e8939aa828cdb1c6066e83d 100644 (file)
@@ -18,6 +18,8 @@ namespace HandBrake.ApplicationServices.Interop
     using HandBrake.ApplicationServices.Interop.HbLib;\r
     using HandBrake.ApplicationServices.Interop.Json.Anamorphic;\r
     using HandBrake.ApplicationServices.Interop.Json.Shared;\r
+    using HandBrake.ApplicationServices.Services.Logging;\r
+    using HandBrake.ApplicationServices.Services.Logging.Model;\r
 \r
     using Newtonsoft.Json;\r
 \r
@@ -303,6 +305,7 @@ namespace HandBrake.ApplicationServices.Interop
         public static Geometry GetAnamorphicSize(AnamorphicGeometry anamorphicGeometry)\r
         {\r
             string encode = JsonConvert.SerializeObject(anamorphicGeometry, Formatting.Indented, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore });\r
+            LogHelper.LogMessage(new LogMessage(encode, LogMessageType.encodeJson, LogLevel.debug));\r
             IntPtr json = HBFunctions.hb_set_anamorphic_size_json(Marshal.StringToHGlobalAnsi(encode));\r
             string result = Marshal.PtrToStringAnsi(json);\r
             return JsonConvert.DeserializeObject<Geometry>(result);\r
diff --git a/win/CS/HandBrake.ApplicationServices/Services/Logging/LogHelper.cs b/win/CS/HandBrake.ApplicationServices/Services/Logging/LogHelper.cs
new file mode 100644 (file)
index 0000000..e088acd
--- /dev/null
@@ -0,0 +1,53 @@
+// --------------------------------------------------------------------------------------------------------------------\r
+// <copyright file="LogHelper.cs" company="HandBrake Project (http://handbrake.fr)">\r
+//   This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License.\r
+// </copyright>\r
+// <summary>\r
+//   The log service.\r
+//   For now, this is just a simple logging service but we could provide support for a formal logging library later.\r
+//   Also, we can consider providing the UI layer with more functional logging. (i.e levels, time/date, highlighting etc)\r
+//   The Interop Classes are not very OO friendly, so this is going to be a static class.\r
+// </summary>\r
+// --------------------------------------------------------------------------------------------------------------------\r
+\r
+namespace HandBrake.ApplicationServices.Services.Logging\r
+{\r
+    using System.Diagnostics;\r
+\r
+    using HandBrake.ApplicationServices.Services.Logging.Model;\r
+\r
+    /// <summary>\r
+    /// The log helper.\r
+    /// </summary>\r
+    public static class LogHelper\r
+    {\r
+        private static LogLevel currentLogLevel = LogLevel.debug; // TODO default to Info when this class is implimented. \r
+\r
+        /// <summary>\r
+        /// Log message.\r
+        /// </summary>\r
+        /// <param name="message">\r
+        /// The message.\r
+        /// </param>\r
+        public static void LogMessage(LogMessage message)\r
+        {\r
+            if (message.LogLevel <= currentLogLevel)\r
+            {\r
+                Debug.WriteLine(message.Content);\r
+            }\r
+\r
+            // TODO cache logging.         \r
+        }\r
+\r
+        /// <summary>\r
+        /// The set log level. Default: Info.\r
+        /// </summary>\r
+        /// <param name="level">\r
+        /// The level.\r
+        /// </param>\r
+        public static void SetLogLevel(LogLevel level)\r
+        {\r
+            currentLogLevel = level;\r
+        }\r
+    }\r
+}\r
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 (file)
index 0000000..c2e2b8f
--- /dev/null
@@ -0,0 +1,37 @@
+// --------------------------------------------------------------------------------------------------------------------\r
+// <copyright file="LogLevel.cs" company="HandBrake Project (http://handbrake.fr)">\r
+//   This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License.\r
+// </copyright>\r
+// <summary>\r
+//   The log level.\r
+// </summary>\r
+// --------------------------------------------------------------------------------------------------------------------\r
+\r
+namespace HandBrake.ApplicationServices.Services.Logging.Model\r
+{\r
+    /// <summary>\r
+    /// The log level.\r
+    /// </summary>\r
+    public enum LogLevel\r
+    {\r
+        /// <summary>\r
+        /// The info.\r
+        /// </summary>\r
+        info,\r
+\r
+        /// <summary>\r
+        /// The warning.\r
+        /// </summary>\r
+        warning, \r
+\r
+        /// <summary>\r
+        /// The error.\r
+        /// </summary>\r
+        error,      \r
+        \r
+        /// <summary>\r
+        /// The debug.\r
+        /// </summary>\r
+        debug, \r
+    }\r
+}\r
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 (file)
index 0000000..9179e2f
--- /dev/null
@@ -0,0 +1,52 @@
+// --------------------------------------------------------------------------------------------------------------------\r
+// <copyright file="LogMessage.cs" company="HandBrake Project (http://handbrake.fr)">\r
+//   This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License.\r
+// </copyright>\r
+// <summary>\r
+//   The message.\r
+// </summary>\r
+// --------------------------------------------------------------------------------------------------------------------\r
+\r
+namespace HandBrake.ApplicationServices.Services.Logging.Model\r
+{\r
+    /// <summary>\r
+    /// The json message.\r
+    /// </summary>\r
+    public class LogMessage\r
+    {\r
+        /// <summary>\r
+        /// Initializes a new instance of the <see cref="LogMessage"/> class.\r
+        /// </summary>\r
+        /// <param name="content">\r
+        /// The content.\r
+        /// </param>\r
+        /// <param name="messageType">\r
+        /// The message type.\r
+        /// </param>\r
+        /// <param name="logLevel">\r
+        /// The log level.\r
+        /// </param>\r
+        public LogMessage(string content, LogMessageType messageType, LogLevel logLevel)\r
+        {\r
+            this.Content = content;\r
+            this.MessageType = messageType;\r
+            this.LogLevel = logLevel;\r
+        }\r
+\r
+        /// <summary>\r
+        /// Gets the content.\r
+        /// </summary>\r
+        public string Content { get; private set; }\r
+\r
+        /// <summary>\r
+        /// Gets a value indicating whether this message was generated by the GUI.\r
+        /// If false, it was provided by libhb.\r
+        /// </summary>\r
+        public LogMessageType MessageType { get; private set; }\r
+\r
+        /// <summary>\r
+        /// Gets the log level.\r
+        /// </summary>\r
+        public LogLevel LogLevel { get; private set; }\r
+    }\r
+}\r
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 (file)
index 0000000..df0ce0f
--- /dev/null
@@ -0,0 +1,23 @@
+// --------------------------------------------------------------------------------------------------------------------\r
+// <copyright file="LogMessageType.cs" company="HandBrake Project (http://handbrake.fr)">\r
+//   This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License.\r
+// </copyright>\r
+// <summary>\r
+//   The log message type.\r
+// </summary>\r
+// --------------------------------------------------------------------------------------------------------------------\r
+\r
+namespace HandBrake.ApplicationServices.Services.Logging.Model\r
+{\r
+    /// <summary>\r
+    /// The log message type.\r
+    /// </summary>\r
+    public enum LogMessageType\r
+    {\r
+        scanJson,\r
+        encodeJson,\r
+        anamorphicJson,\r
+        progressJson,\r
+        libhb,\r
+    }\r
+}\r
index f0969613412483e445956a84ad5408d33fd7263b..e51dc1707c8ead674aec5fb21dd7a2e6e99d7bb6 100644 (file)
@@ -22,6 +22,7 @@ namespace HandBrakeWPF.Startup
 \r
     using HandBrake.ApplicationServices.Services.Encode;\r
     using HandBrake.ApplicationServices.Services.Encode.Interfaces;\r
+    using HandBrake.ApplicationServices.Services.Logging;\r
     using HandBrake.ApplicationServices.Services.Scan;\r
     using HandBrake.ApplicationServices.Services.Scan.Interfaces;\r
 \r