本文整理汇总了C#中HandBrake.ApplicationServices.Model.QueueTask类的典型用法代码示例。如果您正苦于以下问题:C# QueueTask类的具体用法?C# QueueTask怎么用?C# QueueTask使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
QueueTask类属于HandBrake.ApplicationServices.Model命名空间,在下文中一共展示了QueueTask类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GenerateFullQuery
public static QueueTask GenerateFullQuery(frmMain mainWindow)
{
// Create the CLI Query
string query = string.Empty;
query += SourceQuery(mainWindow, mainWindow.drop_mode.SelectedIndex, 0, null);
query += DestinationQuery(mainWindow, QueryEncodeMode.Standard);
query += GenerateTabbedComponentsQuery(mainWindow, true, QueryPictureSettingsMode.UserInterfaceSettings, 0, 0);
// Create the Queue Task and setup the EncodeTask model object.
Preset preset = mainWindow.treeView_presets.SelectedNode.Tag as Preset;
bool isCustom = true;
if (preset != null && preset.IsBuildIn)
{
isCustom = false;
}
EncodeTask task = CreateEncodeTaskObject(mainWindow);
QueueTask queueTask = new QueueTask(query)
{
Source = task.Source,
Destination = task.Destination,
Title = mainWindow.GetTitle(),
CustomQuery = (mainWindow.rtf_query.Text != string.Empty) || isCustom,
Task = task,
Query = query,
};
return queueTask;
}
示例2: GetEncodeJob
/// <summary>
/// The get encode job.
/// </summary>
/// <param name="task">
/// The task.
/// </param>
/// <returns>
/// The <see cref="EncodeJob"/>.
/// </returns>
public static EncodeJob GetEncodeJob(QueueTask task)
{
// Sanity Checking
if (task == null || task.Task == null)
{
return null;
}
return GetEncodeJob(task.Task);
}
示例3: CreateCliLogHeader
/// <summary>
/// Add the CLI Query to the Log File.
/// </summary>
/// <param name="encJob">
/// The Encode Job Object
/// </param>
/// <returns>
/// The create cli log header.
/// </returns>
public static StringBuilder CreateCliLogHeader(QueueTask encJob)
{
StringBuilder logHeader = new StringBuilder();
logHeader.AppendLine(String.Format("{0}", Init.HandBrakeGuiVersionString));
logHeader.AppendLine(String.Format("OS: {0}", Environment.OSVersion));
logHeader.AppendLine(String.Format("CPU: {0}", SystemInfo.GetCpuCount));
logHeader.Append(String.Format("Ram: {0} MB, ", SystemInfo.TotalPhysicalMemory));
logHeader.AppendLine(String.Format("Screen: {0}x{1}", SystemInfo.ScreenBounds.Bounds.Width, SystemInfo.ScreenBounds.Bounds.Height));
logHeader.AppendLine(String.Format("Temp Dir: {0}", Path.GetTempPath()));
logHeader.AppendLine(String.Format("Install Dir: {0}", Application.StartupPath));
logHeader.AppendLine(String.Format("Data Dir: {0}\n", Application.UserAppDataPath));
if (encJob != null)
{
logHeader.AppendLine(String.Format("CLI Query: {0}", encJob.Query));
logHeader.AppendLine(String.Format("User Query: {0}", encJob.CustomQuery));
}
logHeader.AppendLine("-------------------------------------------");
return logHeader;
}
示例4: StartEncode
/// <summary>
/// Start an Encode
/// </summary>
public void StartEncode()
{
if (this.queueProcessor.IsProcessing)
{
this.errorService.ShowMessageBox("HandBrake is already encoding.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
return;
}
// Check if we already have jobs, and if we do, just start the queue.
if (this.queueProcessor.QueueManager.Count != 0)
{
this.queueProcessor.Start();
return;
}
// Otherwise, perform Santiy Checking then add to the queue and start if everything is ok.
if (this.ScannedSource == null || this.CurrentTask == null)
{
this.errorService.ShowMessageBox("You must first scan a source.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
return;
}
if (string.IsNullOrEmpty(this.Destination))
{
this.errorService.ShowMessageBox("The Destination field was empty.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
return;
}
if (File.Exists(this.Destination))
{
MessageBoxResult result = this.errorService.ShowMessageBox("The current file already exists, do you wish to overwrite it?", "Question", MessageBoxButton.YesNo, MessageBoxImage.Question);
if (result == MessageBoxResult.No)
{
return;
}
}
// Create the Queue Task and Start Processing
QueueTask task = new QueueTask
{
Task = new EncodeTask(this.CurrentTask),
CustomQuery = false
};
this.queueProcessor.QueueManager.Add(task);
this.queueProcessor.Start();
this.IsEncoding = true;
}
示例5: Start
/// <summary>
/// Start with a LibHb EncodeJob Object
/// </summary>
/// <param name="job">
/// The job.
/// </param>
/// <param name="enableLogging">
/// The enable Logging.
/// </param>
public void Start(QueueTask job, bool enableLogging)
{
this.startTime = DateTime.Now;
this.loggingEnabled = enableLogging;
try
{
// Sanity Checking and Setup
if (this.IsEncoding)
{
throw new Exception("HandBrake is already encoding.");
}
this.IsEncoding = true;
// Get an EncodeJob object for the Interop Library
EncodeJob encodeJob = InteropModelCreator.GetEncodeJob(job);
// Enable logging if required.
if (enableLogging)
{
try
{
this.SetupLogging(job);
}
catch (Exception)
{
this.IsEncoding = false;
throw;
}
}
// Prvent the system from sleeping if the user asks
if (this.userSettingService.GetUserSetting<bool>(ASUserSettingConstants.PreventSleep) )
{
Win32.PreventSleep();
}
// Verify the Destination Path Exists, and if not, create it.
this.VerifyEncodeDestinationPath(job);
// Start the Encode
this.instance.StartEncode(encodeJob);
// Set the Process Priority
switch (this.userSettingService.GetUserSetting<string>(ASUserSettingConstants.ProcessPriority))
{
case "Realtime":
Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.RealTime;
break;
case "High":
Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.High;
break;
case "Above Normal":
Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.AboveNormal;
break;
case "Normal":
Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.Normal;
break;
case "Low":
Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.Idle;
break;
default:
Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.BelowNormal;
break;
}
// Fire the Encode Started Event
this.InvokeEncodeStarted(EventArgs.Empty);
}
catch (Exception exc)
{
this.InvokeEncodeCompleted(new EncodeCompletedEventArgs(false, exc, "An Error has occured."));
}
}
示例6: SetupLogging
/// <summary>
/// Setup the logging.
/// </summary>
/// <param name="encodeQueueTask">
/// The encode QueueTask.
/// </param>
protected void SetupLogging(QueueTask encodeQueueTask)
{
ShutdownFileWriter();
string logDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\HandBrake\\logs";
string logFile = Path.Combine(logDir, string.Format("last_encode_log{0}.txt", GeneralUtilities.ProcessId));
string logFile2 = Path.Combine(logDir, string.Format("tmp_appReadable_log{0}.txt", GeneralUtilities.ProcessId));
try
{
string query = QueryGeneratorUtility.GenerateQuery(new EncodeTask(encodeQueueTask.Task),
userSettingService.GetUserSetting<int>(ASUserSettingConstants.PreviewScanCount),
userSettingService.GetUserSetting<int>(ASUserSettingConstants.Verbosity),
userSettingService.GetUserSetting<bool>(ASUserSettingConstants.DisableLibDvdNav),
userSettingService.GetUserSetting<bool>(ASUserSettingConstants.DisableQuickSyncDecoding));
this.logBuffer = new StringBuilder();
this.logBuffer.AppendLine(String.Format("CLI Query: {0}", query));
this.logBuffer.AppendLine(String.Format("User Query: {0}", encodeQueueTask.CustomQuery));
this.logBuffer.AppendLine();
// Clear the current Encode Logs)
if (File.Exists(logFile))
{
File.Delete(logFile);
}
if (File.Exists(logFile2))
{
File.Delete(logFile2);
}
this.fileWriter = new StreamWriter(logFile) { AutoFlush = true };
this.fileWriter.WriteLine(header);
this.fileWriter.WriteLine(string.Format("CLI Query: {0}", query));
this.fileWriter.WriteLine(string.Format("User Query: {0}", encodeQueueTask.CustomQuery));
this.fileWriter.WriteLine();
}
catch (Exception)
{
if (this.fileWriter != null)
{
this.fileWriter.Close();
this.fileWriter.Dispose();
}
throw;
}
}
示例7: ScanCompleted
/// <summary>
/// The scan completed.
/// </summary>
/// <param name="job">
/// The job.
/// </param>
/// <param name="instance">
/// The instance.
/// </param>
private void ScanCompleted(QueueTask job, IHandBrakeInstance instance)
{
// Get an EncodeJob object for the Interop Library
EncodeJob encodeJob = InteropModelCreator.GetEncodeJob(job);
// Start the Encode
instance.StartEncode(encodeJob, job.Configuration.PreviewScanCount);
// Fire the Encode Started Event
this.InvokeEncodeStarted(EventArgs.Empty);
// Set the Process Priority
switch (job.Configuration.ProcessPriority)
{
case "Realtime":
Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.RealTime;
break;
case "High":
Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.High;
break;
case "Above Normal":
Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.AboveNormal;
break;
case "Normal":
Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.Normal;
break;
case "Low":
Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.Idle;
break;
default:
Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.BelowNormal;
break;
}
}
示例8: Play
/// <summary>
/// Encode and play a sample
/// </summary>
public void Play()
{
try
{
this.IsEncoding = true;
if (File.Exists(this.CurrentlyPlaying))
File.Delete(this.CurrentlyPlaying);
}
catch (Exception)
{
this.IsEncoding = false;
this.errorService.ShowMessageBox("Unable to delete previous preview file. You may need to restart the application.",
Resources.Error, MessageBoxButton.OK, MessageBoxImage.Error);
}
if (this.Task == null || string.IsNullOrEmpty(Task.Source))
{
this.errorService.ShowMessageBox("You must first scan a source and setup your encode before creating a preview.",
Resources.Error, MessageBoxButton.OK, MessageBoxImage.Error);
return;
}
EncodeTask encodeTask = new EncodeTask(this.Task)
{
PreviewEncodeDuration = this.Duration,
PreviewEncodeStartAt = this.SelectedPreviewImage,
PointToPointMode = PointToPointMode.Preview
};
// Filename handling.
if (string.IsNullOrEmpty(encodeTask.Destination))
{
string filename = Path.ChangeExtension(Path.GetTempFileName(), encodeTask.OutputFormat == OutputFormat.Mkv ? "m4v" : "mkv");
encodeTask.Destination = filename;
this.CurrentlyPlaying = filename;
}
else
{
string directory = Path.GetDirectoryName(encodeTask.Destination) ?? string.Empty;
string filename = Path.GetFileNameWithoutExtension(encodeTask.Destination);
string extension = Path.GetExtension(encodeTask.Destination);
string previewFilename = string.Format("{0}_preview{1}", filename, extension);
string previewFullPath = Path.Combine(directory, previewFilename);
encodeTask.Destination = previewFullPath;
this.CurrentlyPlaying = previewFullPath;
}
// Setup the encode task as a preview encode
encodeTask.IsPreviewEncode = true;
encodeTask.PreviewEncodeStartAt = this.SelectedPreviewImage; // TODO 0 and 1 mean the same. Need to fix this as it knocks the video out of sync with the still preview.
encodeTask.PreviewEncodeDuration = this.Duration;
QueueTask task = new QueueTask(encodeTask, HBConfigurationFactory.Create(), this.ScannedSource.ScanPath);
ThreadPool.QueueUserWorkItem(this.CreatePreview, task);
}
示例9: Start
/// <summary>
/// Execute a HandBrakeCLI process.
/// This should only be called from the UI thread.
/// </summary>
/// <param name="encodeQueueTask">
/// The encodeQueueTask.
/// </param>
public void Start(QueueTask encodeQueueTask)
{
try
{
if (this.IsEncoding)
{
throw new GeneralApplicationException("HandBrake is already encodeing.", "Please try again in a minute", null);
}
this.IsEncoding = true;
this.currentTask = encodeQueueTask;
if (encodeQueueTask.Configuration.IsLoggingEnabled)
{
try
{
this.SetupLogging(currentTask);
}
catch (Exception)
{
this.IsEncoding = false;
throw;
}
}
// Make sure the path exists, attempt to create it if it doesn't
this.VerifyEncodeDestinationPath(currentTask);
string handbrakeCLIPath = Path.Combine(Application.StartupPath, "HandBrakeCLI.exe");
// TODO tidy this code up, it's kinda messy.
string query = this.currentTask.Task.IsPreviewEncode
? QueryGeneratorUtility.GeneratePreviewQuery(
new EncodeTask(this.currentTask.Task),
encodeQueueTask.Configuration,
this.currentTask.Task.PreviewEncodeDuration,
this.currentTask.Task.PreviewEncodeStartAt)
: QueryGeneratorUtility.GenerateQuery(new EncodeTask(this.currentTask.Task), encodeQueueTask.Configuration);
ProcessStartInfo cliStart = new ProcessStartInfo(handbrakeCLIPath, query)
{
RedirectStandardOutput = true,
RedirectStandardError = encodeQueueTask.Configuration.IsLoggingEnabled,
UseShellExecute = false,
CreateNoWindow = true
};
this.HbProcess = new Process { StartInfo = cliStart };
this.HbProcess.Start();
this.startTime = DateTime.Now;
if (encodeQueueTask.Configuration.IsLoggingEnabled)
{
this.HbProcess.ErrorDataReceived += this.HbProcErrorDataReceived;
this.HbProcess.BeginErrorReadLine();
}
this.HbProcess.OutputDataReceived += HbProcess_OutputDataReceived;
this.HbProcess.BeginOutputReadLine();
this.processId = this.HbProcess.Id;
// Set the process Priority
if (this.processId != -1)
{
this.HbProcess.EnableRaisingEvents = true;
this.HbProcess.Exited += this.HbProcessExited;
}
// Set the Process Priority
switch (encodeQueueTask.Configuration.ProcessPriority)
{
case "Realtime":
this.HbProcess.PriorityClass = ProcessPriorityClass.RealTime;
break;
case "High":
this.HbProcess.PriorityClass = ProcessPriorityClass.High;
break;
case "Above Normal":
this.HbProcess.PriorityClass = ProcessPriorityClass.AboveNormal;
break;
case "Normal":
this.HbProcess.PriorityClass = ProcessPriorityClass.Normal;
break;
case "Low":
this.HbProcess.PriorityClass = ProcessPriorityClass.Idle;
break;
default:
this.HbProcess.PriorityClass = ProcessPriorityClass.BelowNormal;
break;
}
//.........这里部分代码省略.........
示例10: Start
/// <summary>
/// Start with a LibHb EncodeJob Object
/// </summary>
/// <param name="job">
/// The job.
/// </param>
public void Start(QueueTask job)
{
this.encodeService.Start(job);
}
示例11: SetupLogging
/// <summary>
/// Setup the logging.
/// </summary>
/// <param name="encodeQueueTask">
/// The encode QueueTask.
/// </param>
/// <param name="isLibhb">
/// Indicates if this is libhb that is encoding or not.
/// </param>
protected void SetupLogging(QueueTask encodeQueueTask, bool isLibhb)
{
this.ShutdownFileWriter();
string logDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\HandBrake\\logs";
string logFile = Path.Combine(logDir, string.Format("last_encode_log{0}.txt", GeneralUtilities.ProcessId));
string logFile2 = Path.Combine(logDir, string.Format("tmp_appReadable_log{0}.txt", GeneralUtilities.ProcessId));
try
{
this.logBuffer = new StringBuilder();
this.logBuffer.AppendLine();
// Clear the current Encode Logs)
if (File.Exists(logFile))
{
File.Delete(logFile);
}
if (File.Exists(logFile2))
{
File.Delete(logFile2);
}
lock (FileWriterLock)
{
this.fileWriter = new StreamWriter(logFile) { AutoFlush = true };
this.fileWriter.WriteLine(this.header);
this.fileWriter.WriteLine();
}
}
catch (Exception)
{
if (this.fileWriter != null)
{
lock (FileWriterLock)
{
this.fileWriter.Flush();
this.fileWriter.Close();
this.fileWriter.Dispose();
}
}
throw;
}
}
示例12: RetryJob
/// <summary>
/// Reset the job state to waiting.
/// </summary>
/// <param name="task">
/// The task.
/// </param>
public void RetryJob(QueueTask task)
{
task.Status = QueueItemStatus.Waiting;
this.queueProcessor.BackupQueue(null);
this.JobsPending = string.Format("{0} jobs pending", this.queueProcessor.Count);
}
示例13: EditJob
/// <summary>
/// Edit this Job
/// </summary>
/// <param name="task">
/// The task.
/// </param>
public void EditJob(QueueTask task)
{
MessageBoxResult result = this.errorService.ShowMessageBox(
"Are you sure you wish to edit this job? It will be removed from the queue and sent to the main window.",
"Modify Job?",
MessageBoxButton.YesNo,
MessageBoxImage.Question);
if (result != MessageBoxResult.Yes)
{
return;
}
// Remove the job if it is not already encoding. Let the user decide if they want to cancel or not.
this.RemoveJob(task);
// Pass a copy of the job back to the Main Screen
IMainViewModel mvm = IoC.Get<IMainViewModel>();
mvm.EditQueueJob(new EncodeTask(task.Task));
}
示例14: Start
/// <summary>
/// Start with a LibHb EncodeJob Object
/// </summary>
/// <param name="job">
/// The job.
/// </param>
/// <param name="enableLogging">
/// The enable Logging.
/// </param>
public void Start(QueueTask job, bool enableLogging)
{
ThreadPool.QueueUserWorkItem(
delegate { this.Service.StartEncode(job, enableLogging); });
}
示例15: Remove
/// <summary>
/// Remove a job from the Queue.
/// This method is Thread Safe
/// </summary>
/// <param name="job">
/// The job.
/// </param>
public void Remove(QueueTask job)
{
lock (QueueLock)
{
queue.Remove(job);
InvokeQueueChanged(EventArgs.Empty);
}
}