예제 #1
0
        /// <summary>
        /// 增加一个任务
        /// </summary>
        /// <param name="task"></param>
        /// <param name="startTime"></param>
        public void AddTask(WlyTaskBase task, DateTime startTime)
        {
            if ((m_dailyList.FirstOrDefault(o => o.Task.ID == task.ID) != null) || (m_mainList.FirstOrDefault(o => o.Task.ID == task.ID) != null))
            {
                return;
            }

            if (!task.Filter(this))
            {
                return;
            }

            if (task is WlyTimeTask || task is WlyDailyTask)
            {
                var info = m_accountInfo.GetTaskInfo(task.ID);
                if (!info.IsComplete || (info.CompleteTime < startTime))
                {
                    if (task is WlyFinalTask)
                    {
                        if (m_finalList.FirstOrDefault(o => o.Task.ID == task.ID) == null)
                        {
                            m_finalList.Add(new WlyTaskRunner(task, startTime > info.NextRunTime ? startTime : info.NextRunTime));
                        }
                    }
                    else if (m_dailyList.FirstOrDefault(o => o.Task.ID == task.ID) == null)
                    {
                        m_dailyList.Add(new WlyTaskRunner(task, startTime > info.NextRunTime ? startTime : info.NextRunTime));
                        m_dailyList = m_dailyList.OrderBy(o => o.StartTime).ToList();
                    }
                }
            }
            else if (task is WlyMainTask)
            {
                var info = m_accountInfo.GetTaskInfo(task.ID);
                m_mainList.Add(new WlyTaskRunner(task, startTime > info.NextRunTime ? startTime : info.NextRunTime));
            }

            if (Application.Current != null)
            {
                Application.Current.Dispatcher.Invoke(() =>
                {
                    TaskList.Clear();
                    foreach (var t in m_dailyList.ToList())
                    {
                        TaskList.Add(t);
                    }

                    foreach (var t in m_mainList.ToList())
                    {
                        TaskList.Add(t);
                    }
                });
            }
        }
예제 #2
0
 public WlyTaskRunner(WlyTaskBase task, DateTime startTime)
 {
     Task      = task;
     StartTime = startTime;
 }