Пример #1
0
        /// <summary>
        /// Add a new page.
        /// </summary>
        /// <param name="page">the page to add</param>
        public static XmlElement Add(NotebookPage page)
        {
            if (!PageExists(page))
            {
                //
                // <p />
                //
                XmlElement nt = db.Doc.CreateElement(PageTag);

                nt.SetAttribute(XmlDatabase.IdAttribute, page.ID);
                nt.SetAttribute(TitleAttribute, page.Title);
                nt.SetAttribute(ReadOnlyAttribute, FormatHelpers.BoolToString(page.ReadOnly));
                nt.SetAttribute(PrivateAttribute, FormatHelpers.BoolToString(page.Private));
                nt.SetAttribute(CreatedAttribute, FormatHelpers.DateTimeToString(page.Created));
                nt.SetAttribute(LastModifiedAttribute, FormatHelpers.DateTimeToString(page.LastModified));

                // If section has been deleted, ignore requests to add page.
                XmlElement section = db.Doc.GetElementById(page.SectionID);

                if (section != null)
                {
                    section.AppendChild(nt);
                }

                return(nt);
            }

            return(null);
        }
Пример #2
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);
                }
            }
        }
Пример #3
0
        private static void InitializeNewDatabase()
        {
            string now = FormatHelpers.DateTimeToString(DateTime.UtcNow);

            db.Doc.DocumentElement.InnerXml +=
                "<n id=\"0\" t=\"My Notebook\" m=\"" + now + "\" x=\"0\" h=\"0\" b=\"#FF7ACC93\" s=\"1\">" +
                "<s id=\"1\" t=\"Quick Notes\" m=\"" + now + "\" x=\"0\" h=\"0\" b=\"#FFF3D275\" s=\"2\">" +
                "<p id=\"2\" t=\"Dimension 4: The Notes Pane\" c=\"" + now + "\" m=\"" + now + "\" x=\"0\" h=\"0\" />" +
                "</s></n>";

            if (!Directory.Exists(NotesAppData))
            {
                Directory.CreateDirectory(NotesAppData);
            }

            string procFileName = Process.GetCurrentProcess().MainModule.FileName;

            File.Copy(procFileName.Remove(procFileName.LastIndexOf('\\')) + "\\Resources\\Files\\DefaultNote", NotesAppData + "\\2", true);
        }
Пример #4
0
        /// <summary>
        /// Update the values on an existing page.
        /// </summary>
        /// <param name="page"></param>
        public static void UpdatePage(NotebookPage page)
        {
            if (page != null)
            {
                XmlElement elem = db.Doc.GetElementById(page.ID);

                if (elem != null)
                {
                    elem.SetAttribute(TitleAttribute, page.Title);
                    elem.SetAttribute(ReadOnlyAttribute, FormatHelpers.BoolToString(page.ReadOnly));
                    elem.SetAttribute(PrivateAttribute, FormatHelpers.BoolToString(page.Private));
                    elem.SetAttribute(CreatedAttribute, FormatHelpers.DateTimeToString(page.Created));
                    elem.SetAttribute(LastModifiedAttribute, FormatHelpers.DateTimeToString(page.LastModified));
                }
                else
                {
                    Add(page);
                }
            }
        }
Пример #5
0
        /// <summary>
        /// Update the values on an existing section.
        /// </summary>
        /// <param name="section"></param>
        public static void UpdateSection(NotebookSection section)
        {
            if (section != null)
            {
                XmlElement elem = db.Doc.GetElementById(section.ID);

                if (elem != null)
                {
                    elem.SetAttribute(TitleAttribute, section.Title);
                    elem.SetAttribute(ColorAttribute, section.Color.ToString());
                    elem.SetAttribute(ReadOnlyAttribute, FormatHelpers.BoolToString(section.ReadOnly));
                    elem.SetAttribute(PrivateAttribute, FormatHelpers.BoolToString(section.Private));
                    elem.SetAttribute(LastModifiedAttribute, FormatHelpers.DateTimeToString(section.LastModified));
                    elem.SetAttribute(LastSelectedAttribute, section.LastSelectedPageID);
                }
                else
                {
                    Add(section);
                }
            }
        }
Пример #6
0
        /// <summary>
        /// Update the values on an existing notebook.
        /// </summary>
        /// <param name="notebook"></param>
        public static void UpdateNotebook(Notebook notebook)
        {
            if (notebook != null)
            {
                XmlElement elem = db.Doc.GetElementById(notebook.ID);

                if (elem != null)
                {
                    elem.SetAttribute(TitleAttribute, notebook.Title);
                    elem.SetAttribute(ColorAttribute, notebook.Color.ToString());
                    elem.SetAttribute(ReadOnlyAttribute, FormatHelpers.BoolToString(notebook.ReadOnly));
                    elem.SetAttribute(PrivateAttribute, FormatHelpers.BoolToString(notebook.Private));
                    elem.SetAttribute(LastModifiedAttribute, FormatHelpers.DateTimeToString(notebook.LastModified));
                    elem.SetAttribute(LastSelectedAttribute, notebook.LastSelectedSectionID);
                }
                else
                {
                    Add(notebook);
                }
            }
        }
Пример #7
0
        /// <summary>
        /// Add a new notebook.
        /// </summary>
        /// <param name="section"></param>
        /// <returns></returns>
        public static XmlElement Add(NotebookSection section)
        {
            if (!SectionExists(section))
            {
                //
                // <n />
                //
                XmlElement nt = db.Doc.CreateElement(SectionTag);

                nt.SetAttribute(XmlDatabase.IdAttribute, section.ID);
                nt.SetAttribute(TitleAttribute, section.Title);
                nt.SetAttribute(ColorAttribute, section.Color.ToString());
                nt.SetAttribute(ReadOnlyAttribute, FormatHelpers.BoolToString(section.ReadOnly));
                nt.SetAttribute(PrivateAttribute, FormatHelpers.BoolToString(section.Private));
                nt.SetAttribute(LastModifiedAttribute, FormatHelpers.DateTimeToString(section.LastModified));
                nt.SetAttribute(LastSelectedAttribute, section.LastSelectedPageID);

                db.Doc.GetElementById(section.NotebookID).AppendChild(nt);

                return(nt);
            }

            return(null);
        }
Пример #8
0
        /// <summary>
        /// Add a new notebook.
        /// </summary>
        /// <param name="notebook"></param>
        /// <returns></returns>
        public static XmlElement Add(Notebook notebook)
        {
            if (!NotebookExists(notebook))
            {
                //
                // <n />
                //
                XmlElement nt = db.Doc.CreateElement(NotebookTag);

                nt.SetAttribute(XmlDatabase.IdAttribute, notebook.ID);
                nt.SetAttribute(TitleAttribute, notebook.Title);
                nt.SetAttribute(ColorAttribute, notebook.Color.ToString());
                nt.SetAttribute(ReadOnlyAttribute, FormatHelpers.BoolToString(notebook.ReadOnly));
                nt.SetAttribute(PrivateAttribute, FormatHelpers.BoolToString(notebook.Private));
                nt.SetAttribute(LastModifiedAttribute, FormatHelpers.DateTimeToString(notebook.LastModified));
                nt.SetAttribute(LastSelectedAttribute, notebook.LastSelectedSectionID);

                db.Doc.DocumentElement.AppendChild(nt);

                return(nt);
            }

            return(null);
        }
Пример #9
0
        /// <summary>
        /// Add new task.
        /// </summary>
        /// <param name="task">The task to add.</param>
        public static void Add(UserTask task)
        {
            XmlElement existing = db.Doc.GetElementById(task.ID);

            if (existing == null)
            {
                //
                // <yyyymmdd></yyyymmdd>
                //
                string date = "nodate";

                if (task.DueDate != null)
                {
                    date = FormatHelpers.DateString((DateTime)task.DueDate);
                }

                XmlNode existingDate = db.Doc.SelectSingleNode("/db/" + date);

                //
                // <t />
                //
                XmlElement tsk = db.Doc.CreateElement(TaskTag);

                tsk.SetAttribute(XmlDatabase.IdAttribute, task.ID);
                tsk.SetAttribute(SubjectAttribute, task.Subject);

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

                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));

                if (existingDate == null)
                {
                    XmlElement elem = db.Doc.CreateElement(date);
                    elem.AppendChild(tsk);

                    if (task.DueDate != null)
                    {
                        db.Doc.SmartInsert(elem, (DateTime)task.DueDate, date);
                    }
                    else
                    {
                        db.Doc.DocumentElement.PrependChild(elem);
                    }
                }
                else
                {
                    existingDate.AppendChild(tsk);
                }
            }
        }