root/TaskScheduler/TaskScheduler/CacheManager/TaskList.cs

45
13
{
13
{
14
    public class TaskList : IList<Task>
14
    public class TaskList : IList<Task>
15
    {
15
    {
16
        private readonly List<Task> _tasks = new List<Task>();
17
        private readonly Cache _cache = HttpRuntime.Cache;
18
        //How long for jobs to wait before waking.
16
        //How long for jobs to wait before waking.
19
        private const double sleepLength = 1;
17
        private const double sleepLength = 1;
18
        private readonly Cache _cache = HttpRuntime.Cache;
19
        private readonly List<Task> _tasks = new List<Task>();
20
20
21
        public List<Task> Tasks
21
        public List<Task> Tasks
22
        {
22
        {
...
...
24
            {
24
            {
25
                if (Count == 0)
25
                if (Count == 0)
26
                {
26
                {
27
                    var 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 Task)
...
...
35
            }
35
            }
36
        }
36
        }
37
37
38
        public CacheItemRemovedCallback CacheItemRemovedCallback { get; set; }
39
38
        #region Implementation of IEnumerable
40
        #region Implementation of IEnumerable
39
41
40
        public IEnumerator<Task> GetEnumerator()
42
        public IEnumerator<Task> GetEnumerator()
...
...
58
        /// <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>
59
        public void Add(Task item)
61
        public void Add(Task item)
60
        {
62
        {
61
            var task = _tasks.Find(t => t.Name == item.Name);
63
            Task task = _tasks.Find(t => t.Name == item.Name);
62
            if (task == null)
64
            if (task == null)
63
            {
65
            {
64
                _tasks.Add(item);
66
                _tasks.Add(item);
...
...
74
            }
76
            }
75
        }
77
        }
76
78
77
        public Task Find(Predicate<Task> match)
78
        {
79
            return _tasks.Find(match);
80
        }
81
82
        public void Clear()
79
        public void Clear()
83
        {
80
        {
84
            throw new NotImplementedException();
81
            throw new NotImplementedException();
...
...
109
            get { return true; }
106
            get { return true; }
110
        }
107
        }
111
108
109
        public Task Find(Predicate<Task> match)
110
        {
111
            return _tasks.Find(match);
112
        }
113
112
        #endregion
114
        #endregion
113
115
114
        #region Implementation of IList<Task>
116
        #region Implementation of IList<Task>
...
...
159
                           CacheItemRemovedCallback);
161
                           CacheItemRemovedCallback);
160
            }
162
            }
161
        }
163
        }
162
163
        public CacheItemRemovedCallback CacheItemRemovedCallback { get; set; }
164
    }
164
    }
165
}
165
}