using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
namespace Handbrake.CLI
{
///
/// Delegate to handle pointers to event subscriptions regarding CLI jobs
///
/// The object which raised the event using this delegate
/// The job which caused this delegate to fire
public delegate void JobStatusHandler(Jobs.Job Job);
///
/// still workin on this
///
class Manager
{
private static Queue m_processQueue = new Queue();
///
/// Raised upon a job being completed
///
public static event JobStatusHandler OnJobCompleted;
///
/// Raised upon a new job starting
///
public static event JobStatusHandler OnJobStarted;
///
/// Raised upon any noteable progress during a job
///
public static event JobStatusHandler OnJobProgress;
///
/// Used for queueing up a job to be processed later
///
/// The job to be processed later
public static void EnqueueJob(Jobs.Job job)
{
//TODO: create new Process object from passed
m_processQueue.Enqueue(CreateProcess(job));
}
///
/// Starts the job queue
///
public static void StartJobs()
{
while (m_processQueue.Count > 0)
{
Process proc = m_processQueue.Dequeue();
proc.Start();
proc.Close();
}
}
///
/// Creates a new Process object from a Job object
///
/// The Job object to create a process from
/// A Process object based on the requirements of the Job passed
private static Process CreateProcess(Jobs.Job job)
{
Process hbProc = new Process();
hbProc.StartInfo.FileName = "hbcli.exe";
hbProc.StartInfo.Arguments = job.ToString();
hbProc.StartInfo.RedirectStandardOutput = true;
hbProc.StartInfo.RedirectStandardError = true;
hbProc.StartInfo.UseShellExecute = false;
hbProc.StartInfo.CreateNoWindow = true;
// Set the process Priority
switch (Properties.Settings.Default.processPriority)
{
case "Realtime":
hbProc.PriorityClass = ProcessPriorityClass.RealTime;
break;
case "High":
hbProc.PriorityClass = ProcessPriorityClass.High;
break;
case "Above Normal":
hbProc.PriorityClass = ProcessPriorityClass.AboveNormal;
break;
case "Normal":
hbProc.PriorityClass = ProcessPriorityClass.Normal;
break;
case "Low":
hbProc.PriorityClass = ProcessPriorityClass.Idle;
break;
default:
hbProc.PriorityClass = ProcessPriorityClass.BelowNormal;
break;
}
return hbProc;
}
}
}