-
Notifications
You must be signed in to change notification settings - Fork 0
/
JobQueue.cs
83 lines (71 loc) · 1.6 KB
/
JobQueue.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
using System.Collections.Generic;
using System.Linq;
using System.Diagnostics;
namespace CmdQueue
{
class JobQueue
{
public List<Job> Jobs { get; set; }
public JobQueue() {
LoadQueue();
}
public void AddItem( Job job ) {
Jobs.Add( job );
SaveQueue();
}
public void RemoveItem( Job job ) {
if ( Jobs.Contains( job ) ) {
Jobs.Remove( job );
SaveQueue();
}
}
public void RemoveItem( int index ) {
if ( HasIndex( index ) ) {
Jobs.RemoveAt( index );
SaveQueue();
}
}
public void MoveItemUp( int index ) {
if ( index > 0 && HasIndex( index ) ) {
Job item = Jobs[index];
Jobs.RemoveAt( index );
Jobs.Insert( index - 1, item );
SaveQueue();
}
}
public void MoveItemDown( int index ) {
if ( index < Jobs.Count - 1 && HasIndex( index ) ) {
Job item = Jobs[index];
Jobs.RemoveAt( index );
Jobs.Insert( index + 1, item );
SaveQueue();
}
}
public bool HasIndex( int index ) {
if ( index >= 0 && Jobs.Count > index && Jobs.ElementAt( index ) != null ) {
return true;
}
return false;
}
public Process GetProcess( Job job ) {
return job.GetProcess();
}
public Process GetProcess( int index ) {
if ( HasIndex( index ) ) {
Job job = Jobs[index];
return GetProcess( job );
}
return null;
}
private void LoadQueue() {
Jobs = AppSettings.Instance.CurrentQueue;
if ( Jobs == null ) Jobs = new List<Job>();
SaveQueue();
}
public void SaveQueue() {
AppSettings.Instance.CurrentQueue = null;
AppSettings.Instance.CurrentQueue = Jobs;
AppSettings.Instance.Save();
}
}
}