<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.ApplicationInsights;

namespace SecuritySystemUWP
{
    internal static class TelemetryHelper
    {
        /// <summary>
        /// Allows tracking page views, exceptions and other telemetry through the Microsoft Application Insights service.
        /// </summary>
        internal static Microsoft.ApplicationInsights.TelemetryClient _TelemetryClient = new TelemetryClient();


        private static void AddCommonProperties(ref IDictionary<string, string> properties)
        {
            
            properties.Add("Custom_AppVersion", EnvironmentSettings.GetAppVersion());
            properties.Add("Custom_OSVersion", EnvironmentSettings.GetOSVersion());

#if MS_INTERNAL_ONLY // do not send this app insights telemetry data for external customers
            properties.Add("userAlias", App.Controller.XmlSettings.MicrosoftAlias);
            properties.Add("Custom_DeviceName", EnvironmentSettings.GetDeviceName());
            properties.Add("Custom_IPAddress", EnvironmentSettings.GetIPAddress());
#endif
        }

        internal static void TrackEvent(string eventName)
        {
            Dictionary<string, string> properties = new Dictionary<string, string>();
            TrackEvent(eventName, properties);
        }

        internal static void TrackEvent(string eventName, IDictionary<string, string> properties)
        {
            AddCommonProperties(ref properties);
            _TelemetryClient.TrackEvent(eventName, properties);
        }

        internal static void TrackMetric(string metricName, double value)
        {
            Dictionary<string, string> properties = new Dictionary<string, string>();
            TrackMetric(metricName, value, properties);
        }

        internal static void TrackMetric(string metricName, double value, IDictionary<string, string> properties)
        {
            AddCommonProperties(ref properties);
            _TelemetryClient.TrackMetric(metricName, value, properties);
        }

        internal static void TrackException(Exception exception)
        {
            Dictionary<string, string> properties = new Dictionary<string, string>();
            TrackException(exception, properties);
        }

        internal static void TrackException(Exception exception, IDictionary<string, string> properties)
        {
            AddCommonProperties(ref properties);
            _TelemetryClient.TrackException(exception, properties);
        }
    }
}<commit_msg>added comments<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.ApplicationInsights;

namespace SecuritySystemUWP
{
    /// <summary>
    /// Helper class for app insights telemetry events.
    /// Allows tracking page views, exceptions and other telemetry through the Microsoft Application Insights service.
    /// </summary>
    internal static class TelemetryHelper
    {
        // app insights telemetry object
        internal static Microsoft.ApplicationInsights.TelemetryClient _TelemetryClient = new TelemetryClient();

        /// <summary>
        /// Helper private method to add additional common properties to all telemetry events
        /// </summary>
        /// <param name="properties">common global telemetry properties to log</param>
        private static void AddCommonProperties(ref IDictionary<string, string> properties)
        {
            
            properties.Add("Custom_AppVersion", EnvironmentSettings.GetAppVersion());
            properties.Add("Custom_OSVersion", EnvironmentSettings.GetOSVersion());

#if MS_INTERNAL_ONLY // Do not send this app insights telemetry data for external customers. Microsoft only.
            properties.Add("userAlias", App.Controller.XmlSettings.MicrosoftAlias);
            properties.Add("Custom_DeviceName", EnvironmentSettings.GetDeviceName());
            properties.Add("Custom_IPAddress", EnvironmentSettings.GetIPAddress());
#endif
        }

        /// <summary>
        /// Log and track custom app insights event with global common properities
        /// See https://azure.microsoft.com/en-us/documentation/articles/app-insights-api-custom-events-metrics/#api-summary
        /// </summary>
        /// <param name="eventName"></param>
        internal static void TrackEvent(string eventName)
        {
            Dictionary<string, string> properties = new Dictionary<string, string>();
            // call helper method to add common properties
            TrackEvent(eventName, properties);
        }

        /// <summary>
        /// Log and track custom app insights event with global common properities
        /// See https://azure.microsoft.com/en-us/documentation/articles/app-insights-api-custom-events-metrics/#api-summary
        /// </summary>
        /// <param name="eventName"></param>
        /// <param name="properties"></param>
        internal static void TrackEvent(string eventName, IDictionary<string, string> properties)
        {
            AddCommonProperties(ref properties);
            _TelemetryClient.TrackEvent(eventName, properties);
        }

        /// <summary>
        /// Log and track custom app insights metrics with global common properities
        /// See https://azure.microsoft.com/en-us/documentation/articles/app-insights-api-custom-events-metrics/#api-summary
        /// </summary>
        /// <param name="metricName"></param>
        /// <param name="value"></param>
        internal static void TrackMetric(string metricName, double value)
        {
            Dictionary<string, string> properties = new Dictionary<string, string>();
            // call helper method to add common properties
            TrackMetric(metricName, value, properties);
        }

        /// <summary>
        /// Log and track custom app insights metrics with global common properities
        /// See https://azure.microsoft.com/en-us/documentation/articles/app-insights-api-custom-events-metrics/#api-summary
        /// </summary>
        /// <param name="metricName"></param>
        /// <param name="value"></param>
        /// <param name="properties"></param>
        internal static void TrackMetric(string metricName, double value, IDictionary<string, string> properties)
        {
            AddCommonProperties(ref properties);
            _TelemetryClient.TrackMetric(metricName, value, properties);
        }

        /// <summary>
        /// Log and track custom app insights exception event with global common properities
        /// See https://azure.microsoft.com/en-us/documentation/articles/app-insights-api-custom-events-metrics/#api-summary
        /// </summary>
        /// <param name="exception"></param>
        internal static void TrackException(Exception exception)
        {
            Dictionary<string, string> properties = new Dictionary<string, string>();
            // call helper method to add common properties
            TrackException(exception, properties);
        }

        /// <summary>
        /// Log and track custom app insights exception event with global common properities
        /// See https://azure.microsoft.com/en-us/documentation/articles/app-insights-api-custom-events-metrics/#api-summary
        /// </summary>
        /// <param name="exception"></param>
        /// <param name="properties"></param>
        internal static void TrackException(Exception exception, IDictionary<string, string> properties)
        {
            AddCommonProperties(ref properties);
            _TelemetryClient.TrackException(exception, properties);
        }
    }
}
{'fraction_non_alphanumeric': 0.10202763786646003, 'fraction_numerical': 0.0, 'mean_word_length': 2.663197729422895, 'pattern_counts': {'":': 0, '<': 65, '<?xml version=': 0, '>': 65, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5827028', 'n_tokens_mistral': 1779, 'n_tokens_neox': 1748, 'n_words': 474}