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 bool ShouldLink(ContactLinkingOperation operation) { switch (operation) { case ContactLinkingOperation.AutoLinkViaEmailAddress: case ContactLinkingOperation.AutoLinkViaIMAddress: break; default: if (operation != ContactLinkingOperation.AutoLinkViaGalLinkId) { return(false); } break; } return(true); }
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); }
private HashSet <ContactInfoForLinking> LinkWithContacts(ContactInfoForLinking contactBeingSaved, IEnumerable <ContactInfoForLinking> otherContacts, int maxLinkCount, out bool linkedToDirectory) { linkedToDirectory = false; HashSet <ContactInfoForLinking> hashSet = new HashSet <ContactInfoForLinking>(ContactInfoForLinkingComparerByItemId.Instance); PersonId personId = contactBeingSaved.PersonId; HashSet <PersonId> hashSet2 = new HashSet <PersonId>(); ContactInfoForLinkingFromDirectory contactInfoForLinkingFromDirectory = null; if (contactBeingSaved.GALLinkState != GALLinkState.NotAllowed && contactBeingSaved.GALLinkID == null) { this.TryFindDirectoryMatch(contactBeingSaved, out contactInfoForLinkingFromDirectory); } foreach (ContactInfoForLinking contactInfoForLinking in otherContacts) { if (!this.CanContinueProcessingContacts()) { break; } if (!contactInfoForLinking.PersonId.Equals(personId) && !ContactInfoForLinkingComparerByItemId.Instance.Equals(contactInfoForLinking, contactBeingSaved) && !hashSet2.Contains(contactInfoForLinking.PersonId)) { ContactLinkingOperation contactLinkingOperation = AutomaticLinkCriteria.CanLink(contactBeingSaved, contactInfoForLinking); if (contactInfoForLinkingFromDirectory != null && contactInfoForLinking.GALLinkState == GALLinkState.Linked && contactInfoForLinking.GALLinkID == contactInfoForLinkingFromDirectory.GALLinkID) { if (contactLinkingOperation == ContactLinkingOperation.None) { contactLinkingOperation = ContactLinkingOperation.AutoLinkViaGalLinkId; } contactInfoForLinkingFromDirectory = null; } if (AutomaticLink.ShouldLink(contactLinkingOperation)) { hashSet2.Add(contactInfoForLinking.PersonId); HashSet <ContactInfoForLinking> hashSet3 = new HashSet <ContactInfoForLinking>(this.contactStoreForContactLinking.GetPersonContacts(contactInfoForLinking.PersonId)); if (hashSet3.Count + hashSet.Count <= maxLinkCount) { hashSet.UnionWith(hashSet3); this.LinkTwoContacts(contactLinkingOperation, contactBeingSaved, contactInfoForLinking); if (hashSet.Count == maxLinkCount) { string text = string.Format(CultureInfo.InvariantCulture, "Stopping linking iteration for PersonID {0} because we have reached maximum number of contacts for the persona.", new object[] { contactBeingSaved.PersonId }); ContactLink.Tracer.TraceDebug <string>((long)this.GetHashCode(), "AutomaticLinking.LinkWithContacts: {0}", text); base.LogEvent(new SchemaBasedLogEvent <ContactLinkingLogSchema.Warning> { { ContactLinkingLogSchema.Warning.Context, text } }); break; } } else { ContactLink.Tracer.TraceDebug <PersonId, VersionedId>((long)this.GetHashCode(), "AutomaticLinking.LinkWithContacts: Skipping link with PersonID {0} for item {1} because we would be over the maximum number of contacts for the persona.", contactInfoForLinking.PersonId, contactBeingSaved.ItemId); this.LogSkippedContactLinking(contactBeingSaved, hashSet.Count, maxLinkCount, contactInfoForLinking, hashSet3.Count); } } } } if (contactInfoForLinkingFromDirectory != null && contactBeingSaved.GALLinkState != GALLinkState.Linked) { this.LogGALLinkOperation(contactBeingSaved, contactInfoForLinkingFromDirectory); contactBeingSaved.SetGALLink(contactInfoForLinkingFromDirectory); linkedToDirectory = true; } return(hashSet); }