Esempio n. 1
0
        /// <summary>
        /// Update the values on an existing task.
        /// </summary>
        /// <param name="task"></param>
        public static void UpdateTask(UserTask task)
        {
            if (task != null)
            {
                XmlElement tsk = db.Doc.GetElementById(task.ID);

                if (tsk != null)
                {
                    XmlNode parent = tsk.ParentNode;

                    DateTime?tskDate = null;

                    if (parent.Name != "nodate")
                    {
                        tskDate = FormatHelpers.SplitDateString(parent.Name);
                    }

                    if (task.DueDate == tskDate)
                    {
                        tsk.SetAttribute(SubjectAttribute, task.Subject);

                        if (task.StartDate == null)
                        {
                            tsk.SetAttribute(StartDateAttribute, "");
                        }
                        else
                        {
                            tsk.SetAttribute(StartDateAttribute, FormatHelpers.DateTimeToShortString(task.StartDate.Value));
                        }

                        tsk.SetAttribute(ReminderAttribute, FormatHelpers.DateTimeToString(task.Reminder));
                        tsk.SetAttribute(IsReminderEnabledAttribute, FormatHelpers.BoolToString(task.IsReminderEnabled));
                        tsk.SetAttribute(StatusAttribute, ((byte)task.Status).ToString());
                        tsk.SetAttribute(PriorityAttribute, ((byte)task.Priority).ToString());
                        tsk.SetAttribute(ProgressAttribute, task.Progress.ToString());
                        tsk.SetAttribute(CategoryAttribute, task.CategoryID);
                        tsk.SetAttribute(OwnerAttribute, task.Owner);
                        tsk.SetAttribute(ReadOnlyAttribute, FormatHelpers.BoolToString(task.ReadOnly));
                        tsk.SetAttribute(PrivateAttribute, FormatHelpers.BoolToString(task.Private));
                        tsk.SetAttribute(LastModifiedAttribute, FormatHelpers.DateTimeToString(task.LastModified));
                    }
                    else
                    {
                        parent.RemoveChild(tsk);

                        if (!parent.HasChildNodes)
                        {
                            parent.ParentNode.RemoveChild(parent);
                        }

                        Add(task);
                    }
                }
                else
                {
                    Add(task);
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Get all tasks.
        /// </summary>
        /// <returns></returns>
        public static UserTask[] GetTasks()
        {
            XmlNodeList tsks = db.Doc.GetElementsByTagName(TaskTag);

            int count = tsks.Count;

            if (count != 0)
            {
                UserTask[] tasks = new UserTask[count];

                for (int i = 0; i < count; i++)
                {
                    //
                    // <t />
                    //
                    XmlNode node = tsks.Item(i);
                    XmlAttributeCollection attribs = node.Attributes;

                    tasks[i]    = new UserTask(false);
                    tasks[i].ID = attribs[XmlDatabase.IdAttribute].Value;

                    if (node.ParentNode.Name != "nodate")
                    {
                        tasks[i].DueDate = FormatHelpers.SplitDateString(node.ParentNode.Name);
                    }
                    else
                    {
                        tasks[i].DueDate = null;
                    }

                    if (attribs[StartDateAttribute].Value == "")
                    {
                        tasks[i].StartDate = null;
                    }
                    else
                    {
                        tasks[i].StartDate = FormatHelpers.ParseShortDateTime(attribs[StartDateAttribute].Value);
                    }

                    tasks[i].Subject           = attribs[SubjectAttribute].Value;
                    tasks[i].Reminder          = FormatHelpers.ParseDateTime(attribs[ReminderAttribute].Value);
                    tasks[i].IsReminderEnabled = FormatHelpers.ParseBool(attribs[IsReminderEnabledAttribute].Value);
                    tasks[i].Status            = (UserTask.StatusPhase) byte.Parse(attribs[StatusAttribute].Value);
                    tasks[i].Priority          = (Priority)byte.Parse(attribs[PriorityAttribute].Value);
                    tasks[i].Progress          = double.Parse(attribs[ProgressAttribute].Value);
                    tasks[i].CategoryID        = attribs[CategoryAttribute].Value;
                    tasks[i].Owner             = attribs[OwnerAttribute].Value;
                    tasks[i].ReadOnly          = FormatHelpers.ParseBool(attribs[ReadOnlyAttribute].Value);
                    tasks[i].Private           = FormatHelpers.ParseBool(attribs[PrivateAttribute].Value);
                    tasks[i].LastModified      = FormatHelpers.ParseDateTime(attribs[LastModifiedAttribute].Value);
                }

                return(tasks);
            }

            return(null);
        }
Esempio n. 3
0
        /// <summary>
        /// Insert an element into the document hierarchy in the correct chronological posistion.
        /// </summary>
        /// <param name="_database"></param>
        /// <param name="element">The element to insert.</param>
        /// <param name="date">The date the element represents.</param>
        public static void SmartInsert(this XmlDocument _database, XmlElement element, DateTime date, string datestring)
        {
            XmlNodeList allItems = _database.DocumentElement.ChildNodes;
            int         count    = allItems.Count;

            int lowerbound = 0;
            int upperbound = count;

            if (count > 0)
            {
                while (true)
                {
                    if (upperbound - lowerbound == 1)
                    {
                        int index = lowerbound;

                        DateTime?itemDate = FormatHelpers.SplitDateString(allItems[index].Name);

                        if (date < itemDate)
                        {
                            _database.DocumentElement.InsertBefore(element, allItems[index]);
                        }
                        else
                        {
                            _database.DocumentElement.InsertAfter(element, allItems[index]);
                        }

                        break;
                    }
                    else
                    {
                        XmlNode  middle     = allItems[lowerbound + (upperbound - lowerbound) / 2];
                        DateTime?middleDate = FormatHelpers.SplitDateString(middle.Name);

                        if (date < middleDate)
                        {
                            upperbound -= (upperbound - lowerbound) / 2;
                        }
                        else
                        {
                            lowerbound += (upperbound - lowerbound) / 2;
                        }
                    }
                }
            }
            else
            {
                _database.DocumentElement.AppendChild(element);
            }
        }
Esempio n. 4
0
        public static UserTask GetTask(string id)
        {
            XmlElement element = db.Doc.GetElementById(id);

            if (element == null)
            {
                return(null);
            }

            XmlAttributeCollection attribs = element.Attributes;

            UserTask task = new UserTask(false);

            task.ID = id;

            if (element.ParentNode.Name != "nodate")
            {
                task.DueDate = FormatHelpers.SplitDateString(element.ParentNode.Name);
            }
            else
            {
                task.DueDate = null;
            }

            if (attribs[StartDateAttribute].Value == "")
            {
                task.StartDate = null;
            }
            else
            {
                task.StartDate = FormatHelpers.ParseShortDateTime(attribs[StartDateAttribute].Value);
            }

            task.Subject           = attribs[SubjectAttribute].Value;
            task.Reminder          = FormatHelpers.ParseDateTime(attribs[ReminderAttribute].Value);
            task.IsReminderEnabled = FormatHelpers.ParseBool(attribs[IsReminderEnabledAttribute].Value);
            task.Status            = (UserTask.StatusPhase) byte.Parse(attribs[StatusAttribute].Value);
            task.Priority          = (Priority)byte.Parse(attribs[PriorityAttribute].Value);
            task.Progress          = double.Parse(attribs[ProgressAttribute].Value);
            task.CategoryID        = attribs[CategoryAttribute].Value;
            task.Owner             = attribs[OwnerAttribute].Value;
            task.ReadOnly          = FormatHelpers.ParseBool(attribs[ReadOnlyAttribute].Value);
            task.Private           = FormatHelpers.ParseBool(attribs[PrivateAttribute].Value);
            task.LastModified      = FormatHelpers.ParseDateTime(attribs[LastModifiedAttribute].Value);

            return(task);
        }