/// <summary> /// Gets the address book from CSV dictionary. /// </summary> //(This would be private, but test generation wouldn't work...) internal static AddressBook GetAddressBookFromLookup(IEnumerable<Dictionary<string, string>> csv) { AddressBook book = new AddressBook(); foreach(var row in csv) { bool isbusiness = (row[Keys.HomePhone] == "" && row[Keys.WorkPhone] != ""); //is business if no home phone AND has business phone bool multiperson = row[Keys.FirstName].Contains('&'); var contact = new Contact { Name = row[Keys.LastName], Email = ContactMailLogic(row, multiperson), IsBusiness = isbusiness, PhoneNumber = isbusiness ? row[Keys.WorkPhone] : row[Keys.HomePhone], Address = GetAddress(row), Notes = row[Keys.Notes] }; //Add one or two people, based on first name containing & if(multiperson) { contact.AddPerson(FirstPerson(row, false)); contact.AddPerson(SecondPerson(row)); } else { contact.AddPerson(FirstPerson(row, true)); } //Update first names with new people contact.UpdateFirstNames(); book.AddContact(contact); } return book; }
public static void SaveToXml(string filepath, AddressBook book) { var serializer = GetSerializer(); using(var writer = new XmlTextWriter(filepath, Encoding.Default)) { serializer.Serialize(writer, book); } book.ResetDirty(); }
//Save just contacts (for filtered export) public static void SaveToXml(string filepath, IEnumerable<Contact> contacts) { var serializer = GetSerializer(); var book = new AddressBook(); book.AddContacts(contacts); using(var writer = new XmlTextWriter(filepath, Encoding.Default)) { serializer.Serialize(writer, book); } }
//only undo/redo can do stuff to addressbook? public UndoRedo(AddressBook addressbook) { m_AddressBook = addressbook; m_Undoable = new Stack<UndoRedoItem>(); m_Redoable = new Stack<UndoRedoItem>(); }
private void SaveAddressBook(string path, AddressBook addressbook) { if(File.Exists(path) && addressbook.IsDirty()) { //Only backup file if it isn't already a backup file! if(!Utilities.IsBackupFile(path)) { var bakFileName = Utilities.GetBackupFileName(path); File.Move(path, bakFileName); File.SetAttributes(bakFileName, File.GetAttributes(bakFileName) | FileAttributes.ReadOnly); } } ImportExport.SaveToXml(path, addressbook); SetFilePath(path); }
private void LoadDefaultAddressBook() { if(Settings.Default.FilePath == "" || ! File.Exists(Settings.Default.FilePath)) m_AddressBook = new AddressBook(); else m_AddressBook = ImportExport.LoadFromXml(Settings.Default.FilePath); DataContext = m_AddressBook; UndoRedo = new UndoRedo(m_AddressBook); listView.Focus(); Title = GetTitle(Settings.Default.FilePath); if(Settings.Default.BirthdaysOnStartup) BirthdaysAlert(); }
public Birthdays(AddressBook addressBook) : this() { m_AddressBook = addressBook; ResetContext(); }