示例#1
0
        /// <summary>
        /// Gets all Tasks that are enabled and have reminders set within one day.
        /// </summary>
        /// <returns></returns>
        private static Reminder[] ActiveTasks()
        {
            XmlDocument db       = TaskDatabase.Database.Doc;
            XmlNodeList elements = db.GetElementsByTagName(TaskDatabase.TaskTag);
            int         count    = elements.Count;

            if (count > 0)
            {
                DateTime now = DateTime.Now;

                Reminder[] reminders  = new Reminder[count];
                int        actualsize = 0;

                for (int i = 0; i < count; i++)
                {
                    XmlNode current = elements[i];
                    XmlAttributeCollection attribs = current.Attributes;

                    bool isReminderEnabled      = FormatHelpers.ParseBool(attribs[TaskDatabase.IsReminderEnabledAttribute].Value);
                    UserTask.StatusPhase status = (UserTask.StatusPhase) int.Parse(attribs[TaskDatabase.StatusAttribute].Value);

                    if (isReminderEnabled && status != UserTask.StatusPhase.Completed)
                    {
                        DateTime taskReminder = FormatHelpers.ParseDateTime(attribs[TaskDatabase.ReminderAttribute].Value);

                        // We only want to queue one day's worth of tasks.
                        if (taskReminder < now.AddDays(1))                        //taskReminder >= now &&
                        {
                            Reminder r = new Reminder();
                            r.ReminderType = ReminderType.Task;
                            r.ID           = attribs[XmlDatabase.IdAttribute].Value;

                            if (current.ParentNode.Name != "nodate")
                            {
                                r.EventEndDate = FormatHelpers.SplitDateString(current.ParentNode.Name);
                            }

                            if (attribs[TaskDatabase.StartDateAttribute].Value == "")
                            {
                                r.EventStartDate = null;
                            }
                            else
                            {
                                r.EventStartDate = FormatHelpers.ParseShortDateTime(attribs[TaskDatabase.StartDateAttribute].Value);
                            }

                            r.AlertStartTime = taskReminder;

                            reminders[actualsize++] = r;
                        }
                    }
                }

                // Trim array to size.
                Array.Resize(ref reminders, actualsize);

                return(reminders);
            }

            return(new Reminder[0]);
        }