From c70981efae72a8392c18a7e92db667eddbc55485 Mon Sep 17 00:00:00 2001 From: sr55 Date: Sun, 10 Jun 2018 21:21:45 +0100 Subject: WinGui: Implement most of the HTTP Worker Process stubs. --- win/CS/HandBrake.Worker/ApiRouter.cs | 52 +++++++++++++++++------------------- 1 file changed, 24 insertions(+), 28 deletions(-) (limited to 'win/CS/HandBrake.Worker/ApiRouter.cs') diff --git a/win/CS/HandBrake.Worker/ApiRouter.cs b/win/CS/HandBrake.Worker/ApiRouter.cs index 876680848..79b0ad262 100644 --- a/win/CS/HandBrake.Worker/ApiRouter.cs +++ b/win/CS/HandBrake.Worker/ApiRouter.cs @@ -14,34 +14,40 @@ namespace HandBrake.Worker using System.Net; using HandBrake.Interop.Interop; + using HandBrake.Interop.Interop.Json.State; using HandBrake.Interop.Utilities; using Newtonsoft.Json; public class ApiRouter { + private readonly JsonSerializerSettings jsonNetSettings = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }; private HandBrakeInstance handbrakeInstance; - public string GetVersionInfo(HttpListenerRequest request) + public string Initialise(HttpListenerRequest request) { - JsonSerializerSettings settings = - new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore }; + if (this.handbrakeInstance == null) + { + this.handbrakeInstance = new HandBrakeInstance(); + } + + // TODO support verbosity + this.handbrakeInstance.Initialize(1); + + return null; + } - string versionInfo = JsonConvert.SerializeObject((object)VersionHelper.GetVersion(), Formatting.Indented, settings); + public string GetVersionInfo(HttpListenerRequest request) + { + string versionInfo = JsonConvert.SerializeObject(VersionHelper.GetVersion(), Formatting.Indented, this.jsonNetSettings); return versionInfo; } public string StartEncode(HttpListenerRequest request) { - if (this.handbrakeInstance == null) - { - this.handbrakeInstance = new HandBrakeInstance(); - } + string requestPostData = GetRequestPostData(request); - string requestPostData = ApiRouter.GetRequestPostData(request); - - this.handbrakeInstance.Initialize(1); this.handbrakeInstance.StartEncode(requestPostData); return null; @@ -49,30 +55,21 @@ namespace HandBrake.Worker public string StopEncode(HttpListenerRequest request) { - if (this.handbrakeInstance != null) - { - this.handbrakeInstance.StopEncode(); - } + this.handbrakeInstance?.StopEncode(); return (string)null; } public string PauseEncode(HttpListenerRequest request) { - if (this.handbrakeInstance != null) - { - this.handbrakeInstance.PauseEncode(); - } + this.handbrakeInstance?.PauseEncode(); return null; } public string ResumeEncode(HttpListenerRequest request) { - if (this.handbrakeInstance != null) - { - this.handbrakeInstance.ResumeEncode(); - } + this.handbrakeInstance?.ResumeEncode(); return null; } @@ -81,7 +78,10 @@ namespace HandBrake.Worker { if (this.handbrakeInstance != null) { - return null; + JsonState statusJson = this.handbrakeInstance.GetEncodeProgress(); + string versionInfo = JsonConvert.SerializeObject(statusJson, Formatting.Indented, this.jsonNetSettings); + + return versionInfo; } return null; @@ -108,8 +108,4 @@ namespace HandBrake.Worker } } } - - public class strixng - { - } } -- cgit v1.2.3