コード例 #1
0
        /// <summary>
        /// Private shared code
        /// </summary>
        /// <param name="condition"></param>
        private void PullTasksWith(Func <ZScheduledTask, bool> condition)
        {
            if (!(head == null || head.link == null))
            {
                List <Node> urgentTasks = new List <Node>();

                Node position = head;
                while (position.link != null)
                {
                    ZScheduledTask task = position.link.task as ZScheduledTask;
                    if (task != null && condition(task))
                    {
                        urgentTasks.Add(PopLink(position));
                    }
                    else
                    {
                        position = position.link;
                    }
                }

                if (urgentTasks.Any())
                {
                    foreach (Node node in urgentTasks)
                    {
                        // stacking to the top
                        node.link = head;
                        head      = node;
                    }
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Returns the most urgent task and removes it from the list;
        /// Using quick sort before popping.
        /// </summary>
        /// <returns></returns>
        public ZScheduledTask Pop()
        {
            SortIfNotAlready();
            ZScheduledTask item = priorityList[priorityList.Count - 1];

            priorityList.RemoveAt(priorityList.Count - 1);
            return(item);
        }
コード例 #3
0
 public void PushTask(ZScheduledTask task, bool priority)
 {
     if (priority)
     {
         priorityList.Push(task);
     }
     else
     {
         taskStack.Push(task);
     }
 }
コード例 #4
0
 public void Schedule(DateTime deadline, TimeSpan buffer)
 {
     if (Content is ZScheduledTask)
     {
         throw new Exception("Task is already scheduled, consider reschedule task.");
     }
     Content = new ZScheduledTask
     {
         Title       = Content.Title,
         Description = Content.Description,
         Deadline    = deadline,
         ZBuffer     = buffer
     };
 }
コード例 #5
0
        public string ExtractDetail()
        {
            string taskString = $"Title: {Content.Title}\n";

            if (!String.IsNullOrWhiteSpace(Content.Description))
            {
                taskString += $"Description: {Content.Description}\n";
            }
            if (Content is ZScheduledTask)
            {
                ZScheduledTask task = Content as ZScheduledTask;
                taskString += $"Deadline: {task.Deadline.ToFormattedString()}\nDeadline Buffer: {task.ZBuffer.ToString()}\n";
            }
            taskString += $"Status: {Enum.GetName(typeof(Category), Status)}\n" +
                          $"Archive Date: {ArchiveDate.ToFormattedString()}\n\n";
            return(taskString);
        }
コード例 #6
0
 public static ZCurrentTask MakeCurrentTaskWithPriority(ZScheduledTask task)
 {
     return(new ZCurrentTask(task, true));
 }
コード例 #7
0
 private ZCurrentTask(ZScheduledTask task, bool prioritized) : base(task)
 {
     Priority = prioritized;
 }
コード例 #8
0
 /// <summary>
 /// The reason that insertion sort is not used here is because of the fact insertion takes
 /// linear time in addition to the logrithmic time taken by binary search
 /// </summary>
 public ZPriorityList Push(ZScheduledTask task)
 {
     sorted = false;
     priorityList.Add(task);
     return(this);
 }
コード例 #9
0
 public void PushTaskWithPriority(ZScheduledTask task)
 {
     priorityList.Push(task);
 }