Ejemplo n.º 1
0
        /// <summary>
        /// XML Serialize instance of an AddressBooks Class
        /// </summary>
        /// <param name="addressBooks">instance to serialize</param>
        public static void SerializeAddressBooks(AddressBooks addressBooks)
        {
            DictToListMapping dictToList = new DictToListMapping(DictToListMapping.DictionaryToList(addressBooks));

            XmlSerializer xmlser     = new XmlSerializer(typeof(DictToListMapping));
            FileStream    fileStream = new FileStream(path, FileMode.Create, FileAccess.Write);

            xmlser.Serialize(fileStream, dictToList);
            fileStream.Close();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// XML Deserialize and store in instance of AddressBooks Class
        /// </summary>
        /// <param name="addressBooks">ref to addressbooks instance</param>
        public static void DeserializeAddressBooks(ref AddressBooks addressBooks)
        {
            DictToListMapping dictToListMapping = new DictToListMapping();

            XmlSerializer xmlser     = new XmlSerializer(typeof(DictToListMapping));
            FileStream    fileStream = new FileStream(path, FileMode.Open);

            dictToListMapping = (DictToListMapping)xmlser.Deserialize(fileStream);
            fileStream.Close();

            addressBooks = DictToListMapping.ListToDictionary(dictToListMapping);
        }
Ejemplo n.º 3
0
 ///Copy constructer
 public DictToListMapping(DictToListMapping dictToList)
 {
     AddressBookName = dictToList.AddressBookName;
     ContactName     = dictToList.ContactName;
     FirstName       = dictToList.FirstName;
     LastName        = dictToList.LastName;
     City            = dictToList.City;
     State           = dictToList.State;
     ZipCode         = dictToList.ZipCode;
     PhoneNumber     = dictToList.PhoneNumber;
     Email           = dictToList.Email;
     DateAdded       = dictToList.DateAdded;
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Method to map addressbooks dictionary to this class lists
        /// </summary>
        /// <param name="addressBooks">instance of AddressBooks Class to map</param>
        /// <returns>Instance of this class after mapping</returns>
        public static DictToListMapping DictionaryToList(AddressBooks addressBooks)
        {
            DictToListMapping dictToList = new DictToListMapping();

            foreach (var element in addressBooks._multiAddressBooks)
            {
                string addressBookName = element.Key;
                foreach (var contact in element.Value.AddressBook)
                {
                    dictToList.AddressBookName.Add(addressBookName);
                    dictToList.ContactName.Add(contact.Key);
                    dictToList.FirstName.Add(contact.Value.FirstName);
                    dictToList.LastName.Add(contact.Value.LastName);
                    dictToList.City.Add(contact.Value.City);
                    dictToList.State.Add(contact.Value.State);
                    dictToList.ZipCode.Add(contact.Value.Zip);
                    dictToList.PhoneNumber.Add(contact.Value.PhoneNumber);
                    dictToList.Email.Add(contact.Value.Email);
                    dictToList.DateAdded.Add(contact.Value.DateAdded);
                }
            }
            return(dictToList);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Method to map this class lists to a addressbooks dictionary
        /// </summary>
        /// <param name="dictToList">Instance of this class to map</param>
        /// <returns>Instance of AddressBooks Class after mapping</returns>
        public static AddressBooks ListToDictionary(DictToListMapping dictToList)
        {
            AddressBooks    addressBooks = new AddressBooks();
            AddressBookMain addressBookMain;
            ContactDetails  contactDetails;

            string addressBookName = "", contactName = "";

            for (int i = 0; i < dictToList.AddressBookName.Count; i++)
            {
                addressBookMain = new AddressBookMain();
                contactDetails  = new ContactDetails();

                addressBookName            = dictToList.AddressBookName[i];
                contactName                = dictToList.ContactName[i];
                contactDetails.FirstName   = dictToList.FirstName[i];
                contactDetails.LastName    = dictToList.LastName[i];
                contactDetails.City        = dictToList.City[i];
                contactDetails.State       = dictToList.State[i];
                contactDetails.Zip         = dictToList.ZipCode[i];
                contactDetails.PhoneNumber = dictToList.PhoneNumber[i];
                contactDetails.Email       = dictToList.Email[i];
                contactDetails.DateAdded   = dictToList.DateAdded[i];

                if (addressBooks._multiAddressBooks.ContainsKey(addressBookName))
                {
                    addressBooks._multiAddressBooks[addressBookName].AddressBook.Add(contactName, contactDetails);
                }
                else
                {
                    addressBookMain.AddressBook.Add(contactName, contactDetails);
                    addressBooks._multiAddressBooks.Add(addressBookName, addressBookMain);
                }
            }
            return(addressBooks);
        }