コード例 #1
0
 private static bool IsMessageInteresting(StoreDriverDeliveryEventArgsImpl argsImpl)
 {
     if (!InferenceClassificationAgent.IsObjectClassInteresting(argsImpl.MessageClass) || argsImpl.IsJournalReport)
     {
         InferenceClassificationProcessing.NumberOfItemsSkipped.Increment();
         return(false);
     }
     return(true);
 }
コード例 #2
0
        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;
                }
            }
        }
コード例 #3
0
        internal bool RunClassificationPipeline(StoreDriverDeliveryEventArgsImpl argsImpl, InferencePropertyBag classificationDiagnostics, VariantConfigurationSnapshot flightFeatures, out MdbDocument document, out bool isClutter, out ConversationClutterInformation conversationClutterInformation)
        {
            document  = null;
            isClutter = false;
            conversationClutterInformation = null;
            InferenceClassificationAgent.tracer.TraceDebug((long)this.GetHashCode(), "Processing incoming message");
            ModelVersionBreadCrumb breadCrumb      = ClutterUtilities.GetModelVersionBreadCrumb(argsImpl.MailboxSession);
            ModelVersionSelector   versionSelector = new ModelVersionSelector(this.modelConfiguration, breadCrumb, delegate(string str)
            {
                this.diagnosticsSession.TraceDebug(str, new object[0]);
            });

            if (versionSelector.ClassificationModelVersion.Version == -2147483648)
            {
                classificationDiagnostics.Add(InferenceSchema.ClassificationStatus, InferenceClassificationAgentLogger.Status.Skipped);
                classificationDiagnostics.Add(InferenceSchema.ClassificationStatusMessage, "ClassificationModelNotFound");
                return(false);
            }
            MdbInferenceRecipient ownerAsInferenceRecipient;

            if (string.Equals(argsImpl.MailboxSession.MailboxOwner.MailboxInfo.DisplayName, argsImpl.MailboxSession.MailboxOwner.LegacyDn, StringComparison.OrdinalIgnoreCase))
            {
                ownerAsInferenceRecipient = new MdbInferenceRecipient(argsImpl.MailboxSession.MailboxOwner, argsImpl.MailboxSession.Culture, argsImpl.MailboxOwner.DisplayName);
            }
            else
            {
                ownerAsInferenceRecipient = new MdbInferenceRecipient(argsImpl.MailboxSession.MailboxOwner, argsImpl.MailboxSession.Culture, null);
            }
            bool?conversationLoadRequired = null;

            if (argsImpl.SharedPropertiesBetweenAgents != null && argsImpl.SharedPropertiesBetweenAgents.ContainsKey(ItemSchema.ConversationLoadRequiredByInference))
            {
                conversationLoadRequired = new bool?((bool)argsImpl.SharedPropertiesBetweenAgents[ItemSchema.ConversationLoadRequiredByInference]);
            }
            DocumentProcessingContext  processingContext          = new DocumentProcessingContext(argsImpl.MailboxSession);
            MdbCompositeItemIdentity   mdbCompositeItemIdentity   = new MdbCompositeItemIdentity(argsImpl.MailboxSession.MdbGuid, argsImpl.MailboxSession.MailboxGuid, StoreObjectId.DummyId, 1);
            MdbInMemoryDocumentAdapter mdbInMemoryDocumentAdapter = new MdbInMemoryDocumentAdapter(mdbCompositeItemIdentity, argsImpl.ReplayItem, MdbInferencePropertyMap.Instance);

            document = new MdbDocument(mdbCompositeItemIdentity, DocumentOperation.Insert, mdbInMemoryDocumentAdapter);
            object uniqueBodyWords;

            document.TryGetProperty(InferenceSchema.UniqueBodyWordsFromProvider, out uniqueBodyWords);
            this.ProcessClassificationDocument(document, classificationDiagnostics, versionSelector.ClassificationModelVersion, processingContext, ownerAsInferenceRecipient, breadCrumb, flightFeatures, uniqueBodyWords, conversationLoadRequired);
            IItem inMemoryItem = mdbInMemoryDocumentAdapter.InMemoryItem;

            if (inMemoryItem == null)
            {
                InferenceClassificationAgent.tracer.TraceError((long)this.GetHashCode(), "The InMemoryItem of the inMemDocAdapter was null");
                classificationDiagnostics.Add(InferenceSchema.ClassificationStatus, InferenceClassificationAgentLogger.Status.Skipped);
                classificationDiagnostics.Add(InferenceSchema.ClassificationStatusMessage, "InMemoryItemNull");
                return(false);
            }
            object obj;

            if (document.TryGetProperty(InferenceSchema.ConversationClutterInformation, out obj))
            {
                conversationClutterInformation = (obj as ConversationClutterInformation);
            }
            classificationDiagnostics.Add(InferenceSchema.ConversationClutterInformation, conversationClutterInformation);
            classificationDiagnostics.Add(InferenceSchema.MarkedAsBulk, InferenceClassificationAgent.IsBulkMail(argsImpl, argsImpl.MailboxOwner));
            isClutter = document.GetProperty <bool>(InferenceSchema.ComputedClutterValue);
            foreach (StorePropertyDefinition propertyDefinition in InferenceClassificationAgent.PropertiesToReplicate)
            {
                InferenceClassificationAgent.CopyIfValid(propertyDefinition, inMemoryItem, argsImpl.PropertiesForAllMessageCopies);
            }
            if (this.classificationComparisonLogger != null && flightFeatures != null && flightFeatures.Inference.InferenceModelComparison.Enabled)
            {
                IEnumerable <int> enumerable = from entry in versionSelector.TrainingModelVersions
                                               where entry.Version != versionSelector.ClassificationModelVersion.Version && (breadCrumb.Contains((short)entry.Version, ModelVersionBreadCrumb.VersionType.Ready) || breadCrumb.Contains((short)entry.Version, ModelVersionBreadCrumb.VersionType.NotReady))
                                               select entry.Version;
                if (enumerable != null && enumerable.Any <int>())
                {
                    Dictionary <OrderedFeatureSet, FeatureValues> dictionary = new Dictionary <OrderedFeatureSet, FeatureValues>();
                    dictionary.Add(ModelConfiguration.GetModelVersionConfiguration(versionSelector.ClassificationModelVersion.Version).FeatureSet, document.GetProperty <FeatureValues>(InferenceSchema.ImportanceFeatureValues));
                    this.classificationComparisonLogger.LogModelComparisonData(document, classificationDiagnostics);
                    foreach (int comparisonVersion in enumerable)
                    {
                        MdbDocument          mdbDocument          = new MdbDocument(mdbCompositeItemIdentity, DocumentOperation.Insert, mdbInMemoryDocumentAdapter);
                        InferencePropertyBag inferencePropertyBag = new InferencePropertyBag();
                        this.ProcessClassificationDocumentForComparisonModel(mdbDocument, inferencePropertyBag, comparisonVersion, document, classificationDiagnostics, dictionary, processingContext, ownerAsInferenceRecipient, breadCrumb, flightFeatures, uniqueBodyWords, conversationLoadRequired);
                        this.classificationComparisonLogger.LogModelComparisonData(mdbDocument, inferencePropertyBag);
                    }
                }
            }
            return(true);
        }