summaryrefslogtreecommitdiffstats
path: root/win/CS/HandBrake.ApplicationServices/Services
diff options
context:
space:
mode:
authorsr55 <[email protected]>2013-08-22 17:02:19 +0000
committersr55 <[email protected]>2013-08-22 17:02:19 +0000
commitc0ad015d6ef51b4edf229d98803d35c781e8b67f (patch)
tree5e40c8b802fbbfe03c3a6b27be80dcfe44d56a72 /win/CS/HandBrake.ApplicationServices/Services
parent88cfc4524c3bb09c1316219c1f83517b35697736 (diff)
WinGui: Strip out legacy CLI scan code.
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@5732 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'win/CS/HandBrake.ApplicationServices/Services')
-rw-r--r--win/CS/HandBrake.ApplicationServices/Services/Interfaces/IHbServiceCallback.cs24
-rw-r--r--win/CS/HandBrake.ApplicationServices/Services/Interfaces/IServerService.cs46
-rw-r--r--win/CS/HandBrake.ApplicationServices/Services/ScanService.cs389
-rw-r--r--win/CS/HandBrake.ApplicationServices/Services/ServerService.cs161
4 files changed, 1 insertions, 619 deletions
diff --git a/win/CS/HandBrake.ApplicationServices/Services/Interfaces/IHbServiceCallback.cs b/win/CS/HandBrake.ApplicationServices/Services/Interfaces/IHbServiceCallback.cs
index 1d10e3062..6f4d9a260 100644
--- a/win/CS/HandBrake.ApplicationServices/Services/Interfaces/IHbServiceCallback.cs
+++ b/win/CS/HandBrake.ApplicationServices/Services/Interfaces/IHbServiceCallback.cs
@@ -20,30 +20,6 @@ namespace HandBrake.ApplicationServices.Services.Interfaces
public interface IHbServiceCallback
{
/// <summary>
- /// The scan progress.
- /// </summary>
- /// <param name="eventArgs">
- /// The event args.
- /// </param>
- [OperationContract(IsOneWay = true)]
- void ScanProgressCallback(ScanProgressEventArgs eventArgs);
-
- /// <summary>
- /// The scan completed.
- /// </summary>
- /// <param name="eventArgs">
- /// The event args.
- /// </param>
- [OperationContract(IsOneWay = true)]
- void ScanCompletedCallback(ScanCompletedEventArgs eventArgs);
-
- /// <summary>
- /// The scan started callback.
- /// </summary>
- [OperationContract(IsOneWay = true)]
- void ScanStartedCallback();
-
- /// <summary>
/// The encode progress callback.
/// </summary>
/// <param name="eventArgs">
diff --git a/win/CS/HandBrake.ApplicationServices/Services/Interfaces/IServerService.cs b/win/CS/HandBrake.ApplicationServices/Services/Interfaces/IServerService.cs
index 60d9d0b57..9aa1f1cb7 100644
--- a/win/CS/HandBrake.ApplicationServices/Services/Interfaces/IServerService.cs
+++ b/win/CS/HandBrake.ApplicationServices/Services/Interfaces/IServerService.cs
@@ -13,7 +13,6 @@ namespace HandBrake.ApplicationServices.Services.Interfaces
using System.ServiceModel;
using HandBrake.ApplicationServices.Model;
- using HandBrake.ApplicationServices.Parsing;
/// <summary>
/// The HandBrakeService interface.
@@ -25,33 +24,9 @@ namespace HandBrake.ApplicationServices.Services.Interfaces
/// Gets the activity log.
/// </summary>
[DataMember]
- string ScanActivityLog { get; }
-
- /// <summary>
- /// Gets the activity log.
- /// </summary>
- [DataMember]
string EncodeActivityLog { get; }
/// <summary>
- /// Gets the souce data.
- /// </summary>
- Source SouceData
- {
- [OperationContract]
- get;
- }
-
- /// <summary>
- /// Gets a value indicating whether is scanning.
- /// </summary>
- bool IsScanning
- {
- [OperationContract]
- get;
- }
-
- /// <summary>
/// Gets a value indicating whether is encoding.
/// </summary>
bool IsEncoding
@@ -74,21 +49,6 @@ namespace HandBrake.ApplicationServices.Services.Interfaces
void Stop();
/// <summary>
- /// The scan source.
- /// </summary>
- /// <param name="path">
- /// The path.
- /// </param>
- /// <param name="title">
- /// The title.
- /// </param>
- /// <param name="previewCount">
- /// The preview Count.
- /// </param>
- [OperationContract]
- void ScanSource(string path, int title, int previewCount);
-
- /// <summary>
/// Start and Encode
/// </summary>
/// <param name="job">
@@ -116,12 +76,6 @@ namespace HandBrake.ApplicationServices.Services.Interfaces
void StopEncode();
/// <summary>
- /// Stop the scan.
- /// </summary>
- [OperationContract]
- void StopScan();
-
- /// <summary>
/// Subscribe for callbacks from the called functions
/// </summary>
/// <returns>
diff --git a/win/CS/HandBrake.ApplicationServices/Services/ScanService.cs b/win/CS/HandBrake.ApplicationServices/Services/ScanService.cs
deleted file mode 100644
index 1ad531dfe..000000000
--- a/win/CS/HandBrake.ApplicationServices/Services/ScanService.cs
+++ /dev/null
@@ -1,389 +0,0 @@
-// --------------------------------------------------------------------------------------------------------------------
-// <copyright file="ScanService.cs" company="HandBrake Project (http://handbrake.fr)">
-// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License.
-// </copyright>
-// <summary>
-// Scan a Source
-// </summary>
-// --------------------------------------------------------------------------------------------------------------------
-
-namespace HandBrake.ApplicationServices.Services
-{
- using System;
- using System.Diagnostics;
- using System.IO;
- using System.Text;
- using System.Threading;
- using System.Windows.Forms;
-
- using HandBrake.ApplicationServices.EventArgs;
- using HandBrake.ApplicationServices.Exceptions;
- using HandBrake.ApplicationServices.Parsing;
- using HandBrake.ApplicationServices.Services.Interfaces;
- using HandBrake.ApplicationServices.Utilities;
-
- using Parser = HandBrake.ApplicationServices.Parsing.Parser;
-
- /// <summary>
- /// Scan a Source
- /// </summary>
- public class ScanService : IScan
- {
- #region Private Variables
-
- /// <summary>
- /// The User Setting Service
- /// </summary>
- private readonly IUserSettingService userSettingService;
-
- /// <summary>
- /// The Log File Header
- /// </summary>
- private readonly StringBuilder header;
-
- /// <summary>
- /// The CLI data parser
- /// </summary>
- private Parser readData;
-
- /// <summary>
- /// The Log Buffer
- /// </summary>
- private StringBuilder logBuffer;
-
- /// <summary>
- /// The Process belonging to the CLI
- /// </summary>
- private Process hbProc;
-
- /// <summary>
- /// The stop scan.
- /// </summary>
- private bool cancelScan;
-
- #endregion
-
- /// <summary>
- /// Initializes a new instance of the <see cref="ScanService"/> class.
- /// </summary>
- /// <param name="userSettingService">
- /// The user Setting Service.
- /// </param>
- public ScanService(IUserSettingService userSettingService)
- {
- this.userSettingService = userSettingService;
- this.logBuffer = new StringBuilder();
-
- header = GeneralUtilities.CreateCliLogHeader();
- }
-
- #region Events
-
- /// <summary>
- /// Scan has Started
- /// </summary>
- public event EventHandler ScanStared;
-
- /// <summary>
- /// Scan has completed
- /// </summary>
- public event ScanCompletedStatus ScanCompleted;
-
- /// <summary>
- /// Encode process has progressed
- /// </summary>
- public event ScanProgessStatus ScanStatusChanged;
-
- #endregion
-
- #region Public Properties
-
- /// <summary>
- /// Gets a value indicating whether IsScanning.
- /// </summary>
- public bool IsScanning { get; private set; }
-
- /// <summary>
- /// Gets the Souce Data.
- /// </summary>
- public Source SouceData { get; private set; }
-
- /// <summary>
- /// Gets ActivityLog.
- /// </summary>
- public string ActivityLog
- {
- get
- {
- string noLog = "No log data available... Log data will show here after you scan a source. \n\nOpen the log file directory to get previous log files.";
- return string.IsNullOrEmpty(this.logBuffer.ToString()) ? this.header + noLog : this.header + this.logBuffer.ToString();
- }
- }
-
- #endregion
-
- #region Public Methods
-
- /// <summary>
- /// Scan a Source Path.
- /// Title 0: scan all
- /// </summary>
- /// <param name="sourcePath">
- /// Path to the file to scan
- /// </param>
- /// <param name="title">
- /// int title number. 0 for scan all
- /// </param>
- /// <param name="previewCount">
- /// The preview Count.
- /// </param>
- /// <param name="postScanAction">
- /// The post Scan Action.
- /// </param>
- public void Scan(string sourcePath, int title, int previewCount, Action<bool> postScanAction)
- {
- Thread t = new Thread(unused => this.ScanSource(sourcePath, title, previewCount, postScanAction));
- t.Start();
- }
-
- /// <summary>
- /// Kill the scan
- /// </summary>
- public void Stop()
- {
- try
- {
- // Try to clean things up as best as possible.
- if (this.readData != null)
- {
- this.readData.OnScanProgress -= this.OnScanProgress;
- }
-
- cancelScan = true;
-
- if (this.hbProc != null && !this.hbProc.HasExited)
- {
- this.hbProc.Kill();
- }
- }
- catch
- {
- // We don't really need to notify the user of any errors here.
- }
- }
-
- /// <summary>
- /// Take a Scan Log file, and process it as if it were from the CLI.
- /// </summary>
- /// <param name="path">
- /// The path to the log file.
- /// </param>
- public void DebugScanLog(string path)
- {
- try
- {
- StreamReader parseLog = new StreamReader(path);
- this.readData = new Parser(parseLog.BaseStream);
- this.SouceData = Source.Parse(this.readData, this.userSettingService.GetUserSetting<bool>(ASUserSettingConstants.DisableLibDvdNav));
- this.SouceData.ScanPath = path;
-
- if (this.ScanCompleted != null)
- {
- this.ScanCompleted(this, new ScanCompletedEventArgs(false, null, string.Empty));
- }
- }
- catch (Exception e)
- {
- throw new GeneralApplicationException("Debug Run Failed", string.Empty, e);
- }
- }
-
- /// <summary>
- /// Shutdown the service.
- /// </summary>
- public void Shutdown()
- {
- // Nothing to do for this implementation.
- }
-
- #endregion
-
- #region Private Methods
-
- /// <summary>
- /// Start a scan for a given source path and title
- /// </summary>
- /// <param name="sourcePath">
- /// Path to the source file
- /// </param>
- /// <param name="title">
- /// the title number to look at
- /// </param>
- /// <param name="previewCount">
- /// The preview Count.
- /// </param>
- /// <param name="postScanAction">
- /// The post Scan Action. Disables the Scan Completed Event
- /// </param>
- private void ScanSource(object sourcePath, int title, int previewCount, Action<bool> postScanAction)
- {
- try
- {
- this.IsScanning = true;
- this.cancelScan = false;
-
- if (this.ScanStared != null)
- {
- this.ScanStared(this, new EventArgs());
- }
-
- this.logBuffer = new StringBuilder();
-
- string handbrakeCLIPath = Path.Combine(Application.StartupPath, "HandBrakeCLI.exe");
- string logDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) +
- "\\HandBrake\\logs";
- string dvdInfoPath = Path.Combine(
- logDir,
- string.Format("last_scan_log{0}.txt", GeneralUtilities.ProcessId));
-
- if (!Directory.Exists(logDir))
- {
- Directory.CreateDirectory(logDir);
- }
-
- // Make we don't pick up a stale last_encode_log.txt (and that we have rights to the file)
- if (File.Exists(dvdInfoPath))
- {
- File.Delete(dvdInfoPath);
- }
-
- string extraArguments = string.Empty;
-
- if (previewCount != 10)
- {
- extraArguments += " --previews " + previewCount;
- }
-
- if (this.userSettingService.GetUserSetting<bool>(ASUserSettingConstants.DisableLibDvdNav))
- {
- extraArguments += " --no-dvdnav";
- }
-
- extraArguments += string.Format(" --min-duration={0}", this.userSettingService.GetUserSetting<int>(ASUserSettingConstants.MinScanDuration));
-
- if (title > 0)
- {
- extraArguments += " --scan ";
- }
-
- // Quick fix for "F:\\" style paths. We need \\\\ (Escaped \ twice)
- string source = sourcePath.ToString().EndsWith("\\") ? string.Format("\"{0}\\\\\"", sourcePath.ToString().TrimEnd('\\'))
- : "\"" + sourcePath + "\"";
- string query = string.Format(@" -i {0} -t{1} {2} -v ", source, title, extraArguments);
-
- this.hbProc = new Process
- {
- StartInfo =
- {
- FileName = handbrakeCLIPath,
- Arguments = string.Format(@" -i {0} -t{1} {2} -v ", source, title, extraArguments),
- RedirectStandardOutput = true,
- RedirectStandardError = true,
- UseShellExecute = false,
- CreateNoWindow = true
- }
- };
-
- // Start the Scan
- this.hbProc.Start();
-
- this.readData = new Parser(this.hbProc.StandardError.BaseStream);
- this.readData.OnScanProgress += this.OnScanProgress;
- this.SouceData = Source.Parse(this.readData, this.userSettingService.GetUserSetting<bool>(ASUserSettingConstants.DisableLibDvdNav));
- this.SouceData.ScanPath = (string)sourcePath;
-
- // Write the Buffer out to file.
- using (StreamWriter scanLog = new StreamWriter(dvdInfoPath))
- {
- // Only write the log file to disk if it's less than 50MB.
- if (this.readData.Buffer.Length < 50000000)
- {
- scanLog.WriteLine(header);
- scanLog.WriteLine(query);
- scanLog.Write(this.readData.Buffer);
-
- this.logBuffer.AppendLine(query);
- this.logBuffer.AppendLine(this.readData.Buffer.ToString());
- }
- else
- {
- throw new GeneralApplicationException(
- "The Log file has not been written to disk as it has grown above the 50MB limit", " This indicates there was a problem during the scan process.", null);
- }
- }
-
- this.IsScanning = false;
-
-
- if (postScanAction != null)
- {
- postScanAction(true);
- }
- else
- {
- if (this.ScanCompleted != null)
- {
- if (logBuffer.ToString().Contains("scan: unrecognized file type"))
- this.ScanCompleted(this, new ScanCompletedEventArgs(false, null, "Unrecognized file type."));
- else
- this.ScanCompleted(this, new ScanCompletedEventArgs(this.cancelScan, null, string.Empty));
- }
- }
- }
- catch (GeneralApplicationException)
- {
- throw;
- }
- catch (Exception exc)
- {
- this.Stop();
-
- if (postScanAction != null)
- {
- postScanAction(false);
- }
- else
- {
- if (this.ScanCompleted != null)
- {
- this.ScanCompleted(this, new ScanCompletedEventArgs(false, exc, "An Error has occured in ScanService.ScanSource()"));
- }
- }
- }
- }
-
- /// <summary>
- /// Fire an event when the scan process progresses
- /// </summary>
- /// <param name="sender">the sender</param>
- /// <param name="currentTitle">the current title being scanned</param>
- /// <param name="titleCount">the total number of titles</param>
- /// <param name="percentage">The Percentage</param>
- private void OnScanProgress(object sender, int currentTitle, int titleCount, decimal percentage)
- {
- ScanProgressEventArgs eventArgs = new ScanProgressEventArgs
- {
- CurrentTitle = currentTitle,
- Titles = titleCount,
- Percentage = percentage
- };
-
- if (this.ScanStatusChanged != null)
- {
- this.ScanStatusChanged(this, eventArgs);
- }
- }
-
- #endregion
- }
-} \ No newline at end of file
diff --git a/win/CS/HandBrake.ApplicationServices/Services/ServerService.cs b/win/CS/HandBrake.ApplicationServices/Services/ServerService.cs
index 22d9e22a8..4e0039c55 100644
--- a/win/CS/HandBrake.ApplicationServices/Services/ServerService.cs
+++ b/win/CS/HandBrake.ApplicationServices/Services/ServerService.cs
@@ -11,27 +11,21 @@ namespace HandBrake.ApplicationServices.Services
{
using System;
using System.Collections.Generic;
- using System.Runtime.Serialization;
using System.ServiceModel;
using System.Threading;
- using System.Windows;
- using HandBrake.ApplicationServices.EventArgs;
using HandBrake.ApplicationServices.Model;
- using HandBrake.ApplicationServices.Parsing;
using HandBrake.ApplicationServices.Services.Interfaces;
using HandBrake.Interop;
using HandBrake.Interop.Interfaces;
using EncodeCompletedEventArgs = HandBrake.ApplicationServices.EventArgs.EncodeCompletedEventArgs;
using EncodeProgressEventArgs = HandBrake.ApplicationServices.EventArgs.EncodeProgressEventArgs;
- using ScanProgressEventArgs = HandBrake.ApplicationServices.EventArgs.ScanProgressEventArgs;
/// <summary>
/// HandBrake WCF Service
/// </summary>
- [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall, IncludeExceptionDetailInFaults = true,
- ConcurrencyMode = ConcurrencyMode.Single)]
+ [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall, IncludeExceptionDetailInFaults = true, ConcurrencyMode = ConcurrencyMode.Single)]
public class ServerService : IServerService
{
#region Constants and Fields
@@ -47,11 +41,6 @@ namespace HandBrake.ApplicationServices.Services
private static IEncode encodeService;
/// <summary>
- /// The scan service.
- /// </summary>
- private static IScan scanService;
-
- /// <summary>
/// The host.
/// </summary>
private static ServiceHost host;
@@ -68,18 +57,6 @@ namespace HandBrake.ApplicationServices.Services
/// <summary>
/// Gets the activity log.
/// </summary>
- [DataMember]
- public string ActivityLog
- {
- get
- {
- return scanService.ActivityLog;
- }
- }
-
- /// <summary>
- /// Gets the activity log.
- /// </summary>
public string EncodeActivityLog { get; private set; }
/// <summary>
@@ -88,34 +65,10 @@ namespace HandBrake.ApplicationServices.Services
public bool IsEncoding { get; private set; }
/// <summary>
- /// Gets a value indicating whether is scanning.
- /// </summary>
- [DataMember]
- public bool IsScanning
- {
- get
- {
- return scanService.IsScanning;
- }
- }
-
- /// <summary>
/// Gets the activity log.
/// </summary>
public string ScanActivityLog { get; private set; }
- /// <summary>
- /// Gets the souce data.
- /// </summary>
- [DataMember]
- public Source SouceData
- {
- get
- {
- return scanService.SouceData;
- }
- }
-
#endregion
#region Implemented Interfaces
@@ -133,27 +86,6 @@ namespace HandBrake.ApplicationServices.Services
encodeService.ProcessLogs(destination);
}
- /// <summary>
- /// The scan source.
- /// </summary>
- /// <param name="path">
- /// The path.
- /// </param>
- /// <param name="title">
- /// The title.
- /// </param>
- /// <param name="previewCount">
- /// The preview Count.
- /// </param>
- public void ScanSource(string path, int title, int previewCount)
- {
- Console.WriteLine("Starting Source Scan for: " + path);
- scanService.ScanStared += this.ScanStaredHandler;
- scanService.ScanStatusChanged += this.ScanStatusChangedHandler;
- scanService.ScanCompleted += this.ScanCompletedHandler;
-
- scanService.Scan(path, title, previewCount, null);
- }
/// <summary>
/// Start the service
@@ -173,7 +105,6 @@ namespace HandBrake.ApplicationServices.Services
// Setup the services we are going to use.
IHandBrakeInstance instance = new HandBrakeInstance();
- scanService = new LibScan(instance);
encodeService = new LibEncode(new UserSettingService(), instance); // TODO this needs wired up with castle
shutdownFlag = new ManualResetEvent(false);
@@ -221,14 +152,6 @@ namespace HandBrake.ApplicationServices.Services
}
/// <summary>
- /// Stop the scan.
- /// </summary>
- public void StopScan()
- {
- scanService.Stop();
- }
-
- /// <summary>
/// The subscribe.
/// </summary>
/// <returns>
@@ -292,88 +215,6 @@ namespace HandBrake.ApplicationServices.Services
#region Methods
/// <summary>
- /// The scan service scan completed event handler
- /// </summary>
- /// <param name="sender">
- /// The sender.
- /// </param>
- /// <param name="e">
- /// The e.
- /// </param>
- private void ScanCompletedHandler(object sender, ScanCompletedEventArgs e)
- {
- Subscribers.ForEach(
- delegate(IHbServiceCallback callback)
- {
- if (((ICommunicationObject)callback).State == CommunicationState.Opened)
- {
- Console.WriteLine("Scan Completed Callback");
- callback.ScanCompletedCallback(e);
- }
- else
- {
- Subscribers.Remove(callback);
- }
- });
-
- scanService.ScanStared -= this.ScanStaredHandler;
- scanService.ScanStatusChanged -= this.ScanStatusChangedHandler;
- scanService.ScanCompleted -= this.ScanCompletedHandler;
- }
-
- /// <summary>
- /// The scan service scan stared.
- /// </summary>
- /// <param name="sender">
- /// The sender.
- /// </param>
- /// <param name="e">
- /// The e.
- /// </param>
- private void ScanStaredHandler(object sender, EventArgs e)
- {
- Subscribers.ForEach(
- delegate(IHbServiceCallback callback)
- {
- if (((ICommunicationObject)callback).State == CommunicationState.Opened)
- {
- Console.WriteLine("Scan Started Callback");
- callback.ScanStartedCallback();
- }
- else
- {
- Subscribers.Remove(callback);
- }
- });
- }
-
- /// <summary>
- /// The scan service scan status changed event handler
- /// </summary>
- /// <param name="sender">
- /// The sender.
- /// </param>
- /// <param name="e">
- /// The e.
- /// </param>
- private void ScanStatusChangedHandler(object sender, ScanProgressEventArgs e)
- {
- Subscribers.ForEach(
- delegate(IHbServiceCallback callback)
- {
- if (((ICommunicationObject)callback).State == CommunicationState.Opened)
- {
- Console.WriteLine("Scan Changed Callback");
- callback.ScanProgressCallback(e);
- }
- else
- {
- Subscribers.Remove(callback);
- }
- });
- }
-
- /// <summary>
/// The encode service_ encode completed.
/// </summary>
/// <param name="sender">