private void LogSkippedContactLinkingWithDirectory(ContactInfoForLinking contactBeingSaved, int currentCountOfContactsAdded, int maximumNumberOfContactsToAdd) { base.LogEvent(new SchemaBasedLogEvent <ContactLinkingLogSchema.SkippedContactLink> { { ContactLinkingLogSchema.SkippedContactLink.LinkingPersonId, contactBeingSaved.PersonId }, { ContactLinkingLogSchema.SkippedContactLink.LinkingItemId, contactBeingSaved.ItemId }, { ContactLinkingLogSchema.SkippedContactLink.LinkToPersonId, "N/A - Directory" }, { ContactLinkingLogSchema.SkippedContactLink.CurrentCountOfContactsAdded, currentCountOfContactsAdded }, { ContactLinkingLogSchema.SkippedContactLink.MaximumContactsAllowedToAdd, maximumNumberOfContactsToAdd } }); }
private void LogLinkOperation(ContactLinkingOperation operation, ContactInfoForLinking contactToUpdate, ContactInfoForLinking otherContact) { base.LogEvent(new SchemaBasedLogEvent <ContactLinkingLogSchema.ContactLinking> { { ContactLinkingLogSchema.ContactLinking.LinkOperation, operation }, { ContactLinkingLogSchema.ContactLinking.LinkingPersonId, contactToUpdate.PersonId }, { ContactLinkingLogSchema.ContactLinking.LinkingItemId, contactToUpdate.ItemId }, { ContactLinkingLogSchema.ContactLinking.LinkToPersonId, otherContact.PersonId }, { ContactLinkingLogSchema.ContactLinking.LinkToItemId, otherContact.ItemId } }); }
private static HashSet<string> GetEmailAddresses(ADRawEntry person) { HashSet<string> hashSet = new HashSet<string>(); object obj; if (person.TryGetValueWithoutDefault(ADRecipientSchema.EmailAddresses, out obj)) { ProxyAddressCollection proxyAddressCollection = obj as ProxyAddressCollection; if (proxyAddressCollection != null) { foreach (ProxyAddress proxyAddress in proxyAddressCollection) { SmtpProxyAddress smtpProxyAddress = proxyAddress as SmtpProxyAddress; if (smtpProxyAddress != null) { string text = ContactInfoForLinking.CanonicalizeEmailAddress(smtpProxyAddress.SmtpAddress); if (!string.IsNullOrEmpty(text)) { hashSet.Add(text); } } } } } return hashSet; }
private void LogSkippedContactLinking(ContactInfoForLinking contactBeingSaved, int currentCountOfContactsAdded, int maximumNumberOfContactsToAdd, ContactInfoForLinking matchedContact, int otherPersonaContactCount) { base.LogEvent(new SchemaBasedLogEvent <ContactLinkingLogSchema.SkippedContactLink> { { ContactLinkingLogSchema.SkippedContactLink.LinkingPersonId, contactBeingSaved.PersonId }, { ContactLinkingLogSchema.SkippedContactLink.LinkingItemId, contactBeingSaved.ItemId }, { ContactLinkingLogSchema.SkippedContactLink.LinkToPersonId, matchedContact.PersonId }, { ContactLinkingLogSchema.SkippedContactLink.LinkToItemId, matchedContact.ItemId }, { ContactLinkingLogSchema.SkippedContactLink.LinkToPersonContactCount, otherPersonaContactCount }, { ContactLinkingLogSchema.SkippedContactLink.CurrentCountOfContactsAdded, currentCountOfContactsAdded }, { ContactLinkingLogSchema.SkippedContactLink.MaximumContactsAllowedToAdd, maximumNumberOfContactsToAdd } }); }
private void UpdatePersonaId(ContactInfoForLinking contactToUpdate, PersonId newPersonId) { PersonId personId = contactToUpdate.PersonId; contactToUpdate.PersonId = newPersonId; this.contactStoreForContactLinking.ContactRemovedFromPerson(personId, contactToUpdate); this.contactStoreForContactLinking.ContactAddedToPerson(newPersonId, contactToUpdate); }
internal void UnlinkContact(ContactInfoForLinking contactBeingUnlinked, IList <ContactInfoForLinking> linkedContacts) { Util.ThrowOnNullArgument(contactBeingUnlinked, "contactBeingUnlinked"); Util.ThrowOnNullArgument(linkedContacts, "linkedContacts"); Util.ThrowOnArgumentOutOfRangeOnLessThan(linkedContacts.Count, 1, "linkedContacts"); bool flag = ManualLink.IsGALLinked(linkedContacts); if (linkedContacts.Count == 1 && flag) { this.UnlinkContactFromGAL(linkedContacts); return; } if (linkedContacts.Count > 1) { PersonId personId = linkedContacts[0].PersonId; contactBeingUnlinked.ClearGALLink(flag ? GALLinkState.NotAllowed : GALLinkState.NotLinked); contactBeingUnlinked.Linked = false; contactBeingUnlinked.PersonId = PersonId.CreateNew(); contactBeingUnlinked.LinkRejectHistory = new HashSet <PersonId>(new PersonId[] { personId }); contactBeingUnlinked.UserApprovedLink = false; HashSet <PersonId> hashSet = new HashSet <PersonId>(); if (!contactBeingUnlinked.PersonId.Equals(personId)) { hashSet.Add(contactBeingUnlinked.PersonId); } foreach (ContactInfoForLinking contactInfoForLinking in linkedContacts) { if (!contactInfoForLinking.ItemId.ObjectId.Equals(contactBeingUnlinked.ItemId.ObjectId)) { hashSet.UnionWith(contactInfoForLinking.LinkRejectHistory); } } bool flag2 = linkedContacts.Count == 2 && !flag; using (IEnumerator <ContactInfoForLinking> enumerator2 = linkedContacts.GetEnumerator()) { while (enumerator2.MoveNext()) { ContactInfoForLinking contactInfoForLinking2 = enumerator2.Current; if (!contactInfoForLinking2.ItemId.ObjectId.Equals(contactBeingUnlinked.ItemId.ObjectId)) { contactInfoForLinking2.UserApprovedLink = true; contactInfoForLinking2.LinkRejectHistory = hashSet; if (flag2) { contactInfoForLinking2.Linked = false; } } } return; } } ContactLink.Tracer.TraceDebug <VersionedId, string>((long)this.GetHashCode(), "ManualLink.Unlink: contact is not linked with other contacts", contactBeingUnlinked.ItemId, contactBeingUnlinked.GivenName); }
public void PushContactOntoWorkingSet(IStorePropertyBag contact) { Util.ThrowOnNullArgument(contact, "contact"); if (!this.initializedWorkingSet) { this.InitializeWorkingSet(); } ContactInfoForLinking contact2 = base.CreateContactInfoForLinking(contact); this.AddContactToWorkingSet(contact2); }
private void AddToContactsByPersonId(ContactInfoForLinking contact) { IList <ContactInfoForLinking> list; if (!this.contactsByPersonId.TryGetValue(contact.PersonId, out list)) { list = new List <ContactInfoForLinking>(2); this.contactsByPersonId[contact.PersonId] = list; } list.Add(contact); }
protected ContactInfoForLinking(PropertyBagAdaptor propertyBag) : this(propertyBag.GetValueOrDefault <bool>(ContactSchema.Linked, false), propertyBag.GetValueOrDefault <PersonId>(ContactSchema.PersonId, null), ContactInfoForLinking.GetPropertyAsHashSet <PersonId>(propertyBag, ContactSchema.LinkRejectHistory, new HashSet <PersonId>()), propertyBag.GetValueOrDefault <Guid?>(ContactSchema.GALLinkID, null), propertyBag.GetValueOrDefault <byte[]>(ContactSchema.AddressBookEntryId, null), propertyBag.GetValueOrDefault <GALLinkState>(ContactSchema.GALLinkState, GALLinkState.NotLinked), propertyBag.GetValueOrDefault <string[]>(ContactSchema.SmtpAddressCache, Array <string> .Empty), propertyBag.GetValueOrDefault <bool>(ContactSchema.UserApprovedLink, false)) { this.ItemId = propertyBag.GetValueOrDefault <VersionedId>(ItemSchema.Id, null); this.EmailAddresses = ContactInfoForLinking.GetEmailAddresses(propertyBag); this.GivenName = propertyBag.GetValueOrDefault <string>(ContactSchema.GivenName, string.Empty); this.Surname = propertyBag.GetValueOrDefault <string>(ContactSchema.Surname, string.Empty); this.DisplayName = propertyBag.GetValueOrDefault <string>(StoreObjectSchema.DisplayName, string.Empty); this.PartnerNetworkId = propertyBag.GetValueOrDefault <string>(ContactSchema.PartnerNetworkId, string.Empty); this.PartnerNetworkUserId = propertyBag.GetValueOrDefault <string>(ContactSchema.PartnerNetworkUserId, string.Empty); this.IMAddress = ContactInfoForLinking.CanonicalizeEmailAddress(propertyBag.GetValueOrDefault <string>(ContactSchema.IMAddress, string.Empty)); this.IsDL = ObjectClass.IsOfClass(propertyBag.GetValueOrDefault <string>(StoreObjectSchema.ItemClass, string.Empty), "IPM.DistList"); }
private static HashSet <string> GetEmailAddresses(PropertyBagAdaptor propertyBag) { HashSet <string> hashSet = new HashSet <string>(); foreach (StorePropertyDefinition propertyDefinition in ContactSchema.EmailAddressProperties) { string text = ContactInfoForLinking.CanonicalizeEmailAddress(propertyBag.GetValueOrDefault <string>(propertyDefinition, string.Empty)); if (!string.IsNullOrEmpty(text)) { hashSet.Add(text); } } return(hashSet); }
internal static ContactLinkingOperation CanLink(ContactInfoForLinking contact1, ContactInfoForLinking contact2) { Util.ThrowOnNullArgument(contact1, "contact1"); Util.ThrowOnNullArgument(contact2, "contact2"); if (!AutomaticLinkCriteria.CanMergeGALLinkState(contact1, contact2)) { return(ContactLinkingOperation.AutoLinkSkippedConflictingGALLinkState); } if (AutomaticLinkCriteria.IsPresentInLinkRejectHistory(contact1, contact2) || AutomaticLinkCriteria.IsPresentInLinkRejectHistory(contact2, contact1)) { return(ContactLinkingOperation.AutoLinkSkippedInLinkRejectHistory); } return(AutomaticLinkRegularContactComparer.Instance.Match(contact1, contact2)); }
private void UpdatePersonPropertiesInAllContacts(ContactInfoForLinking contactBeingSaved, ICollection <ContactInfoForLinking> matchingContacts) { if (matchingContacts.Count > 0) { foreach (ContactInfoForLinking contactInfoForLinking in matchingContacts) { if (!contactInfoForLinking.Linked) { ContactLink.Tracer.TraceWarning <ContactInfoForLinking>((long)this.GetHashCode(), "Matching contact had linked property set to false. Contact Information: {0}", contactInfoForLinking); contactInfoForLinking.Linked = true; } this.UpdatePersonaId(contactInfoForLinking, contactBeingSaved.PersonId); contactInfoForLinking.LinkRejectHistory = contactBeingSaved.LinkRejectHistory; contactInfoForLinking.UpdateGALLinkFrom(contactBeingSaved); } } }
internal IEnumerable <ContactInfoForLinking> Link(ContactInfoForLinking contactBeingSaved, IEnumerable <ContactInfoForLinking> otherContacts) { PersonId personId = contactBeingSaved.PersonId; HashSet <ContactInfoForLinking> hashSet = new HashSet <ContactInfoForLinking>(this.contactStoreForContactLinking.GetPersonContacts(personId)); int num = (hashSet.Count > 0) ? hashSet.Count : 1; int maxLinkCount = AutomaticLink.MaximumNumberOfContactsPerPerson.Value - num; bool flag = false; HashSet <ContactInfoForLinking> hashSet2 = this.LinkWithContacts(contactBeingSaved, otherContacts, maxLinkCount, out flag); if (hashSet2.Count > 0 || flag) { hashSet2.Add(contactBeingSaved); hashSet2.UnionWith(hashSet); this.UpdatePersonPropertiesInAllContacts(contactBeingSaved, hashSet2); } return(hashSet2); }
public PersonId Unlink(MailboxSession session, PersonId personId, VersionedId contactId) { Util.ThrowOnNullArgument(session, "session"); Util.ThrowOnNullArgument(personId, "personId"); Util.ThrowOnNullArgument(contactId, "contactId"); base.PerformanceTracker.Start(); PersonId result; try { IList <ContactInfoForLinking> list = this.QueryPersonContacts(session, personId); if (list == null || list.Count == 0) { throw new ObjectNotFoundException(ServerStrings.ExItemNotFound); } base.LogEvent(new SchemaBasedLogEvent <ContactLinkingLogSchema.ContactUnlinking> { { ContactLinkingLogSchema.ContactUnlinking.ItemId, contactId.ObjectId }, { ContactLinkingLogSchema.ContactUnlinking.PersonId, personId } }); ContactInfoForLinking matchingContactByItemId = ManualLink.GetMatchingContactByItemId(list, contactId); if (matchingContactByItemId != null) { this.UnlinkContact(matchingContactByItemId, list); base.Commit(list); result = matchingContactByItemId.PersonId; } else { ContactLink.Tracer.TraceDebug <VersionedId, PersonId>((long)this.GetHashCode(), "ManualLink.Unlink: contact {0} not found in person set: {1}", contactId, personId); result = null; } } finally { base.PerformanceTracker.Stop(); base.LogEvent(base.PerformanceTracker.GetLogEvent()); } return(result); }
private static void MergeGALLinkState(ContactInfoForLinking contactBeingSaved, ContactInfoForLinking otherContact) { switch (contactBeingSaved.GALLinkState) { case GALLinkState.NotLinked: contactBeingSaved.UpdateGALLinkFrom(otherContact); return; case GALLinkState.Linked: case GALLinkState.NotAllowed: otherContact.UpdateGALLinkFrom(contactBeingSaved); return; default: return; } }
public bool TryFind(ContactInfoForLinking contactInfo, out ContactInfoForLinkingFromDirectory matchingContactInfo) { Util.ThrowOnNullArgument(contactInfo, "contactInfo"); if (this.recipientSession == null) { DirectoryPersonSearcher.Tracer.TraceError(0L, "No recipient session available to perform search"); matchingContactInfo = null; return(false); } ADRawEntry adrawEntry = DirectoryPersonSearcher.TryFind(this.recipientSession, DirectoryPersonSearcher.GetFilterForFindByAddresses(contactInfo)); if (adrawEntry != null) { ContactInfoForLinkingFromDirectory contactInfoForLinkingFromDirectory = ContactInfoForLinkingFromDirectory.Create(adrawEntry); matchingContactInfo = contactInfoForLinkingFromDirectory; return(true); } matchingContactInfo = null; return(false); }
public override void ContactAddedToPerson(PersonId personId, ContactInfoForLinking contact) { Util.ThrowOnNullArgument(personId, "personId"); Util.ThrowOnNullArgument(contact, "contact"); if (!personId.Equals(contact.PersonId)) { ContactStoreForBulkContactLinking.Tracer.TraceDebug <PersonId, PersonId>((long)this.GetHashCode(), "ContactStoreForBulkContactLinking.ContactAddedToPerson: PersonId of the contact is not properly set. Found {0}. Expected {1}", contact.PersonId, personId); throw new InvalidOperationException("ContactStoreForBulkContactLinking.ContactAddedToPerson: PersonId of the contact is not properly set."); } if (contact is ContactInfoForLinkingFromCoreObject) { ContactStoreForBulkContactLinking.Tracer.TraceDebug <VersionedId, PersonId>((long)this.GetHashCode(), "ContactStoreForBulkContactLinking.ContactAddedToPerson: contact not added to contactsByPersonId as it is object being saved. ItemId {0}, PersonId {1}", contact.ItemId, contact.PersonId); return; } if (!this.initializedWorkingSet) { this.InitializeWorkingSet(); } this.AddToContactsByPersonId(contact); }
private bool TryFindDirectoryMatch(ContactInfoForLinking contactBeingSaved, out ContactInfoForLinkingFromDirectory contactFromDirectory) { contactFromDirectory = null; if (contactBeingSaved.IsDL) { ContactLink.Tracer.TraceDebug <string>((long)this.GetHashCode(), "AutomaticLink.TryFindDirectoryMatch: skipping linking {0} with directory because it is a PDL.", contactBeingSaved.DisplayName); return(false); } if (contactBeingSaved.GALLinkState != GALLinkState.NotLinked) { ContactLink.Tracer.TraceDebug <string, GALLinkState>((long)this.GetHashCode(), "AutomaticLink.TryFindDirectoryMatch: skipping linking {0} with directory because GALLinkState={1}", contactBeingSaved.DisplayName, contactBeingSaved.GALLinkState); return(false); } if (!this.directoryPersonSearcher.TryFind(contactBeingSaved, out contactFromDirectory)) { ContactLink.Tracer.TraceDebug <string>((long)this.GetHashCode(), "AutomaticLink.TryFindDirectoryMatch: did not find person in directory to match with contact {0}", contactBeingSaved.DisplayName); return(false); } ContactLink.Tracer.TraceDebug <string>((long)this.GetHashCode(), "AutomaticLink.TryFindDirectoryMatch: Found person in directory to match with contact {0}", contactBeingSaved.DisplayName); return(true); }
private void LogGALLinkOperation(ContactInfoForLinking contactToUpdate, ContactInfoForLinkingFromDirectory galContact) { base.LogEvent(new SchemaBasedLogEvent <ContactLinkingLogSchema.ContactLinking> { { ContactLinkingLogSchema.ContactLinking.LinkOperation, ContactLinkingOperation.AutoLinkViaEmailOrImAddressInDirectoryPerson }, { ContactLinkingLogSchema.ContactLinking.LinkingPersonId, contactToUpdate.PersonId }, { ContactLinkingLogSchema.ContactLinking.LinkingItemId, contactToUpdate.ItemId }, { ContactLinkingLogSchema.ContactLinking.LinkToPersonId, galContact.GALLinkID } }); }
protected void SetLinkingProperties(PropertyBagAdaptor propertyBag) { propertyBag.SetValue(ContactSchema.Linked, this.Linked); propertyBag.SetValue(ContactSchema.PersonId, this.PersonId); if (this.LinkRejectHistory.Count > 0) { propertyBag.SetValue(ContactSchema.LinkRejectHistory, ContactInfoForLinking.ToArray <PersonId>(this.LinkRejectHistory)); } else { propertyBag.DeleteValue(ContactSchema.LinkRejectHistory); } if (this.GALLinkID != null) { propertyBag.SetValue(ContactSchema.GALLinkID, this.GALLinkID.Value); } else { propertyBag.DeleteValue(ContactSchema.GALLinkID); } if (this.addressBookEntryId != null) { propertyBag.SetValue(ContactSchema.AddressBookEntryId, this.addressBookEntryId); } else { propertyBag.DeleteValue(ContactSchema.AddressBookEntryId); } if (this.SmtpAddressCache != null) { propertyBag.SetValue(ContactSchema.SmtpAddressCache, this.SmtpAddressCache); } else { propertyBag.DeleteValue(ContactSchema.SmtpAddressCache); } propertyBag.SetValue(ContactSchema.GALLinkState, this.GALLinkState); propertyBag.SetValue(ContactSchema.UserApprovedLink, this.UserApprovedLink); }
public override void ContactRemovedFromPerson(PersonId personId, ContactInfoForLinking contact) { Util.ThrowOnNullArgument(personId, "personId"); Util.ThrowOnNullArgument(contact, "contact"); if (contact is ContactInfoForLinkingFromCoreObject) { ContactStoreForBulkContactLinking.Tracer.TraceDebug <VersionedId, PersonId>((long)this.GetHashCode(), "ContactStoreForBulkContactLinking.ContactRemovedFromPerson: contact not removed from contactsByPersonId as it is object being saved. ItemId {0}, PersonId {1}", contact.ItemId, contact.PersonId); return; } if (!this.initializedWorkingSet) { this.InitializeWorkingSet(); } IList <ContactInfoForLinking> list; if (this.contactsByPersonId.TryGetValue(personId, out list)) { list.Remove(contact); return; } ContactStoreForBulkContactLinking.Tracer.TraceDebug <PersonId>((long)this.GetHashCode(), "ContactStoreForBulkContactLinking.ReportPersonIdUpdate: Couldn't find contact list for PersonId: {0}", personId); }
private static QueryFilter GetFilterForFindByAddresses(ContactInfoForLinking contactInfo) { List <QueryFilter> list = new List <QueryFilter>(contactInfo.EmailAddresses.Count + 1); if (contactInfo.EmailAddresses.Count > 0) { DirectoryPersonSearcher.AddFilterForEachEmailAddress("smtp:", contactInfo.EmailAddresses, list); } if (!string.IsNullOrEmpty(contactInfo.IMAddress)) { list.Add(DirectoryPersonSearcher.GetFilterForFindByImAddress(contactInfo.IMAddress)); } if (list.Count == 0) { return(null); } if (list.Count == 1) { return(list[0]); } return(new OrFilter(list.ToArray())); }
private void LinkTwoContacts(ContactLinkingOperation operation, ContactInfoForLinking contact1, ContactInfoForLinking contact2) { if (!contact1.Linked && contact2.Linked) { this.LogLinkOperation(operation, contact1, contact2); this.UpdatePersonaId(contact1, contact2.PersonId); contact1.Linked = true; } else if (contact1.Linked && !contact2.Linked) { this.LogLinkOperation(operation, contact2, contact1); this.UpdatePersonaId(contact2, contact1.PersonId); contact2.Linked = true; } else if (contact1.Linked && contact2.Linked) { this.LogLinkOperation(operation, contact2, contact1); this.UpdatePersonaId(contact2, contact1.PersonId); } else { if (!contact2.IsNew && contact1.IsNew) { this.LogLinkOperation(operation, contact1, contact2); this.UpdatePersonaId(contact1, contact2.PersonId); } else { this.LogLinkOperation(operation, contact2, contact1); this.UpdatePersonaId(contact2, contact1.PersonId); } contact1.Linked = true; contact2.Linked = true; } contact1.LinkRejectHistory.UnionWith(contact2.LinkRejectHistory); contact2.LinkRejectHistory = contact1.LinkRejectHistory; AutomaticLink.MergeGALLinkState(contact1, contact2); }
internal void LinkNewOrUpdatedContactBeforeSave(ICoreItem contactBeingSaved, Func <ContactInfoForLinking, IContactStoreForContactLinking, IEnumerable <ContactInfoForLinking> > otherContactsDelegate) { base.PerformanceTracker.Start(); try { Util.ThrowOnNullArgument(otherContactsDelegate, "otherContactsDelegate"); if (!this.CanContinueProcessingContacts()) { throw new InvalidOperationException("Can't start contact linking operation as conditions to continue processing are not met."); } if (this.IsValidContactBeingSaved(contactBeingSaved)) { ContactInfoForLinking contactInfoForLinking = ContactInfoForLinkingFromCoreObject.Create(contactBeingSaved); base.Commit(this.Link(contactInfoForLinking, otherContactsDelegate(contactInfoForLinking, this.contactStoreForContactLinking))); } } catch (Exception value) { ContactLink.Tracer.TraceDebug <MailboxInfoForLinking>(0L, "AutomaticLink::LinkNewOrUpdatedContactBeforeSave. Unhandled exception processing {0}.", base.MailboxInfo); base.LogEvent(new SchemaBasedLogEvent <ContactLinkingLogSchema.Error> { { ContactLinkingLogSchema.Error.Context, "Unhandled Exception" }, { ContactLinkingLogSchema.Error.Exception, value } }); throw; } finally { base.PerformanceTracker.Stop(); base.LogEvent(base.PerformanceTracker.GetLogEvent()); } }
public override string ToString() { StringBuilder stringBuilder = new StringBuilder(300); ContactInfoForLinking.AddToString(stringBuilder, "Type", base.GetType().Name); ContactInfoForLinking.AddToString(stringBuilder, "DisplayName", this.DisplayName); ContactInfoForLinking.AddToString(stringBuilder, "GivenName", this.GivenName); ContactInfoForLinking.AddToString(stringBuilder, "Surname", this.Surname); ContactInfoForLinking.AddToString(stringBuilder, "EmailAddresses", this.EmailAddresses); ContactInfoForLinking.AddToString(stringBuilder, "PartnerNetworkId", this.PartnerNetworkId); ContactInfoForLinking.AddToString(stringBuilder, "PartnerNetworkUserId", this.PartnerNetworkUserId); ContactInfoForLinking.AddToString(stringBuilder, "IMAddress", this.IMAddress); ContactInfoForLinking.AddToString(stringBuilder, "ItemId", this.ItemId); ContactInfoForLinking.AddToString(stringBuilder, "PersonId", this.personId); ContactInfoForLinking.AddToString(stringBuilder, "Linked", this.linked); ContactInfoForLinking.AddToString(stringBuilder, "LinkRejectHistory", this.linkRejectHistory); ContactInfoForLinking.AddToString(stringBuilder, "GALLinkState", this.galLinkState); ContactInfoForLinking.AddToString(stringBuilder, "GALLinkID", this.galLinkID); ContactInfoForLinking.AddToString(stringBuilder, "AddressBookEntryId", this.addressBookEntryId); ContactInfoForLinking.AddToString(stringBuilder, "SmtpAddressCache", this.smtpAddressCache); ContactInfoForLinking.AddToString(stringBuilder, "UserApprovedLink", this.userApprovedLink); ContactInfoForLinking.AddToString(stringBuilder, "IsDirty", this.isDirty); return(stringBuilder.ToString()); }
private IEnumerable <ContactInfoForLinking> GetOtherContactsEnumeratorForBulk(ContactInfoForLinking contactInfoContactBeingSaved, IContactStoreForContactLinking contactStoreForContactLinking) { return(contactStoreForContactLinking.GetAllContacts().Take(AutomaticLink.MaximumNumberOfContactsToProcess.Value)); }
public void Link(MailboxSession session, PersonId linkingPersonId, PersonId linkToPersonId) { Util.ThrowOnNullArgument(session, "session"); Util.ThrowOnNullArgument(linkingPersonId, "linkingPersonId"); Util.ThrowOnNullArgument(linkToPersonId, "linkToPersonId"); base.PerformanceTracker.Start(); try { if (linkingPersonId.Equals(linkToPersonId)) { ContactLink.Tracer.TraceDebug <PersonId>((long)this.GetHashCode(), "ManualLink.Link: ignoring link operation because linkingPersonId and linkToPerson are the same person: {0}", linkToPersonId); } else { IList <ContactInfoForLinking> list = this.QueryPersonContacts(session, linkingPersonId); if (list.Count == 0) { ContactLink.Tracer.TraceError <PersonId>((long)this.GetHashCode(), "ManualLink.Link: no contacts for PersonId={0} can be found", linkingPersonId); throw new ObjectNotFoundException(ServerStrings.ExItemNotFound); } IList <ContactInfoForLinking> list2 = this.QueryPersonContacts(session, linkToPersonId); if (list2.Count == 0) { ContactLink.Tracer.TraceError <PersonId>((long)this.GetHashCode(), "ManualLink.Link: no contacts for PersonId={0} can be found", linkToPersonId); throw new ObjectNotFoundException(ServerStrings.ExItemNotFound); } if (list.Count + list2.Count > AutomaticLink.MaximumNumberOfContactsPerPerson.Value) { ContactLink.Tracer.TraceError((long)this.GetHashCode(), "ManualLink.Link: Can't link Personas as their aggregated contact count exceeds maximum allowed. Persona {0}: {1}. Persona {2}: {3}", new object[] { linkingPersonId, list.Count, linkToPersonId, list2.Count }); throw new InvalidOperationException(ServerStrings.ContactLinkingMaximumNumberOfContactsPerPersonError); } bool flag = ManualLink.IsGALLinked(list); bool flag2 = ManualLink.IsGALLinked(list2); if (flag && flag2 && list[0].GALLinkID != list2[0].GALLinkID) { throw new InvalidOperationException(ServerStrings.PersonIsAlreadyLinkedWithGALContact); } base.LogEvent(new SchemaBasedLogEvent <ContactLinkingLogSchema.ContactLinking> { { ContactLinkingLogSchema.ContactLinking.LinkOperation, ContactLinkingOperation.ManualLinking }, { ContactLinkingLogSchema.ContactLinking.LinkingPersonId, linkingPersonId }, { ContactLinkingLogSchema.ContactLinking.LinkToPersonId, linkToPersonId } }); ContactInfoForLinking galContact = flag ? list[0] : (flag2 ? list2[0] : null); this.LinkContacts(list, list2, galContact); base.Commit(list); base.Commit(list2); } } finally { base.PerformanceTracker.Stop(); base.LogEvent(base.PerformanceTracker.GetLogEvent()); } }
internal void LinkContacts(IList <ContactInfoForLinking> contacts, IList <ContactInfoForLinking> otherContacts, ContactInfoForLinking galContact) { Util.ThrowOnNullArgument(contacts, "contacts"); Util.ThrowOnArgumentOutOfRangeOnLessThan(contacts.Count, 1, "contacts"); Util.ThrowOnNullArgument(otherContacts, "otherContacts"); Util.ThrowOnArgumentOutOfRangeOnLessThan(otherContacts.Count, 1, "otherContacts"); PersonId personId = otherContacts[0].PersonId; HashSet <PersonId> hashSet = new HashSet <PersonId>(); ManualLink.MergeLinkRejectHistory(hashSet, contacts); ManualLink.MergeLinkRejectHistory(hashSet, otherContacts); hashSet.Remove(contacts[0].PersonId); hashSet.Remove(otherContacts[0].PersonId); ManualLink.UpdateLinkRejectHistory(contacts, hashSet); ManualLink.UpdateLinkRejectHistory(otherContacts, hashSet); GALLinkState galLinkState; Guid? galLinkId; byte[] addressBookEntryId; string[] smtpAddressCache; if (galContact != null) { galLinkState = GALLinkState.Linked; galLinkId = galContact.GALLinkID; addressBookEntryId = galContact.AddressBookEntryId; smtpAddressCache = galContact.SmtpAddressCache; } else { if (contacts[0].GALLinkState == GALLinkState.NotAllowed || otherContacts[0].GALLinkState == GALLinkState.NotAllowed) { galLinkState = GALLinkState.NotAllowed; } else { galLinkState = GALLinkState.NotLinked; } galLinkId = null; addressBookEntryId = null; smtpAddressCache = Array <string> .Empty; } foreach (ContactInfoForLinking contactInfoForLinking in contacts) { if (!contactInfoForLinking.Linked || !contactInfoForLinking.PersonId.Equals(personId)) { contactInfoForLinking.Linked = true; contactInfoForLinking.PersonId = personId; } else { ContactLink.Tracer.TraceDebug <VersionedId, string>((long)this.GetHashCode(), "ManualLink.Link: contact is already linked with PersonId set: {0}, {1}", contactInfoForLinking.ItemId, contactInfoForLinking.GivenName); } contactInfoForLinking.UpdateGALLink(galLinkState, galLinkId, addressBookEntryId, smtpAddressCache); contactInfoForLinking.UserApprovedLink = true; } foreach (ContactInfoForLinking contactInfoForLinking2 in otherContacts) { if (!contactInfoForLinking2.Linked) { contactInfoForLinking2.Linked = true; } contactInfoForLinking2.UpdateGALLink(galLinkState, galLinkId, addressBookEntryId, smtpAddressCache); contactInfoForLinking2.UserApprovedLink = true; } }
public void UpdateGALLinkFrom(ContactInfoForLinking otherContact) { ArgumentValidator.ThrowIfNull("otherContact", otherContact); this.UpdateGALLink(otherContact.GALLinkState, otherContact.GALLinkID, otherContact.AddressBookEntryId, otherContact.SmtpAddressCache); }
internal static bool CanMergeGALLinkState(ContactInfoForLinking contactBeingSaved, ContactInfoForLinking otherContact) { return(contactBeingSaved.GALLinkState == GALLinkState.NotLinked || otherContact.GALLinkState == GALLinkState.NotLinked || (contactBeingSaved.GALLinkState == GALLinkState.NotAllowed && otherContact.GALLinkState == GALLinkState.NotAllowed) || (contactBeingSaved.GALLinkState == GALLinkState.Linked && otherContact.GALLinkState == GALLinkState.Linked && contactBeingSaved.GALLinkID == otherContact.GALLinkID)); }