]> granicus.if.org Git - handbrake/commitdiff
WinGui: HandBrake.Worker tidyup.
authorsr55 <sr55.hb@outlook.com>
Sun, 10 Jun 2018 12:34:39 +0000 (13:34 +0100)
committersr55 <sr55.hb@outlook.com>
Sun, 10 Jun 2018 12:34:39 +0000 (13:34 +0100)
win/CS/HandBrake.Worker/ApiRouter.cs
win/CS/HandBrake.Worker/HttpServer.cs
win/CS/HandBrake.Worker/Program.cs

index 9b7b6a16374d5dfaade6b499e4e7f8344b44a3df..8766808489d534b37af32cde964a67e009c6b050 100644 (file)
@@ -8,15 +8,15 @@
 // </summary>
 // --------------------------------------------------------------------------------------------------------------------
 
-
 namespace HandBrake.Worker
 {
+    using System.IO;
+    using System.Net;
+
     using HandBrake.Interop.Interop;
     using HandBrake.Interop.Utilities;
+
     using Newtonsoft.Json;
-    using System;
-    using System.IO;
-    using System.Net;
 
     public class ApiRouter
     {
@@ -24,64 +24,92 @@ namespace HandBrake.Worker
 
         public string GetVersionInfo(HttpListenerRequest request)
         {
-            return string.Format(JsonConvert.SerializeObject((object)VersionHelper.GetVersion(), Formatting.Indented, new JsonSerializerSettings()
-            {
-                NullValueHandling = NullValueHandling.Ignore
-            }), Array.Empty<object>());
+            JsonSerializerSettings settings =
+                new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore };
+
+            string versionInfo = JsonConvert.SerializeObject((object)VersionHelper.GetVersion(), Formatting.Indented, settings);
+
+            return versionInfo;
         }
 
         public string StartEncode(HttpListenerRequest request)
         {
             if (this.handbrakeInstance == null)
+            {
                 this.handbrakeInstance = new HandBrakeInstance();
+            }
+
             string requestPostData = ApiRouter.GetRequestPostData(request);
+
             this.handbrakeInstance.Initialize(1);
             this.handbrakeInstance.StartEncode(requestPostData);
-            return (string)null;
+
+            return null;
         }
 
         public string StopEncode(HttpListenerRequest request)
         {
             if (this.handbrakeInstance != null)
+            {
                 this.handbrakeInstance.StopEncode();
+            }
+
             return (string)null;
         }
 
         public string PauseEncode(HttpListenerRequest request)
         {
             if (this.handbrakeInstance != null)
+            {
                 this.handbrakeInstance.PauseEncode();
-            return (string)null;
+            }
+
+            return null;
         }
 
         public string ResumeEncode(HttpListenerRequest request)
         {
             if (this.handbrakeInstance != null)
+            {
                 this.handbrakeInstance.ResumeEncode();
-            return (string)null;
+            }
+
+            return null;
         }
 
         public string PollEncodeProgress(HttpListenerRequest request)
         {
-            if (this.handbrakeInstance == null)
-                ;
-            return (string)null;
+            if (this.handbrakeInstance != null)
+            {
+                return null;
+            }
+
+            return null;
         }
 
         public string SetConfiguration(HttpListenerRequest request)
         {
-            return (string)null;
+            return null;
         }
 
         private static string GetRequestPostData(HttpListenerRequest request)
         {
             if (!request.HasEntityBody)
-                return (string)null;
+            {
+                return null;
+            }
+
             using (Stream inputStream = request.InputStream)
             {
                 using (StreamReader streamReader = new StreamReader(inputStream, request.ContentEncoding))
+                {
                     return streamReader.ReadToEnd();
+                }
             }
         }
     }
+
+    public class strixng
+    {
+    }
 }
index 4f23fa190595145449868e9b19518ed2ed7b4d7e..a920a85b33f3e854cb4d5477370591fbcbdefdd9 100644 (file)
@@ -57,13 +57,16 @@ namespace HandBrake.Worker
                             (c) =>
                                 {
                                     var context = c as HttpListenerContext;
+                                    if (context == null)
+                                    {
+                                        return;
+                                    }
+
                                     try
                                     {
-                                        string requestType = context.Request.HttpMethod;
                                         string path = context.Request.RawUrl.TrimStart('/');
 
-                                        Func<HttpListenerRequest, string> actionToPerform;
-                                        if (apiHandlers.TryGetValue(path, out actionToPerform))
+                                        if (this.apiHandlers.TryGetValue(path, out var actionToPerform))
                                         {
                                             string rstr = actionToPerform(context.Request);
                                             byte[] buf = Encoding.UTF8.GetBytes(rstr);
@@ -84,7 +87,6 @@ namespace HandBrake.Worker
                                     }
                                     finally
                                     {
-                                        // always close the stream
                                         context?.Response.OutputStream.Close();
                                     }
                                 },
index 09e9a8d4dfd5a8b9e01143cfffd6047839787a94..139cf8c8f9305c5a68e2e561f17706a188a7bf6b 100644 (file)
@@ -12,8 +12,6 @@ namespace HandBrake.Worker
     using System;
     using System.Collections.Generic;
     using System.Net;
-    using HandBrake.Interop.Utilities;
-    using Newtonsoft.Json;
 
     public class Program
     {
@@ -71,19 +69,6 @@ namespace HandBrake.Worker
 
             return apiHandlers;
         }
-
-        public static string GetVersionInfo(HttpListenerRequest request)
-        {
-            string version = VersionHelper.GetVersion();
-            JsonSerializerSettings settings = new JsonSerializerSettings
-                                                  {
-                                                      NullValueHandling = NullValueHandling.Ignore,
-                                                  };
-
-            string versionJson = JsonConvert.SerializeObject(version, Formatting.Indented, settings);
-
-            return string.Format(versionJson);
-        }
     }
 }