Example #1
0
            public string CheckMergeAllowed(IResourceList contacts)
            {
                int entryIdCount = 0;

                foreach (IResource contact in contacts)
                {
                    REGISTRY.ClearNeeded(contact);
                    if (contact.HasProp(PROP.EntryID) && !contact.HasProp("UserCreated"))
                    {
                        ++entryIdCount;
                        if (entryIdCount > 1)
                        {
                            return("Please select only one contact which is synchronized with Outlook");
                        }
                    }
                }
                return(null);
            }
Example #2
0
        private IContact FindOrCreateRegularContact(string entryID)
        {
            IContact  contactBO = null;
            IResource resource  = Contact.FindByEntryID(entryID);

            if (resource != null)
            {
                contactBO = Core.ContactManager.GetContact(resource);
                UpdateFields(contactBO);
                contactBO.AddAccount(_emailAddress);
            }
            else
            {
                contactBO = TryGettingLastExportedContact();
                if (contactBO != null)
                {
                    UpdateFields(contactBO);
                    contactBO.AddAccount(_emailAddress);
                    return(contactBO);
                }
                IResourceList contacts = _namesExist
                    ? Core.ContactManager.FindContactList(_namePrefix, _firstName, _middleName, _lastName, _suffix)
                    : Core.ContactManager.FindContactList(_fullName);

                IResourceList contactsWithEmail = null;
                IResource     accntRes          = Core.ContactManager.FindOrCreateEmailAccount(_emailAddress);
                if (accntRes != null)
                {
                    contactsWithEmail = accntRes.GetLinksOfType("Contact", "EmailAcct");
                    contacts          = contacts.Intersect(contactsWithEmail, true);
                }
                IResource candidat = null;
                foreach (IResource res in contacts)
                {
                    if (res.HasProp(PROP.EntryID))
                    {
                        REGISTRY.ClearNeeded(res);
                    }
                }
                foreach (IResource res in contacts)
                {
                    if (!res.HasProp(PROP.EntryID))
                    {
                        candidat = res;
                        break;
                    }
                }

                if (candidat != null)
                {
                    contactBO = Core.ContactManager.GetContact(candidat);
                    UpdateFields(contactBO);
                    contactBO.AddAccount(_emailAddress);
                }
                else
                {
                    IResource blankContact = null;
                    if (contactsWithEmail != null)
                    {
                        foreach (IResource res in contactsWithEmail)
                        {
                            if (ContactManager.IsEmptyContact(res))
                            {
                                blankContact = res;
                                break;
                            }
                        }
                    }
                    bool updateContact = false;
                    if (blankContact != null)
                    {
                        string strEntryID = blankContact.GetStringProp(PROP.EntryID);
                        if (strEntryID == null || strEntryID == entryID)
                        {
                            updateContact = true;
                        }
                    }
                    if (updateContact)
                    {
                        contactBO = Core.ContactManager.GetContact(blankContact);
                        UpdateFields(contactBO);
                        contactBO.AddAccount(_emailAddress);
                    }
                    else
                    {
                        contactBO = CreateContact( );
                        contactBO.AddAccount(_emailAddress);
                    }
                }
            }
            return(contactBO);
        }