public ADRawEntry FindByAdObjectIdGuidOrSmtpAddressCache(Guid adObjectIdGuid, string[] smtpAddressCache, IEnumerable <PropertyDefinition> adProperties) { ArgumentValidator.ThrowIfEmpty("adObjectIdGuid", adObjectIdGuid); ArgumentValidator.ThrowIfNull("adProperties", adProperties); if (this.recipientSession == null) { DirectoryPersonSearcher.Tracer.TraceError(0L, "No recipient session available to perform search"); return(null); } ADObjectId entryId = new ADObjectId(adObjectIdGuid); ADRawEntry adrawEntry = this.recipientSession.ReadADRawEntry(entryId, adProperties); if (adrawEntry != null) { DirectoryPersonSearcher.Tracer.TraceDebug <Guid>(0L, "Found AD entry for AD Object Id Guid:{0}.", adObjectIdGuid); return(adrawEntry); } DirectoryPersonSearcher.Tracer.TraceDebug <Guid>(0L, "Nothing found for AD Object Id:{0}, trying with smtp address cache.", adObjectIdGuid); if (smtpAddressCache == null || smtpAddressCache.Length == 0) { DirectoryPersonSearcher.Tracer.TraceDebug <Guid>(0L, "Nothing in SMTP Address Cache to fallback to in order to find AD Object with Id: {0}.", adObjectIdGuid); return(null); } QueryFilter filterForFindByEmailAddress = DirectoryPersonSearcher.GetFilterForFindByEmailAddress(string.Empty, smtpAddressCache); ADRawEntry[] array = DirectoryPersonSearcher.Find(this.recipientSession, filterForFindByEmailAddress, 1, adProperties); if (array == null || array.Length == 0) { DirectoryPersonSearcher.Tracer.TraceDebug(0L, "Found no matching recipient in AD for the smtp address cache."); return(null); } return(array[0]); }
public void ItemOperation(COWSettings settings, IDumpsterItemOperations dumpster, COWTriggerAction operation, COWTriggerActionState state, StoreSession session, StoreObjectId itemId, CoreItem item, CoreFolder folder, bool onBeforeNotification, OperationResult result, CallbackContext callbackContext) { Util.ThrowOnNullArgument(session, "session"); Util.ThrowOnNullArgument(item, "item"); EnumValidator.ThrowIfInvalid <COWTriggerAction>(operation, "operation"); EnumValidator.ThrowIfInvalid <COWTriggerActionState>(state, "state"); EnumValidator.ThrowIfInvalid <OperationResult>(result, "result"); COWContactLinking.Tracer.TraceDebug <StoreObjectId>((long)this.GetHashCode(), "COWContactLinking.ItemOperation: processing contact linking for item {0}.", itemId); MailboxSession mailboxSession = (MailboxSession)session; MailboxInfoForLinking mailboxInfo = MailboxInfoForLinking.CreateFromMailboxSession(mailboxSession); ContactLinkingPerformanceTracker performanceTracker = new ContactLinkingPerformanceTracker(mailboxSession); DirectoryPersonSearcher directoryPersonSearcher = new DirectoryPersonSearcher(mailboxSession.MailboxOwner); ContactStoreForContactLinking contactStoreForContactLinking = new ContactStoreForCowContactLinking(mailboxSession, performanceTracker); ContactLinkingLogger logger = new ContactLinkingLogger("COWContactLinking", mailboxInfo); AutomaticLink automaticLink = new AutomaticLink(mailboxInfo, logger, performanceTracker, directoryPersonSearcher, contactStoreForContactLinking); automaticLink.LinkNewOrUpdatedContactBeforeSave(item, new Func <ContactInfoForLinking, IContactStoreForContactLinking, IEnumerable <ContactInfoForLinking> >(this.GetOtherContactsEnumeratorForCOW)); if (!onBeforeNotification) { item.SaveFlags |= PropertyBagSaveFlags.ForceNotificationPublish; try { item.Save(SaveMode.NoConflictResolution); } finally { item.SaveFlags &= ~PropertyBagSaveFlags.ForceNotificationPublish; } } callbackContext.ContactLinkingProcessingState = ContactLinkingProcessingState.Processed; }
public DirectoryPersonSearcher(IExchangePrincipal exchangePrincipal) { ADSessionSettings adsessionSettings = DirectoryPersonSearcher.GetADSessionSettings(exchangePrincipal); if (adsessionSettings != null) { this.recipientSession = DirectorySessionFactory.Default.GetTenantOrRootOrgRecipientSession(true, ConsistencyMode.PartiallyConsistent, adsessionSettings, 70, ".ctor", "f:\\15.00.1497\\sources\\dev\\data\\src\\storage\\Contacts\\DirectoryPersonSearcher.cs"); } }
private static QueryFilter GetFilterForFindByEmailAddress(string prefix, ICollection <string> emailAddresses) { List <QueryFilter> list = new List <QueryFilter>(emailAddresses.Count); DirectoryPersonSearcher.AddFilterForEachEmailAddress(prefix, emailAddresses, list); if (list.Count == 0) { return(null); } if (list.Count == 1) { return(list[0]); } return(new OrFilter(list.ToArray())); }
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); }
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 static ADRawEntry TryFind(IRecipientSession recipientSession, QueryFilter filter) { ADRawEntry[] array = null; try { array = DirectoryPersonSearcher.Find(recipientSession, filter, 2, ContactInfoForLinkingFromDirectory.RequiredADProperties); } catch (ADTransientException arg) { DirectoryPersonSearcher.Tracer.TraceError <ADTransientException>(0L, "Unable to find recipient in AD due exception ", arg); return(null); } if (array == null || array.Length == 0) { DirectoryPersonSearcher.Tracer.TraceDebug(0L, "Found no matching recipient in AD"); return(null); } if (array.Length > 1) { DirectoryPersonSearcher.Tracer.TraceDebug(0L, "Found more than one matching recipient in AD"); return(null); } return(array[0]); }
internal static void PerformContactLinkingAfterMigration(StoreSession storeSession) { MailboxSession mailboxSession = storeSession as MailboxSession; if (mailboxSession == null) { ContactLink.Tracer.TraceDebug(0L, "AutomaticLink::PerformContactLinkingAfterMigration. Skiping session as it is not a MailboxSession."); return; } ContactLink.Tracer.TraceDebug <MailboxSession>(0L, "StoreSession::PerformContactLinking. Starting linking for {0}.", mailboxSession); ExDateTime exDateTime = ExDateTime.Now.Add(AutomaticLink.AllocatedTimeSlotForLinkingOnMigration.Value); MailboxInfoForLinking mailboxInfoForLinking = MailboxInfoForLinking.CreateFromMailboxSession(mailboxSession); ContactLinkingPerformanceTracker performanceTracker = new ContactLinkingPerformanceTracker(mailboxSession); DirectoryPersonSearcher directoryPersonSearcher = new DirectoryPersonSearcher(mailboxSession.MailboxOwner); ContactStoreForBulkContactLinking contactStoreForBulkContactLinking = new ContactStoreForBulkContactLinking(mailboxSession, performanceTracker); ContactLinkingLogger contactLinkingLogger = new ContactLinkingLogger("PerformContactLinkingAfterMigration", mailboxInfoForLinking); bool flag = false; contactLinkingLogger.LogEvent(new SchemaBasedLogEvent <ContactLinkingLogSchema.MigrationStart> { { ContactLinkingLogSchema.MigrationStart.DueTime, (DateTime)exDateTime } }); try { AutomaticLink.RefreshContactLinkingDefaultFolderIds(mailboxSession); AutomaticLink automaticLink = new AutomaticLink(mailboxInfoForLinking, contactLinkingLogger, performanceTracker, directoryPersonSearcher, contactStoreForBulkContactLinking); automaticLink.LinkAllExistingContactsTimeBound(exDateTime); flag = true; } catch (DefaultFolderNameClashException e) { AutomaticLink.TraceAndLogExceptionDuringLinkingPostMigration(mailboxInfoForLinking, contactLinkingLogger, e); } catch (AccessDeniedException e2) { AutomaticLink.TraceAndLogExceptionDuringLinkingPostMigration(mailboxInfoForLinking, contactLinkingLogger, e2); } catch (ConnectionFailedTransientException e3) { AutomaticLink.TraceAndLogExceptionDuringLinkingPostMigration(mailboxInfoForLinking, contactLinkingLogger, e3); } catch (FolderSaveTransientException e4) { AutomaticLink.TraceAndLogExceptionDuringLinkingPostMigration(mailboxInfoForLinking, contactLinkingLogger, e4); } catch (MailboxUnavailableException e5) { AutomaticLink.TraceAndLogExceptionDuringLinkingPostMigration(mailboxInfoForLinking, contactLinkingLogger, e5); } catch (ObjectNotFoundException e6) { AutomaticLink.TraceAndLogExceptionDuringLinkingPostMigration(mailboxInfoForLinking, contactLinkingLogger, e6); } catch (StorageTransientException e7) { AutomaticLink.TraceAndLogExceptionDuringLinkingPostMigration(mailboxInfoForLinking, contactLinkingLogger, e7); } catch (StoragePermanentException e8) { AutomaticLink.TraceAndLogExceptionDuringLinkingPostMigration(mailboxInfoForLinking, contactLinkingLogger, e8); } catch (Exception e9) { AutomaticLink.TraceAndLogExceptionDuringLinkingPostMigration(mailboxInfoForLinking, contactLinkingLogger, e9); throw; } finally { contactLinkingLogger.LogEvent(new SchemaBasedLogEvent <ContactLinkingLogSchema.MigrationEnd> { { ContactLinkingLogSchema.MigrationEnd.Success, flag } }); ContactLink.Tracer.TraceDebug <MailboxInfoForLinking, bool>(0L, "AutomaticLink::PerformContactLinkingAfterMigration. Done processing {0}. Contact linking completed successfully: {1}", mailboxInfoForLinking, flag); } }