private static bool IsDeliveryFolderInteresting(OriginalDeliveryFolderInfo deliveryFolderInfo) { if (deliveryFolderInfo.FolderType == OriginalDeliveryFolderInfo.DeliveryFolderType.Inbox || deliveryFolderInfo.FolderType == OriginalDeliveryFolderInfo.DeliveryFolderType.Clutter) { return(true); } InferenceClassificationProcessing.NumberOfItemsSkippedDueToDeliveryFolder.Increment(); InferenceClassificationProcessing.NumberOfItemsSkipped.Increment(); return(false); }
public void OnPromotedMessageHandler(StoreDriverEventSource source, StoreDriverDeliveryEventArgs args) { this.wasMessageDelivered = false; this.logValues = null; StoreDriverDeliveryEventArgsImpl storeDriverDeliveryEventArgsImpl = (StoreDriverDeliveryEventArgsImpl)args; Stopwatch stopwatch = Stopwatch.StartNew(); InferencePropertyBag inferencePropertyBag = new InferencePropertyBag(); MdbDocument mdbDocument = null; VariantConfigurationSnapshot variantConfigurationSnapshot = null; try { InferenceClassificationAgent.tracer.TraceDebug(0L, "Called InferenceClassificationAgent.OnPromotedMessageHandler"); inferencePropertyBag.Add(InferenceSchema.MessageClassificationTime, ExDateTime.UtcNow); inferencePropertyBag.Add(InferenceSchema.ServerName, this.server.Name); if (storeDriverDeliveryEventArgsImpl.MailboxSession != null) { inferencePropertyBag.Add(DocumentSchema.MailboxId, storeDriverDeliveryEventArgsImpl.MailboxSession.MailboxGuid.ToString()); inferencePropertyBag.Add(InferenceSchema.ClutterEnabled, storeDriverDeliveryEventArgsImpl.MailboxSession.Mailbox.GetValueOrDefault <bool>(MailboxSchema.InferenceClutterEnabled, false)); inferencePropertyBag.Add(InferenceSchema.ClassificationEnabled, storeDriverDeliveryEventArgsImpl.MailboxSession.Mailbox.GetValueOrDefault <bool>(MailboxSchema.InferenceClassificationEnabled, false)); inferencePropertyBag.Add(InferenceSchema.HasBeenClutterInvited, storeDriverDeliveryEventArgsImpl.MailboxSession.Mailbox.GetValueOrDefault <bool>(MailboxSchema.InferenceHasBeenClutterInvited, false)); } inferencePropertyBag.Add(InferenceSchema.InternetMessageId, storeDriverDeliveryEventArgsImpl.ReplayItem.InternetMessageId); inferencePropertyBag.Add(InferenceSchema.Locale, InferenceClassificationAgent.GetLocale(storeDriverDeliveryEventArgsImpl)); if (storeDriverDeliveryEventArgsImpl.MailboxOwner != null && storeDriverDeliveryEventArgsImpl.MailboxOwner.OrganizationId != null && storeDriverDeliveryEventArgsImpl.MailboxOwner.OrganizationId.OrganizationalUnit != null) { inferencePropertyBag.Add(InferenceSchema.TenantName, storeDriverDeliveryEventArgsImpl.MailboxOwner.OrganizationId.OrganizationalUnit.Name); } if (!InferenceClassificationAgent.IsMailboxInteresting(storeDriverDeliveryEventArgsImpl)) { inferencePropertyBag.Add(InferenceSchema.ClassificationStatus, InferenceClassificationAgentLogger.Status.Skipped); inferencePropertyBag.Add(InferenceSchema.ClassificationStatusMessage, "MailboxNotInteresting"); } else if (!InferenceClassificationAgent.IsMessageInteresting(storeDriverDeliveryEventArgsImpl)) { inferencePropertyBag.Add(InferenceSchema.ClassificationStatus, InferenceClassificationAgentLogger.Status.Skipped); inferencePropertyBag.Add(InferenceSchema.ClassificationStatusMessage, "MessageNotInteresting"); } else { storeDriverDeliveryEventArgsImpl.PropertiesForAllMessageCopies = (storeDriverDeliveryEventArgsImpl.PropertiesForAllMessageCopies ?? new Dictionary <PropertyDefinition, object>()); Guid guid = Guid.NewGuid(); storeDriverDeliveryEventArgsImpl.PropertiesForAllMessageCopies[MessageItemSchema.InferenceMessageIdentifier] = guid; inferencePropertyBag.Add(InferenceSchema.MessageIdentifier, guid); variantConfigurationSnapshot = FlightModule.GetFlightFeatures(storeDriverDeliveryEventArgsImpl.MailboxOwner); if (variantConfigurationSnapshot != null) { inferencePropertyBag.Add(InferenceSchema.UserFlightFeatures, variantConfigurationSnapshot); } IDeliveryClassificationStrategy deliveryClassificationStrategy = ClassificationStrategyFactory.Create(storeDriverDeliveryEventArgsImpl.MailboxSession, variantConfigurationSnapshot); inferencePropertyBag.Add(InferenceSchema.IsUiEnabled, deliveryClassificationStrategy != null); OriginalDeliveryFolderInfo originalDeliveryFolderInfo = InferenceClassificationAgent.GetOriginalDeliveryFolderInfo(storeDriverDeliveryEventArgsImpl); storeDriverDeliveryEventArgsImpl.PropertiesForAllMessageCopies[ItemSchema.OriginalDeliveryFolderInfo] = originalDeliveryFolderInfo.Serialize(); inferencePropertyBag.Add(InferenceSchema.OriginalDeliveryFolder, originalDeliveryFolderInfo); if (!InferenceClassificationAgent.IsDeliveryFolderInteresting(originalDeliveryFolderInfo)) { inferencePropertyBag.Add(InferenceSchema.ClassificationStatus, InferenceClassificationAgentLogger.Status.Skipped); inferencePropertyBag.Add(InferenceSchema.ClassificationStatusMessage, "DeliveryFolderNotInteresting"); } else if (!this.isPipelineEnabled) { inferencePropertyBag.Add(InferenceSchema.ClassificationStatus, InferenceClassificationAgentLogger.Status.Failed); inferencePropertyBag.Add(InferenceSchema.ClassificationStatusMessage, "PipelineDisabled"); InferenceClassificationProcessing.NumberOfItemsSkippedDueToDisabledPipeline.Increment(); } else { ConversationClutterInformation conversationClutterInformation = null; bool flag = false; InferenceClassificationResult inferenceClassificationResult = InferenceClassificationResult.None; if (this.RunClassificationPipeline(storeDriverDeliveryEventArgsImpl, inferencePropertyBag, variantConfigurationSnapshot, out mdbDocument, out flag, out conversationClutterInformation)) { if (flag) { inferenceClassificationResult |= InferenceClassificationResult.IsClutterModel; } string value = string.Empty; bool flag2 = false; bool flag3; InferenceClassificationResult inferenceClassificationResult2; string text; bool flag4; if (InferenceClassificationAgent.CheckForRuleAndConversationOverrides(storeDriverDeliveryEventArgsImpl.SharedPropertiesBetweenAgents, originalDeliveryFolderInfo, out flag3, out inferenceClassificationResult2, out text, out flag4)) { flag = flag3; value = text; } inferenceClassificationResult |= inferenceClassificationResult2; if (flag4 && conversationClutterInformation != null) { flag = conversationClutterInformation.IsNewMessageClutter(flag, out flag2); } inferencePropertyBag.Add(InferenceSchema.IsClutter, flag); if (flag) { inferenceClassificationResult |= InferenceClassificationResult.IsClutterFinal; } if (deliveryClassificationStrategy != null) { deliveryClassificationStrategy.ApplyClassification(storeDriverDeliveryEventArgsImpl, inferenceClassificationResult); if (flag2 && conversationClutterInformation != null) { conversationClutterInformation.MarkItemsAsNotClutter(); } } storeDriverDeliveryEventArgsImpl.PropertiesForAllMessageCopies[ItemSchema.InferenceClassificationResult] = inferenceClassificationResult; inferencePropertyBag.Add(InferenceSchema.InferenceClassificationResult, inferenceClassificationResult); inferencePropertyBag.Add(InferenceSchema.ClassificationStatus, InferenceClassificationAgentLogger.Status.Succeeded); inferencePropertyBag.Add(InferenceSchema.ClassificationStatusMessage, value); } } } } catch (Exception ex) { if (ex is OutOfMemoryException || ex is StackOverflowException || ex is ThreadAbortException) { throw; } Exception innerException = ex.InnerException; if (innerException is StorageTransientException) { InferenceClassificationProcessing.NumberOfTransientExceptions.Increment(); } else if (innerException is QuotaExceededException) { InferenceClassificationProcessing.NumberOfQuotaExceededExceptions.Increment(); } this.diagnosticsSession.LogDiagnosticsInfo(DiagnosticsLoggingTag.Failures, "Received exception {0}", new object[] { ex }); inferencePropertyBag.Add(InferenceSchema.ClassificationStatus, InferenceClassificationAgentLogger.Status.Failed); inferencePropertyBag.Add(InferenceSchema.ClassificationStatusMessage, "Exception"); inferencePropertyBag.Add(InferenceSchema.ClassificationAgentException, ex); } finally { stopwatch.Stop(); InferenceClassificationAgent.tracer.TraceDebug <long>((long)this.GetHashCode(), "InferenceClassification agent took {0} ms to process the item.", stopwatch.ElapsedMilliseconds); inferencePropertyBag.Add(InferenceSchema.TimeTakenToClassify, stopwatch.ElapsedMilliseconds); if (storeDriverDeliveryEventArgsImpl.MailboxSession != null) { InferenceClassificationAgent.RecordPerformanceCounter(storeDriverDeliveryEventArgsImpl.MailboxSession.MdbGuid.ToString(), stopwatch.ElapsedMilliseconds); } InferenceClassificationTracking inferenceClassificationTracking = InferenceClassificationTracking.Create(); this.logValues = this.classificationAgentLogger.ExtractClassificationProperties(inferencePropertyBag, mdbDocument, inferenceClassificationTracking); if (variantConfigurationSnapshot != null && variantConfigurationSnapshot.Inference.InferenceStampTracking.Enabled) { storeDriverDeliveryEventArgsImpl.PropertiesForAllMessageCopies[MessageItemSchema.InferenceClassificationTrackingEx] = inferenceClassificationTracking.ToString(); } if (mdbDocument != null) { mdbDocument.Dispose(); mdbDocument = null; } } }
private static bool CheckForRuleAndConversationOverrides(Dictionary <PropertyDefinition, object> sharedPropertiesBetweenAgents, OriginalDeliveryFolderInfo deliveryFolderInfo, out bool isClutter, out InferenceClassificationResult classificationResult, out string overrideMessage, out bool isConversationFixupNeeded) { isClutter = false; isConversationFixupNeeded = true; classificationResult = InferenceClassificationResult.None; overrideMessage = string.Empty; if (sharedPropertiesBetweenAgents == null) { return(false); } if (sharedPropertiesBetweenAgents.ContainsKey(ItemSchema.InferenceConversationClutterActionApplied)) { isClutter = (bool)sharedPropertiesBetweenAgents[ItemSchema.InferenceConversationClutterActionApplied]; classificationResult = InferenceClassificationResult.ConversationActionOverride; overrideMessage = "OverriddenByConversationClutterAction"; isConversationFixupNeeded = false; return(true); } if (sharedPropertiesBetweenAgents.ContainsKey(ItemSchema.InferenceNeverClutterOverrideApplied)) { isClutter = false; classificationResult |= InferenceClassificationResult.NeverClutterOverride; overrideMessage = "OverriddenByNeverClutterRule"; isConversationFixupNeeded = true; return(true); } bool flag = sharedPropertiesBetweenAgents.ContainsKey(ItemSchema.ItemMovedByRule) && (bool)sharedPropertiesBetweenAgents[ItemSchema.ItemMovedByRule]; bool flag2 = sharedPropertiesBetweenAgents.ContainsKey(ItemSchema.ItemMovedByConversationAction) && (bool)sharedPropertiesBetweenAgents[ItemSchema.ItemMovedByConversationAction]; if (flag2 && deliveryFolderInfo.IsDeliveryFolderInbox) { isClutter = false; classificationResult = InferenceClassificationResult.NeverClutterOverride; overrideMessage = "OverriddenByNeverClutterConversationAction"; isConversationFixupNeeded = false; return(true); } if (flag2 && deliveryFolderInfo.IsDeliveryFolderClutter) { isClutter = true; classificationResult = InferenceClassificationResult.AlwaysClutterOverride; overrideMessage = "OverriddenByAlwaysClutterConversationAction"; isConversationFixupNeeded = false; return(true); } if (flag && deliveryFolderInfo.IsDeliveryFolderInbox) { isClutter = false; classificationResult = InferenceClassificationResult.NeverClutterOverride; overrideMessage = "OverriddenByNeverClutterRule"; isConversationFixupNeeded = true; return(true); } if (flag && deliveryFolderInfo.IsDeliveryFolderClutter) { isClutter = true; classificationResult = InferenceClassificationResult.AlwaysClutterOverride; overrideMessage = "OverriddenByAlwaysClutterRule"; isConversationFixupNeeded = false; return(true); } object obj; if (sharedPropertiesBetweenAgents.TryGetValue(ItemSchema.IsStopProcessingRuleApplicable, out obj) && (bool)obj) { classificationResult = InferenceClassificationResult.StopProcessingRulesOverride; return(false); } return(false); }