/// <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;
                    }
                }
            }
        }
        /// <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);
        }
Beispiel #3
0
 public void PushTask(ZScheduledTask task, bool priority)
 {
     if (priority)
     {
         priorityList.Push(task);
     }
     else
     {
         taskStack.Push(task);
     }
 }
 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
     };
 }
Beispiel #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);
        }
 public static ZCurrentTask MakeCurrentTaskWithPriority(ZScheduledTask task)
 {
     return(new ZCurrentTask(task, true));
 }
 private ZCurrentTask(ZScheduledTask task, bool prioritized) : base(task)
 {
     Priority = prioritized;
 }
 /// <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);
 }
Beispiel #9
0
 public void PushTaskWithPriority(ZScheduledTask task)
 {
     priorityList.Push(task);
 }