private void DeleteExistingTestContacts(string name, string email) { sync.Load(); ContactsMatcher.SyncContacts(sync); ContactMatch match = sync.ContactByProperty(name, email); try { while (match != null) { if (match.GoogleContact != null) { match.GoogleContact.Delete(); } if (match.OutlookContact != null) { match.OutlookContact.Delete(); } sync.Load(); ContactsMatcher.SyncContacts(sync); match = sync.ContactByProperty(name, email); } } catch { } Outlook.ContactItem prevOutlookContact = sync.OutlookContacts.Find("[Email1Address] = '" + email + "'") as Outlook.ContactItem; if (prevOutlookContact != null) { prevOutlookContact.Delete(); } }
public void TestGooglePhoto() { sync.SyncOption = SyncOption.MergeOutlookWins; string timestamp = DateTime.Now.Ticks.ToString(); string name = "AN OUTLOOK TEST CONTACT"; string email = "*****@*****.**"; name = name.Replace(" ", "_"); Assert.IsTrue(File.Exists(AppDomain.CurrentDomain.BaseDirectory + "\\SamplePic.jpg")); // delete previously failed test contacts DeleteExistingTestContacts(name, email); sync.Load(); ContactsMatcher.SyncContacts(sync); // create new contact to sync Outlook.ContactItem outlookContact = sync.OutlookApplication.CreateItem(Outlook.OlItemType.olContactItem) as Outlook.ContactItem; outlookContact.FullName = name; outlookContact.FileAs = name; outlookContact.Email1Address = email; outlookContact.Email2Address = email.Replace("00", "01"); outlookContact.Email3Address = email.Replace("00", "02"); outlookContact.HomeAddress = "10 Parades"; outlookContact.PrimaryTelephoneNumber = "123"; outlookContact.Save(); ContactEntry googleContact = new ContactEntry(); ContactSync.UpdateContact(outlookContact, googleContact); ContactMatch match = new ContactMatch(outlookContact, googleContact); //save contact to google. sync.SaveGoogleContact(match); googleContact = null; //load the same contact from google. sync.Load(); ContactsMatcher.SyncContacts(sync); match = sync.ContactByProperty(name, email); Image pic = Utilities.CropImageGoogleFormat(Image.FromFile(AppDomain.CurrentDomain.BaseDirectory + "\\SamplePic.jpg")); bool saved = Utilities.SaveGooglePhoto(sync, match.GoogleContact, pic); Assert.IsTrue(saved); sync.Load(); ContactsMatcher.SyncContacts(sync); match = sync.ContactByProperty(name, email); Image image = Utilities.GetGooglePhoto(sync, match.GoogleContact); Assert.IsNotNull(image); //delete test contacts match.Delete(); }
public void TestSync() { sync.SyncOption = SyncOption.MergeOutlookWins; string timestamp = DateTime.Now.Ticks.ToString(); string name = "AN OUTLOOK TEST CONTACT"; string email = "*****@*****.**"; name = name.Replace(" ", "_"); // delete previously failed test contacts DeleteExistingTestContacts(name, email); sync.Load(); ContactsMatcher.SyncContacts(sync); // create new contact to sync Outlook.ContactItem outlookContact = sync.OutlookApplication.CreateItem(Outlook.OlItemType.olContactItem) as Outlook.ContactItem; outlookContact.FullName = name; outlookContact.FileAs = name; outlookContact.Email1Address = email; outlookContact.Email2Address = email.Replace("00", "01"); outlookContact.Email3Address = email.Replace("00", "02"); outlookContact.HomeAddress = "10 Parades"; outlookContact.PrimaryTelephoneNumber = "123"; outlookContact.Save(); ContactEntry googleContact = new ContactEntry(); ContactSync.UpdateContact(outlookContact, googleContact); ContactMatch match = new ContactMatch(outlookContact, googleContact); //save contact to google. sync.SaveGoogleContact(match); googleContact = null; //load the same contact from google. sync.Load(); ContactsMatcher.SyncContacts(sync); match = sync.ContactByProperty(name, email); Outlook.ContactItem recreatedOutlookContact = sync.OutlookApplication.CreateItem(Outlook.OlItemType.olContactItem) as Outlook.ContactItem; ContactSync.MergeContacts(match.GoogleContact, recreatedOutlookContact); // match recreatedOutlookContact with outlookContact Assert.AreEqual(outlookContact.FullName, recreatedOutlookContact.FullName); Assert.AreEqual(outlookContact.FileAs, recreatedOutlookContact.FileAs); Assert.AreEqual(outlookContact.Email1Address, recreatedOutlookContact.Email1Address); Assert.AreEqual(outlookContact.Email2Address, recreatedOutlookContact.Email2Address); Assert.AreEqual(outlookContact.Email3Address, recreatedOutlookContact.Email3Address); Assert.AreEqual(outlookContact.PrimaryTelephoneNumber, recreatedOutlookContact.PrimaryTelephoneNumber); Assert.AreEqual(outlookContact.HomeAddress, recreatedOutlookContact.HomeAddress); //delete test contacts match.Delete(); }
public void TestMassSyncToGoogle() { // NEED TO DELETE CONTACTS MANUALY int c = 300; string[] names = new string[c]; string[] emails = new string[c]; Outlook.ContactItem outlookContact; ContactMatch match; for (int i = 0; i < c; i++) { names[i] = "TEST name" + i; emails[i] = "email" + i + "@domain.com"; } // count existing google contacts int excount = sync.GoogleContacts.Count; DateTime start = DateTime.Now; Console.WriteLine("Started mass sync to google of " + c + " contacts"); for (int i = 0; i < c; i++) { outlookContact = sync.OutlookApplication.CreateItem(Outlook.OlItemType.olContactItem) as Outlook.ContactItem; outlookContact.FullName = names[i]; outlookContact.FileAs = names[i]; outlookContact.Email1Address = emails[i]; outlookContact.Save(); ContactEntry googleContact = new ContactEntry(); ContactSync.UpdateContact(outlookContact, googleContact); match = new ContactMatch(outlookContact, googleContact); //save contact to google. sync.SaveGoogleContact(match); } sync.Load(); ContactsMatcher.SyncContacts(sync); // all contacts should be synced Assert.AreEqual(c, sync.Contacts.Count - excount); DateTime end = DateTime.Now; TimeSpan time = end - start; Console.WriteLine("Synced " + c + " contacts to google in " + time.TotalSeconds + " s (" + ((float)time.TotalSeconds / (float)c) + " s per contact)"); // received: Synced 50 contacts to google in 30.137 s (0.60274 s per contact) }
public void TestExtendedProps() { sync.SyncOption = SyncOption.MergeOutlookWins; string timestamp = DateTime.Now.Ticks.ToString(); string name = "AN OUTLOOK TEST CONTACT"; string email = "*****@*****.**"; name = name.Replace(" ", "_"); // delete previously failed test contacts DeleteExistingTestContacts(name, email); sync.Load(); ContactsMatcher.SyncContacts(sync); // create new contact to sync Outlook.ContactItem outlookContact = sync.OutlookApplication.CreateItem(Outlook.OlItemType.olContactItem) as Outlook.ContactItem; outlookContact.FullName = name; outlookContact.FileAs = name; outlookContact.Email1Address = email; outlookContact.Email2Address = email.Replace("00", "01"); outlookContact.Email3Address = email.Replace("00", "02"); outlookContact.HomeAddress = "10 Parades"; outlookContact.PrimaryTelephoneNumber = "123"; outlookContact.Save(); ContactEntry googleContact = new ContactEntry(); ContactSync.UpdateContact(outlookContact, googleContact); ContactMatch match = new ContactMatch(outlookContact, googleContact); sync.SaveGoogleContact(match); // read contact from google googleContact = null; sync.Load(); ContactsMatcher.SyncContacts(sync); foreach (ContactMatch m in sync.Contacts) { if (m.GoogleContact.Title.Text == name) { googleContact = m.GoogleContact; break; } } // get extended prop Assert.AreEqual(ContactPropertiesUtils.GetOutlookId(outlookContact), ContactPropertiesUtils.GetGoogleOutlookContactId(sync.SyncProfile, googleContact)); //delete test contacts match.Delete(); }
public void TestResetMatches() { sync.SyncOption = SyncOption.MergeOutlookWins; string groupName = "A_TEST_GROUP"; string timestamp = DateTime.Now.Ticks.ToString(); string name = "AN OUTLOOK TEST CONTACT"; string email = "*****@*****.**"; name = name.Replace(" ", "_"); // delete previously failed test contacts DeleteExistingTestContacts(name, email); sync.Load(); ContactsMatcher.SyncContacts(sync); // create new contact to sync Outlook.ContactItem outlookContact = sync.OutlookApplication.CreateItem(Outlook.OlItemType.olContactItem) as Outlook.ContactItem; outlookContact.FullName = name; outlookContact.FileAs = name; outlookContact.Email1Address = email; outlookContact.Email2Address = email.Replace("00", "01"); outlookContact.Email3Address = email.Replace("00", "02"); outlookContact.HomeAddress = "10 Parades"; outlookContact.PrimaryTelephoneNumber = "123"; outlookContact.Save(); ContactEntry googleContact = new ContactEntry(); ContactSync.UpdateContact(outlookContact, googleContact); ContactMatch match = new ContactMatch(outlookContact, googleContact); //save contact to google. sync.SaveContact(match); //load the same contact from google. sync.Load(); ContactsMatcher.SyncContacts(sync); match = sync.ContactByProperty(name, email); // delete outlook contact match.OutlookContact.Delete(); match.OutlookContact = null; //load the same contact from google. sync.Load(); ContactsMatcher.SyncContacts(sync); match = sync.ContactByProperty(name, email); // reset matches sync.ResetMatch(match); // load same contact match sync.Load(); ContactsMatcher.SyncContacts(sync); match = sync.ContactByProperty(name, email); // google contact should still be present Assert.IsNotNull(match.GoogleContact); //delete test contacts match.Delete(); // create new contact to sync outlookContact = sync.OutlookApplication.CreateItem(Outlook.OlItemType.olContactItem) as Outlook.ContactItem; outlookContact.FullName = name; outlookContact.FileAs = name; outlookContact.Email1Address = email; outlookContact.Email2Address = email.Replace("00", "01"); outlookContact.Email3Address = email.Replace("00", "02"); outlookContact.HomeAddress = "10 Parades"; outlookContact.PrimaryTelephoneNumber = "123"; outlookContact.Save(); // same test for delete google contact... googleContact = new ContactEntry(); ContactSync.UpdateContact(outlookContact, googleContact); match = new ContactMatch(outlookContact, googleContact); //save contact to google. sync.SaveContact(match); //load the same contact from google. sync.Load(); ContactsMatcher.SyncContacts(sync); match = sync.ContactByProperty(name, email); // delete google contact match.GoogleContact.Delete(); match.GoogleContact = null; //load the same contact from google. sync.Load(); ContactsMatcher.SyncContacts(sync); match = sync.ContactByProperty(name, email); // reset matches sync.ResetMatch(match); // load same contact match sync.Load(); ContactsMatcher.SyncContacts(sync); match = sync.ContactByProperty(name, email); // google contact should still be present Assert.IsNotNull(match.OutlookContact); //delete test contacts match.Delete(); }
public void TestSyncDeletedOutlookGroup() { sync.SyncOption = SyncOption.MergeOutlookWins; string groupName = "A_TEST_GROUP"; string timestamp = DateTime.Now.Ticks.ToString(); string name = "AN OUTLOOK TEST CONTACT"; string email = "*****@*****.**"; name = name.Replace(" ", "_"); // delete previously failed test contacts DeleteExistingTestContacts(name, email); sync.Load(); ContactsMatcher.SyncContacts(sync); // create new contact to sync Outlook.ContactItem outlookContact = sync.OutlookApplication.CreateItem(Outlook.OlItemType.olContactItem) as Outlook.ContactItem; outlookContact.FullName = name; outlookContact.FileAs = name; outlookContact.Email1Address = email; outlookContact.Email2Address = email.Replace("00", "01"); outlookContact.Email3Address = email.Replace("00", "02"); outlookContact.HomeAddress = "10 Parades"; outlookContact.PrimaryTelephoneNumber = "123"; outlookContact.Categories = groupName; outlookContact.Save(); ContactEntry googleContact = new ContactEntry(); ContactSync.UpdateContact(outlookContact, googleContact); ContactMatch match = new ContactMatch(outlookContact, googleContact); //save contact to google. sync.SaveContact(match); //load the same contact from google. sync.Load(); ContactsMatcher.SyncContacts(sync); match = sync.ContactByProperty(name, email); // delete group from outlook Utilities.RemoveOutlookGroup(match.OutlookContact, groupName); sync.SyncOption = SyncOption.OutlookToGoogleOnly; //save contact to google. sync.SaveContact(match); //load the same contact from google. sync.Load(); ContactsMatcher.SyncContacts(sync); match = sync.ContactByProperty(name, email); // google and outlook should now have no category Assert.AreEqual(null, match.OutlookContact.Categories); Assert.AreEqual(0, Utilities.GetGoogleGroups(sync, match.GoogleContact).Count); //delete test contacts match.Delete(); // delete test group GroupEntry group = sync.GetGoogleGroupByName(groupName); group.Delete(); }
public void TestSyncDeletedOulook() { sync.SyncOption = SyncOption.MergeOutlookWins; string timestamp = DateTime.Now.Ticks.ToString(); string name = "AN OUTLOOK TEST CONTACT"; string email = "*****@*****.**"; name = name.Replace(" ", "_"); // delete previously failed test contacts DeleteExistingTestContacts(name, email); sync.Load(); ContactsMatcher.SyncContacts(sync); // create new contact to sync Outlook.ContactItem outlookContact = sync.OutlookApplication.CreateItem(Outlook.OlItemType.olContactItem) as Outlook.ContactItem; outlookContact.FullName = name; outlookContact.FileAs = name; outlookContact.Email1Address = email; outlookContact.Email2Address = email.Replace("00", "01"); outlookContact.Email3Address = email.Replace("00", "02"); outlookContact.HomeAddress = "10 Parades"; outlookContact.PrimaryTelephoneNumber = "123"; outlookContact.Save(); ContactEntry googleContact = new ContactEntry(); ContactSync.UpdateContact(outlookContact, googleContact); ContactMatch match = new ContactMatch(outlookContact, googleContact); //save contacts sync.SaveContact(match); // delete outlook contact outlookContact.Delete(); // sync sync.Load(); ContactsMatcher.SyncContacts(sync); // find match match = null; foreach (ContactMatch m in sync.Contacts) { if (m.GoogleContact.Title.Text == name) { match = m; break; } } // delete sync.SaveContact(match); // sync sync.Load(); ContactsMatcher.SyncContacts(sync); // check if google contact still exists googleContact = null; foreach (ContactMatch m in sync.Contacts) { if (m.GoogleContact.Title.Text == name) { googleContact = m.GoogleContact; break; } } Assert.IsNull(googleContact); }
public void Sync() { lock (_syncRoot) { try { if (string.IsNullOrEmpty(SyncProfile)) { Logger.Log("Must set a sync profile. This should be different on each user/computer you sync on.", EventType.Error); return; } LogSyncParams(); SyncedCount = 0; appointmentsSynchronizer.SyncedCount = 0; contactsSynchronizer.SyncedCount = 0; DeletedCount = 0; appointmentsSynchronizer.DeletedCount = 0; contactsSynchronizer.DeletedCount = 0; ErrorCount = 0; appointmentsSynchronizer.ErrorCount = 0; contactsSynchronizer.ErrorCount = 0; SkippedCount = 0; appointmentsSynchronizer.SkippedCount = 0; contactsSynchronizer.SkippedCount = 0; SkippedCountNotMatches = 0; appointmentsSynchronizer.SkippedCountNotMatches = 0; contactsSynchronizer.SkippedCountNotMatches = 0; ConflictResolution = ConflictResolution.Cancel; DeleteGoogleResolution = DeleteResolution.Cancel; DeleteOutlookResolution = DeleteResolution.Cancel; if (SyncContacts) { contactsSynchronizer.MatchContacts(); } if (SyncAppointments) { appointmentsSynchronizer.SetTimeZone(); appointmentsSynchronizer.MatchAppointments(); } if (SyncContacts) { if (contactsSynchronizer.Contacts == null) { return; } TotalCount = contactsSynchronizer.Contacts.Count + SkippedCountNotMatches + appointmentsSynchronizer.SkippedCountNotMatches + contactsSynchronizer.SkippedCountNotMatches; //Resolve Google duplicates from matches to be synced contactsSynchronizer.ResolveDuplicateContacts(contactsSynchronizer.GoogleContactDuplicates); //Remove Outlook duplicates from matches to be synced if (contactsSynchronizer.OutlookContactDuplicates != null) { for (int i = contactsSynchronizer.OutlookContactDuplicates.Count - 1; i >= 0; i--) { ContactMatch match = contactsSynchronizer.OutlookContactDuplicates[i]; if (contactsSynchronizer.Contacts.Contains(match)) { //ToDo: If there has been a resolution for a duplicate above, there is still skipped increased, check how to distinguish SkippedCount++; contactsSynchronizer.Contacts.Remove(match); } } } Logger.Log("Syncing groups...", EventType.Information); ContactsMatcher.SyncGroups(contactsSynchronizer); Logger.Log("Syncing contacts...", EventType.Information); ContactsMatcher.SyncContacts(contactsSynchronizer); contactsSynchronizer.SaveContacts(contactsSynchronizer.Contacts); } if (SyncAppointments) { if (appointmentsSynchronizer.Appointments == null) { return; } TotalCount += appointmentsSynchronizer.Appointments.Count + SkippedCountNotMatches + appointmentsSynchronizer.SkippedCountNotMatches + contactsSynchronizer.SkippedCountNotMatches; Logger.Log("Syncing appointments...", EventType.Information); AppointmentsMatcher.SyncAppointments(appointmentsSynchronizer); appointmentsSynchronizer.DeleteAppointments(); } } finally { if (contactsSynchronizer.OutlookContacts != null) { Marshal.ReleaseComObject(contactsSynchronizer.OutlookContacts); contactsSynchronizer.OutlookContacts = null; } if (appointmentsSynchronizer.OutlookAppointments != null) { Marshal.ReleaseComObject(appointmentsSynchronizer.OutlookAppointments); appointmentsSynchronizer.OutlookAppointments = null; } contactsSynchronizer.GoogleContacts = null; appointmentsSynchronizer.GoogleAppointments = null; contactsSynchronizer.OutlookContactDuplicates = null; contactsSynchronizer.GoogleContactDuplicates = null; contactsSynchronizer.GoogleGroups = null; contactsSynchronizer.Contacts = null; appointmentsSynchronizer.Appointments = null; } } }