コード例 #1
0
        /// <summary>
        /// Add new contact
        /// </summary>
        /// <param name="contact">the contact to add</param>
        public static XmlElement Add(Contact contact)
        {
            if (!ContactExists(contact))
            {
                //
                // <c />
                //
                XmlElement ct = db.Doc.CreateElement(ContactTag);

                ct.SetAttribute(XmlDatabase.IdAttribute, contact.ID);
                ct.SetAttribute(NameAttribute, contact.RawName);
                ct.SetAttribute(WorkAttribute, contact.RawWork);
                ct.SetAttribute(EmailAttribute, contact.RawEmail);
                ct.SetAttribute(WebSiteAttribute, contact.RawWebsite);
                ct.SetAttribute(IMAttribute, contact.RawIM);
                ct.SetAttribute(PhoneAttribute, contact.RawPhone);
                ct.SetAttribute(AddressAttribute, contact.RawAddress);
                ct.SetAttribute(DateAttribute, contact.RawSpecialDate);
                ct.SetAttribute(TileAttribute, contact.RawTile);
                ct.SetAttribute(ReadOnlyAttribute, FormatHelpers.BoolToString(contact.ReadOnly));
                ct.SetAttribute(PrivateAttribute, FormatHelpers.BoolToString(contact.Private));
                ct.SetAttribute(GenderAttribute, ((byte)contact.Gender).ToString());

                SmartInsert(db.Doc.DocumentElement, ct, contact);

                return(ct);
            }

            return(null);
        }
コード例 #2
0
ファイル: NoteDatabase.cs プロジェクト: mingslogar/dimension4
        /// <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);
        }
コード例 #3
0
        public static Contact GetContact(string id)
        {
            XmlElement element = db.Doc.GetElementById(id);

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

            XmlAttributeCollection attribs = element.Attributes;

            Contact contact = new Contact(false);

            contact.ID             = id;
            contact.RawName        = attribs[NameAttribute].Value;
            contact.RawWork        = attribs[WorkAttribute].Value;
            contact.RawEmail       = attribs[EmailAttribute].Value;
            contact.RawWebsite     = attribs[WebSiteAttribute].Value;
            contact.RawIM          = attribs[IMAttribute].Value;
            contact.RawPhone       = attribs[PhoneAttribute].Value;
            contact.RawAddress     = attribs[AddressAttribute].Value;
            contact.RawSpecialDate = attribs.GetValue(DateAttribute, DateAttributeDefault);
            contact.RawTile        = attribs[TileAttribute].Value;
            contact.ReadOnly       = FormatHelpers.ParseBool(attribs[ReadOnlyAttribute].Value);
            contact.Private        = FormatHelpers.ParseBool(attribs[PrivateAttribute].Value);
            contact.Gender         = (Gender)byte.Parse(attribs.GetValue(GenderAttribute, GenderAttributeDefault));

            return(contact);
        }
コード例 #4
0
        /// <summary>
        /// Get all contacts.
        /// </summary>
        public static IEnumerable <Contact> GetContacts()
        {
            XmlNodeList contacts = db.Doc.SelectNodes("/db/" + ContactTag);

            foreach (XmlNode node in contacts)
            {
                //
                // <c />
                //
                XmlAttributeCollection attribs = node.Attributes;

                Contact c = new Contact(false);
                c.ID             = attribs[XmlDatabase.IdAttribute].Value;
                c.RawName        = attribs[NameAttribute].Value;
                c.RawWork        = attribs[WorkAttribute].Value;
                c.RawEmail       = attribs[EmailAttribute].Value;
                c.RawWebsite     = attribs[WebSiteAttribute].Value;
                c.RawIM          = attribs[IMAttribute].Value;
                c.RawPhone       = attribs[PhoneAttribute].Value;
                c.RawAddress     = attribs[AddressAttribute].Value;
                c.RawSpecialDate = attribs.GetValue(DateAttribute, DateAttributeDefault);
                c.RawTile        = attribs[TileAttribute].Value;
                c.ReadOnly       = FormatHelpers.ParseBool(attribs[ReadOnlyAttribute].Value);
                c.Private        = FormatHelpers.ParseBool(attribs[PrivateAttribute].Value);

                yield return(c);
            }
        }
コード例 #5
0
ファイル: TaskDatabase.cs プロジェクト: mingslogar/dimension4
        /// <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);
                }
            }
        }
コード例 #6
0
ファイル: TaskDatabase.cs プロジェクト: mingslogar/dimension4
        /// <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);
        }
コード例 #7
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);
            }
        }
コード例 #8
0
ファイル: TaskDatabase.cs プロジェクト: mingslogar/dimension4
        public static void UpdateCategory(Category category)
        {
            XmlElement element = db.Doc.GetElementById(category.ID);

            if (element == null)
            {
                AddCategory(category);
            }
            else
            {
                element.SetAttribute(CategoryColorAttribute, category.Color.ToString());
                element.SetAttribute(CategoryNameAttribute, category.Name);
                element.SetAttribute(CategoryDescriptionAttribute, category.Description);
                element.SetAttribute(CategoryReadOnlyAttribute, FormatHelpers.BoolToString(category.ReadOnly));
            }
        }
コード例 #9
0
ファイル: TaskDatabase.cs プロジェクト: mingslogar/dimension4
        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);
        }
コード例 #10
0
ファイル: TaskDatabase.cs プロジェクト: mingslogar/dimension4
        public static bool AddCategory(Category category)
        {
            if (GetCategory(category.ID) != null)
            {
                return(false);
            }

            XmlElement element = db.Doc.CreateElement(CategoryTag);

            element.SetAttribute(XmlDatabase.IdAttribute, category.ID);
            element.SetAttribute(CategoryColorAttribute, category.Color.ToString());
            element.SetAttribute(CategoryNameAttribute, category.Name);
            element.SetAttribute(CategoryDescriptionAttribute, category.Description);
            element.SetAttribute(CategoryReadOnlyAttribute, FormatHelpers.BoolToString(category.ReadOnly));

            db.Doc.DocumentElement.PrependChild(element);

            return(true);
        }
コード例 #11
0
ファイル: NoteDatabase.cs プロジェクト: mingslogar/dimension4
        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);
        }
コード例 #12
0
ファイル: TaskDatabase.cs プロジェクト: mingslogar/dimension4
        public static Category GetCategory(string id)
        {
            XmlElement element = db.Doc.GetElementById(id);

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

            XmlAttributeCollection attribs = element.Attributes;

            Category category = new Category(false);

            category.ID       = id;
            category.Name     = attribs[CategoryNameAttribute].Value;
            category.Color    = (Color)ColorConverter.ConvertFromString(attribs[CategoryColorAttribute].Value);
            category.ReadOnly = FormatHelpers.ParseBool(attribs[CategoryReadOnlyAttribute].Value);

            return(category);
        }
コード例 #13
0
ファイル: NoteDatabase.cs プロジェクト: mingslogar/dimension4
        /// <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);
                }
            }
        }
コード例 #14
0
ファイル: NoteDatabase.cs プロジェクト: mingslogar/dimension4
        public static Notebook GetNotebook(XmlNode node)
        {
            if (node == null)
            {
                return(null);
            }

            XmlAttributeCollection attribs = node.Attributes;

            Notebook notebook = new Notebook(false);

            notebook.ID                    = attribs[XmlDatabase.IdAttribute].Value;
            notebook.Title                 = attribs[TitleAttribute].Value;
            notebook.Color                 = (Color)ColorConverter.ConvertFromString(attribs[ColorAttribute].Value);
            notebook.ReadOnly              = FormatHelpers.ParseBool(attribs[ReadOnlyAttribute].Value);
            notebook.Private               = FormatHelpers.ParseBool(attribs[PrivateAttribute].Value);
            notebook.LastModified          = FormatHelpers.ParseDateTime(attribs[LastModifiedAttribute].Value);
            notebook.LastSelectedSectionID = attribs[LastSelectedAttribute].Value;

            return(notebook);
        }
コード例 #15
0
ファイル: NoteDatabase.cs プロジェクト: mingslogar/dimension4
        /// <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);
                }
            }
        }
コード例 #16
0
ファイル: NoteDatabase.cs プロジェクト: mingslogar/dimension4
        /// <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);
                }
            }
        }
コード例 #17
0
ファイル: NoteDatabase.cs プロジェクト: mingslogar/dimension4
        public static NotebookPage GetPage(XmlNode node)
        {
            if (node == null)
            {
                return(null);
            }

            XmlAttributeCollection attribs = node.Attributes;

            NotebookPage page = new NotebookPage(false);

            page.ID           = attribs[XmlDatabase.IdAttribute].Value;
            page.SectionID    = node.ParentNode.Attributes[XmlDatabase.IdAttribute].Value;
            page.Title        = attribs[TitleAttribute].Value;
            page.ReadOnly     = FormatHelpers.ParseBool(attribs[ReadOnlyAttribute].Value);
            page.Private      = FormatHelpers.ParseBool(attribs[PrivateAttribute].Value);
            page.Created      = FormatHelpers.ParseDateTime(attribs[CreatedAttribute].Value);
            page.LastModified = FormatHelpers.ParseDateTime(attribs[LastModifiedAttribute].Value);

            return(page);
        }
コード例 #18
0
ファイル: TaskDatabase.cs プロジェクト: mingslogar/dimension4
        public static Category[] GetCategories()
        {
            XmlNodeList elems = db.Doc.SelectNodes("/db/" + CategoryTag);

            Category[] categories = new Category[elems.Count];

            for (int i = 0; i < elems.Count; i++)
            {
                XmlAttributeCollection attribs = elems[i].Attributes;

                Category c = new Category(false);
                c.ID       = attribs[XmlDatabase.IdAttribute].Value;
                c.Color    = (Color)ColorConverter.ConvertFromString(attribs[CategoryColorAttribute].Value);
                c.Name     = attribs[CategoryNameAttribute].Value;
                c.ReadOnly = FormatHelpers.ParseBool(attribs[CategoryReadOnlyAttribute].Value);

                categories[i] = c;
            }

            return(categories);
        }
コード例 #19
0
ファイル: NoteDatabase.cs プロジェクト: mingslogar/dimension4
        public static NotebookSection GetSection(XmlNode node)
        {
            if (node == null)
            {
                return(null);
            }

            XmlAttributeCollection attribs = node.Attributes;

            NotebookSection section = new NotebookSection(false);

            section.ID                 = attribs[XmlDatabase.IdAttribute].Value;
            section.NotebookID         = node.ParentNode.Attributes[XmlDatabase.IdAttribute].Value;
            section.Title              = attribs[TitleAttribute].Value;
            section.Color              = (Color)ColorConverter.ConvertFromString(attribs[ColorAttribute].Value);
            section.ReadOnly           = FormatHelpers.ParseBool(attribs[ReadOnlyAttribute].Value);
            section.Private            = FormatHelpers.ParseBool(attribs[PrivateAttribute].Value);
            section.LastModified       = FormatHelpers.ParseDateTime(attribs[LastModifiedAttribute].Value);
            section.LastSelectedPageID = attribs[LastSelectedAttribute].Value;

            return(section);
        }
コード例 #20
0
        /// <summary>
        /// Update the values on an existing contact.
        /// </summary>
        /// <param name="contact"></param>
        public static void UpdateContact(Contact contact)
        {
            if (contact != null)
            {
                XmlElement elem = db.Doc.GetElementById(contact.ID);

                if (elem != null)
                {
                    string oldName = elem.GetAttribute(NameAttribute);

                    // If the contact name changed, re-insert it into the database
                    // to ensure database stays in alphabetical order.
                    if (oldName != contact.RawName)
                    {
                        elem.SetAttribute(NameAttribute, contact.RawName);
                        elem.ParentNode.RemoveChild(elem);
                        SmartInsert(db.Doc.DocumentElement, elem, contact);
                    }

                    elem.SetAttribute(WorkAttribute, contact.RawWork);
                    elem.SetAttribute(EmailAttribute, contact.RawEmail);
                    elem.SetAttribute(WebSiteAttribute, contact.RawWebsite);
                    elem.SetAttribute(IMAttribute, contact.RawIM);
                    elem.SetAttribute(PhoneAttribute, contact.RawPhone);
                    elem.SetAttribute(AddressAttribute, contact.RawAddress);
                    elem.SetAttribute(DateAttribute, contact.RawSpecialDate);
                    elem.SetAttribute(TileAttribute, contact.RawTile);
                    elem.SetAttribute(ReadOnlyAttribute, FormatHelpers.BoolToString(contact.ReadOnly));
                    elem.SetAttribute(PrivateAttribute, FormatHelpers.BoolToString(contact.Private));
                    elem.SetAttribute(GenderAttribute, ((byte)contact.Gender).ToString());
                }
                else
                {
                    Add(contact);
                }
            }
        }
コード例 #21
0
ファイル: NoteDatabase.cs プロジェクト: mingslogar/dimension4
        /// <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);
        }
コード例 #22
0
ファイル: NoteDatabase.cs プロジェクト: mingslogar/dimension4
        /// <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);
        }
コード例 #23
0
ファイル: TaskDatabase.cs プロジェクト: mingslogar/dimension4
        /// <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);
                }
            }
        }
コード例 #24
0
ファイル: TaskDatabase.cs プロジェクト: mingslogar/dimension4
        /// <summary>
        /// Get all tasks tagged with the specified date.
        /// </summary>
        /// <param name="dueDate">the date tasks should be returned for</param>
        public static UserTask[] GetTasks(DateTime?dueDate)
        {
            //
            // <yyyymmdd></yyyymmdd>
            //
            string datestring = "nodate";

            if (dueDate != null)
            {
                datestring = FormatHelpers.DateString((DateTime)dueDate);
            }

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

            if (existingDate != null)
            {
                XmlNodeList tsks = existingDate.ChildNodes;

                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;
                        tasks[i].DueDate = dueDate;

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

            return(null);
        }