OSDN Git Service

WinGui:
[handbrake-jp/handbrake-jp-git.git] / win / C# / CLI / Manager.cs
1 using System;\r
2 using System.Collections.Generic;\r
3 using System.Text;\r
4 using System.Diagnostics;\r
5 \r
6 namespace Handbrake.CLI\r
7 {\r
8     /// <summary>\r
9     /// Delegate to handle pointers to event subscriptions regarding CLI jobs\r
10     /// </summary>\r
11     /// <param name="Sender">The object which raised the event using this delegate</param>\r
12     /// <param name="Job">The job which caused this delegate to fire</param>\r
13     public delegate void JobStatusHandler(Jobs.Job Job);\r
14 \r
15     /// <summary>\r
16     /// still workin on this\r
17     /// </summary>\r
18     class Manager\r
19     {\r
20         private static Queue<Process> m_processQueue = new Queue<Process>();\r
21 \r
22         /// <summary>\r
23         /// Raised upon a job being completed\r
24         /// </summary>\r
25         public static event JobStatusHandler OnJobCompleted;\r
26 \r
27         /// <summary>\r
28         /// Raised upon a new job starting\r
29         /// </summary>\r
30         public static event JobStatusHandler OnJobStarted;\r
31 \r
32         /// <summary>\r
33         /// Raised upon any noteable progress during a job\r
34         /// </summary>\r
35         public static event JobStatusHandler OnJobProgress;\r
36 \r
37         /// <summary>\r
38         /// Used for queueing up a job to be processed later\r
39         /// </summary>\r
40         /// <param name="job">The job to be processed later</param>\r
41         public static void EnqueueJob(Jobs.Job job)\r
42         {\r
43             //TODO: create new Process object from passed \r
44             m_processQueue.Enqueue(CreateProcess(job));\r
45         }\r
46 \r
47         /// <summary>\r
48         /// Starts the job queue\r
49         /// </summary>\r
50         public static void StartJobs()\r
51         {\r
52             while (m_processQueue.Count > 0)\r
53             {\r
54                 Process proc = m_processQueue.Dequeue();\r
55                 proc.Start();\r
56                 proc.Close();\r
57             }\r
58         }\r
59 \r
60         /// <summary>\r
61         /// Creates a new Process object from a Job object\r
62         /// </summary>\r
63         /// <param name="job">The Job object to create a process from</param>\r
64         /// <returns>A Process object based on the requirements of the Job passed</returns>\r
65         private static Process CreateProcess(Jobs.Job job)\r
66         {\r
67             Process hbProc = new Process();\r
68             hbProc.StartInfo.FileName = "hbcli.exe";\r
69             hbProc.StartInfo.Arguments = job.ToString();\r
70             hbProc.StartInfo.RedirectStandardOutput = true;\r
71             hbProc.StartInfo.RedirectStandardError = true;\r
72             hbProc.StartInfo.UseShellExecute = false;\r
73             hbProc.StartInfo.CreateNoWindow = true;\r
74 \r
75             // Set the process Priority\r
76             switch (Properties.Settings.Default.processPriority)\r
77             {\r
78                 case "Realtime":\r
79                     hbProc.PriorityClass = ProcessPriorityClass.RealTime;\r
80                     break;\r
81                 case "High":\r
82                     hbProc.PriorityClass = ProcessPriorityClass.High;\r
83                     break;\r
84                 case "Above Normal":\r
85                     hbProc.PriorityClass = ProcessPriorityClass.AboveNormal;\r
86                     break;\r
87                 case "Normal":\r
88                     hbProc.PriorityClass = ProcessPriorityClass.Normal;\r
89                     break;\r
90                 case "Low":\r
91                     hbProc.PriorityClass = ProcessPriorityClass.Idle;\r
92                     break;\r
93                 default:\r
94                     hbProc.PriorityClass = ProcessPriorityClass.BelowNormal;\r
95                     break;\r
96             }\r
97 \r
98             return hbProc;\r
99         }\r
100     }\r
101 }\r