Exemplo n.º 1
0
        /// <summary>
        /// Records event with parameters
        /// </summary>
        /// <param name="area">Telemetry area name such as 'Toolbox'.</param>
        /// <param name="eventName">Event name.</param>
        /// <param name="parameters">
        /// Either string/object dictionary or anonymous
        /// collection of string/object pairs.
        /// </param>
        /// <summary>
        public void ReportEvent(TelemetryArea area, string eventName, object parameters = null)
        {
            Check.ArgumentStringNullOrEmpty("eventName", eventName);

            string completeEventName = MakeEventName(area, eventName);

            if (parameters == null)
            {
                this.TelemetryRecorder.RecordEvent(completeEventName);
            }
            else if (parameters is string)
            {
                this.TelemetryRecorder.RecordEvent(completeEventName, parameters as string);
            }
            else
            {
                IDictionary <string, object> dict           = DictionaryExtension.FromAnonymousObject(parameters);
                IDictionary <string, object> dictWithPrefix = new Dictionary <string, object>();

                foreach (KeyValuePair <string, object> kvp in dict)
                {
                    Check.ArgumentStringNullOrEmpty("parameterName", kvp.Key);
                    dictWithPrefix[this.PropertyNamePrefix + area.ToString() + "." + kvp.Key] = kvp.Value ?? string.Empty;
                }
                this.TelemetryRecorder.RecordEvent(completeEventName, dictWithPrefix);
            }
        }
Exemplo n.º 2
0
        public void RecordEvent(string eventName, object parameters = null)
        {
            using (StreamWriter sw = File.AppendText(FileTelemetryRecorder.TestLog)) {
                SimpleTelemetryEvent telemetryEvent = new SimpleTelemetryEvent(eventName);
                telemetryEvent.Properties = DictionaryExtension.FromAnonymousObject(parameters);

                string json = JsonConvert.SerializeObject(telemetryEvent);
                sw.WriteLine(json);
            }
        }
Exemplo n.º 3
0
 public void RecordEvent(string eventName, object parameters = null)
 {
     this.stringBuilder.AppendLine(eventName);
     if (parameters != null)
     {
         if (parameters is string)
         {
             WriteProperty("Value", parameters as string);
         }
         else
         {
             WriteDictionary(DictionaryExtension.FromAnonymousObject(parameters));
         }
     }
 }
Exemplo n.º 4
0
        /// <summary>
        /// Records event with parameters
        /// </summary>
        /// <param name="area">Telemetry area name such as 'Toolbox'.</param>
        /// <param name="eventName">Event name.</param>
        /// <param name="parameters">
        /// Either string/object dictionary or anonymous
        /// collection of string/object pairs.
        /// </param>
        public void ReportEvent(string area, string eventName, object parameters = null)
        {
            if (string.IsNullOrEmpty(area))
            {
                throw new ArgumentException(nameof(area));
            }

            if (string.IsNullOrEmpty(eventName))
            {
                throw new ArgumentException(nameof(eventName));
            }

            string completeEventName = MakeEventName(area, eventName);

            if (parameters == null)
            {
                this.TelemetryRecorder.RecordEvent(completeEventName);
            }
            else if (parameters is string)
            {
                this.TelemetryRecorder.RecordEvent(completeEventName, parameters as string);
            }
            else
            {
                IDictionary <string, object> dict           = DictionaryExtension.FromAnonymousObject(parameters);
                IDictionary <string, object> dictWithPrefix = new Dictionary <string, object>();

                foreach (KeyValuePair <string, object> kvp in dict)
                {
                    if (string.IsNullOrEmpty(kvp.Key))
                    {
                        throw new ArgumentException("parameterName");
                    }

                    dictWithPrefix[this.PropertyNamePrefix + area.ToString() + "." + kvp.Key] = kvp.Value ?? string.Empty;
                }
                this.TelemetryRecorder.RecordEvent(completeEventName, dictWithPrefix);
            }
        }
Exemplo n.º 5
0
 /// <summary>
 /// Records event with parameters
 /// </summary>
 public void RecordEvent(string eventName, object parameters = null)
 {
     if (this.IsEnabled)
     {
         TelemetryEvent telemetryEvent = new TelemetryEvent(eventName);
         if (parameters != null)
         {
             var stringParameter = parameters as string;
             if (stringParameter != null)
             {
                 telemetryEvent.Properties["Value"] = stringParameter;
             }
             else
             {
                 IDictionary <string, object> dict = DictionaryExtension.FromAnonymousObject(parameters);
                 foreach (KeyValuePair <string, object> kvp in dict)
                 {
                     telemetryEvent.Properties[kvp.Key] = kvp.Value;
                 }
             }
         }
         _session.PostEvent(telemetryEvent);
     }
 }