/// <summary> /// Set this item as manually syncable, briefly. As a side effect of making the change triggers sync. /// </summary> /// <remarks>In order to allow manual sync, we need to be able to override the disablement of syncing - /// but only briefly.</remarks> /// <param name="olItem">The item which may be synced despite syncing being disabled</param> public static void SetManualOverride(this Outlook.ContactItem olItem) { var p = olItem.UserProperties.Add(OverridePropertyName, Outlook.OlUserPropertyType.olDateTime); p.Value = DateTime.UtcNow; olItem.Save(); }
// Occurs before the form region is displayed. // Use this.OutlookItem to get a reference to the current Outlook item. // Use this.OutlookFormRegion to get a reference to the form region. private void ClearMessage_FormRegionShowing(object sender, System.EventArgs e) { dynamic outlookObject = (dynamic)this.OutlookItem; if (outlookObject.MessageClass == "IPM.Note") { chkSendViaClearMessage.Visible = false; } //Check the object is of type Contact if (outlookObject.MessageClass == "IPM.Contact") { chkSendViaClearMessage.Visible = true; Outlook.ContactItem contactItem = (Outlook.ContactItem) this.OutlookItem; //Getting the custom property defined for the checkbox var CustomProperty = contactItem.UserProperties.Find("SendViaClearMessage", true); if (CustomProperty != null) { //Setting the state of the checkbox from the property chkSendViaClearMessage.Checked = contactItem.UserProperties["SendViaClearMessage"].Value; } else { //This process will get exceuted if the old contact doesn't have the property. contactItem.UserProperties.Add("SendViaClearMessage", Outlook.OlUserPropertyType.olYesNo, true, Type.Missing); contactItem.UserProperties["SendViaClearMessage"].Value = chkSendViaClearMessage.Checked; contactItem.Subject = contactItem.LastNameAndFirstName; contactItem.Save(); } Marshal.FinalReleaseComObject(contactItem); } }
public override void Update() { if (ContainsSomeInformation()) { _item.Save(); } }
public bool CreateContact() { Outlook.ContactItem contact = OutlookSync.Syncer.CurrentApplication.CreateItem(Outlook.OlItemType.olContactItem) as Outlook.ContactItem; if (contact == null) { return(false); } contact.FirstName = Name; if (Email != null) { contact.Email1Address = Email; } if (Phone != null) { contact.HomeTelephoneNumber = Phone; } contact.Save(); return(true); }
private void AddDefaultContact() { Outlook.ContactItem newContact = (Outlook.ContactItem) this.Application.CreateItem(Outlook.OlItemType.olContactItem); try { newContact.FirstName = "Chris"; newContact.LastName = "Berry"; newContact.Email1Address = "*****@*****.**"; newContact.CustomerID = "123456"; newContact.PrimaryTelephoneNumber = "(425)555-0111"; newContact.MailingAddressStreet = "123 Main St."; newContact.MailingAddressCity = "Redmond"; var mailUserProperties = newContact.UserProperties; // Where 1 is OlFormatText (introduced in Outlook 2007) newContact.UserProperties.Add("CaseID", Outlook.OlUserPropertyType.olText, true, 1); newContact.UserProperties["CaseID"].Value = "1234567890123456"; //newContact.UserProperties["Case Id"].Value = "1234567890123456"; newContact.MailingAddressState = "WA"; newContact.Save(); newContact.Display(true); } catch { MessageBox.Show("The new contact was not saved."); } }
private void CreateContactExample(string first, string last) { try { Outlook.ContactItem contact = Application.CreateItem(Outlook.OlItemType.olContactItem) as Outlook.ContactItem; contact.FirstName = first; contact.LastName = last; contact.JobTitle = "Account Representative"; contact.CompanyName = "Contoso Ltd."; contact.OfficeLocation = "36/2529"; contact.BusinessTelephoneNumber = "4255551212 x432"; contact.WebPage = "http://www.contoso.com"; contact.BusinessAddressStreet = "1 Microsoft Way"; contact.BusinessAddressCity = "Redmond"; contact.BusinessAddressState = "WA"; contact.BusinessAddressPostalCode = "98052"; contact.BusinessAddressCountry = "United States of America"; contact.Email1Address = "*****@*****.**"; contact.Email1AddressType = "SMTP"; contact.Email1DisplayName = "Melissa MacBeth ([email protected])"; contact.Save(); } catch { MessageBox.Show("The new contact was not saved."); } }
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(); }
private void CorrectPhoneNumber(Outlook.ContactItem contact) { if (!string.IsNullOrEmpty(contact.MobileTelephoneNumber)) { contact.MobileTelephoneNumber = contact.MobileTelephoneNumber.StartsWith("0") ? contact.MobileTelephoneNumber.Replace(" ", "") : "0" + contact.MobileTelephoneNumber.Replace(" ", ""); contact.Save(); } }
public void AddContact(object sender, ContactEventArgs e) { Outlook.ContactItem newContact = (Outlook.ContactItem) this.Application.CreateItem(Outlook.OlItemType.olContactItem); try { newContact.FirstName = e.firstName; newContact.LastName = e.lastName; newContact.MiddleName = e.middleName; newContact.HomeAddressStreet = e.privateStreet; newContact.HomeAddressCity = e.privateCity; newContact.HomeAddressState = e.privateRegion; newContact.HomeAddressPostalCode = e.privatePostcode; newContact.HomeAddressCountry = e.privateCountry; newContact.BusinessAddressStreet = e.businessStreet; newContact.BusinessAddressCity = e.businessCity; newContact.BusinessAddressState = e.businessRegion; newContact.BusinessAddressPostalCode = e.businessPostcode; newContact.BusinessAddressCountry = e.businessCountry; newContact.HomeTelephoneNumber = e.privatePhone; newContact.MobileTelephoneNumber = e.mobilePhone; newContact.HomeFaxNumber = e.privateFax; newContact.BusinessTelephoneNumber = e.businessPhone; newContact.Business2TelephoneNumber = e.business2Phone; newContact.BusinessFaxNumber = e.businessFax; newContact.PagerNumber = e.pager; newContact.Email1Address = e.privateEmail; newContact.Email2Address = e.businessEmail; newContact.Email3Address = e.business2Email; newContact.Body = e.notes; newContact.Birthday = e.birthday; newContact.Companies = e.company; newContact.JobTitle = e.jobTitle; if (e.gender == "male") { newContact.Gender = Outlook.OlGender.olMale; } else if (e.gender == "female") { newContact.Gender = Outlook.OlGender.olFemale; } else { newContact.Gender = Outlook.OlGender.olUnspecified; } newContact.Save(); } catch { MessageBox.Show("The new contact was not saved."); } }
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(); }
private void btnImportAddresses_Click(CommandBarButton ctrl, ref bool cancel) { Cursor.Current = Cursors.WaitCursor; try { // System.Data.DataSet ds = new System.Data.DataSet(); EmployeeTableAdapters.EmployeesTableAdapter td = new SyncMyAddress.EmployeeTableAdapters.EmployeesTableAdapter(); Employee.EmployeesDataTable ds = new Employee.EmployeesDataTable(); ds = td.GetData(); MAPIFolder contactsFolder = Application.Session.GetDefaultFolder(OlDefaultFolders.olFolderContacts); //Outlook.ContactItem contactItem; Outlook.Items contacts; contacts = contactsFolder.Items.Restrict("[MessageClass]='IPM.Contact'"); foreach (System.Data.DataRow dr in ds.Rows) { Outlook.ContactItem existingContact = (Outlook.ContactItem)contacts.Find("[Email1Address] = '" + dr["EmailID"] + "'"); if (existingContact != null) { existingContact.FirstName = (dr["FullName"] == null) ? string.Empty : dr["FullName"].ToString(); existingContact.CustomerID = (dr["EmpID"] == null) ? string.Empty : dr["EmpID"].ToString(); existingContact.JobTitle = (dr["Designation"] == null) ? string.Empty : dr["Designation"].ToString(); existingContact.Department = (dr["Department"] == null) ? string.Empty : dr["Department"].ToString(); existingContact.Email1Address = (dr["EmailID"] == null) ? string.Empty : dr["EmailID"].ToString(); existingContact.ManagerName = (dr["ManagerID"] == null) ? string.Empty : dr["ManagerID"].ToString(); existingContact.WebPage = "www.appsassociates.com"; existingContact.Save(); } else { Outlook.ContactItem newContact = Application.CreateItem(Outlook.OlItemType.olContactItem) as Outlook.ContactItem; newContact.FirstName = (dr["FullName"] == null) ? string.Empty : dr["FullName"].ToString(); newContact.CustomerID = (dr["EmpID"] == null) ? string.Empty : dr["EmpID"].ToString(); newContact.JobTitle = (dr["Designation"] == null) ? string.Empty : dr["Designation"].ToString(); newContact.Department = (dr["Department"] == null) ? string.Empty : dr["Department"].ToString(); newContact.Email1Address = (dr["EmailID"] == null) ? string.Empty : dr["EmailID"].ToString(); newContact.ManagerName = (dr["ManagerID"] == null) ? string.Empty : dr["ManagerID"].ToString(); newContact.WebPage = "www.appsassociates.com"; newContact.Save(); } } MessageBox.Show("Successfully Imported...!"); } catch (System.Exception ex) { MessageBox.Show("Sync Process is not completed. Error Message: " + ex.Message); } catch { MessageBox.Show("Sync Process is not completed"); } Cursor.Current = Cursors.Default; }
private void AddContact() { Outlook.MAPIFolder inBox = this.Application.ActiveExplorer().Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox); var folder = inBox; Outlook.ContactItem contact = folder.Items.Add("1234567890123456") as Outlook.ContactItem; contact.FirstName = "Michael"; contact.LastName = "Affronti"; contact.UserProperties["Shoe Size"].Value = "9"; contact.UserProperties["Case Id"].Value = "1234567890123456"; contact.Save(); }
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 static bool SetOutlookPhoto(Outlook.ContactItem outlookContact, string fullImagePath) { try { outlookContact.AddPicture(fullImagePath); outlookContact.Save(); return(true); } catch { return(false); } }
public static void ClearCrmId(this Outlook.ContactItem olItem) { var state = SyncStateManager.Instance.GetExistingSyncState(olItem); olItem.ClearUserProperty(SyncStateManager.CrmIdPropertyName); if (state != null) { state.CrmEntryId = null; } olItem.Save(); }
/// <summary> /// Remove synchronize keys from Outlook contact. In same delete all cache data /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnOutlokSync_Click(object sender, EventArgs e) { LoggerProvider.Instance.Logger.Info("User request for clear synchronize keys in Outlook. I remove all cache data for Google and Outlook."); Utils.RemoveCacheFile(false); Utils.RemoveCacheFile(true); pBar.Value = 1; pBar.Update(); pBar.Refresh(); OutlookProvider op = OutlookProvider.Instance; Outlook.Items it = op.OutlookItems(); int _ouMaxContacts = op.CountContact(); object works = null; Outlook.ContactItem oci = null; int counter = 0; for (int i = 0; i < _ouMaxContacts; i++) { pBar.Value = counter; pBar.PerformStep(); pBar.Refresh(); if (counter > pBar.Maximum) { counter = 0; } if (i == 0) { works = it.GetFirst(); } else { works = it.GetNext(); } if (works is Outlook.DistListItem) { continue; } oci = works as Outlook.ContactItem; if (works == null) { continue; } if (!string.IsNullOrEmpty(oci.User3)) { oci.User3 = string.Empty; oci.Save(); } } }
//gavdcodeend 06 //gavdcodebegin 07 private void btnAddContact_Click(object sender, RibbonControlEventArgs e) { Outlook.Application myApplication = Globals.ThisAddIn.Application; Outlook.ContactItem newContact = (Outlook.ContactItem) myApplication.CreateItem(Outlook.OlItemType.olContactItem); newContact.FirstName = "He Is"; newContact.LastName = "Somebody"; newContact.Email1Address = "*****@*****.**"; newContact.PrimaryTelephoneNumber = "(123)4567890"; newContact.MailingAddressStreet = "Here 123"; newContact.MailingAddressCity = "There"; newContact.Save(); newContact.Display(true); }
/// <summary> /// 保存 Outlook 地址簿. /// </summary> /// <param name="dataList"></param> public void WriteAddressBookList(List <UserAddressBook> dataList) { Outlook.NameSpace mynamespace = outlookApp.GetNamespace("MAPI"); Outlook.MAPIFolder myFolder = mynamespace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts); foreach (UserAddressBook newData in dataList) { // 存在标志. Outlook.ContactItem existContactItem = null; foreach (Outlook.ContactItem item in myFolder.Items) { if (item.Email1Address == newData.Email) { existContactItem = item; break; } } if (existContactItem == null) { // 地址簿中,没有检索到数据. existContactItem = myFolder.Items.Add(); // 邮件地址. existContactItem.Email1Address = newData.Email; } // 姓名. existContactItem.LastName = newData.UserName; // 号码. existContactItem.MobileTelephoneNumber = newData.Mobile; // 部门. existContactItem.Department = newData.Department; // 保存. existContactItem.Save(); } }
public static void ChangeCrmId(this Outlook.ContactItem olItem, string text) { var crmId = new CrmId(text); var state = SyncStateManager.Instance.GetExistingSyncState(olItem); var userProperty = olItem.UserProperties.Find(SyncStateManager.CrmIdPropertyName) ?? olItem.UserProperties.Add(SyncStateManager.CrmIdPropertyName, Outlook.OlUserPropertyType.olText); userProperty.Value = crmId.ToString(); if (state != null) { state.CrmEntryId = crmId; } olItem.Save(); }
private void ImportContactsToMSOutlook() { try { Outlook.Application oApp = InitializeOutlook(); Outlook.NameSpace oNS = oApp.GetNamespace("MAPI"); Outlook.MAPIFolder oContactsFolder = oNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts) as Outlook.MAPIFolder; int i = 0; Outlook.ContactItem contact = null; foreach (string oneContact in listPathsVcfFiles) { i++; percentProgress = (float)i / listPathsVcfFiles.Count * 100; try { contact = oApp.Session.OpenSharedItem(oneContact) as Outlook.ContactItem; contact.Save(); contact = null; } catch { contact = null; countErrorCopy++; using (StreamWriter sw = File.AppendText(pathToLog)) { sw.WriteLine(String.Format("{0}. Error imported file, path={1}", countErrorCopy, oneContact)); sw.Close(); } continue; } } done = true; } catch (Exception ex) { MessageBox.Show("Error during adding new contacts to Outlook\n" + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
public bool AddNewContact(cls_Contact contact) { Outlook.MAPIFolder mAPIFolder = ns.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts); Outlook.Items items = mAPIFolder.Items; try { Outlook.ContactItem newContact = items.Add(Outlook.OlItemType.olContactItem) as Outlook.ContactItem; newContact.Title = contact.PatientID; newContact.JobTitle = contact.DiseaseName; newContact.FirstName = contact.FirstName; newContact.LastName = contact.LastName; newContact.MiddleName = contact.FatherName; newContact.Suffix = contact.SSID; newContact.HomeTelephoneNumber = contact.Phone; newContact.MobileTelephoneNumber = contact.Mobile; newContact.Body = contact.Notes; newContact.User1 = contact.Birthday; newContact.Email1Address = contact.Email; newContact.HomeAddress = contact.Address; newContact.Save(); contacts.Add(contact); if (mAPIFolder != null) { Marshal.ReleaseComObject(mAPIFolder); } if (items != null) { Marshal.ReleaseComObject(items); } if (newContact != null) { Marshal.ReleaseComObject(newContact); } return(true); } catch (Exception) { return(false); } }
private static void ImportData() { List <ContactItemHelper> itemData = ContactItemHelper.LoadDataFromFile(dataImportFile); foreach (ContactItemHelper contactData in itemData) { // Create a new sales opportunity contact. Outlook.ContactItem newContact = Globals.ThisAddIn.OpportunitiesFolder.Items.Add( Constants.MessageClassOpportunities) as Outlook.ContactItem; // Set properties for the contact item. object[] errors = newContact.PropertyAccessor.SetProperties( ContactItemHelper.PropertyReferences, contactData.PropertyValues); // Check any errors returned by the SetProperties method. DumpErrorsFromSetProperties(contactData, errors); newContact.Save(); } }
//<Snippet1> private void AddContact() { Outlook.ContactItem newContact = (Outlook.ContactItem) this.Application.CreateItem(Outlook.OlItemType.olContactItem); try { newContact.FirstName = "Jo"; newContact.LastName = "Berry"; newContact.Email1Address = "*****@*****.**"; newContact.CustomerID = "123456"; newContact.PrimaryTelephoneNumber = "(425)555-0111"; newContact.MailingAddressStreet = "123 Main St."; newContact.MailingAddressCity = "Redmond"; newContact.MailingAddressState = "WA"; newContact.Save(); newContact.Display(true); } catch { MessageBox.Show("The new contact was not saved."); } }
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 FixUserProperties() { Outlook.Application outlookApp; Outlook.NameSpace outlookNamespace; Outlook.Items outlookContacts; outlookApp = new Outlook.Application(); outlookNamespace = outlookApp.GetNamespace("mapi"); outlookNamespace.Logon("Outlook", null, true, false); try { Outlook.MAPIFolder contactsFolder = outlookNamespace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts); outlookContacts = contactsFolder.Items; string oldPrefixId = string.Format("google/contacts/{0}/id", ConfigurationManager.AppSettings["Gmail.Username"]); string oldPrefixUpdated = string.Format("google/contacts/{0}/updated", ConfigurationManager.AppSettings["Gmail.Username"]); int hashCode = ConfigurationManager.AppSettings["Gmail.Username"].GetHashCode(); int maxUserIdLength = 32 - ("g/con/" + "/up").Length; string userId = ConfigurationManager.AppSettings["Gmail.Username"]; if (userId.Length > maxUserIdLength) { userId = userId.GetHashCode().ToString("X"); //if a user id would overflow UserProperty name, then use that user id hash code as id. } string newPrefixId = "g/con/" + userId + "/id"; string newPrefixUpdated = "g/con/" + userId + "/up"; //max property length: 32 //foreach (Outlook.ContactItem contact in outlookContacts) for (int i = 0; i < outlookContacts.Count; i++) { try { if (!(outlookContacts[i] is Outlook.ContactItem)) { continue; } } catch (Exception) { continue; } Outlook.ContactItem contact = outlookContacts[i] as Outlook.ContactItem; Outlook.UserProperty updatedProp = contact.UserProperties[newPrefixUpdated]; if (updatedProp != null) { string lastUpdatedStr = (string)updatedProp.Value; updatedProp.Delete(); updatedProp = contact.UserProperties.Add(newPrefixUpdated, Outlook.OlUserPropertyType.olDateTime, true); DateTime lastUpdated = DateTime.Parse(lastUpdatedStr); updatedProp.Value = lastUpdated; if (!contact.Saved) { contact.Save(); } continue; } Outlook.UserProperty prop = contact.UserProperties[newPrefixId]; if (prop != null) { continue; } prop = contact.UserProperties[oldPrefixId]; if (prop != null) { string id = (string)prop.Value; prop.Delete(); prop = contact.UserProperties.Add(newPrefixId, Outlook.OlUserPropertyType.olText, true); prop.Value = id; } prop = contact.UserProperties[oldPrefixUpdated]; if (prop != null) { DateTime lastUpdated = (DateTime)prop.Value; prop.Delete(); prop = contact.UserProperties.Add(newPrefixUpdated, Outlook.OlUserPropertyType.olDateTime, true); prop.Value = lastUpdated; } if (!contact.Saved) { contact.Save(); } } } finally { outlookNamespace.Logoff(); } }
private void AddOutlookContact(Banckle.ContactDetails contact) { Outlook.ContactItem newContact = (Outlook.ContactItem) this.Application.CreateItem(Outlook.OlItemType.olContactItem); Banckle.Email[] emails = new Email[3]; Banckle.Phone[] phone = new Banckle.Phone[2]; Banckle.Address[] address = new Banckle.Address[3]; try { newContact.FullName = String.IsNullOrWhiteSpace(contact.name) ? "" : contact.name; if (contact.emails.Length > 0) { if (contact.emails.Length >= 3) { newContact.Email1AddressType = String.IsNullOrWhiteSpace(contact.emails[0].type) ? "" : contact.emails[0].type; newContact.Email1Address = String.IsNullOrWhiteSpace(contact.emails[0].address) ? "" : contact.emails[0].address; newContact.Email2AddressType = String.IsNullOrWhiteSpace(contact.emails[1].type) ? "" : contact.emails[1].type; newContact.Email2Address = String.IsNullOrWhiteSpace(contact.emails[1].address) ? "" : contact.emails[1].address; newContact.Email3AddressType = String.IsNullOrWhiteSpace(contact.emails[2].type) ? "" : contact.emails[2].type; newContact.Email3Address = String.IsNullOrWhiteSpace(contact.emails[2].address) ? "" : contact.emails[2].address; } if (contact.emails.Length == 2) { newContact.Email1AddressType = String.IsNullOrWhiteSpace(contact.emails[0].type) ? "" : contact.emails[0].type; newContact.Email1Address = String.IsNullOrWhiteSpace(contact.emails[0].address) ? "" : contact.emails[0].address; newContact.Email2AddressType = String.IsNullOrWhiteSpace(contact.emails[1].type) ? "" : contact.emails[1].type; newContact.Email2Address = String.IsNullOrWhiteSpace(contact.emails[1].address) ? "" : contact.emails[1].address; } if (contact.emails.Length == 1) { newContact.Email1AddressType = String.IsNullOrWhiteSpace(contact.emails[0].type) ? "" : contact.emails[0].type; newContact.Email1Address = String.IsNullOrWhiteSpace(contact.emails[0].address) ? "" : contact.emails[0].address; } } if (contact.phones.Length > 0) { if (contact.phones.Length >= 2) { newContact.PrimaryTelephoneNumber = String.IsNullOrWhiteSpace(contact.phones[0].number) ? "" : contact.phones[0].number; newContact.OtherTelephoneNumber = String.IsNullOrWhiteSpace(contact.phones[1].number) ? "" : contact.phones[1].number; } if (contact.phones.Length == 1) { newContact.PrimaryTelephoneNumber = String.IsNullOrWhiteSpace(contact.phones[0].number) ? "" : contact.phones[0].number; } } if (contact.addresses.Length > 0) { if (contact.addresses.Length >= 3) { newContact.MailingAddress = String.IsNullOrWhiteSpace(contact.addresses[0].building) ? "" : contact.addresses[0].building; newContact.MailingAddressStreet = String.IsNullOrWhiteSpace(contact.addresses[0].street) ? "" : contact.addresses[0].street; newContact.MailingAddressCity = String.IsNullOrWhiteSpace(contact.addresses[0].city) ? "" : contact.addresses[0].city; newContact.MailingAddressPostalCode = String.IsNullOrWhiteSpace(contact.addresses[0].zip) ? "" : contact.addresses[0].zip; newContact.MailingAddressState = String.IsNullOrWhiteSpace(contact.addresses[0].state) ? "" : contact.addresses[0].state; newContact.MailingAddressCountry = String.IsNullOrWhiteSpace(contact.addresses[0].country) ? "" : contact.addresses[0].country; newContact.HomeAddress = String.IsNullOrWhiteSpace(contact.addresses[1].building) ? "" : contact.addresses[1].building; newContact.HomeAddressStreet = String.IsNullOrWhiteSpace(contact.addresses[1].street) ? "" : contact.addresses[1].street; newContact.HomeAddressCity = String.IsNullOrWhiteSpace(contact.addresses[1].city) ? "" : contact.addresses[1].city; newContact.HomeAddressPostalCode = String.IsNullOrWhiteSpace(contact.addresses[1].zip) ? "" : contact.addresses[1].zip; newContact.HomeAddressState = String.IsNullOrWhiteSpace(contact.addresses[1].state) ? "" : contact.addresses[1].state; newContact.HomeAddressCountry = String.IsNullOrWhiteSpace(contact.addresses[1].country) ? "" : contact.addresses[1].country; newContact.OtherAddress = String.IsNullOrWhiteSpace(contact.addresses[2].building) ? "" : contact.addresses[2].building; newContact.OtherAddressStreet = String.IsNullOrWhiteSpace(contact.addresses[2].street) ? "" : contact.addresses[2].street; newContact.OtherAddressCity = String.IsNullOrWhiteSpace(contact.addresses[2].city) ? "" : contact.addresses[2].city; newContact.OtherAddressPostalCode = String.IsNullOrWhiteSpace(contact.addresses[2].zip) ? "" : contact.addresses[2].zip; newContact.OtherAddressState = String.IsNullOrWhiteSpace(contact.addresses[2].state) ? "" : contact.addresses[2].state; newContact.OtherAddressCountry = String.IsNullOrWhiteSpace(contact.addresses[2].country) ? "" : contact.addresses[2].country; } if (contact.addresses.Length == 2) { newContact.MailingAddress = String.IsNullOrWhiteSpace(contact.addresses[0].building) ? "" : contact.addresses[0].building; newContact.MailingAddressStreet = String.IsNullOrWhiteSpace(contact.addresses[0].street) ? "" : contact.addresses[0].street; newContact.MailingAddressCity = String.IsNullOrWhiteSpace(contact.addresses[0].city) ? "" : contact.addresses[0].city; newContact.MailingAddressPostalCode = String.IsNullOrWhiteSpace(contact.addresses[0].zip) ? "" : contact.addresses[0].zip; newContact.MailingAddressState = String.IsNullOrWhiteSpace(contact.addresses[0].state) ? "" : contact.addresses[0].state; newContact.MailingAddressCountry = String.IsNullOrWhiteSpace(contact.addresses[0].country) ? "" : contact.addresses[0].country; newContact.HomeAddress = String.IsNullOrWhiteSpace(contact.addresses[1].building) ? "" : contact.addresses[1].building; newContact.HomeAddressStreet = String.IsNullOrWhiteSpace(contact.addresses[1].street) ? "" : contact.addresses[1].street; newContact.HomeAddressCity = String.IsNullOrWhiteSpace(contact.addresses[1].city) ? "" : contact.addresses[1].city; newContact.HomeAddressPostalCode = String.IsNullOrWhiteSpace(contact.addresses[1].zip) ? "" : contact.addresses[1].zip; newContact.HomeAddressState = String.IsNullOrWhiteSpace(contact.addresses[1].state) ? "" : contact.addresses[1].state; newContact.HomeAddressCountry = String.IsNullOrWhiteSpace(contact.addresses[1].country) ? "" : contact.addresses[1].country; } if (contact.addresses.Length == 1) { newContact.MailingAddress = String.IsNullOrWhiteSpace(contact.addresses[0].building) ? "" : contact.addresses[0].building; newContact.MailingAddressStreet = String.IsNullOrWhiteSpace(contact.addresses[0].street) ? "" : contact.addresses[0].street; newContact.MailingAddressCity = String.IsNullOrWhiteSpace(contact.addresses[0].city) ? "" : contact.addresses[0].city; newContact.MailingAddressPostalCode = String.IsNullOrWhiteSpace(contact.addresses[0].zip) ? "" : contact.addresses[0].zip; newContact.MailingAddressState = String.IsNullOrWhiteSpace(contact.addresses[0].state) ? "" : contact.addresses[0].state; newContact.MailingAddressCountry = String.IsNullOrWhiteSpace(contact.addresses[0].country) ? "" : contact.addresses[0].country; } } newContact.Save(); } catch (Exception ex) { System.Windows.Forms.MessageBox.Show("The new contact was not saved, because \r" + ex.Message + "\r" + ex.StackTrace); } }
/// <summary> /// Event handler for CGrabber application new mail arrived event. /// </summary> /// <param name="entryIdCollection">Entry Id collection.</param> private void CGrabberApplicationNewMailEx(string entryIdCollection) { var namespaceitem = this.cgrabberApplication.GetNamespace("MAPI"); var stores = this.cgrabberApplication.Session.Stores; foreach (var folder in from Outlook.Store store in stores select store.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox)) { try { var mailItem = (Outlook.MailItem)namespaceitem.GetItemFromID(entryIdCollection, folder.StoreID); if (null == mailItem) { return; } var searchResult = false; if (mailItem.Body != null) { searchResult = SearchKeywords.Any(keyword => mailItem.Body.IndexOf(keyword) != -1); } var searchResultHtmlBody = false; if (mailItem.HTMLBody != null) { searchResultHtmlBody = SearchKeywords.Any(keyword => mailItem.HTMLBody.IndexOf(keyword) != -1); } var subjectSearchResult = false; if (mailItem.Subject != null) { subjectSearchResult = SearchKeywords.Any(keyword => mailItem.Subject.IndexOf(keyword) != -1); } if (!searchResult && !searchResultHtmlBody && !subjectSearchResult) { return; } Outlook.MAPIFolder contactsFolder = null; Outlook.Items items = null; Outlook.ContactItem contact = null; try { contactsFolder = this.cgrabberApplication.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts); items = contactsFolder.Items; var filter = "[Email1Address] = '" + mailItem.SenderEmailAddress + "'"; Outlook.ContactItem existingContact = null; existingContact = items.Find(filter) as Outlook.ContactItem; if (existingContact != null) { return; } else { filter = "[Email2Address] = '" + mailItem.SenderEmailAddress + "'"; existingContact = items.Find(filter) as Outlook.ContactItem; if (existingContact != null) { return; } else { filter = "[Email3Address] = '" + mailItem.SenderEmailAddress + "'"; existingContact = items.Find(filter) as Outlook.ContactItem; if (existingContact != null) { return; } else { contact = items.Add(Outlook.OlItemType.olContactItem) as Outlook.ContactItem; if (null == contact) { return; } contact.Email1Address = mailItem.SenderEmailAddress; contact.Email1DisplayName = mailItem.SenderName; contact.Save(); } } } } catch (Exception) { } finally { if (contact != null) { Marshal.ReleaseComObject(contact); } if (items != null) { Marshal.ReleaseComObject(items); } if (contactsFolder != null) { Marshal.ReleaseComObject(contactsFolder); } } } catch (Exception) { continue; } } }
private void backgroundWorkerSync_DoWork(object sender, DoWorkEventArgs e) { BackgroundWorker worker = sender as BackgroundWorker; if (_application != null) { for (int i = 0; i < _people.Count; i++) { if (worker.CancellationPending) { e.Cancel = true; break; } else { Person p = _people[i]; worker.ReportProgress((i * 100) / _people.Count, "Processing contact " + i + " of " + _people.Count + " - " + p.FirstName + " " + p.LastName); Outlook.ContactItem contact = FindContactByName(p.FirstName, p.LastName); bool isUpdate = true; if (contact == null) { //Create new contact contact = (Outlook.ContactItem) this._application.CreateItem(Outlook.OlItemType.olContactItem); isUpdate = false; } string notes = "Basecamp People Sync Update - " + DateTime.Now.ToLongDateString() + " " + DateTime.Now.ToLongTimeString() + "\r\n\r\n"; notes += "----------------------------------------------------\r\n"; if (!string.IsNullOrEmpty(p.FirstName)) { if (!string.IsNullOrEmpty(contact.FirstName) && contact.FirstName != p.FirstName) { notes += "First Name: " + contact.FirstName + " to " + p.FirstName + "\r\n"; } contact.FirstName = p.FirstName; } if (!string.IsNullOrEmpty(p.LastName)) { if (!string.IsNullOrEmpty(contact.LastName) && contact.LastName != p.LastName) { notes += "Last Name: " + contact.LastName + " to " + p.LastName + "\r\n"; } contact.LastName = p.LastName; } if (!string.IsNullOrEmpty(p.IMService) && !string.IsNullOrEmpty(p.IMHandle)) { if (!string.IsNullOrEmpty(contact.IMAddress) && contact.IMAddress != (p.IMService + ": " + p.IMHandle)) { notes += "IM Address: " + contact.IMAddress + " to " + p.IMService + ": " + p.IMHandle + "\r\n"; } contact.IMAddress = p.IMService + ": " + p.IMHandle; } if (!string.IsNullOrEmpty(p.FaxPhone)) { if (!string.IsNullOrEmpty(contact.BusinessFaxNumber) && contact.BusinessFaxNumber != p.FaxPhone) { notes += "Fax Number: " + contact.BusinessFaxNumber + " to " + p.FaxPhone + "\r\n"; } contact.BusinessFaxNumber = p.FaxPhone; } if (!string.IsNullOrEmpty(p.OfficePhone)) { if (string.IsNullOrEmpty(p.OfficePhoneExt)) { if (!string.IsNullOrEmpty(contact.BusinessTelephoneNumber) && contact.BusinessTelephoneNumber != p.OfficePhone) { notes += "Office Phone: " + contact.BusinessTelephoneNumber + " to " + p.OfficePhone + "\r\n"; } contact.BusinessTelephoneNumber = p.OfficePhone; } else { if (!string.IsNullOrEmpty(contact.BusinessTelephoneNumber) && contact.BusinessTelephoneNumber != (p.OfficePhone + " x" + p.OfficePhoneExt)) { notes += "Office Phone: " + contact.BusinessTelephoneNumber + " to " + p.OfficePhone + " x" + p.OfficePhoneExt + "\r\n"; } contact.BusinessTelephoneNumber = p.OfficePhone + " x" + p.OfficePhoneExt; } } if (!string.IsNullOrEmpty(p.EmailAddress)) { int updatedEmail = 0; if (string.IsNullOrEmpty(contact.Email1Address)) { //Empty primary email contact.Email1Address = p.EmailAddress; updatedEmail = 1; } else { //Put the email in the first empty email slot if (contact.Email1Address.ToLower() != p.EmailAddress.ToLower()) { if (string.IsNullOrEmpty(contact.Email2Address)) { updatedEmail = 2; contact.Email2Address = p.EmailAddress; } else if (contact.Email2Address.ToLower() != p.EmailAddress.ToLower()) { if (string.IsNullOrEmpty(contact.Email3Address)) { updatedEmail = 3; contact.Email3Address = p.EmailAddress; } else { notes += "Email (" + p.EmailAddress + ") Not Stored. No free email address slots.\r\n"; } } } if (updatedEmail != 0) { notes += "Email " + updatedEmail.ToString() + " Address to " + p.EmailAddress + "\r\n"; } } } if (!string.IsNullOrEmpty(p.HomePhone)) { if (!string.IsNullOrEmpty(contact.HomeTelephoneNumber) && contact.HomeTelephoneNumber != p.HomePhone) { notes += "Home Number: " + contact.HomeTelephoneNumber + " to " + p.HomePhone + "\r\n"; } contact.HomeTelephoneNumber = p.HomePhone; } if (!string.IsNullOrEmpty(p.MobilePhone)) { if (!string.IsNullOrEmpty(contact.HomeTelephoneNumber) && contact.HomeTelephoneNumber != p.HomePhone) { notes += "Mobile Number: " + contact.HomeTelephoneNumber + " to " + p.HomePhone + "\r\n"; } contact.MobileTelephoneNumber = p.MobilePhone; } if (!string.IsNullOrEmpty(p.Title)) { if (!string.IsNullOrEmpty(contact.JobTitle) && contact.JobTitle != p.Title) { notes += "Job Title: " + contact.JobTitle + " to " + p.Title + "\r\n"; } contact.JobTitle = p.Title; } string filename = ""; if (!string.IsNullOrEmpty(p.AvatarUrl)) { //Save the image to disk, load it into contact and then delete after save string path = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + Path.DirectorySeparatorChar + "BasecampSync"; if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } Bitmap picture = p.GetAvatarBitmap(); if (picture != null) { filename = path + Path.DirectorySeparatorChar + p.Id.ToString() + ".jpg"; picture.Save(filename, System.Drawing.Imaging.ImageFormat.Jpeg); contact.AddPicture(filename); notes += "Updated Picture\r\n"; } } if (!string.IsNullOrEmpty(_company.Name)) { if (!string.IsNullOrEmpty(contact.CompanyName) && contact.CompanyName != _company.Name) { notes += "Company Name: " + contact.CompanyName + " to " + _company.Name + "\r\n"; } contact.CompanyName = _company.Name; } if (!string.IsNullOrEmpty(_company.AddressOne)) { if (!string.IsNullOrEmpty(_company.AddressTwo)) { if (!string.IsNullOrEmpty(contact.BusinessAddressStreet) && contact.BusinessAddressStreet != (_company.AddressOne + "\n" + _company.AddressTwo)) { notes += "Business Address Street: " + contact.BusinessAddressStreet + " to " + _company.AddressOne + "\n" + _company.AddressTwo + "\r\n"; } contact.BusinessAddressStreet = _company.AddressOne + "\n" + _company.AddressTwo; } else { if (!string.IsNullOrEmpty(contact.BusinessAddressStreet) && contact.BusinessAddressStreet != _company.AddressOne) { notes += "Business Address Street: " + contact.BusinessAddressStreet + " to " + _company.AddressOne + "\r\n"; } contact.BusinessAddressStreet = _company.AddressOne; } } if (!string.IsNullOrEmpty(_company.City)) { if (!string.IsNullOrEmpty(contact.BusinessAddressCity) && contact.BusinessAddressCity != _company.City) { notes += "Business Address City: " + contact.BusinessAddressCity + " to " + _company.City + "\r\n"; } contact.BusinessAddressCity = _company.City; } if (!string.IsNullOrEmpty(_company.State)) { if (!string.IsNullOrEmpty(contact.BusinessAddressState) && contact.BusinessAddressState != _company.State) { notes += "Business Address State: " + contact.BusinessAddressState + " to " + _company.State + "\r\n"; } contact.BusinessAddressState = _company.State; } if (!string.IsNullOrEmpty(_company.Zip)) { if (!string.IsNullOrEmpty(contact.BusinessAddressPostalCode) && contact.BusinessAddressPostalCode != _company.Zip) { notes += "Business Address Postal Code: " + contact.BusinessAddressPostalCode + " to " + _company.Zip + "\r\n"; } contact.BusinessAddressPostalCode = _company.Zip; } if (!string.IsNullOrEmpty(_company.Country)) { if (!string.IsNullOrEmpty(contact.BusinessAddressCountry) && contact.BusinessAddressCountry != _company.Country) { notes += "Business Address Country: " + contact.BusinessAddressCountry + " to " + _company.Country + "\r\n"; } contact.BusinessAddressCountry = _company.Country; } if (!string.IsNullOrEmpty(_company.OfficePhone)) { if (!string.IsNullOrEmpty(contact.CompanyMainTelephoneNumber) && contact.CompanyMainTelephoneNumber != _company.OfficePhone) { notes += "Company Phone Number: " + contact.CompanyMainTelephoneNumber + " to " + _company.OfficePhone + "\r\n"; } contact.CompanyMainTelephoneNumber = _company.OfficePhone; } if (!string.IsNullOrEmpty(_company.WebAddress) && string.IsNullOrEmpty(contact.WebPage)) { notes += "Web Page to " + _company.WebAddress + "\r\n"; contact.WebPage = _company.WebAddress; } notes += "----------------------------------------------------\r\n"; if (isUpdate) { if (!string.IsNullOrEmpty(contact.Body)) { contact.Body += "\r\n\r\n"; } contact.Body += notes; } contact.Save(); if (filename != "") { File.Delete(filename); } } } } }
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 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(); }