From 5cce72f890bc7b6075a55aa4364b8817c22f11c0 Mon Sep 17 00:00:00 2001 From: sr55 Date: Sun, 1 Mar 2015 17:53:54 +0000 Subject: [PATCH] WinGui: Removing the Isolation code as it's not used, and planned for libhb instead. git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@6958 b64f7644-9d1e-0410-96f1-a4d463321fa5 --- .../HandBrake.ApplicationServices.csproj | 3 - .../Isolation/BackgroundServiceConnector.cs | 179 --------------- .../Isolation/IsolatedEncodeService.cs | 216 ------------------ .../Interfaces/IEncodeServiceWrapper.cs | 18 -- .../Services/Interfaces/IQueueProcessor.cs | 2 +- .../Services/QueueProcessor.cs | 4 +- .../Services/EncodeServiceWrapper.cs | 27 +-- .../Services/NotificationService.cs | 2 +- .../Startup/CastleBootstrapper.cs | 2 +- win/CS/HandBrakeWPF/UserSettingConstants.cs | 10 - .../HandBrakeWPF/ViewModels/LogViewModel.cs | 4 +- .../HandBrakeWPF/ViewModels/MainViewModel.cs | 4 +- .../ViewModels/OptionsViewModel.cs | 49 ---- .../ViewModels/StaticPreviewViewModel.cs | 4 +- win/CS/HandBrakeWPF/Views/OptionsView.xaml | 16 -- 15 files changed, 16 insertions(+), 524 deletions(-) delete mode 100644 win/CS/HandBrake.ApplicationServices/Isolation/BackgroundServiceConnector.cs delete mode 100644 win/CS/HandBrake.ApplicationServices/Isolation/IsolatedEncodeService.cs delete mode 100644 win/CS/HandBrake.ApplicationServices/Services/Encode/Interfaces/IEncodeServiceWrapper.cs diff --git a/win/CS/HandBrake.ApplicationServices/HandBrake.ApplicationServices.csproj b/win/CS/HandBrake.ApplicationServices/HandBrake.ApplicationServices.csproj index fccf0154e..7b0c96fd8 100644 --- a/win/CS/HandBrake.ApplicationServices/HandBrake.ApplicationServices.csproj +++ b/win/CS/HandBrake.ApplicationServices/HandBrake.ApplicationServices.csproj @@ -201,8 +201,6 @@ - - @@ -213,7 +211,6 @@ - diff --git a/win/CS/HandBrake.ApplicationServices/Isolation/BackgroundServiceConnector.cs b/win/CS/HandBrake.ApplicationServices/Isolation/BackgroundServiceConnector.cs deleted file mode 100644 index 0fa7c2474..000000000 --- a/win/CS/HandBrake.ApplicationServices/Isolation/BackgroundServiceConnector.cs +++ /dev/null @@ -1,179 +0,0 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. -// -// -// Background Service Connector. -// HandBrake has the ability to connect to a service app that will control Libhb. -// This acts as process isolation. -// -// -------------------------------------------------------------------------------------------------------------------- - -namespace HandBrake.ApplicationServices.Isolation -{ - using System; - using System.Diagnostics; - using System.ServiceModel; - using System.Threading; - - using HandBrake.ApplicationServices.Exceptions; - using HandBrake.ApplicationServices.Services.Encode.EventArgs; - using HandBrake.ApplicationServices.Services.Interfaces; - - /// - /// Background Service Connector. - /// HandBrake has the ability to connect to a service app that will control Libhb. - /// This acts as process isolation. - /// - public class BackgroundServiceConnector : IHbServiceCallback, IDisposable - { - #region Constants and Fields - - /// - /// Gets or sets the pipe factory. - /// DuplexChannelFactory is necessary for Callbacks. - /// - private static DuplexChannelFactory pipeFactory; - - /// - /// The background process. - /// - private static Process backgroundProcess; - - #endregion - - #region Properties - - /// - /// Gets or sets a value indicating whether is connected. - /// - public bool IsConnected { get; set; } - - /// - /// Gets or sets the service. - /// - public IServerService Service { get; set; } - - #endregion - - #region Public Server Management Methods - - /// - /// The can connect. - /// - /// - /// The System.Boolean. - /// - public bool CanConnect() - { - return true; - } - - /// - /// The connect. - /// - /// - /// The port. - /// - public void Connect(string port) - { - if (backgroundProcess == null) - { - ProcessStartInfo processStartInfo = new ProcessStartInfo( - "HandBrake.Server.exe", port) - { - UseShellExecute = false, - CreateNoWindow = true, - RedirectStandardOutput = true, - }; - - backgroundProcess = new Process { StartInfo = processStartInfo }; - backgroundProcess.Start(); - } - - // When the process writes out a line, it's pipe server is ready and can be contacted for - // work. Reading line blocks until this happens. - backgroundProcess.StandardOutput.ReadLine(); - - ThreadPool.QueueUserWorkItem(delegate - { - try - { - pipeFactory = new DuplexChannelFactory( - new InstanceContext(this), - new NetTcpBinding(), - new EndpointAddress(string.Format("net.tcp://127.0.0.1:{0}/IHbService", port))); - - // Connect and Subscribe to the Server - this.Service = pipeFactory.CreateChannel(); - this.Service.Subscribe(); - this.IsConnected = true; - } - catch (Exception exc) - { - throw new GeneralApplicationException("Unable to connect to background worker process", "Please restart HandBrake", exc); - } - }); - } - - /// - /// The disconnect. - /// - public void Shutdown() - { - try - { - if (backgroundProcess != null && !backgroundProcess.HasExited) - { - this.Service.Unsubscribe(); - } - } - catch (Exception exc) - { - throw new GeneralApplicationException("Unable to disconnect to background worker process", - "It may have already close. Check for any left over HandBrake.Server.exe processes", exc); - } - } - - #endregion - - #region Implemented Interfaces - - /// - /// The dispose. - /// - public void Dispose() - { - this.Service.Unsubscribe(); - } - - /// - /// The encode progress callback. - /// - /// - /// The event Args. - /// - public virtual void EncodeProgressCallback(EncodeProgressEventArgs eventArgs) - { - } - - /// - /// The encode completed callback. - /// - /// - /// The event Args. - /// - public virtual void EncodeCompletedCallback(EncodeCompletedEventArgs eventArgs) - { - } - - /// - /// The encode started callback. - /// - public virtual void EncodeStartedCallback() - { - } - - #endregion - } -} \ No newline at end of file diff --git a/win/CS/HandBrake.ApplicationServices/Isolation/IsolatedEncodeService.cs b/win/CS/HandBrake.ApplicationServices/Isolation/IsolatedEncodeService.cs deleted file mode 100644 index a98941b1f..000000000 --- a/win/CS/HandBrake.ApplicationServices/Isolation/IsolatedEncodeService.cs +++ /dev/null @@ -1,216 +0,0 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. -// -// -// Isolated Scan Service -// This is an implementation of the IEncode implementation that runs scans on a seperate process -// -// -------------------------------------------------------------------------------------------------------------------- - -namespace HandBrake.ApplicationServices.Isolation -{ - using System; - using System.Threading; - - using HandBrake.ApplicationServices.Exceptions; - using HandBrake.ApplicationServices.Model; - using HandBrake.ApplicationServices.Services.Encode.EventArgs; - using HandBrake.ApplicationServices.Services.Encode.Interfaces; - - /// - /// Isolated Scan Service. - /// This is an implementation of the IEncode implementation that runs scans on a seperate process - /// - public class IsolatedEncodeService : BackgroundServiceConnector, IEncode - { - #region Constructors and Destructors - - /// - /// Initializes a new instance of the class. - /// - /// - /// The port. - /// - public IsolatedEncodeService(string port) - { - try - { - if (this.CanConnect()) - { - this.Connect(port); - } - } - catch (Exception exception) - { - throw new GeneralApplicationException("Unable to connect to scan worker process.", "Try restarting HandBrake", exception); - } - } - - #endregion - - #region Events - - /// - /// The encode completed. - /// - public event EncodeCompletedStatus EncodeCompleted; - - /// - /// The encode started. - /// - public event EventHandler EncodeStarted; - - /// - /// The encode status changed. - /// - public event EncodeProgessStatus EncodeStatusChanged; - - #endregion - - #region Properties - - /// - /// Gets ActivityLog. - /// - public string ActivityLog - { - get - { - return this.IsConnected ? this.Service.EncodeActivityLog : "Unable to connect to background worker service ..."; - } - } - - /// - /// Gets the log index. - /// - public int LogIndex - { - get - { - return -1; - } - } - - /// - /// Gets a value indicating whether can pause. - /// - public bool CanPause - { - get - { - return false; // TODO make this work. - } - } - - /// - /// Gets a value indicating whether is pasued. - /// - public bool IsPasued { get; private set; } - - /// - /// Gets a value indicating whether IsEncoding. - /// - public bool IsEncoding - { - get - { - return this.IsConnected && this.Service.IsEncoding; - } - } - - #endregion - - #region Public Methods - - /// - /// The encode completed callback. - /// - /// - /// The event args. - /// - public override void EncodeCompletedCallback(EncodeCompletedEventArgs eventArgs) - { - if (this.EncodeCompleted != null) - { - ThreadPool.QueueUserWorkItem(delegate { this.EncodeCompleted(this, eventArgs); }); - } - - base.EncodeCompletedCallback(eventArgs); - } - - /// - /// The encode progress callback. - /// - /// - /// The event args. - /// - public override void EncodeProgressCallback(EncodeProgressEventArgs eventArgs) - { - if (this.EncodeStatusChanged != null) - { - ThreadPool.QueueUserWorkItem(delegate { this.EncodeStatusChanged(this, eventArgs); }); - } - - base.EncodeProgressCallback(eventArgs); - } - - #endregion - - #region Implemented Interfaces - - #region IEncode - - /// - /// Copy the log file to the desired destinations - /// - /// - /// The destination. - /// - /// - /// The configuration. - /// - public void ProcessLogs(string destination, HBConfiguration configuration) - { - ThreadPool.QueueUserWorkItem(delegate { this.Service.ProcessEncodeLogs(destination, configuration); }); - } - - /// - /// Start with a LibHb EncodeJob Object - /// - /// - /// The job. - /// - public void Start(QueueTask job) - { - ThreadPool.QueueUserWorkItem( - delegate { this.Service.StartEncode(job); }); - } - - /// - /// The pause. - /// - public void Pause() - { - } - - /// - /// The resume. - /// - public void Resume() - { - } - - /// - /// Kill the CLI process - /// - public void Stop() - { - ThreadPool.QueueUserWorkItem(delegate { this.Service.StopEncode(); }); - } - - #endregion - - #endregion - } -} \ No newline at end of file diff --git a/win/CS/HandBrake.ApplicationServices/Services/Encode/Interfaces/IEncodeServiceWrapper.cs b/win/CS/HandBrake.ApplicationServices/Services/Encode/Interfaces/IEncodeServiceWrapper.cs deleted file mode 100644 index 6163bcffc..000000000 --- a/win/CS/HandBrake.ApplicationServices/Services/Encode/Interfaces/IEncodeServiceWrapper.cs +++ /dev/null @@ -1,18 +0,0 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. -// -// -// IEncodeServiceWrapper Interface -// -// -------------------------------------------------------------------------------------------------------------------- - -namespace HandBrake.ApplicationServices.Services.Encode.Interfaces -{ - /// - /// EncodeServiceWrapper Interface - /// - public interface IEncodeServiceWrapper : IEncode - { - } -} diff --git a/win/CS/HandBrake.ApplicationServices/Services/Interfaces/IQueueProcessor.cs b/win/CS/HandBrake.ApplicationServices/Services/Interfaces/IQueueProcessor.cs index 7cb0ef7b6..4e5b51d93 100644 --- a/win/CS/HandBrake.ApplicationServices/Services/Interfaces/IQueueProcessor.cs +++ b/win/CS/HandBrake.ApplicationServices/Services/Interfaces/IQueueProcessor.cs @@ -55,7 +55,7 @@ namespace HandBrake.ApplicationServices.Services.Interfaces /// /// Gets the IEncodeService instance. /// - IEncodeServiceWrapper EncodeService { get; } + IEncode EncodeService { get; } /// /// Gets a value indicating whether IsProcessing. diff --git a/win/CS/HandBrake.ApplicationServices/Services/QueueProcessor.cs b/win/CS/HandBrake.ApplicationServices/Services/QueueProcessor.cs index 991b2132e..ba6a3a92e 100644 --- a/win/CS/HandBrake.ApplicationServices/Services/QueueProcessor.cs +++ b/win/CS/HandBrake.ApplicationServices/Services/QueueProcessor.cs @@ -66,7 +66,7 @@ namespace HandBrake.ApplicationServices.Services /// /// Services are not setup /// - public QueueProcessor(IEncodeServiceWrapper encodeService) + public QueueProcessor(IEncode encodeService) { this.EncodeService = encodeService; @@ -143,7 +143,7 @@ namespace HandBrake.ApplicationServices.Services /// /// Gets the IEncodeService instance. /// - public IEncodeServiceWrapper EncodeService { get; private set; } + public IEncode EncodeService { get; private set; } /// /// Gets a value indicating whether IsProcessing. diff --git a/win/CS/HandBrakeWPF/Services/EncodeServiceWrapper.cs b/win/CS/HandBrakeWPF/Services/EncodeServiceWrapper.cs index b63b74078..867f523c8 100644 --- a/win/CS/HandBrakeWPF/Services/EncodeServiceWrapper.cs +++ b/win/CS/HandBrakeWPF/Services/EncodeServiceWrapper.cs @@ -14,20 +14,17 @@ namespace HandBrakeWPF.Services using System; using HandBrake.ApplicationServices.Exceptions; - using HandBrake.ApplicationServices.Isolation; using HandBrake.ApplicationServices.Model; using HandBrake.ApplicationServices.Services.Encode; using HandBrake.ApplicationServices.Services.Encode.EventArgs; using HandBrake.ApplicationServices.Services.Encode.Interfaces; - using HandBrakeWPF.Services.Interfaces; - /// /// We have multiple implementations of Iencode. This is a wrapper class for the GUI so that the /// implementation used is controllable via user settings. /// Over time, this class will go away when the LibHB and process isolation code matures. /// - public class EncodeServiceWrapper : IEncodeServiceWrapper + public class EncodeServiceWrapper : IEncode { #region Constants and Fields @@ -43,32 +40,18 @@ namespace HandBrakeWPF.Services /// /// Initializes a new instance of the class. /// - /// - /// The user setting service. - /// - public EncodeServiceWrapper(IUserSettingService userSettingService) + public EncodeServiceWrapper() { - var useProcessIsolation = - userSettingService.GetUserSetting(UserSettingConstants.EnableProcessIsolation); - var port = userSettingService.GetUserSetting(UserSettingConstants.ServerPort); - try { - if (useProcessIsolation) - { - this.encodeService = new IsolatedEncodeService(port); - } - else - { - this.encodeService = new LibEncode(); - } + this.encodeService = new LibEncode(); } catch (Exception exc) { // Try to recover from errors. throw new GeneralApplicationException( - "Unable to initialise LibHB or Background worker service", - "HandBrake will not be able to operate correctly.", + "Unable to initialise LibHB or Background worker service", + "HandBrake will not be able to operate correctly.", exc); } diff --git a/win/CS/HandBrakeWPF/Services/NotificationService.cs b/win/CS/HandBrakeWPF/Services/NotificationService.cs index ba3c0cf99..1a647a970 100644 --- a/win/CS/HandBrakeWPF/Services/NotificationService.cs +++ b/win/CS/HandBrakeWPF/Services/NotificationService.cs @@ -37,7 +37,7 @@ namespace HandBrakeWPF.Services /// /// The user Setting Service. /// - public NotificationService(IEncodeServiceWrapper encodeService, IQueueProcessor queueProcessor, IUserSettingService userSettingService) + public NotificationService(IEncode encodeService, IQueueProcessor queueProcessor, IUserSettingService userSettingService) { this.userSettingService = userSettingService; // encodeService.EncodeCompleted += this.EncodeServiceEncodeCompleted; diff --git a/win/CS/HandBrakeWPF/Startup/CastleBootstrapper.cs b/win/CS/HandBrakeWPF/Startup/CastleBootstrapper.cs index 10da855fa..c8b327cd3 100644 --- a/win/CS/HandBrakeWPF/Startup/CastleBootstrapper.cs +++ b/win/CS/HandBrakeWPF/Startup/CastleBootstrapper.cs @@ -62,7 +62,7 @@ namespace HandBrakeWPF.Startup // Services this.windsorContainer.Register(Component.For().ImplementedBy().LifeStyle.Is(LifestyleType.Singleton)); this.windsorContainer.Register(Component.For().ImplementedBy().LifeStyle.Is(LifestyleType.Singleton)); - this.windsorContainer.Register(Component.For().ImplementedBy().LifeStyle.Is(LifestyleType.Singleton)); + this.windsorContainer.Register(Component.For().ImplementedBy().LifeStyle.Is(LifestyleType.Singleton)); this.windsorContainer.Register(Component.For().ImplementedBy().LifeStyle.Is(LifestyleType.Singleton)); this.windsorContainer.Register(Component.For().ImplementedBy().LifeStyle.Is(LifestyleType.Singleton)); this.windsorContainer.Register(Component.For().ImplementedBy()); diff --git a/win/CS/HandBrakeWPF/UserSettingConstants.cs b/win/CS/HandBrakeWPF/UserSettingConstants.cs index fb3f6a04b..1c5464079 100644 --- a/win/CS/HandBrakeWPF/UserSettingConstants.cs +++ b/win/CS/HandBrakeWPF/UserSettingConstants.cs @@ -96,16 +96,6 @@ namespace HandBrakeWPF /// public const string VLCPath = "VLC_Path"; - /// - /// The enable process isolation. - /// - public const string EnableProcessIsolation = "EnableProcessIsolation"; - - /// - /// The server port. - /// - public const string ServerPort = "ServerPort"; - /// /// Growl Encodes /// diff --git a/win/CS/HandBrakeWPF/ViewModels/LogViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/LogViewModel.cs index 21921b5d6..008d70dcb 100644 --- a/win/CS/HandBrakeWPF/ViewModels/LogViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/LogViewModel.cs @@ -30,7 +30,7 @@ namespace HandBrakeWPF.ViewModels /// /// Backing field for the encodeService service /// - private readonly IEncodeServiceWrapper encodeService; + private readonly IEncode encodeService; /// /// Backing field for the Scan Service @@ -58,7 +58,7 @@ namespace HandBrakeWPF.ViewModels /// /// The scan service. /// - public LogViewModel(IEncodeServiceWrapper encodeService, IScan scanService) + public LogViewModel(IEncode encodeService, IScan scanService) { this.encodeService = encodeService; this.scanService = scanService; diff --git a/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs index d3fd9900c..f204b084d 100644 --- a/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs @@ -97,7 +97,7 @@ namespace HandBrakeWPF.ViewModels /// /// The Encode Service /// - private readonly IEncodeServiceWrapper encodeService; + private readonly IEncode encodeService; /// /// Windows 7 API Pack wrapper @@ -229,7 +229,7 @@ namespace HandBrakeWPF.ViewModels /// The when Done Service. /// *** Leave in Constructor. *** /// - public MainViewModel(IUserSettingService userSettingService, IScan scanService, IEncodeServiceWrapper encodeService, IPresetService presetService, + public MainViewModel(IUserSettingService userSettingService, IScan scanService, IEncode encodeService, IPresetService presetService, IErrorService errorService, IShellViewModel shellViewModel, IUpdateService updateService, INotificationService notificationService, IPrePostActionService whenDoneService) { diff --git a/win/CS/HandBrakeWPF/ViewModels/OptionsViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/OptionsViewModel.cs index 77132cf11..31841a335 100644 --- a/win/CS/HandBrakeWPF/ViewModels/OptionsViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/OptionsViewModel.cs @@ -260,16 +260,6 @@ namespace HandBrakeWPF.ViewModels /// private UpdateCheckInformation updateInfo; - /// - /// The enable process isolation. - /// - private bool enableProcessIsolation; - - /// - /// The server port. - /// - private int serverPort; - /// /// The show advanced tab backing field. /// @@ -1060,38 +1050,6 @@ namespace HandBrakeWPF.ViewModels } } - /// - /// Gets or sets a value indicating whether ClearQueueOnEncodeCompleted. - /// - public bool EnableProcessIsolation - { - get - { - return this.enableProcessIsolation; - } - set - { - this.enableProcessIsolation = value; - this.NotifyOfPropertyChange(() => this.EnableProcessIsolation); - } - } - - /// - /// Gets or sets the server port. - /// - public int ServerPort - { - get - { - return this.serverPort; - } - set - { - this.serverPort = value; - this.NotifyOfPropertyChange(() => this.ServerPort); - } - } - /// /// Gets or sets a value indicating whether enable lib hb. /// @@ -1541,11 +1499,6 @@ namespace HandBrakeWPF.ViewModels // Use dvdnav this.DisableLibdvdNav = userSettingService.GetUserSetting(UserSettingConstants.DisableLibDvdNav); - - int port; - int.TryParse(userSettingService.GetUserSetting(UserSettingConstants.ServerPort), out port); - this.ServerPort = port; - this.EnableProcessIsolation = userSettingService.GetUserSetting(UserSettingConstants.EnableProcessIsolation); } /// @@ -1606,8 +1559,6 @@ namespace HandBrakeWPF.ViewModels } userSettingService.SetUserSetting(UserSettingConstants.DisableLibDvdNav, this.DisableLibdvdNav); - userSettingService.SetUserSetting(UserSettingConstants.EnableProcessIsolation, this.EnableProcessIsolation); - userSettingService.SetUserSetting(UserSettingConstants.ServerPort, this.ServerPort.ToString(CultureInfo.InvariantCulture)); } /// diff --git a/win/CS/HandBrakeWPF/ViewModels/StaticPreviewViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/StaticPreviewViewModel.cs index 5099a2d9a..ff1b1a0c9 100644 --- a/win/CS/HandBrakeWPF/ViewModels/StaticPreviewViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/StaticPreviewViewModel.cs @@ -55,7 +55,7 @@ namespace HandBrakeWPF.ViewModels /// /// Backing field for the encode service. /// - private readonly IEncodeServiceWrapper encodeService; + private readonly IEncode encodeService; /// /// The error service @@ -134,7 +134,7 @@ namespace HandBrakeWPF.ViewModels // Live Preview this.userSettingService = userSettingService; - this.encodeService = new EncodeServiceWrapper(userSettingService); // Preview needs a seperate instance rather than the shared singleton. This could maybe do with being refactored at some point + this.encodeService = new EncodeServiceWrapper(); // Preview needs a seperate instance rather than the shared singleton. This could maybe do with being refactored at some point this.Title = "Preview"; this.Percentage = "0.00%"; diff --git a/win/CS/HandBrakeWPF/Views/OptionsView.xaml b/win/CS/HandBrakeWPF/Views/OptionsView.xaml index 2315eea55..52f9568d2 100644 --- a/win/CS/HandBrakeWPF/Views/OptionsView.xaml +++ b/win/CS/HandBrakeWPF/Views/OptionsView.xaml @@ -325,22 +325,6 @@ - - - - - - - - - - - - - - - -