Exemplo n.º 1
0
        //---------------------------------------------------------------------
        //  Iterate over all contacts in the AB represented by parentId, find all
        //  contact resources with corresponding IEMessages not existing in the AB,
        //  and remove them from AB - remove EntryID property AND unlink with AB
        //  resource.
        //---------------------------------------------------------------------
        private void RemoveContactFromSync(string parentId, string storeId)
        {
            IResource AB = Core.ResourceStore.FindUniqueResource("AddressBook", PROP.EntryID, parentId);

            if (AB != null)
            {
                IResourceList contacts = AB.GetLinksOfType("Contact", "InAddressBook");
                foreach (IResource contact in contacts.ValidResources)
                {
                    if (contact.HasProp(PROP.EntryID))
                    {
                        IEMessage contactMsg = OutlookSession.OpenMessage(contact.GetStringProp(PROP.EntryID), storeId);
                        if (contactMsg != null)
                        {
                            //  Item exists in the Outlook folder, the object is not
                            //  needed anymore.
                            contactMsg.Dispose();
                        }
                        else
                        {
                            Contact.RemoveFromSync(contact, true);
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        private void FindResourceToDelete(IEFolder parentFolder, IResource parentMAPIFolder, string storeId)
        {
            // NOTE: In Cached Exchange mode (at least), messages can be opened successfully
            // immediately after they are permanently deleted, but opening them through
            // the short-term entry ID that we got in the notification still does not work.
            // Thus, if the message was permanently deleted in Outlook, the code below will
            // not find the deleted message, and we will have to rely on background enumeration
            // to delete it.
            // When the message is permanently deleted in OmniaMea, we immediately delete
            // the resource as well.
            IResourceList children = parentMAPIFolder.GetLinksOfType(null, PROP.MAPIFolder);

            foreach (IResource child in children.ValidResources)
            {
                if (child.HasProp(PROP.EntryID))
                {
                    IEMessage deletedItem = OutlookSession.OpenMessage(child.GetStringProp(PROP.EntryID), storeId);
                    if (deletedItem != null)
                    {
                        //  Item exists in the folder, the object is not needed anymore
                        deletedItem.Dispose();
                    }
                    else
                    {
                        Trace.WriteLine("Failed to open resource with ID=" + child.Id + ", queueing for delete");
                        _resourceToDelete = child;
                        break;
                    }
                }
            }
            if (_resourceToDelete == null)
            {
                HashSet set = new HashSet(children.Count);
                Tracer._Trace("Cannot find deleted mail.");
                Tracer._Trace("Try another algorithm.");
                foreach (IResource child in children.ValidResources)
                {
                    if (!child.HasProp(PROP.EntryID))
                    {
                        continue;
                    }
                    set.Add(child.GetStringProp(PROP.EntryID));
                }

                IEMessages messages = parentFolder.GetMessages();
                if (messages != null)
                {
                    using ( messages )
                    {
                        for (int i = 0; i < messages.GetCount(); i++)
                        {
                            IEMessage message = messages.OpenMessage(i);
                            if (message != null)
                            {
                                using ( message )
                                {
                                    string entryid = message.GetBinProp(MAPIConst.PR_ENTRYID);
                                    if (entryid != null)
                                    {
                                        set.Remove(entryid);
                                    }
                                }
                            }
                        }
                    }
                }
                if (set.Count > 0)
                {
                    foreach (HashSet.Entry entry in set)
                    {
                        FindResourcesByEntryId((string)entry.Key);
                        if (_resourceToDelete != null)
                        {
                            Tracer._Trace("Resource found for deleting.");
                            break;
                        }
                    }
                }
            }
        }