コード例 #1
0
        public void PublishTelemetryEvent_SingleProperty_TelemteryIsEnabled_EnablesAndChainsThrough()
        {
            using (ShimsContext.Create())
            {
                // TelemetryAction used here is arbitrary
                const TelemetryAction   action   = TelemetryAction.ColorContrast_Click_Eyedropper;
                const TelemetryProperty property = TelemetryProperty.Comment;
                const string            value    = "Friday";
                string actualName = null;
                IReadOnlyDictionary <string, string> actualTelemetryPropertyBag = null;
                ITelemetry telemetry = new StubITelemetry
                {
                    PublishEventStringIReadOnlyDictionaryOfStringString = (name, telemetryPropertyBag) =>
                    {
                        actualName = name;
                        actualTelemetryPropertyBag = telemetryPropertyBag;
                    }
                };
                ShimLogger.IsEnabledGet = () => true;
                ShimLogger.TelemetryGet = () => telemetry;

                Logger.PublishTelemetryEvent(action, property, value);

                Assert.AreEqual(action.ToString(), actualName);
                Assert.AreEqual(1, actualTelemetryPropertyBag.Count);
                Assert.AreEqual(value, actualTelemetryPropertyBag[property.ToString()]);
            }
        }
        public void PublishTelemetryEventContainer_TelemetryIsEnabled_EnablesAndChainsThrough()
        {
            using (ShimsContext.Create())
            {
                // Specific values of TelemetryAction and TelemetryProperty are unimportant for this test
                TelemetryAction   action   = (TelemetryAction)6;
                TelemetryProperty property = (TelemetryProperty)7;
                var fakeId    = "id";
                var fakeEvent = new TelemetryEvent(action, new Dictionary <TelemetryProperty, string>
                {
                    { property, fakeId },
                });

                string actualName = null;
                IReadOnlyDictionary <string, string> actualTelemetryPropertyBag = null;
                ITelemetry telemetry = new StubITelemetry
                {
                    PublishEventStringIReadOnlyDictionaryOfStringString = (name, telemetryPropertyBag) =>
                    {
                        actualName = name;
                        actualTelemetryPropertyBag = telemetryPropertyBag;
                    }
                };
                TelemetrySink.IsTelemetryAllowed = true;
                ShimTelemetrySink.TelemetryGet   = () => telemetry;

                Logger.PublishTelemetryEvent(fakeEvent);

                Assert.AreEqual(fakeEvent.Action.ToString(), actualName);
                Assert.AreEqual(1, actualTelemetryPropertyBag.Count);
                Assert.AreEqual(fakeId, actualTelemetryPropertyBag[property.ToString()]);
            }
        }
        public void PublishTelemetryEvent_SingleProperty_TelemteryIsEnabled_EnablesAndChainsThrough()
        {
            using (ShimsContext.Create())
            {
                // Specific values of TelemetryAction and TelemetryProperty are unimportant for this test
                const TelemetryAction   action   = (TelemetryAction)4;
                const TelemetryProperty property = (TelemetryProperty)5;
                const string            value    = "Friday";
                string actualName = null;
                IReadOnlyDictionary <string, string> actualTelemetryPropertyBag = null;
                ITelemetry telemetry = new StubITelemetry
                {
                    PublishEventStringIReadOnlyDictionaryOfStringString = (name, telemetryPropertyBag) =>
                    {
                        actualName = name;
                        actualTelemetryPropertyBag = telemetryPropertyBag;
                    }
                };
                TelemetrySink.IsTelemetryAllowed = true;
                ShimTelemetrySink.TelemetryGet   = () => telemetry;

                Logger.PublishTelemetryEvent(action, property, value);

                Assert.AreEqual(action.ToString(), actualName);
                Assert.AreEqual(1, actualTelemetryPropertyBag.Count);
                Assert.AreEqual(value, actualTelemetryPropertyBag[property.ToString()]);
            }
        }
コード例 #4
0
        /// <summary>
        /// Publishes event to the current telemetry pipeline
        /// </summary>
        /// <param name="action">The action being recorded</param>
        /// <param name="propertyBag">Associated property bag--this may be null</param>
        public static void PublishTelemetryEvent(TelemetryAction action, IReadOnlyDictionary <TelemetryProperty, string> propertyBag = null)
        {
            // Conversions to strings are expensive, so skip it if possible
            if (!IsEnabled)
            {
                return;
            }

            TelemetrySink.PublishTelemetryEvent(action.ToString(), ConvertFromProperties(propertyBag));
        }
コード例 #5
0
        /// <summary>
        /// Publishes event with single property/value pair to the current telemetry pipeline
        /// </summary>
        /// <param name="action"></param>
        /// <param name="property"></param>
        /// <param name="value"></param>
        public static void PublishTelemetryEvent(TelemetryAction action, TelemetryProperty property, string value)
        {
            // Conversions to strings are expensive, so skip it if possible
            if (!IsEnabled)
            {
                return;
            }

            TelemetrySink.PublishTelemetryEvent(action.ToString(), property.ToString(), value);
        }
コード例 #6
0
        private static string GetActionName(TelemetryAction action)
        {
            switch (action)
            {
            case TelemetryAction.Restore:
            case TelemetryAction.Search:
                return(action.ToString());

            default:
                throw new ArgumentException("Unknown value of " + nameof(TelemetryAction), nameof(action));
            }
        }
コード例 #7
0
ファイル: Logger.cs プロジェクト: lisli1/axe-windows
        /// <summary>
        /// Publishes event with single property/value pair to the current telemetry pipeline
        /// </summary>
        /// <param name="action"></param>
        /// <param name="property"></param>
        /// <param name="value"></param>
        public static void PublishTelemetryEvent(TelemetryAction action, TelemetryProperty property, string value)
        {
            // Check IsEnabled because ToString on enums is expensive
            if (!IsEnabled)
            {
                return;
            }

            PublishTelemetryEvent(action, new Dictionary <TelemetryProperty, string>
            {
                { property, value }
            });
        }
        public void ProcessEventFactories_ProcessorIsNotNull_HasEvents_ProcessorIsInvokedInOrder()
        {
            const TelemetryAction action1 = TelemetryAction.Event_Load;
            const TelemetryAction action2 = TelemetryAction.Event_Save;
            List <TelemetryEvent> receivedTelemetryEvents = new List <TelemetryEvent>();

            _testSubject.AddEventFactory(() => new TelemetryEvent(action1, new Dictionary <TelemetryProperty, string>()));
            _testSubject.AddEventFactory(() => new TelemetryEvent(action2, new Dictionary <TelemetryProperty, string>()));

            _testSubject.ProcessEventFactories((telemetryEvent) => receivedTelemetryEvents.Add(telemetryEvent));

            Assert.AreEqual(2, receivedTelemetryEvents.Count);
            Assert.AreEqual(action1, receivedTelemetryEvents[0].Action);
            Assert.AreEqual(action2, receivedTelemetryEvents[1].Action);
        }
コード例 #9
0
ファイル: Logger.cs プロジェクト: lisli1/axe-windows
        /// <summary>
        /// Publishes event to the current telemetry pipeline
        /// </summary>
        /// <param name="action">The action being recorded</param>
        /// <param name="propertyBag">Associated property bag--this may be null</param>
        public static void PublishTelemetryEvent(TelemetryAction action, IReadOnlyDictionary <TelemetryProperty, string> propertyBag)
        {
            // Check IsEnabled because ToString on enums is expensive
            if (!IsEnabled)
            {
                return;
            }

            try
            {
                Telemetry?.PublishEvent(action.ToString(), ConvertFromProperties(propertyBag));
            }
#pragma warning disable CA1031
            catch { }
#pragma warning restore CA1031
        }
コード例 #10
0
        public void PublishTelemetryEvent_MultiProperty_TelemteryIsEnabled_EnablesAndChainsThrough()
        {
            using (ShimsContext.Create())
            {
                // TelemetryAction used here is arbitrary
                const TelemetryAction   action   = TelemetryAction.ColorContrast_Click_Eyedropper;
                const TelemetryProperty property = TelemetryProperty.Error;
                const string            value    = "Saturday";
                string actualName = null;
                IReadOnlyDictionary <TelemetryProperty, string> actualConverterInput       = null;
                IReadOnlyDictionary <string, string>            actualTelemetryPropertyBag = null;
                ITelemetry telemetry = new StubITelemetry
                {
                    PublishEventStringIReadOnlyDictionaryOfStringString = (name, telemetryPropertyBag) =>
                    {
                        actualName = name;
                        actualTelemetryPropertyBag = telemetryPropertyBag;
                    }
                };
                ShimLogger.IsEnabledGet = () => true;
                ShimLogger.TelemetryGet = () => telemetry;

                Dictionary <string, string> expectedConverterOutput = new Dictionary <string, string>
                {
                    { "abc", "def" },
                };
                ShimLogger.ConvertFromPropertiesIReadOnlyDictionaryOfTelemetryPropertyString = (input) =>
                {
                    actualConverterInput = input;
                    return(expectedConverterOutput);
                };

                Dictionary <TelemetryProperty, string> initalInput = new Dictionary <TelemetryProperty, string>
                {
                    { property, value },
                };

                Logger.PublishTelemetryEvent(action, initalInput);

                Assert.AreEqual(action.ToString(), actualName);
                Assert.AreEqual(initalInput, actualConverterInput);
                Assert.AreSame(expectedConverterOutput, actualTelemetryPropertyBag);
                Assert.AreEqual(action.ToString(), actualName);
            }
        }
コード例 #11
0
        public void PublishTelemetryEvent_MultiProperty_TelemteryIsEnabled_EnablesAndChainsThrough()
        {
            using (ShimsContext.Create())
            {
                // Specific values of TelemetryAction and TelemetryProperty are unimportant for this test
                const TelemetryAction   action   = (TelemetryAction)8;
                const TelemetryProperty property = (TelemetryProperty)9;
                const string            value    = "Saturday";
                string actualName = null;
                IReadOnlyDictionary <TelemetryProperty, string> actualConverterInput       = null;
                IReadOnlyDictionary <string, string>            actualTelemetryPropertyBag = null;
                ITelemetry telemetry = new StubITelemetry
                {
                    PublishEventStringIReadOnlyDictionaryOfStringString = (name, telemetryPropertyBag) =>
                    {
                        actualName = name;
                        actualTelemetryPropertyBag = telemetryPropertyBag;
                    }
                };
                TelemetrySink.IsTelemetryAllowed = true;
                ShimTelemetrySink.TelemetryGet   = () => telemetry;

                Dictionary <string, string> expectedConverterOutput = new Dictionary <string, string>
                {
                    { "abc", "def" },
                };
                ShimLogger.ConvertFromPropertiesIReadOnlyDictionaryOfTelemetryPropertyString = (input) =>
                {
                    actualConverterInput = input;
                    return(expectedConverterOutput);
                };

                Dictionary <TelemetryProperty, string> initalInput = new Dictionary <TelemetryProperty, string>
                {
                    { property, value },
                };

                Logger.PublishTelemetryEvent(action, initalInput);

                Assert.AreEqual(action.ToString(), actualName);
                Assert.AreEqual(initalInput, actualConverterInput);
                Assert.AreSame(expectedConverterOutput, actualTelemetryPropertyBag);
                Assert.AreEqual(action.ToString(), actualName);
            }
        }
コード例 #12
0
        public PackageSourceTelemetry(IEnumerable <SourceRepository> sources, Guid parentId, TelemetryAction action)
        {
            if (sources == null)
            {
                throw new ArgumentNullException(nameof(sources));
            }

            // Multiple sources can use the same feed url. We can't know which one protocol events come from, so choose any.
            _sources = new Dictionary <string, SourceRepository>();
            foreach (var source in sources)
            {
                _sources[source.PackageSource.Source] = source;
            }

            var data = new Dictionary <string, Data>(_sources.Count);

            foreach (var source in _sources.Keys)
            {
                data[source] = new Data();
            }
            _data = data;

            _resourceStringTable                  = new ConcurrentDictionary <string, ConcurrentDictionary <string, string> >();
            ProtocolDiagnostics.HttpEvent        += ProtocolDiagnostics_HttpEvent;
            ProtocolDiagnostics.ResourceEvent    += ProtocolDiagnostics_ResourceEvent;
            ProtocolDiagnostics.NupkgCopiedEvent += ProtocolDiagnostics_NupkgCopiedEvent;
            _parentId   = parentId;
            _actionName = GetActionName(action);
        }
コード例 #13
0
 public PackageSourceTelemetry(IEnumerable <SourceRepository> sources, Guid parentId, TelemetryAction action, PackageSourceMapping packageSourceMappingConfiguration)
     : this(sources, parentId, action)
 {
     _packageSourceMappingConfiguration = packageSourceMappingConfiguration;
 }
コード例 #14
0
ファイル: Logger.cs プロジェクト: lisli1/axe-windows
 /// <summary>
 /// Publishes event to the current telemetry pipeline
 /// </summary>
 /// <param name="action">The action being recorded</param>
 /// <param name="propertyBag">Associated property bag--this may be null</param>
 public static void PublishTelemetryEvent(TelemetryAction action)
 {
     PublishTelemetryEvent(action, null);
 }
コード例 #15
0
 public TelemetryEvent(TelemetryAction action, IReadOnlyDictionary <TelemetryProperty, string> properties)
 {
     this.Action     = action;
     this.Properties = properties;
 }