if (this.instance != null)
{
this.instance.StopEncode();
+ this.instance.EncodeCompleted -= this.InstanceEncodeCompleted;
+ this.instance.EncodeProgress -= this.InstanceEncodeProgress;
+ this.instance.Dispose();
+ this.instance = null;
this.ServiceLogMessage("Encode Stopped");
}
}
string hbLog = this.ProcessLogs(this.currentTask.Destination, this.isPreviewInstance, this.currentConfiguration);
long filesize = this.GetFilesize(this.currentTask.Destination);
- // Raise the Encode Completed EVent.
+ // Raise the Encode Completed Event.
this.InvokeEncodeCompleted(
e.Error
? new EventArgs.EncodeCompletedEventArgs(false, null, string.Empty, this.currentTask.Destination, hbLog, filesize)
: new EventArgs.EncodeCompletedEventArgs(true, null, string.Empty, this.currentTask.Destination, hbLog, filesize));
+
+ // 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 Encode instance: " + exc );
+ }
}
private long GetFilesize(string destination)
using HandBrake.Interop.Utilities;\r
\r
using HandBrakeWPF.EventArgs;\r
+ using HandBrakeWPF.Instance;\r
using HandBrakeWPF.Properties;\r
using HandBrakeWPF.Services.Interfaces;\r
using HandBrakeWPF.Services.Queue.Interfaces;\r
+ using HandBrakeWPF.Services.Scan.Interfaces;\r
using HandBrakeWPF.Utilities;\r
using HandBrakeWPF.ViewModels.Interfaces;\r
\r
/// </summary>\r
public class PrePostActionService : IPrePostActionService\r
{\r
- /// <summary>\r
- /// The queue processor.\r
- /// </summary>\r
private readonly IQueueProcessor queueProcessor;\r
-\r
- /// <summary>\r
- /// The user setting service.\r
- /// </summary>\r
private readonly IUserSettingService userSettingService;\r
-\r
- /// <summary>\r
- /// The window manager.\r
- /// </summary>\r
private readonly IWindowManager windowManager;\r
+ private readonly IScan scanService;\r
\r
/// <summary>\r
/// Initializes a new instance of the <see cref="PrePostActionService"/> class.\r
/// <param name="windowManager">\r
/// The window Manager.\r
/// </param>\r
- public PrePostActionService(IQueueProcessor queueProcessor, IUserSettingService userSettingService, IWindowManager windowManager)\r
+ public PrePostActionService(IQueueProcessor queueProcessor, IUserSettingService userSettingService, IWindowManager windowManager, IScan scanService)\r
{\r
this.queueProcessor = queueProcessor;\r
this.userSettingService = userSettingService;\r
this.windowManager = windowManager;\r
+ this.scanService = scanService;\r
\r
this.queueProcessor.QueueCompleted += QueueProcessorQueueCompleted;\r
this.queueProcessor.EncodeService.EncodeCompleted += EncodeService_EncodeCompleted;\r
});\r
\r
if (!titleSpecificView.IsCancelled)\r
- {\r
+ { \r
// Do something when the encode ends.\r
switch (this.userSettingService.GetUserSetting<string>(UserSettingConstants.WhenCompleteAction))\r
{\r
ProcessStartInfo shutdown = new ProcessStartInfo("Shutdown", "-s -t 60");\r
shutdown.UseShellExecute = false;\r
Process.Start(shutdown);\r
+ Execute.OnUIThread(() => System.Windows.Application.Current.Shutdown());\r
break;\r
case "Log off":\r
case "Ausloggen":\r
+ this.scanService.Dispose();\r
Win32.ExitWindowsEx(0, 0);\r
break;\r
case "Suspend":\r
using System.Windows.Media.Imaging;
using HandBrake.Interop.Interop;
- using HandBrake.Interop.Interop.HbLib;
using HandBrake.Interop.Interop.Interfaces;
using HandBrake.Interop.Interop.Json.Scan;
using HandBrake.Interop.Interop.Model;
using HandBrakeWPF.Instance;
using HandBrakeWPF.Services.Encode.Model;
- using HandBrakeWPF.Services.Encode.Model.Models;
using HandBrakeWPF.Services.Scan.EventArgs;
using HandBrakeWPF.Services.Scan.Factories;
using HandBrakeWPF.Services.Scan.Interfaces;
using HandBrakeWPF.Services.Scan.Model;
using HandBrakeWPF.Utilities;
- using Chapter = Model.Chapter;
using ILog = Logging.Interfaces.ILog;
using LogLevel = Logging.Model.LogLevel;
using LogMessageType = Logging.Model.LogMessageType;
using LogService = Logging.LogService;
using ScanProgressEventArgs = HandBrake.Interop.Interop.EventArgs.ScanProgressEventArgs;
- using Subtitle = Model.Subtitle;
using Title = Model.Title;
/// <summary>
/// Scan a Source
/// </summary>
- public class LibScan : IScan
+ public class LibScan : IScan, IDisposable
{
#region Private Variables
{
this.ServiceLogMessage("Manually Stopping Scan ...");
this.IsScanning = false;
- this.instance.StopScan();
+
+ var handBrakeInstance = this.instance;
+ if (handBrakeInstance != null)
+ {
+ handBrakeInstance.StopScan();
+ handBrakeInstance.ScanProgress -= this.InstanceScanProgress;
+ handBrakeInstance.ScanCompleted -= this.InstanceScanCompleted;
+ handBrakeInstance.Dispose();
+ this.instance = null;
+ }
}
catch (Exception exc)
{
finally
{
this.ScanCompleted?.Invoke(this, new ScanCompletedEventArgs(this.isCancelled, null, null, null));
+ this.instance = null;
this.ServiceLogMessage("Scan Stopped ...");
}
}
/// The preview Count.
/// </param>
/// <param name="configuraiton">
- /// The configuraiton.
+ /// The configuration.
/// </param>
private void ScanSource(object sourcePath, int title, int previewCount, HBConfiguration configuraiton)
{
/// </param>
private void InstanceScanCompleted(object sender, System.EventArgs e)
{
- this.ServiceLogMessage("Processing Scan Information ...");
- bool cancelled = this.isCancelled;
- this.isCancelled = false;
-
- // TODO -> Might be a better place to fix this.
- string path = this.currentSourceScanPath;
- if (this.currentSourceScanPath.Contains("\""))
+ try
{
- path = this.currentSourceScanPath.Trim('\"');
- }
+ this.ServiceLogMessage("Processing Scan Information ...");
+ bool cancelled = this.isCancelled;
+ this.isCancelled = false;
- // Process into internal structures.
- Source sourceData = null;
- if (this.instance?.Titles != null)
- {
- sourceData = new Source { Titles = ConvertTitles(this.instance.Titles), ScanPath = path };
- }
+ // TODO -> Might be a better place to fix this.
+ string path = this.currentSourceScanPath;
+ if (this.currentSourceScanPath.Contains("\""))
+ {
+ path = this.currentSourceScanPath.Trim('\"');
+ }
- this.IsScanning = false;
+ // Process into internal structures.
+ Source sourceData = null;
+ if (this.instance?.Titles != null)
+ {
+ sourceData = new Source { Titles = this.ConvertTitles(this.instance.Titles), ScanPath = path };
+ }
- if (this.postScanOperation != null)
- {
- try
+ this.IsScanning = false;
+
+ if (this.postScanOperation != null)
{
- this.postScanOperation(true, sourceData);
+ try
+ {
+ this.postScanOperation(true, sourceData);
+ }
+ catch (Exception exc)
+ {
+ Debug.WriteLine(exc);
+ }
+
+ this.postScanOperation = null; // Reset
+ this.ServiceLogMessage("Scan Finished for Queue Edit ...");
}
- catch (Exception exc)
+ else
{
- Debug.WriteLine(exc);
+ this.ScanCompleted?.Invoke(
+ this,
+ new ScanCompletedEventArgs(cancelled, null, string.Empty, sourceData));
+ this.ServiceLogMessage("Scan Finished ...");
}
-
- this.postScanOperation = null; // Reset
- this.ServiceLogMessage("Scan Finished for Queue Edit ...");
}
- else
+ finally
{
- this.ScanCompleted?.Invoke(this, new ScanCompletedEventArgs(cancelled, null, string.Empty, sourceData));
- this.ServiceLogMessage("Scan Finished ...");
+ var handBrakeInstance = this.instance;
+ if (handBrakeInstance != null)
+ {
+ handBrakeInstance.ScanProgress -= this.InstanceScanProgress;
+ handBrakeInstance.ScanCompleted -= this.InstanceScanCompleted;
+ }
}
}
return titleList;
}
#endregion
+
+ public void Dispose()
+ {
+ if (this.instance != null)
+ {
+ try
+ {
+ this.instance.Dispose();
+ this.instance = null;
+ }
+ catch (Exception e)
+ {
+ this.ServiceLogMessage("Unable to Dispose of LibScan: " + e);
+ }
+ }
+ }
}
}
\ No newline at end of file