]> granicus.if.org Git - handbrake/commitdiff
WinGui: Further work in the process isolation service.
authorsr55 <sr55.hb@outlook.com>
Sat, 1 Sep 2012 21:55:29 +0000 (21:55 +0000)
committersr55 <sr55.hb@outlook.com>
Sat, 1 Sep 2012 21:55:29 +0000 (21:55 +0000)
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@4927 b64f7644-9d1e-0410-96f1-a4d463321fa5

12 files changed:
win/CS/HandBrake.ApplicationServices/Services/Interfaces/IServerService.cs
win/CS/HandBrake.ApplicationServices/Services/ServerService.cs
win/CS/HandBrake.Server/Program.cs
win/CS/HandBrakeWPF/Isolation/BackgroundServiceConnector.cs
win/CS/HandBrakeWPF/Isolation/IsolatedEncodeService.cs
win/CS/HandBrakeWPF/Isolation/IsolatedScanService.cs
win/CS/HandBrakeWPF/UserSettingConstants.cs
win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs
win/CS/HandBrakeWPF/ViewModels/OptionsViewModel.cs
win/CS/HandBrakeWPF/Views/MainView.xaml
win/CS/HandBrakeWPF/Views/OptionsView.xaml
win/CS/HandBrakeWPF/defaultsettings.xml

index 49eedffa57011ec941d366e4711a4c938af1766f..60d9d0b57d5827ff5b7ec04f699befe9927fc174 100644 (file)
@@ -63,7 +63,10 @@ namespace HandBrake.ApplicationServices.Services.Interfaces
         /// <summary>\r
         /// Start the WCF Service\r
         /// </summary>\r
-        void Start();\r
+        /// <param name="port">\r
+        /// The port.\r
+        /// </param>\r
+        void Start(string port);\r
 \r
         /// <summary>\r
         /// Stop the WCF Service\r
index 9984ade210868f73368c061f4ced732606429a64..277a7c5b3e72a02f5ce48e5f084d04f1ed24851e 100644 (file)
@@ -146,15 +146,15 @@ namespace HandBrake.ApplicationServices.Services
         /// <summary>\r
         /// Start the service\r
         /// </summary>\r
-        public void Start()\r
+        public void Start(string port)\r
         {\r
-            using (this.host = new ServiceHost(typeof(ServerService), new Uri("net.tcp://localhost:8000")))\r
+            using (this.host = new ServiceHost(typeof(ServerService), new Uri(string.Format("net.tcp://127.0.0.1:{0}", port))))\r
             {\r
                 // Setup a listener\r
                 this.host.AddServiceEndpoint(typeof(IServerService), new NetTcpBinding(), "IHbService");\r
                 this.host.Open();\r
-                Console.WriteLine("::: HandBrake Server :::");\r
-                Console.WriteLine("Service Started");\r
+                Console.WriteLine("::: HandBrake Isolation Server:::");\r
+                Console.WriteLine("Service Started. Waiting for Clients...");\r
 \r
                 // Setup the services we are going to use.\r
                 scanService = new ScanService(new UserSettingService()); // TODO this needs wired up with castle\r
index baf39e69289125ec522f5f15a99e8f0495b51616..3ec5e2248fa88d591bcdc9bd49d32cf1b92e1e7c 100644 (file)
@@ -1,6 +1,7 @@
 namespace HandBrake.Server\r
 {\r
     using System;\r
+    using System.Linq;\r
 \r
     using HandBrake.ApplicationServices.Services;\r
     using HandBrake.ApplicationServices.Services.Interfaces;\r
         /// </param>\r
         static void Main(string[] args)\r
         {\r
-            IServerService server = new ServerService();\r
-            server.Start();\r
+            if (args.Count() != 1)\r
+            {\r
+                Console.WriteLine("Invalid Arguments");\r
+                Console.ReadLine();\r
+            }\r
+            else\r
+            {\r
+                IServerService server = new ServerService();\r
+                server.Start(args[0]);\r
+            }\r
         }\r
     }\r
 }\r
index 0d08f2dca3d0f83723ad560226e61286ba7cf45b..db175b45adea16c716e96a3ffadd024470ba2dc5 100644 (file)
@@ -35,6 +35,11 @@ namespace HandBrakeWPF.Isolation
         /// </summary>\r
         private readonly IErrorService errorService;\r
 \r
+        /// <summary>\r
+        /// The user setting service.\r
+        /// </summary>\r
+        private readonly IUserSettingService userSettingService;\r
+\r
         /// <summary>\r
         /// Gets or sets the pipe factory.\r
         /// DuplexChannelFactory is necessary for Callbacks.\r
@@ -56,9 +61,13 @@ namespace HandBrakeWPF.Isolation
         /// <param name="errorService">\r
         /// The error service.\r
         /// </param>\r
-        public BackgroundServiceConnector(IErrorService errorService)\r
+        /// <param name="userSettingService">\r
+        /// The user Setting Service.\r
+        /// </param>\r
+        public BackgroundServiceConnector(IErrorService errorService, IUserSettingService userSettingService)\r
         {\r
             this.errorService = errorService;\r
+            this.userSettingService = userSettingService;\r
         }\r
 \r
         /// <summary>\r
@@ -91,9 +100,19 @@ namespace HandBrakeWPF.Isolation
         /// </summary>\r
         public void Connect()\r
         {\r
+            string port = this.userSettingService.GetUserSetting<string>(UserSettingConstants.ServerPort);\r
+\r
             if (backgroundProcess == null)\r
             {\r
-               // backgroundProcess = Process.Start("HandBrake.Server.exe");\r
+                ProcessStartInfo processStartInfo = new ProcessStartInfo(\r
+                    "HandBrake.Server.exe", port)\r
+                {\r
+                    UseShellExecute = false,\r
+                    CreateNoWindow = false,\r
+                };\r
+\r
+                backgroundProcess = new Process { StartInfo = processStartInfo };\r
+                backgroundProcess.Start();\r
             }\r
 \r
             ThreadPool.QueueUserWorkItem(delegate\r
@@ -103,7 +122,7 @@ namespace HandBrakeWPF.Isolation
                         pipeFactory = new DuplexChannelFactory<IServerService>(\r
                             new InstanceContext(this),\r
                             new NetTcpBinding(),\r
-                            new EndpointAddress("net.tcp://127.0.0.1:8000/IHbService"));\r
+                            new EndpointAddress(string.Format("net.tcp://127.0.0.1:{0}/IHbService", port)));\r
 \r
                         // Connect and Subscribe to the Server\r
                         Service = pipeFactory.CreateChannel();\r
index 3c5363c28e2d28567e5f58a8026fdec1b83c9757..504024b43d3a3d174c21a16fe93439a7c04a2459 100644 (file)
@@ -34,8 +34,11 @@ namespace HandBrakeWPF.Isolation
         /// <param name="errorService">\r
         /// The error Service.\r
         /// </param>\r
-        public IsolatedEncodeService(IErrorService errorService)\r
-            : base(errorService)\r
+        /// <param name="userSettingService">\r
+        /// The user Setting Service.\r
+        /// </param>\r
+        public IsolatedEncodeService(IErrorService errorService, IUserSettingService userSettingService)\r
+            : base(errorService, userSettingService)\r
         {\r
             try\r
             {\r
index 608b00c217881c40fe926e02755cec96a1854a28..b50f1b3ea6d0d3224fa739dd3cbc63a304ba280b 100644 (file)
@@ -60,7 +60,11 @@ namespace HandBrakeWPF.Isolation
         /// <param name="errorService">\r
         /// The error Service.\r
         /// </param>\r
-        public IsolatedScanService(IErrorService errorService) : base(errorService)\r
+        /// <param name="userSettingService">\r
+        /// The user Setting Service.\r
+        /// </param>\r
+        public IsolatedScanService(IErrorService errorService, IUserSettingService userSettingService)\r
+            : base(errorService, userSettingService)\r
         {\r
             try\r
             {\r
index 9397a3e6cca4494a271f6b89ae30a9c690024a81..865847d87d885906363840d970f15875cc661cc7 100644 (file)
@@ -161,6 +161,16 @@ namespace HandBrakeWPF
         /// </summary>\r
         public const string VLC_Path = "VLC_Path";\r
 \r
+        /// <summary>\r
+        /// The enable process isolation.\r
+        /// </summary>\r
+        public const string EnableProcessIsolation = "EnableProcessIsolation";\r
+\r
+        /// <summary>\r
+        /// The server port.\r
+        /// </summary>\r
+        public const string ServerPort = "ServerPort";\r
+\r
         #endregion\r
     }\r
 }
\ No newline at end of file
index 59d442393ff5f9b9de429f184b5c9ee0989df7da..a6ae77489aab4c116832ccdc7a0bc48d6f6a99b3 100644 (file)
@@ -166,9 +166,6 @@ namespace HandBrakeWPF.ViewModels
         /// Initializes a new instance of the <see cref="MainViewModel"/> class.\r
         /// The viewmodel for HandBrakes main window.\r
         /// </summary>\r
-        /// <param name="windowManager">\r
-        /// The window manager.\r
-        /// </param>\r
         /// <param name="userSettingService">\r
         /// The User Setting Service\r
         /// </param>\r
@@ -193,7 +190,7 @@ namespace HandBrakeWPF.ViewModels
         /// <param name="driveDetectService">\r
         /// The drive Detect Service.\r
         /// </param>\r
-        public MainViewModel(IWindowManager windowManager, IUserSettingService userSettingService, IScan scanService, IEncode encodeService, IPresetService presetService,\r
+        public MainViewModel(IUserSettingService userSettingService, IScan scanService, IEncode encodeService, IPresetService presetService,\r
             IErrorService errorService, IShellViewModel shellViewModel, IUpdateService updateService, IDriveDetectService driveDetectService)\r
         {\r
             GeneralUtilities.SetInstanceId();\r
@@ -808,6 +805,11 @@ namespace HandBrakeWPF.ViewModels
             this.SourceMenu = this.GenerateSourceMenu();\r
 \r
             this.driveDetectService.StartDetection(this.DriveTrayChanged);\r
+\r
+            if (this.userSettingService.GetUserSetting<bool>(UserSettingConstants.EnableProcessIsolation))\r
+            {\r
+                this.EnableIsolationServices();\r
+            }\r
         }\r
 \r
         /// <summary>\r
@@ -1181,7 +1183,7 @@ namespace HandBrakeWPF.ViewModels
         /// The test isolation services.\r
         /// Swaps out the implementation of IScan to the IsolatedScanService version.\r
         /// </summary>\r
-        public void TestIsolationServices()\r
+        public void EnableIsolationServices()\r
         {\r
             // Unhook the old services\r
             this.scanService.ScanStared -= this.ScanStared;\r
@@ -1190,8 +1192,8 @@ namespace HandBrakeWPF.ViewModels
             this.queueProcessor.EncodeService.EncodeStatusChanged -= this.EncodeStatusChanged;\r
 \r
             // Replace the Services\r
-            this.scanService = new IsolatedScanService(this.errorService);\r
-            this.encodeService = new IsolatedEncodeService(this.errorService);\r
+            this.scanService = new IsolatedScanService(this.errorService, this.userSettingService);\r
+            this.encodeService = new IsolatedEncodeService(this.errorService, this.userSettingService);\r
             this.queueProcessor.SwapEncodeService(this.encodeService);\r
 \r
             // Add the new Event Hooks\r
index 119cb9d10870e92944126b29047857ccc57b0fb3..963abdf60c429a454e6a2357a40daae59211b3fe 100644 (file)
@@ -22,6 +22,7 @@ namespace HandBrakeWPF.ViewModels
     using Caliburn.Micro;\r
 \r
     using HandBrake.ApplicationServices;\r
+    using HandBrake.ApplicationServices.Exceptions;\r
     using HandBrake.ApplicationServices.Services.Interfaces;\r
     using HandBrake.ApplicationServices.Utilities;\r
 \r
@@ -338,6 +339,16 @@ namespace HandBrakeWPF.ViewModels
         /// </summary>\r
         private UpdateCheckInformation updateInfo;\r
 \r
+        /// <summary>\r
+        /// The enable process isolation.\r
+        /// </summary>\r
+        private bool enableProcessIsolation;\r
+\r
+        /// <summary>\r
+        /// The server port.\r
+        /// </summary>\r
+        private int serverPort;\r
+\r
         #endregion\r
 \r
         #region Constructors and Destructors\r
@@ -345,9 +356,6 @@ namespace HandBrakeWPF.ViewModels
         /// <summary>\r
         /// Initializes a new instance of the <see cref="OptionsViewModel"/> class.\r
         /// </summary>\r
-        /// <param name="windowManager">\r
-        /// The window manager.\r
-        /// </param>\r
         /// <param name="userSettingService">\r
         /// The user Setting Service.\r
         /// </param>\r
@@ -357,7 +365,7 @@ namespace HandBrakeWPF.ViewModels
         /// <param name="updateService">\r
         /// The update Service.\r
         /// </param>\r
-        public OptionsViewModel(IWindowManager windowManager, IUserSettingService userSettingService, IShellViewModel shellViewModel, IUpdateService updateService )\r
+        public OptionsViewModel(IUserSettingService userSettingService, IShellViewModel shellViewModel, IUpdateService updateService )\r
         {\r
             this.Title = "Options";\r
             this.userSettingService = userSettingService;\r
@@ -1313,6 +1321,38 @@ namespace HandBrakeWPF.ViewModels
             }\r
         }\r
 \r
+        /// <summary>\r
+        /// Gets or sets a value indicating whether ClearQueueOnEncodeCompleted.\r
+        /// </summary>\r
+        public bool EnableProcessIsolation\r
+        {\r
+            get\r
+            {\r
+                return this.enableProcessIsolation;\r
+            }\r
+            set\r
+            {\r
+                this.enableProcessIsolation = value;\r
+                this.NotifyOfPropertyChange(() => this.EnableProcessIsolation);\r
+            }\r
+        }\r
+\r
+        /// <summary>\r
+        /// Gets or sets the server port.\r
+        /// </summary>\r
+        public int ServerPort\r
+        {\r
+            get\r
+            {\r
+                return this.serverPort;\r
+            }\r
+            set\r
+            {\r
+                this.serverPort = value;\r
+                this.NotifyOfPropertyChange(() => this.ServerPort);\r
+            }\r
+        }\r
+\r
         #endregion\r
 \r
         #endregion\r
@@ -1601,8 +1641,13 @@ namespace HandBrakeWPF.ViewModels
             // Min Title Length\r
             this.MinLength = this.userSettingService.GetUserSetting<int>(ASUserSettingConstants.MinScanDuration);\r
 \r
-            // Use Experimental dvdnav\r
+            // Use dvdnav\r
             this.DisableLibdvdNav = userSettingService.GetUserSetting<bool>(ASUserSettingConstants.DisableLibDvdNav);\r
+\r
+            int port;\r
+            int.TryParse(userSettingService.GetUserSetting<string>(UserSettingConstants.ServerPort), out port);\r
+            this.ServerPort = port;\r
+            this.EnableProcessIsolation = userSettingService.GetUserSetting<bool>(UserSettingConstants.EnableProcessIsolation);\r
         }\r
 \r
         /// <summary>\r
@@ -1817,6 +1862,8 @@ namespace HandBrakeWPF.ViewModels
             }\r
 \r
             userSettingService.SetUserSetting(ASUserSettingConstants.DisableLibDvdNav, this.DisableLibdvdNav);\r
+            userSettingService.SetUserSetting(UserSettingConstants.EnableProcessIsolation, this.EnableProcessIsolation);\r
+            userSettingService.SetUserSetting(UserSettingConstants.ServerPort, this.ServerPort.ToString());\r
         }\r
 \r
         /// <summary>\r
index c7f6c14c4d56cb4879b43599cb36008a418b52e5..fdf2047447ebc6d4b7996346aa6a7b349d8cf49a 100644 (file)
                 <MenuItem Header="Debug" Foreground="Transparent" >\r
                     <MenuItem Header="Show CLI Equiv" Micro:Message.Attach="[Event Click] = [Action ShowCliQuery]" />\r
                     <MenuItem Header="Debug Scan Log" Micro:Message.Attach="[Event Click] = [Action DebugScanLog]" />\r
-                    <MenuItem Header="Test Isolation Service" Micro:Message.Attach="[Event Click] = [Action TestIsolationServices]" />\r
+                    <MenuItem Header="Test Isolation Service" Micro:Message.Attach="[Event Click] = [Action EnableIsolationServices]" />\r
                 </MenuItem>\r
             </Menu>\r
 \r
index f8a85347651dc3c6fe08de8754757e796061e2a2..7c3ead9cfbf70ffc141f6fc974b9dfac2e4acc61 100644 (file)
                         </StackPanel>\r
 \r
                     </StackPanel>\r
+\r
+\r
+                    <StackPanel Orientation="Vertical" Margin="0,10,0,20">\r
+\r
+                        <TextBlock Text="Experimental Features" Grid.Column="0" FontSize="14" Margin="0,0,0,10"/>\r
+                        \r
+                        <TextBlock Text="These options are for developer testing of features that are currently in progress!!!!" FontWeight="Bold" Margin="0,0,0,10" />\r
+\r
+                        <StackPanel Orientation="Vertical" Grid.Column="1" Margin="20,0,0,0">\r
+                            <CheckBox Content="Enable Process Isolation (Run Scans and Encodes via an intermediate service)" IsChecked="{Binding EnableProcessIsolation}" />\r
+\r
+                            <StackPanel Orientation="Horizontal" Margin="0,10,0,0" Grid.Column="1">\r
+                                <TextBlock Text="Server Port:" VerticalAlignment="Center" />\r
+                                <TextBox Width="50" MaxLength="5" Text="{Binding ServerPort}" />\r
+                            </StackPanel>\r
+                        </StackPanel>\r
+\r
+                    </StackPanel>\r
                 </StackPanel>\r
 \r
                 <StackPanel Name="Updates" Orientation="Vertical" Margin="10,10,0,0"\r
index 6bd00ae0d694d653ed5dd896379e48d5eed809f5..03dbccef2b3fe3472778f6565ec4c7ac130374b7 100644 (file)
       <anyType xmlns:q1="http://www.w3.org/2001/XMLSchema" d4p1:type="q1:boolean" xmlns:d4p1="http://www.w3.org/2001/XMLSchema-instance">false</anyType>\r
     </value>\r
   </item>\r
+\r
+  <item>\r
+    <key>\r
+      <string>ServerPort</string>\r
+    </key>\r
+    <value>\r
+      <anyType xmlns:q1="http://www.w3.org/2001/XMLSchema" d4p1:type="q1:string" xmlns:d4p1="http://www.w3.org/2001/XMLSchema-instance">8000</anyType>\r
+    </value>\r
+  </item>\r
+  <item>\r
+    <key>\r
+      <string>EnableProcessIsolation</string>\r
+    </key>\r
+    <value>\r
+      <anyType xmlns:q1="http://www.w3.org/2001/XMLSchema" d4p1:type="q1:boolean" xmlns:d4p1="http://www.w3.org/2001/XMLSchema-instance">false</anyType>\r
+    </value>\r
+  </item>\r
 </dictionary>
\ No newline at end of file