public void SendNotification() { EmailNotificationHandler.Tracer.TraceDebug <string>((long)this.GetHashCode(), "EmailNotificationHandler.SendNotification: Processing notifications for Group {0}.", this.groupMailbox.ExternalDirectoryObjectId); IExtensibleLogger logger = MailboxAssociationDiagnosticsFrameFactory.Default.CreateLogger(this.groupMailbox.ExchangeGuid, this.groupMailbox.OrganizationId); IMailboxAssociationPerformanceTracker performanceTracker = MailboxAssociationDiagnosticsFrameFactory.Default.CreatePerformanceTracker(null); using (MailboxAssociationDiagnosticsFrameFactory.Default.CreateDiagnosticsFrame("EmailNotificationHandler", "SendNotification", logger, performanceTracker)) { GroupMailboxAccessLayerHelper.ExecuteOperationWithRetry(logger, "EmailNotificationHandler.SendNotification", delegate { using (MailboxSession session = MailboxSession.OpenAsTransport(this.exchangePrincipal, this.clientInfoString)) { EmailNotificationHandler.Tracer.TraceDebug <Guid, string>((long)this.GetHashCode(), "EmailNotificationHandler.SendNotification: Created transport session for mailbox {0}. Group {1}.", session.MailboxGuid, this.groupMailbox.ExternalDirectoryObjectId); StoreObjectId draftsFolderId = session.GetDefaultFolderId(DefaultFolderType.Drafts); while (!this.pendingRecipients.IsEmpty) { IMailboxLocator recipient; while (this.pendingRecipients.TryDequeue(out recipient)) { performanceTracker.IncrementAssociationsRead(); GroupMailboxAccessLayerHelper.ExecuteOperationWithRetry(logger, "EmailNotificationHandler.ComposeAndDeliverMessage", delegate { this.ComposeAndDeliverMessage(session, draftsFolderId, recipient, performanceTracker, logger); }, (Exception e) => !(e is StoragePermanentException) && GrayException.IsGrayException(e)); } } } }, new Predicate <Exception>(GrayException.IsGrayException)); } EmailNotificationHandler.Tracer.TraceDebug((long)this.GetHashCode(), "EmailNotificationHandler.SendNotification: Task completed."); }
public List <string> Execute() { IExtensibleLogger logger = GroupEscalationGetterDiagnosticsFrameFactory.Default.CreateLogger(this.groupSession.MailboxGuid, this.groupSession.OrganizationId); IMailboxAssociationPerformanceTracker mailboxAssociationPerformanceTracker = GroupEscalationGetterDiagnosticsFrameFactory.Default.CreatePerformanceTracker(null); List <string> result; using (GroupEscalationGetterDiagnosticsFrameFactory.Default.CreateDiagnosticsFrame("XSO", "EscalationGetter", logger, mailboxAssociationPerformanceTracker)) { StoreBuilder storeBuilder = new StoreBuilder(this.groupSession, XSOFactory.Default, logger, this.groupSession.ClientInfoString); using (IAssociationStore associationStore = storeBuilder.Create(this.group, mailboxAssociationPerformanceTracker)) { IEnumerable <IPropertyBag> associationsByType = associationStore.GetAssociationsByType("IPM.MailboxAssociation.User", MailboxAssociationBaseSchema.ShouldEscalate, EscalationGetter.EscalateProperties); List <string> list = new List <string>(); foreach (IPropertyBag propertyBag in associationsByType) { string text = propertyBag[MailboxAssociationBaseSchema.LegacyDN] as string; if (text != null) { list.Add(text); } else { EscalationGetter.Tracer.TraceError <string>((long)this.GetHashCode(), "EscalationGetter.Execute: Missing LegacyDn for item with Id {0}.", propertyBag[ItemSchema.Id].ToString()); } bool valueOrDefault = associationStore.GetValueOrDefault <bool>(propertyBag, MailboxAssociationBaseSchema.IsAutoSubscribed, false); if (valueOrDefault) { mailboxAssociationPerformanceTracker.IncrementAutoSubscribedMembers(); } } result = list; } } return(result); }
public void ReplicateQueuedAssociations() { QueuedInProcessAssociationReplicator.Tracer.TraceDebug((long)this.GetHashCode(), "MailboxTaskProcessor.ReplicateQueuedAssociations: Processing associations."); ADUser mailboxAdUser = this.mailbox.FindAdUser(); IDiagnosticsFrameFactory <IExtensibleLogger, IMailboxAssociationPerformanceTracker> diagnosticsFrameFactory = this.diagnosticsFrameFactoryCreator(); IMailboxAssociationPerformanceTracker performanceTracker = diagnosticsFrameFactory.CreatePerformanceTracker(null); IExtensibleLogger logger = diagnosticsFrameFactory.CreateLogger(mailboxAdUser.ExchangeGuid, mailboxAdUser.OrganizationId); IAssociationReplicator replicator = this.immediateReplicatorCreator(logger, performanceTracker); using (MailboxAssociationDiagnosticsFrameFactory.Default.CreateDiagnosticsFrame("QueuedInProcessAssociationReplicator", "ReplicateAssociations", logger, performanceTracker)) { bool inProcessReplicationSucceeded = true; GroupMailboxAccessLayerHelper.ExecuteOperationWithRetry(logger, "QueuedInProcessAssociationReplicator.ReplicateAssociations", delegate { IStoreBuilder storeBuilder = this.storeBuilderCreator(logger, this.clientInfoString); using (IAssociationStore associationStore = storeBuilder.Create(this.mailbox, performanceTracker)) { QueuedInProcessAssociationReplicator.Tracer.TraceDebug <string>((long)this.GetHashCode(), "QueuedInProcessAssociationReplicator.ReplicateAssociationsImplementation: Created store provider. Mailbox={0}.", mailboxAdUser.ExternalDirectoryObjectId); UserAssociationAdaptor masterAdaptor = new UserAssociationAdaptor(associationStore, this.adSession, this.mailbox); while (this.pendingAssociations.Count > 0) { MailboxAssociation association = this.pendingAssociations.Dequeue(); inProcessReplicationSucceeded &= this.ReplicateSingleAssociation(replicator, masterAdaptor, association); } if (!inProcessReplicationSucceeded) { IReplicationAssistantInvoker replicationAssistantInvoker = this.replicationAssistantInvokerCreator(logger, this.replicationServerFqdn); replicationAssistantInvoker.Invoke("QueuedInProcessAssociationReplicatorRpcReplication", masterAdaptor, new MailboxAssociation[0]); } } }, new Predicate <Exception>(GrayException.IsGrayException)); } QueuedInProcessAssociationReplicator.Tracer.TraceDebug((long)this.GetHashCode(), "MailboxTaskProcessor.SendNotificationImplementation: Task completed."); }
private bool IsGroupMemberInMailboxAssociation() { IExtensibleLogger logger = MailboxAssociationDiagnosticsFrameFactory.Default.CreateLogger(this.groupMailboxToLogon.MailboxInfo.MailboxGuid, this.organizationId); IMailboxAssociationPerformanceTracker performanceTracker = MailboxAssociationDiagnosticsFrameFactory.Default.CreatePerformanceTracker(null); bool result; using (MailboxAssociationDiagnosticsFrameFactory.Default.CreateDiagnosticsFrame("XSO", "CheckMembership", logger, performanceTracker)) { try { using (MailboxSession mailboxSession = MailboxSession.OpenAsAdmin(this.groupMailboxToLogon, CultureInfo.InvariantCulture, this.clientInfoString)) { using (IAssociationStore associationStore = this.GetAssociationStore(mailboxSession, performanceTracker)) { using (IMailboxAssociationUser memberAssociationInformation = this.GetMemberAssociationInformation(associationStore)) { result = (memberAssociationInformation != null && (bool)memberAssociationInformation[MailboxAssociationBaseSchema.IsMember]); } } } } catch (AssociationNotFoundException) { GroupMailboxAuthorizationHandler.Tracer.TraceDebug <string, string>((long)this.GetHashCode(), "MemberRetrieval: Unable to make IsMember() check for the user {0} on the mailbox {1}", this.accessingUserInfo.Identity, this.groupMailboxToLogon.MailboxInfo.DisplayName); result = false; } catch (LocalizedException) { GroupMailboxAuthorizationHandler.Tracer.TraceDebug <string, string>((long)this.GetHashCode(), "MemberRetrieval: Unable to make IsMember() check for the user {0} on the mailbox {1}", this.accessingUserInfo.Identity, this.groupMailboxToLogon.MailboxInfo.DisplayName); result = false; } } return(result); }
public List <string> Execute() { IExtensibleLogger logger = MailboxAssociationDiagnosticsFrameFactory.Default.CreateLogger(this.groupSession.MailboxGuid, this.groupSession.OrganizationId); IMailboxAssociationPerformanceTracker performanceTracker = MailboxAssociationDiagnosticsFrameFactory.Default.CreatePerformanceTracker(null); List <string> result; using (MailboxAssociationDiagnosticsFrameFactory.Default.CreateDiagnosticsFrame("XSO", "PinnersGetter", logger, performanceTracker)) { StoreBuilder storeBuilder = new StoreBuilder(this.groupSession, XSOFactory.Default, logger, this.groupSession.ClientInfoString); using (IAssociationStore associationStore = storeBuilder.Create(this.group, performanceTracker)) { IEnumerable <IPropertyBag> associationsByType = associationStore.GetAssociationsByType("IPM.MailboxAssociation.User", MailboxAssociationBaseSchema.IsPin, PinnersGetter.PinnerProperties); List <string> list = new List <string>(); foreach (IPropertyBag propertyBag in associationsByType) { string text = propertyBag[MailboxAssociationBaseSchema.LegacyDN] as string; if (text != null) { list.Add(text); } else { PinnersGetter.Tracer.TraceError <string>((long)this.GetHashCode(), "PinnersGetter.Execute: Missing LegacyDn for item with Id {0}.", propertyBag[ItemSchema.Id].ToString()); } } result = list; } } return(result); }
public InProcessAssociationReplicator(IExtensibleLogger logger, IMailboxAssociationPerformanceTracker performanceTracker, OpenAsAdminOrSystemServiceBudgetTypeType budgetType = OpenAsAdminOrSystemServiceBudgetTypeType.RunAsBackgroundLoad) { ArgumentValidator.ThrowIfNull("logger", logger); ArgumentValidator.ThrowIfNull("performanceTracker", performanceTracker); this.Logger = logger; this.PerformanceTracker = performanceTracker; this.budgetType = budgetType; }
public IAssociationStore Create(IMailboxLocator targetMailbox, IMailboxAssociationPerformanceTracker performanceTracker) { StoreBuilder.Tracer.TraceDebug <IMailboxLocator>((long)this.GetHashCode(), "StoreBuilder.Create: Instantiating Store Provider for mailbox {0}", targetMailbox); ADUser aduser = targetMailbox.FindAdUser(); MailboxSession mailboxSession = this.currentStoreSession as MailboxSession; if (mailboxSession != null) { StoreBuilder.Tracer.TraceDebug <Guid, Guid, LogonType>((long)this.GetHashCode(), "StoreBuilder.Create: Target MailboxGuid {0}. CurrentStoreSession MailboxGuid {1}. CurrentStoreSession LogonType {2}", aduser.ExchangeGuid, mailboxSession.MailboxGuid, mailboxSession.LogonType); if (mailboxSession.LogonType == LogonType.Owner || mailboxSession.LogonType == LogonType.Admin || mailboxSession.LogonType == LogonType.Transport || mailboxSession.LogonType == LogonType.SystemService) { if (mailboxSession.MailboxGuid == aduser.ExchangeGuid) { StoreBuilder.Tracer.TraceDebug((long)this.GetHashCode(), "StoreBuilder.Create: Returning CurrentStoreSession"); performanceTracker.SetMailboxSessionToTrack(mailboxSession); return(new LocalAssociationStore(targetMailbox, mailboxSession, false, this.xsoFactory, performanceTracker, this.logger)); } } else { StoreBuilder.Tracer.TraceDebug((long)this.GetHashCode(), "StoreBuilder.Create: Can't use CurrentStoreSession as LogonType is unknown"); } } Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); performanceTracker.SetNewSessionRequired(true); ExchangePrincipal exchangePrincipal = ExchangePrincipal.FromADUser(aduser, null); StoreBuilder.Tracer.TraceDebug <string, string>((long)this.GetHashCode(), "StoreBuilder.Create: TargetMailbox location {0}. Current Server Name: {1}.", exchangePrincipal.MailboxInfo.Location.ServerFqdn, LocalServerCache.LocalServerFqdn); if (exchangePrincipal.MailboxInfo.Location.ServerFqdn.Equals(LocalServerCache.LocalServerFqdn, StringComparison.OrdinalIgnoreCase)) { MailboxSession mailboxSession2 = MailboxSession.OpenAsAdmin(exchangePrincipal, CultureInfo.InvariantCulture, this.clientInfoString); StoreBuilder.Tracer.TraceDebug((long)this.GetHashCode(), "StoreBuilder.Create: Returning new Admin session"); stopwatch.Stop(); performanceTracker.SetNewSessionLatency(stopwatch.ElapsedMilliseconds); performanceTracker.SetMailboxSessionToTrack(mailboxSession2); return(new LocalAssociationStore(targetMailbox, mailboxSession2, true, this.xsoFactory, performanceTracker, this.logger)); } stopwatch.Stop(); performanceTracker.SetNewSessionLatency(stopwatch.ElapsedMilliseconds); performanceTracker.SetNewSessionWrongServer(true); throw new WrongServerException(ServerStrings.IncorrectServerError(aduser.PrimarySmtpAddress, exchangePrincipal.MailboxInfo.Location.ServerFqdn), aduser.ExchangeGuid, exchangePrincipal.MailboxInfo.Location.ServerFqdn, exchangePrincipal.MailboxInfo.Location.ServerVersion, null); }
public void Execute(Action <MailboxAssociationFromStore, IAssociationAdaptor, ADUser, IExtensibleLogger> task) { IExtensibleLogger logger = MailboxAssociationDiagnosticsFrameFactory.Default.CreateLogger(this.mailbox.ExchangeGuid, this.mailbox.OrganizationId); IMailboxAssociationPerformanceTracker performanceTracker = MailboxAssociationDiagnosticsFrameFactory.Default.CreatePerformanceTracker(null); using (MailboxAssociationDiagnosticsFrameFactory.Default.CreateDiagnosticsFrame("MailboxAssociationContext.Execute", this.clientInfoString, logger, performanceTracker)) { StoreBuilder storeBuilder = new StoreBuilder(null, XSOFactory.Default, logger, this.clientInfoString); GroupMailboxAccessLayer groupMailboxAccessLayer = new GroupMailboxAccessLayer(this.adSession, storeBuilder, performanceTracker, logger, this.clientInfoString); MailboxLocator mailboxLocator = this.groupMailboxAccessLayerFactory.CreateMasterLocator(); using (IAssociationStore associationStore = storeBuilder.Create(mailboxLocator, groupMailboxAccessLayer.PerformanceTracker)) { BaseAssociationAdaptor associationAdaptor = this.groupMailboxAccessLayerFactory.CreateAssociationAdaptor(mailboxLocator, associationStore); if (this.associationId.AssociationIdType == null) { this.ExecuteForAllAssociations(task, associationAdaptor, logger); } else { this.ExecuteForSingleAssociation(task, associationAdaptor, logger); } } } }
private void ComposeAndDeliverMessage(MailboxSession session, StoreObjectId draftsFolderId, IMailboxLocator recipient, IMailboxAssociationPerformanceTracker performanceTracker, IExtensibleLogger logger) { EmailNotificationHandler.Tracer.TraceDebug <IMailboxLocator, string>((long)this.GetHashCode(), "EmailNotificationHandler.ComposeAndDeliverMessage: Processing recipient {0}. Group {1}.", recipient, this.groupMailbox.ExternalDirectoryObjectId); using (MessageItem messageItem = MessageItem.Create(session, draftsFolderId)) { ADUser recipient2 = recipient.FindAdUser(); IMessageComposer messageComposer = this.messageComposerBuilder.Build(recipient2); messageComposer.WriteToMessage(messageItem); bool flag = false; if (this.groupMailbox.WhenCreatedUTC != null) { TimeSpan timeSpan = DateTime.UtcNow - this.groupMailbox.WhenCreatedUTC.Value; if (timeSpan < EmailNotificationHandler.DelaySendTime) { messageItem[MessageItemSchema.DeferredSendTime] = DateTime.UtcNow + EmailNotificationHandler.DelaySendTime - timeSpan; flag = true; } } else { messageItem[MessageItemSchema.DeferredSendTime] = DateTime.UtcNow + EmailNotificationHandler.DelaySendTime; flag = true; } if (flag) { logger.LogEvent(new SchemaBasedLogEvent <MailboxAssociationLogSchema.Warning> { { MailboxAssociationLogSchema.Warning.Context, "EmailNotificationHandler" }, { MailboxAssociationLogSchema.Warning.Message, string.Format("Welcome email for recipient {0}, Group {1} is delayed to send", recipient, this.groupMailbox.ExternalDirectoryObjectId) } }); EmailNotificationHandler.Tracer.TraceDebug <IMailboxLocator, string>((long)this.GetHashCode(), "EmailNotificationHandler.ComposeAndDeliverMessage: Welcome email for recipient {0}, Group {1} is delayed to send.", recipient, this.groupMailbox.ExternalDirectoryObjectId); } StoreObjectId saveSentMessageFolder = session.GetDefaultFolderId(DefaultFolderType.TemporarySaves) ?? session.CreateDefaultFolder(DefaultFolderType.TemporarySaves); messageItem.Send(saveSentMessageFolder, SubmitMessageFlags.IgnoreSendAsRight); performanceTracker.IncrementAssociationsUpdated(); } }
private LocalAssociationStore GetAssociationStore(MailboxSession adminMailboxSession, IMailboxAssociationPerformanceTracker performanceTracker) { IRecipientSession adrecipientSession = adminMailboxSession.GetADRecipientSession(true, ConsistencyMode.IgnoreInvalid); IMailboxLocator mailboxLocator = new GroupMailboxLocator(adrecipientSession, this.groupMailboxToLogon.ExternalDirectoryObjectId, this.groupMailboxToLogon.LegacyDn); return(new LocalAssociationStore(mailboxLocator, adminMailboxSession, false, new XSOFactory(), performanceTracker, MailboxAssociationDiagnosticsFrameFactory.Default.CreateLogger(this.groupMailboxToLogon.MailboxInfo.MailboxGuid, this.organizationId))); }
internal GroupMailboxAccessLayer(IRecipientSession adSession, IStoreBuilder storeProviderBuilder, IMailboxAssociationPerformanceTracker performanceTracker, IExtensibleLogger logger, string clientString) { ArgumentValidator.ThrowIfNull("adSession", adSession); ArgumentValidator.ThrowIfNull("storeProviderBuilder", storeProviderBuilder); ArgumentValidator.ThrowIfNull("performanceTracker", performanceTracker); ArgumentValidator.ThrowIfNull("logger", logger); this.adSession = adSession; this.storeProviderBuilder = storeProviderBuilder; this.PerformanceTracker = performanceTracker; this.Logger = logger; this.mailboxCollectionBuilder = new MailboxCollectionBuilder(adSession); this.clientString = clientString; }
public SetGroupPinState(IExtensibleLogger logger, IAssociationReplicator associationReplicator, bool pin, IGroupAssociationAdaptor masterAdaptor, GroupMailboxLocator itemLocator, IMailboxAssociationPerformanceTracker performanceTracker = null, bool isModernGroupsNewArchitecture = false) : base(logger, masterAdaptor, new IMailboxLocator[] { itemLocator }) { this.associationReplicator = associationReplicator; this.pin = pin; this.performanceTracker = performanceTracker; this.isModernGroupsNewArchitecture = isModernGroupsNewArchitecture; }
public PriorityReplicator(IExtensibleLogger logger, IMailboxAssociationPerformanceTracker performanceTracker, string replicationServerFqdn, IMailboxLocator priorityLocator) : this(new InProcessAssociationReplicator(logger, performanceTracker, OpenAsAdminOrSystemServiceBudgetTypeType.RunAsBackgroundLoad), new RpcAssociationReplicator(logger, replicationServerFqdn), priorityLocator) { }
public LocalAssociationStore(IMailboxLocator mailboxLocator, IMailboxSession session, bool shouldDisposeSession, IXSOFactory xsoFactory, IMailboxAssociationPerformanceTracker performanceTracker, IExtensibleLogger logger) { ArgumentValidator.ThrowIfNull("mailboxLocator", mailboxLocator); ArgumentValidator.ThrowIfNull("session", session); ArgumentValidator.ThrowIfNull("xsoFactory", xsoFactory); ArgumentValidator.ThrowIfNull("performanceTracker", performanceTracker); ArgumentValidator.ThrowIfNull("logger", logger); this.mailboxLocator = mailboxLocator; this.session = session; this.shouldDisposeSession = shouldDisposeSession; this.xsoFactory = xsoFactory; this.performanceTracker = performanceTracker; this.logger = logger; this.disposeTracker = this.GetDisposeTracker(); this.mailboxAssociationFolder = new LazilyInitialized <IFolder>(new Func <IFolder>(this.GetOrCreateDefaultAssociationsFolder)); }