public LibEncode(IHbFunctionsProvider hbFunctionsProvider, IUserSettingService userSettingService, ILogInstanceManager logInstanceManager, int encodeCounter, IPortService portService) : base(userSettingService) { this.userSettingService = userSettingService; this.logInstanceManager = logInstanceManager; this.hbFunctionsProvider = hbFunctionsProvider; this.encodeCounter = encodeCounter; this.portService = portService; this.encodeTaskFactory = new EncodeTaskFactory(this.userSettingService, hbFunctionsProvider.GetHbFunctionsWrapper()); }
public void Start(EncodeTask task, HBConfiguration configuration, string basePresetName) { try { // Sanity Checking and Setup if (this.IsEncoding) { throw new GeneralApplicationException(Resources.Queue_AlreadyEncoding, Resources.Queue_AlreadyEncodingSolution, null); } // Setup this.startTime = DateTime.Now; this.currentTask = task; this.currentConfiguration = configuration; if (this.userSettingService.GetUserSetting <bool>(UserSettingConstants.ProcessIsolationEnabled)) { this.InitLogging(task.IsPreviewEncode); } else { this.encodeLogService = this.logInstanceManager.MasterLogInstance; this.encodeLogService.Reset(); } if (this.instance != null) { // Cleanup try { this.instance.EncodeCompleted -= this.InstanceEncodeCompleted; this.instance.EncodeProgress -= this.InstanceEncodeProgress; this.instance.Dispose(); this.instance = null; } catch (Exception exc) { this.ServiceLogMessage("Failed to cleanup previous instance: " + exc); } } this.ServiceLogMessage("Starting Encode ..."); if (!string.IsNullOrEmpty(basePresetName)) { this.TimedLogMessage(string.Format("base preset: {0}", basePresetName)); } int verbosity = this.userSettingService.GetUserSetting <int>(UserSettingConstants.Verbosity); // Prevent port stealing if multiple jobs start at the same time. lock (portLock) { this.instance = task.IsPreviewEncode ? HandBrakeInstanceManager.GetPreviewInstance(verbosity, this.userSettingService) : HandBrakeInstanceManager.GetEncodeInstance(verbosity, configuration, this.encodeLogService, userSettingService); this.instance.EncodeCompleted += this.InstanceEncodeCompleted; this.instance.EncodeProgress += this.InstanceEncodeProgress; this.IsEncoding = true; this.isPreviewInstance = task.IsPreviewEncode; // Verify the Destination Path Exists, and if not, create it. this.VerifyEncodeDestinationPath(task); // Get an EncodeJob object for the Interop Library this.instance.StartEncode(EncodeTaskFactory.Create(task, configuration, hbFunctionsProvider.GetHbFunctionsWrapper())); } // Fire the Encode Started Event this.InvokeEncodeStarted(System.EventArgs.Empty); } catch (Exception exc) { this.IsEncoding = false; this.ServiceLogMessage("Failed to start encoding ..." + Environment.NewLine + exc); this.InvokeEncodeCompleted(new EventArgs.EncodeCompletedEventArgs(false, exc, "Unable to start encoding", this.currentTask.Source, this.currentTask.Destination, null, 0)); } }