diff options
author | sr55 <[email protected]> | 2018-06-10 13:34:39 +0100 |
---|---|---|
committer | sr55 <[email protected]> | 2018-06-10 13:34:39 +0100 |
commit | 4a6a1bf9702977b1ea89a516c02bef64fb1b6e98 (patch) | |
tree | e6ffc90d8f81cc60df67d2741dc7580dc814b207 | |
parent | 0bbe6e4bde56799acd6c8096c04f80ca3aa27fb0 (diff) |
WinGui: HandBrake.Worker tidyup.
-rw-r--r-- | win/CS/HandBrake.Worker/ApiRouter.cs | 60 | ||||
-rw-r--r-- | win/CS/HandBrake.Worker/HttpServer.cs | 10 | ||||
-rw-r--r-- | win/CS/HandBrake.Worker/Program.cs | 15 |
3 files changed, 50 insertions, 35 deletions
diff --git a/win/CS/HandBrake.Worker/ApiRouter.cs b/win/CS/HandBrake.Worker/ApiRouter.cs index 9b7b6a163..876680848 100644 --- a/win/CS/HandBrake.Worker/ApiRouter.cs +++ b/win/CS/HandBrake.Worker/ApiRouter.cs @@ -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 + { + } } diff --git a/win/CS/HandBrake.Worker/HttpServer.cs b/win/CS/HandBrake.Worker/HttpServer.cs index 4f23fa190..a920a85b3 100644 --- a/win/CS/HandBrake.Worker/HttpServer.cs +++ b/win/CS/HandBrake.Worker/HttpServer.cs @@ -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(); } }, diff --git a/win/CS/HandBrake.Worker/Program.cs b/win/CS/HandBrake.Worker/Program.cs index 09e9a8d4d..139cf8c8f 100644 --- a/win/CS/HandBrake.Worker/Program.cs +++ b/win/CS/HandBrake.Worker/Program.cs @@ -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); - } } } |