internal static string CreateAttachmentsSignal(MessageItem messageItem, List <Dictionary <string, string> > attachmentsProperties, string receiverEmail, Guid tenantId)
        {
            List <AnalyticsSignal>      list        = new List <AnalyticsSignal>();
            Dictionary <string, string> properties  = new Dictionary <string, string>();
            Dictionary <string, string> properties2 = new Dictionary <string, string>
            {
                {
                    "Context",
                    "ReceivedRegularAttachment"
                }
            };

            AnalyticsSignal.AnalyticsActor actor = new AnalyticsSignal.AnalyticsActor
            {
                Id         = receiverEmail,
                Properties = SharePointSignalRestDataProvider.CreateSignalProperties(properties),
                TenantId   = tenantId
            };
            AnalyticsSignal.AnalyticsAction action = new AnalyticsSignal.AnalyticsAction
            {
                ActionType = "Received",
                Properties = SharePointSignalRestDataProvider.CreateSignalProperties(properties2)
            };
            StringBuilder stringBuilder = new StringBuilder();

            for (int i = 0; i < messageItem.Recipients.Count; i++)
            {
                stringBuilder.AppendFormat("{0}|{1}", messageItem.Recipients[i].Participant.DisplayName, messageItem.Recipients[i].Participant.SmtpEmailAddress);
                if (i < messageItem.Recipients.Count - 1)
                {
                    stringBuilder.Append(",");
                }
            }
            Dictionary <string, string> dictionary = new Dictionary <string, string>
            {
                {
                    "ConversationId",
                    OfficeGraphAgentUtils.GetCoversationIdBase64(messageItem)
                },
                {
                    "ConversationTopic",
                    messageItem.ConversationTopic
                },
                {
                    "CreationTime",
                    messageItem.CreationTime.ToISOString()
                },
                {
                    "FromDisplayName",
                    messageItem.From.DisplayName
                },
                {
                    "FromEmail",
                    messageItem.From.SmtpEmailAddress
                },
                {
                    "Subject",
                    messageItem.Subject
                },
                {
                    "Importance",
                    messageItem.Importance.ToString()
                },
                {
                    "MailPreview",
                    messageItem.Preview
                },
                {
                    "Recipients",
                    stringBuilder.ToString()
                },
                {
                    "StoreObjectId",
                    messageItem.StoreObjectId.ToBase64String()
                }
            };

            foreach (Dictionary <string, string> dictionary2 in attachmentsProperties)
            {
                Dictionary <string, string> dictionary3 = new Dictionary <string, string>();
                foreach (KeyValuePair <string, string> keyValuePair in dictionary)
                {
                    dictionary3.Add(keyValuePair.Key, keyValuePair.Value);
                }
                foreach (KeyValuePair <string, string> keyValuePair2 in dictionary2)
                {
                    dictionary3.Add(keyValuePair2.Key, keyValuePair2.Value);
                }
                AnalyticsSignal.AnalyticsItem item = new AnalyticsSignal.AnalyticsItem
                {
                    Id         = dictionary2["AttachmentId"],
                    Properties = SharePointSignalRestDataProvider.CreateSignalProperties(dictionary3)
                };
                AnalyticsSignal item2 = new AnalyticsSignal
                {
                    Actor  = actor,
                    Action = action,
                    Item   = item,
                    Source = "Exchange Office Graph Delivery Agent"
                };
                list.Add(item2);
            }
            Dictionary <string, object> dictionary4 = new Dictionary <string, object>();

            dictionary4["signals"] = list;
            return(new JavaScriptSerializer().Serialize(dictionary4));
        }
        internal static string GetCoversationIdBase64(MessageItem messageItem)
        {
            ConversationId conversationId = (ConversationId)OfficeGraphAgentUtils.GetPropertyFromMessage(messageItem, ItemSchema.ConversationId, string.Empty);

            return(conversationId.ToBase64String());
        }
Esempio n. 3
0
 public void DeliveredMessageEventHandler(StoreDriverEventSource source, StoreDriverDeliveryEventArgs args)
 {
     try
     {
         StoreDriverDeliveryEventArgsImpl storeDriverDeliveryEventArgsImpl = args as StoreDriverDeliveryEventArgsImpl;
         if (storeDriverDeliveryEventArgsImpl != null && this.IsInputValid(storeDriverDeliveryEventArgsImpl))
         {
             VariantConfigurationSnapshot snapshot = VariantConfiguration.GetSnapshot(storeDriverDeliveryEventArgsImpl.MailboxOwner.GetContext(null), null, null);
             if (snapshot.OfficeGraph.OfficeGraphAgent.Enabled)
             {
                 OfficeGraph.ItemsSeen.Increment();
                 bool flag = false;
                 OfficeGraphSignalType signalType = OfficeGraphSignalType.Attachment;
                 string   signal  = string.Empty;
                 bool     enabled = snapshot.OfficeGraph.OfficeGraphGenerateSignals.Enabled;
                 DateTime utcNow  = DateTime.UtcNow;
                 storeDriverDeliveryEventArgsImpl.MessageItem.Load();
                 string sharePointUrl;
                 List <Dictionary <string, string> > attachmentsProperties;
                 if (this.IsInterestingMailWithAttachments(storeDriverDeliveryEventArgsImpl.MessageItem, storeDriverDeliveryEventArgsImpl.MailboxSession, out sharePointUrl, out attachmentsProperties))
                 {
                     OfficeGraph.ItemsFilteredTotal.Increment();
                     if (enabled)
                     {
                         signal     = OfficeGraphAgentUtils.CreateAttachmentsSignal(storeDriverDeliveryEventArgsImpl.MessageItem, attachmentsProperties, storeDriverDeliveryEventArgsImpl.MailboxOwner.PrimarySmtpAddress.ToString(), storeDriverDeliveryEventArgsImpl.MailItem.TenantId);
                         signalType = OfficeGraphSignalType.Attachment;
                         flag       = true;
                     }
                     else
                     {
                         OfficeGraphAgent.tracer.TraceDebug((long)this.traceId, "Skipped generating signal since feature disabled.");
                     }
                 }
                 else
                 {
                     OfficeGraphAgent.tracer.TraceDebug((long)this.traceId, "Skipped item since it did not pass filter criteria.");
                 }
                 if (flag)
                 {
                     TimeSpan timeSpan = DateTime.UtcNow - utcNow;
                     OfficeGraph.LastSignalCreationTime.RawValue = (long)timeSpan.TotalMilliseconds;
                     OfficeGraph.AverageSignalCreationTime.IncrementBy((long)timeSpan.TotalMilliseconds);
                     OfficeGraph.AverageSignalCreationTimeBase.Increment();
                     utcNow = DateTime.UtcNow;
                     byte[] bytes          = storeDriverDeliveryEventArgsImpl.MailboxSession.OrganizationId.GetBytes(Encoding.ASCII);
                     string organizationId = Convert.ToBase64String(bytes);
                     OfficeGraphLog.LogSignal(signalType, signal, organizationId, sharePointUrl);
                     timeSpan = DateTime.UtcNow - utcNow;
                     OfficeGraph.LastSignalPersistingTime.RawValue = (long)timeSpan.TotalMilliseconds;
                     OfficeGraph.AverageSignalPersistingTime.IncrementBy((long)timeSpan.TotalMilliseconds);
                     OfficeGraph.AverageSignalPersistingTimeBase.Increment();
                     OfficeGraph.SignalPersisted.Increment();
                 }
             }
             else
             {
                 OfficeGraphAgent.tracer.TraceDebug((long)this.traceId, "Skipped item since agent is disabled.");
             }
         }
     }
     catch (Exception ex)
     {
         OfficeGraph.TotalExceptions.Increment();
         OfficeGraphAgent.tracer.TraceError <Exception>((long)this.traceId, "OfficeGraphAgent.DeliveredMessageEventHandler encountered an exception: {0}", ex);
         StoreDriverDeliveryDiagnostics.LogEvent(MailboxTransportEventLogConstants.Tuple_OfficeGraphAgentException, ex.Message, new object[]
         {
             ex
         });
     }
 }