root/TaskScheduler/TaskScheduler/CacheManager/TaskList.cs

57
11
11
12
namespace CacheManager
12
namespace CacheManager
13
{
13
{
14
    public class TaskList : IList<Task>
14
    public class TaskList : IList<ITask>
15
    {
15
    {
16
        //How long for jobs to wait before waking.
16
        //How long for jobs to wait before waking.
17
        private const double sleepLength = 1;
17
        private const double sleepLength = 1;
18
        private readonly Cache _cache = HttpRuntime.Cache;
18
        private readonly Cache _cache = HttpRuntime.Cache;
19
        private readonly List<Task> _tasks = new List<Task>();
19
        private readonly List<ITask> _tasks = new List<ITask>();
20
20
21
        public List<Task> Tasks
21
        public List<ITask> Tasks
22
        {
22
        {
23
            get
23
            get
24
            {
24
            {
...
...
27
                    IDictionaryEnumerator enumerator = _cache.GetEnumerator();
27
                    IDictionaryEnumerator enumerator = _cache.GetEnumerator();
28
                    do
28
                    do
29
                    {
29
                    {
30
                        if (enumerator.Current is Task)
30
                        if (enumerator.Current is ITask)
31
                            _tasks.Add(enumerator.Current as Task);
31
                            _tasks.Add(enumerator.Current as ITask);
32
                    } while (enumerator.MoveNext());
32
                    } while (enumerator.MoveNext());
33
                }
33
                }
34
                return _tasks;
34
                return _tasks;
...
...
39
39
40
        #region Implementation of IEnumerable
40
        #region Implementation of IEnumerable
41
41
42
        public IEnumerator<Task> GetEnumerator()
42
        public IEnumerator<ITask> GetEnumerator()
43
        {
43
        {
44
            return _tasks.GetEnumerator();
44
            return _tasks.GetEnumerator();
45
        }
45
        }
...
...
58
        /// </summary>
58
        /// </summary>
59
        /// <param name="item">The object to add to the <see cref="T:System.Collections.Generic.ICollection`1"/>.</param>
59
        /// <param name="item">The object to add to the <see cref="T:System.Collections.Generic.ICollection`1"/>.</param>
60
        /// <exception cref="T:System.NotSupportedException">The <see cref="T:System.Collections.Generic.ICollection`1"/> is
read-only.</exception>
60
        /// <exception cref="T:System.NotSupportedException">The <see cref="T:System.Collections.Generic.ICollection`1"/> is
read-only.</exception>
61
        public void Add(Task item)
61
        public void Add(ITask item)
62
        {
62
        {
63
            Task task = _tasks.Find(t => t.Name == item.Name);
63
            ITask task = _tasks.Find(t => t.Name == item.Name);
64
            if (task == null)
64
            if (task == null)
65
            {
65
            {
66
                _tasks.Add(item);
66
                _tasks.Add(item);
...
...
81
            throw new NotImplementedException();
81
            throw new NotImplementedException();
82
        }
82
        }
83
83
84
        public bool Contains(Task item)
84
        public bool Contains(ITask item)
85
        {
85
        {
86
            return _tasks.Contains(item);
86
            return _tasks.Contains(item);
87
        }
87
        }
88
88
89
        public void CopyTo(Task[] array, int arrayIndex)
89
        public void CopyTo(ITask[] array, int arrayIndex)
90
        {
90
        {
91
            throw new NotImplementedException();
91
            throw new NotImplementedException();
92
        }
92
        }
93
93
94
        public bool Remove(Task item)
94
        public bool Remove(ITask item)
95
        {
95
        {
96
            throw new NotImplementedException();
96
            throw new NotImplementedException();
97
        }
97
        }
...
...
106
            get { return true; }
106
            get { return true; }
107
        }
107
        }
108
108
109
        public Task Find(Predicate<Task> match)
109
        public ITask Find(Predicate<ITask> match)
110
        {
110
        {
111
            return _tasks.Find(match);
111
            return _tasks.Find(match);
112
        }
112
        }
...
...
115
115
116
        #region Implementation of IList<Task>
116
        #region Implementation of IList<Task>
117
117
118
        public int IndexOf(Task item)
118
        public int IndexOf(ITask item)
119
        {
119
        {
120
            return _tasks.IndexOf(item);
120
            return _tasks.IndexOf(item);
121
        }
121
        }
122
122
123
        public void Insert(int index, Task item)
123
        public void Insert(int index, ITask item)
124
        {
124
        {
125
            throw new NotImplementedException();
125
            throw new NotImplementedException();
126
        }
126
        }
...
...
130
            throw new NotImplementedException();
130
            throw new NotImplementedException();
131
        }
131
        }
132
132
133
        public Task this[int index]
133
        public ITask this[int index]
134
        {
134
        {
135
            get { return _tasks[index]; }
135
            get { return _tasks[index]; }
136
            set { throw new NotImplementedException(); }
136
            set { throw new NotImplementedException(); }
...
...
142
        /// Caches the update.
142
        /// Caches the update.
143
        /// </summary>
143
        /// </summary>
144
        /// <param name="item">The item.</param>
144
        /// <param name="item">The item.</param>
145
        private void CacheUpdate(Task item)
145
        private void CacheUpdate(ITask item)
146
        {
146
        {
147
            _cache.Remove(item.Name);
147
            _cache.Remove(item.Name);
148
148
...
...
153
        /// Caches the add.
153
        /// Caches the add.
154
        /// </summary>
154
        /// </summary>
155
        /// <param name="item">The item.</param>
155
        /// <param name="item">The item.</param>
156
        private void CacheAdd(Task item)
156
        private void CacheAdd(ITask item)
157
        {
157
        {
158
            if (_cache[item.Name] == null)
158
            if (_cache[item.Name] == null)
159
            {
159
            {