Beispiel #1
0
        public void LoadContactGroups()
        {
            var contactGroup1 = new ContactGroup()
            {
                ContactGroupId   = 1,
                ContactGroupName = "TestGroup1"
            };
            var contactGroup2 = new ContactGroup()
            {
                ContactGroupId   = 2,
                ContactGroupName = "TestGroup2"
            };
            var contactGroup3 = new ContactGroup()
            {
                ContactGroupId   = 3,
                ContactGroupName = "TestGroup3"
            };
            var contactGroup4 = new ContactGroup()
            {
                ContactGroupId   = 4,
                ContactGroupName = "TestGroup3"
            };

            ContactGroups.Add(contactGroup1);
            ContactGroups.Add(contactGroup2);
            ContactGroups.Add(contactGroup3);
            ContactGroups.Add(contactGroup4);
        }
Beispiel #2
0
        /// <summary>
        /// Loads the address book from the specified reader.
        /// </summary>
        protected override void Load(TextReader reader)
        {
            XmlDocument xmlDoc = new XmlDocument();

            xmlDoc.Load(reader);

            foreach (XmlElement contactGroupElem in xmlDoc.DocumentElement.SelectNodes("ContactGroup"))
            {
                ContactGroup contactGroup = new ContactGroup(contactGroupElem.GetAttribute("name"))
                {
                    Parent = this
                };

                foreach (XmlElement contactElem in contactGroupElem.SelectNodes("Contact"))
                {
                    Contact contact = new Contact(contactElem.GetAttribute("name"))
                    {
                        Parent = contactGroup
                    };

                    foreach (XmlElement phoneNumberElem in contactElem.SelectNodes("PhoneNumber"))
                    {
                        contact.ContactItems.Add(
                            new PhoneNumber(phoneNumberElem.InnerText)
                        {
                            Parent = contact
                        });
                    }

                    foreach (XmlElement emailElem in contactElem.SelectNodes("Email"))
                    {
                        contact.ContactItems.Add(
                            new Email(emailElem.InnerText)
                        {
                            Parent = contact
                        });
                    }

                    contact.ContactItems.Sort();
                    contactGroup.Contacts.Add(contact);
                }

                contactGroup.Contacts.Sort();
                ContactGroups.Add(contactGroup);
            }

            ContactGroups.Sort();
        }
Beispiel #3
0
        /// <summary>
        /// Download address book from file
        /// </summary>
        public bool Load(string fileName, out string errMsg)
        {
            try {
                // address book cleaning
                ContactGroups.Clear();

                // loading address book
                var xmlDoc = new XmlDocument();
                xmlDoc.Load(fileName);

                var contactGroupNodes = xmlDoc.DocumentElement.SelectNodes("ContactGroup");

                foreach (XmlElement contactGroupElem in contactGroupNodes)
                {
                    var contactGroup = new ContactGroup(contactGroupElem.GetAttribute("name"))
                    {
                        Parent = this
                    };

                    var contactNodes = contactGroupElem.SelectNodes("Contact");
                    foreach (XmlElement contactElem in contactNodes)
                    {
                        var contact = new Contact(contactElem.GetAttribute("name"))
                        {
                            Parent = contactGroup
                        };

                        var phoneNumberNodes = contactElem.SelectNodes("PhoneNumber");
                        foreach (XmlElement phoneNumberElem in phoneNumberNodes)
                        {
                            contact.ContactRecords.Add(
                                new PhoneNumber(phoneNumberElem.InnerText)
                            {
                                Parent = contact
                            });
                        }

                        var emailNodes = contactElem.SelectNodes("Email");
                        foreach (XmlElement emailElem in emailNodes)
                        {
                            contact.ContactRecords.Add(
                                new Email(emailElem.InnerText)
                            {
                                Parent = contact
                            });
                        }

                        contact.ContactRecords.Sort();
                        contactGroup.Contacts.Add(contact);
                    }

                    contactGroup.Contacts.Sort();
                    ContactGroups.Add(contactGroup);
                }

                ContactGroups.Sort();

                errMsg = "";
                return(true);
            } catch (Exception ex) {
                errMsg = AbPhrases.LoadAddressBookError + ":" + Environment.NewLine + ex.Message;
                return(false);
            }
        }
Beispiel #4
0
        /// <summary>
        /// Загрузить адресную книгу из файла
        /// </summary>
        public bool Load(string fileName, out string errMsg)
        {
            try
            {
                // очистка адресной книги
                ContactGroups.Clear();

                // загрузка адресной книги
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.Load(fileName);

                XmlNodeList contactGroupNodes = xmlDoc.DocumentElement.SelectNodes("ContactGroup");

                foreach (XmlElement contactGroupElem in contactGroupNodes)
                {
                    ContactGroup contactGroup = new ContactGroup(contactGroupElem.GetAttribute("name"));
                    contactGroup.Parent = this;

                    XmlNodeList contactNodes = contactGroupElem.SelectNodes("Contact");
                    foreach (XmlElement contactElem in contactNodes)
                    {
                        Contact contact = new Contact(contactElem.GetAttribute("name"));
                        contact.Parent = contactGroup;

                        XmlNodeList phoneNumberNodes = contactElem.SelectNodes("PhoneNumber");
                        foreach (XmlElement phoneNumberElem in phoneNumberNodes)
                        {
                            contact.ContactRecords.Add(
                                new PhoneNumber(phoneNumberElem.InnerText)
                            {
                                Parent = contact
                            });
                        }

                        XmlNodeList emailNodes = contactElem.SelectNodes("Email");
                        foreach (XmlElement emailElem in emailNodes)
                        {
                            contact.ContactRecords.Add(
                                new Email(emailElem.InnerText)
                            {
                                Parent = contact
                            });
                        }

                        contact.ContactRecords.Sort();
                        contactGroup.Contacts.Add(contact);
                    }

                    contactGroup.Contacts.Sort();
                    ContactGroups.Add(contactGroup);
                }

                ContactGroups.Sort();

                errMsg = "";
                return(true);
            }
            catch (Exception ex)
            {
                errMsg = AbPhrases.LoadAddressBookError + ":" + Environment.NewLine + ex.Message;
                return(false);
            }
        }