public void FallBackToDefaultConfigurationGracefully()
        {
            var config = new AnalyticsConfig("");

            Assert.AreEqual(config.GetCategory("c", "t"),
                            DefaultEventCategory);
            Assert.True(config.IsEnabled("c", "t"));
        }
        public void HandleConfigPrecedenceRulesCorrectly()
        {
            var config = new AnalyticsConfig(_configString);

            // d.e should route to *.* as there is no match
            Assert.False(config.IsEnabled("d", "e"));
            Assert.AreEqual(DefaultEventCategory, config.GetCategory("d", "e"));
            // d.a should route to *.a as there is not a better match
            Assert.True(config.IsEnabled("d", "a"));
            Assert.AreEqual("function", config.GetCategory("d", "a"));

            // b.d should route to b.* as there is not a better match
            Assert.True(config.IsEnabled("b", "d"));
            Assert.AreEqual("function-2", config.GetCategory("b", "d"));

            // b.a should route to b.* as a match on class is preferred on a match on type (i.e. b.* > *.a)
            Assert.True(config.IsEnabled("b", "a"));
            Assert.AreEqual("function-2", config.GetCategory("b", "a"));

            // b.c should route to b.c as it is an exact match
            Assert.True(config.IsEnabled("b", "c"));
            Assert.AreEqual("function-3", config.GetCategory("b", "c"));
        }
Example #3
0
        /// <summary>
        /// Queues an event for sending. If the queue was full, returns a task corresponding to sending the data to
        /// the endpoint.
        /// </summary>
        public async Task SendAsync <T>(string eventClass, string eventType, Dictionary <string, T> eventAttributes, string playerId = null)
        {
            if (!_config.IsEnabled(eventClass, eventType))
            {
                return;
            }
            // Get previous event ID after an atomic increment
            var eventId = Interlocked.Increment(ref _eventId) - 1;

            var postParams = PostParams(eventClass, eventType, eventAttributes, eventId, playerId);
            var uri        = RequestUri(eventClass, eventType);

            _queuedRequests.Enqueue(new QueuedRequest(uri, JsonConvert.SerializeObject(postParams)));

            if (IsQueueFull)
            {
                await DispatchEventQueue();
            }
        }