private OutLook.ContactItem checkForUpdatedItemsInDB() { Microsoft.Office.Interop.Outlook.Items OutlookItems; //OutLook.MAPIFolder Folder_Contacts; // Folder_Contacts = (OutLook.MAPIFolder)OutLookApp.Session.GetDefaultFolder(OutLook.OlDefaultFolders.olFolderContacts); OutlookItems = folder.Items; progressBar1.Maximum = folder.Items.Count; for (int i = 1; i < OutlookItems.Count; i++) { object missing = System.Reflection.Missing.Value; Microsoft.Office.Interop.Outlook.ContactItem contact = (Microsoft.Office.Interop.Outlook.ContactItem)OutlookItems[i]; if (progressBar1.Value < progressBar1.Maximum) { MethodInvoker m = new MethodInvoker(() => progressBar1.Value++); progressBar1.Invoke(m); } if (contact != null) { OutLook.UserProperty userProperty2 = contact.UserProperties.Find("Organizational ID", missing); if (userProperty2 != null && userProperty2.Value != string.Empty) { if (!ifExistsInDB(userProperty2.Value)) { contact.Delete(); } } } } MethodInvoker m2 = new MethodInvoker(() => progressBar1.Value = 0); progressBar1.Invoke(m2); return(null); }
/// <summary> /// Allows to delete the selected task /// </summary> /// <param name="sender">Sender</param> /// <param name="e">EventArgs</param> private void mnuItemDeleteTask_Click(object sender, EventArgs e) { if (this.lstTasks.SelectedIndices.Count != 0) { OLTaskItem task = this.lstTasks.SelectedItems[0].Tag as OLTaskItem; if (task != null) { if (MessageBox.Show("Are you sure you want to delete this task?", "Delete task", MessageBoxButtons.YesNo) == DialogResult.Yes) { if (task.OriginalItem is Outlook.MailItem) { Outlook.MailItem mail = task.OriginalItem as Outlook.MailItem; mail.Delete(); } else if (task.OriginalItem is Outlook.ContactItem) { Outlook.ContactItem contact = task.OriginalItem as Outlook.ContactItem; contact.Delete(); } else if (task.OriginalItem is Outlook.TaskItem) { Outlook.TaskItem t = task.OriginalItem as Outlook.TaskItem; t.Delete(); } else { // Do nothing } } // At the end, synchronously "refresh" tasks in case they have changed this.RetrieveTasks(); } } }
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 Delete() { if (GoogleContact != null) { GoogleContact.Delete(); } if (OutlookContact != null) { OutlookContact.Delete(); } }
private void DeleteContact(string lastName, string firstName) { Outlook.ContactItem contact = this.Application.GetNamespace("MAPI"). GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts). Items. Find( string.Format("[LastName]='{0}' AND [FirstName]='{1}'", lastName, firstName)) as Outlook.ContactItem; if (contact != null) { contact.Delete(); } }
//gavdcodeend 07 //gavdcodebegin 08 private void btnDeleteContact_Click(object sender, RibbonControlEventArgs e) { Outlook.Application myApplication = Globals.ThisAddIn.Application; Outlook.NameSpace outlookNameSpace = myApplication.GetNamespace("MAPI"); Outlook.MAPIFolder myContactsFolder = outlookNameSpace.GetDefaultFolder( Outlook.OlDefaultFolders.olFolderContacts); Outlook.Items myContactItems = myContactsFolder.Items; Outlook.ContactItem myContact = (Outlook.ContactItem)myContactItems. Find("[FirstName]='a' and [LastName]='b'"); if (myContact != null) { myContact.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 Save() { #region Local Store if (UseLocalStore) { try { if (!Directory.Exists(mStoreUserDirectory)) { Directory.CreateDirectory(mStoreUserDirectory); } NTContact[] contacts = new NTContact[this.Count]; int j = 0; lock (this) { for (int i = this.Count - 1; i >= 0; i--) { if (this[i].NTContactStore == NTContactStoreType.Local && this[i].NTDeleted != "true") { contacts[j] = this[i]; j++; } } } try { Array.Resize(ref contacts, j); XmlSerializer xser = new XmlSerializer(typeof(NTContact[])); StreamWriter sw = new StreamWriter(mStoreUserDirectory + mStoreFilename); xser.Serialize(sw, contacts); sw.Close(); } catch (Exception ex) { #if (TRACE) Console.WriteLine("Save Contacts Book | Local Store : Failed - " + ex.Message); #endif } } catch (Exception) { #if (DEBUG) throw; #endif } } #endregion #if !(REMWAVE_LITE) #region Server Store if (UseServerStore) { try { NTContact[] contacts = new NTContact[this.Count]; int j = 0; lock (this) { for (int i = this.Count - 1; i >= 0; i--) { if (this[i].NTContactStore == NTContactStoreType.Server & (this[i].NTContactChanged | this[i].NTDeleted == "true")) { contacts[j] = this[i]; contacts[j].NTContactChanged = false; j++; } } } Array.Resize(ref contacts, j); Remwave.Client.RSIFeaturesWS.RSIService ss = new Remwave.Client.RSIFeaturesWS.RSIService(); XmlSerializer xser = new XmlSerializer(typeof(NTContact[])); StringWriter sw = new StringWriter(); xser.Serialize(sw, contacts); ss.servicePhonebookPutAsync(mUserAccount.Username, mUserAccount.Password, mProperties, sw.ToString()); sw.Close(); } catch (Exception ex) { #if (TRACE) Console.WriteLine("Save Contacts Book | Server Store : Failed - " + ex.Message); #endif } } #endregion #region Outlook Store if (UseOutlookStore) { try { //TODO CREATE OR UPDATE lock (this) { for (int i = this.Count - 1; i >= 0; i--) { if (this[i].NTContactStore == NTContactStoreType.Outlook && (this[i].NTContactChanged || this[i].NTDeleted == "true")) { try { Outlook.ContactItem oItem = NTTranslator(this[i]); if (this[i].NTDeleted == "true") { oItem.Delete(); } else { oItem.Save(); } } catch (Exception ex) { #if (TRACE) Console.WriteLine("Save Contacts Book | Outlook Store : Failed - " + ex.Message); #endif } this[i].NTContactChanged = false; } } } } catch (Exception) { #if (DEBUG) throw; #endif } } #endregion #endif }