Beispiel #1
0
        private void LogAppInsightsEvent(Microsoft.Bot.Connector.Activity activity)
        {
            try
            {
                var            tc  = new TelemetryClient();
                EventTelemetry evt = new EventTelemetry();
                evt.Properties.Add("ConversationId", activity.Conversation.Id);
                var location = activity.GetLocation();
                if (location != null)
                {
                    evt.Properties.Add("Latitude", location.Item1.ToString());
                    evt.Properties.Add("Longtitude", location.Item2.ToString());
                }
                var upn = activity.GetUPN();
                if (!string.IsNullOrEmpty(upn))
                {
                    evt.Properties.Add("Requestor", upn);
                }
                evt.Name = "Conversation";
                tc.TrackEvent(evt);

                MetricTelemetry msgMt = new MetricTelemetry("Message", 1);
                msgMt.Name = "Message";
                if (!string.IsNullOrEmpty(upn))
                {
                    msgMt.Properties.Add("UPN", upn);
                    tc.TrackMetric(msgMt);
                }

                //if (activity.Attachments?.Count > 0)
                //{
                //    //meaning a room is booked by Cortana
                //    MetricTelemetry bookMt = new MetricTelemetry("Booked", 1);
                //    var room = activity.GetBookedRoomNumber();
                //    bookMt.Properties.Add("Requestor", activity.GetUPN());
                //    bookMt.Properties.Add("RoomNumber",activity.GetBookedRoomNumber());
                //    Trace.TraceInformation($"[{upn}] booked [{room}]");
                //    tc.TrackMetric(bookMt);
                //}
            }
            catch (Exception exp)
            {
                Trace.TraceError($"[Exception]Unable to track events : {exp.Message}");
            }
            finally
            {
            }
        }