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; }
private bool TryEnumerateContactsAndApplyUpdates(Action <ContactInfoForLinking> updateOperation, string sessionName, ILogEvent operationIntentionEvent) { List <ContactInfoForLinkingFromPropertyBag> list = new List <ContactInfoForLinkingFromPropertyBag>(this.contacts.Count); bool flag = false; foreach (IStorePropertyBag propertyBag in this.contacts) { ContactInfoForLinkingWithPropertyBagUpdater contactInfoForLinkingWithPropertyBagUpdater = ContactInfoForLinkingWithPropertyBagUpdater.Create(this.mailboxSession, propertyBag, this.contactProperties); updateOperation(contactInfoForLinkingWithPropertyBagUpdater); list.Add(contactInfoForLinkingWithPropertyBagUpdater); if (contactInfoForLinkingWithPropertyBagUpdater.IsDirty) { flag = true; } } if (!flag) { GALLinkingFixer.Tracer.TraceDebug((long)this.personId.GetHashCode(), "GALLinkingFixer::Contact properties are up to date, no need to update contact in store or in memory."); return(true); } GALLinkingFixer.Tracer.TraceDebug((long)this.personId.GetHashCode(), "GALLinkingFixer::Contact properties are NOT up to date, update contact in store and in memory."); bool result; try { List <IStorePropertyBag> list2 = new List <IStorePropertyBag>(this.contacts.Count); MailboxInfoForLinking mailboxInfo = MailboxInfoForLinking.CreateFromMailboxSession(this.mailboxSession); ContactLinkingLogger contactLinkingLogger = new ContactLinkingLogger(sessionName, mailboxInfo); ContactLinkingPerformanceTracker contactLinkingPerformanceTracker = new ContactLinkingPerformanceTracker(this.mailboxSession); contactLinkingPerformanceTracker.Start(); contactLinkingLogger.LogEvent(operationIntentionEvent); foreach (ContactInfoForLinkingFromPropertyBag contactInfoForLinkingFromPropertyBag in list) { ContactInfoForLinkingWithPropertyBagUpdater contactInfoForLinkingWithPropertyBagUpdater2 = (ContactInfoForLinkingWithPropertyBagUpdater)contactInfoForLinkingFromPropertyBag; contactInfoForLinkingWithPropertyBagUpdater2.Commit(contactLinkingLogger, contactLinkingPerformanceTracker); list2.Add(contactInfoForLinkingWithPropertyBagUpdater2.PropertyBag); } contactLinkingPerformanceTracker.Stop(); contactLinkingLogger.LogEvent(contactLinkingPerformanceTracker.GetLogEvent()); this.contacts.Clear(); this.contacts.AddRange(list2); GALLinkingFixer.Tracer.TraceDebug((long)this.personId.GetHashCode(), "GALLinkingFixer::Contacts successfully updated in store and in memory."); result = true; } catch (StorageTransientException arg) { GALLinkingFixer.Tracer.TraceError <StorageTransientException>((long)this.personId.GetHashCode(), "Failed while fixing GAL Linking properties on the contact, exception: {0}.", arg); result = false; } catch (StoragePermanentException arg2) { GALLinkingFixer.Tracer.TraceError <StoragePermanentException>((long)this.personId.GetHashCode(), "Failed while fixing GAL Linking properties on the contact, exception: {0}.", arg2); result = false; } return(result); }
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); } }