protected ContactInfoForLinkingFromDirectory(ADRawEntry person) { this.GALLinkID = person.Id.ObjectGuid; this.AddressBookEntryId = ContactInfoForLinkingFromDirectory.GetAddressBookId(person); this.SmtpAddressCache = ContactInfoForLinkingFromDirectory.GetSmtpAddressCache(person); this.EmailAddresses = ContactInfoForLinkingFromDirectory.GetEmailAddresses(person); this.IMAddress = (person[ADUserSchema.RTCSIPPrimaryUserAddress] as string); }
public void Link(MailboxSession session, IRecipientSession adSession, PersonId linkingPersonId, ADObjectId linkToADObjectId) { Util.ThrowOnNullArgument(session, "session"); Util.ThrowOnNullArgument(adSession, "adSession"); Util.ThrowOnNullArgument(linkingPersonId, "linkingPersonId"); Util.ThrowOnNullArgument(linkToADObjectId, "linkToADObjectId"); base.PerformanceTracker.Start(); try { 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); } bool flag = ManualLink.IsGALLinked(list); if (flag) { if (!(list[0].GALLinkID == linkToADObjectId.ObjectGuid)) { throw new InvalidOperationException(ServerStrings.PersonIsAlreadyLinkedWithGALContact); } ContactLink.Tracer.TraceDebug <PersonId, ADObjectId>((long)this.GetHashCode(), "ManualLink.Link: Linking PersonId {0} is already linked to GAL object {1}", linkingPersonId, linkToADObjectId); } else { ContactInfoForLinkingFromDirectory contactInfoForLinkingFromDirectory = this.LoadADContact(adSession, linkToADObjectId); if (contactInfoForLinkingFromDirectory == null) { ContactLink.Tracer.TraceError <ADObjectId>((long)this.GetHashCode(), "ManualLink.Link: no AD contact for ADObjectId={0} can be found", linkToADObjectId); throw new ObjectNotFoundException(ServerStrings.ExItemNotFound); } base.LogEvent(new SchemaBasedLogEvent <ContactLinkingLogSchema.ContactLinking> { { ContactLinkingLogSchema.ContactLinking.LinkOperation, ContactLinkingOperation.ManualLinking }, { ContactLinkingLogSchema.ContactLinking.LinkingPersonId, linkingPersonId }, { ContactLinkingLogSchema.ContactLinking.LinkToPersonId, linkToADObjectId } }); this.LinkContactsWithGAL(list, contactInfoForLinkingFromDirectory); base.Commit(list); } } finally { base.PerformanceTracker.Stop(); base.LogEvent(base.PerformanceTracker.GetLogEvent()); } }
private static byte[] GetAddressBookId(ADRawEntry person) { string text = (string)person[ADRecipientSchema.LegacyExchangeDN]; RecipientDisplayType? recipientDisplayType = (RecipientDisplayType?)person[ADRecipientSchema.RecipientDisplayType]; Eidt eidt; if (!string.IsNullOrEmpty(text) && recipientDisplayType != null && ContactInfoForLinkingFromDirectory.TryGetEidt(recipientDisplayType.Value, out eidt)) { return Microsoft.Exchange.Data.Storage.AddressBookEntryId.MakeAddressBookEntryID(text, eidt); } return null; }
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 bool TryUpdateGALLinkingPropertiesIfChanged(ADRawEntry adPerson) { ArgumentValidator.ThrowIfNull("adPerson", adPerson); GALLinkingFixer.Tracer.TraceDebug <Guid>((long)this.personId.GetHashCode(), "GALLinkingFixer::Updating GAL Linking properties on contact from the latest one in AD Person: {0}.", adPerson.Id.ObjectGuid); ContactInfoForLinkingFromDirectory adContactInfo = ContactInfoForLinkingFromDirectory.Create(adPerson); return(this.TryEnumerateContactsAndApplyUpdates(delegate(ContactInfoForLinking contactInfo) { contactInfo.SetGALLink(adContactInfo); }, "UpdateGALLinkingPropertiesIfChanged", new SchemaBasedLogEvent <ContactLinkingLogSchema.GALLinkFixup> { { ContactLinkingLogSchema.GALLinkFixup.PersonId, this.personId }, { ContactLinkingLogSchema.GALLinkFixup.ADObjectIdGuid, this.adObjectIdGuid } })); }
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 } }); }
private ContactInfoForLinkingFromDirectory LoadADContact(IRecipientSession adSession, ADObjectId adObjectId) { return(ContactInfoForLinkingFromDirectory.Create(adSession, adObjectId)); }
internal void LinkContactsWithGAL(IList <ContactInfoForLinking> personalContacts, ContactInfoForLinkingFromDirectory galContact) { foreach (ContactInfoForLinking contactInfoForLinking in personalContacts) { contactInfoForLinking.SetGALLink(galContact); contactInfoForLinking.UserApprovedLink = true; } }
public void SetGALLink(ContactInfoForLinkingFromDirectory directoryContact) { ArgumentValidator.ThrowIfNull("directoryContact", directoryContact); this.UpdateGALLink(GALLinkState.Linked, new Guid?(directoryContact.GALLinkID), directoryContact.AddressBookEntryId, directoryContact.SmtpAddressCache); this.Linked = true; }
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); }