Esempio n. 1
0
        // Transform the summary data into the format used in event sending.
        private SummaryEventOutput MakeSummaryEvent(EventSummary summary)
        {
            Dictionary <string, EventSummaryFlag> flagsOut = new Dictionary <string, EventSummaryFlag>();

            foreach (KeyValuePair <EventsCounterKey, EventsCounterValue> entry in summary.Counters)
            {
                EventSummaryFlag flag;
                if (!flagsOut.TryGetValue(entry.Key.Key, out flag))
                {
                    flag = new EventSummaryFlag
                    {
                        Default  = entry.Value.Default,
                        Counters = new List <EventSummaryCounter>()
                    };
                    flagsOut[entry.Key.Key] = flag;
                }
                flag.Counters.Add(new EventSummaryCounter(entry.Key.Variation, entry.Value.FlagValue,
                                                          entry.Key.Version, entry.Value.Count));
            }
            return(new SummaryEventOutput
            {
                Kind = "summary",
                StartDate = summary.StartDate,
                EndDate = summary.EndDate,
                Features = flagsOut
            });
        }
Esempio n. 2
0
        // Returns the current summarized event data.
        internal EventSummary Snapshot()
        {
            EventSummary ret = _eventsState;

            _eventsState = new EventSummary();
            return(ret);
        }
        internal string SerializeOutputEvents(Event[] events, EventSummary summary, out int eventCountOut)
        {
            var stringWriter = new StringWriter();
            var scope        = new EventOutputFormatterScope(_config, stringWriter, _config.InlineUsersInEvents);

            eventCountOut = scope.WriteOutputEvents(events, summary);
            return(stringWriter.ToString());
        }
Esempio n. 4
0
        internal List <EventOutput> MakeOutputEvents(Event[] events, EventSummary summary)
        {
            List <EventOutput> eventsOut = new List <EventOutput>(events.Length + 1);

            foreach (Event e in events)
            {
                EventOutput eo = MakeOutputEvent(e);
                if (eo != null)
                {
                    eventsOut.Add(eo);
                }
            }
            if (summary.Counters.Count > 0)
            {
                eventsOut.Add(MakeSummaryEvent(summary));
            }
            return(eventsOut);
        }
        internal int WriteOutputEvents(Event[] events, EventSummary summary)
        {
            var eventCount = 0;

            _jsonWriter.WriteStartArray();
            foreach (Event e in events)
            {
                if (WriteOutputEvent(e))
                {
                    eventCount++;
                }
            }
            if (summary.Counters.Count > 0)
            {
                WriteSummaryEvent(summary);
                eventCount++;
            }
            _jsonWriter.WriteEndArray();
            _jsonWriter.Flush();
            return(eventCount);
        }
        private void WriteSummaryEvent(EventSummary summary)
        {
            _jsonWriter.WriteStartObject();

            _jsonWriter.WritePropertyName("kind");
            _jsonWriter.WriteValue("summary");
            _jsonWriter.WritePropertyName("startDate");
            _jsonWriter.WriteValue(summary.StartDate);
            _jsonWriter.WritePropertyName("endDate");
            _jsonWriter.WriteValue(summary.EndDate);

            _jsonWriter.WritePropertyName("features");
            _jsonWriter.WriteStartObject();

            var unprocessedCounters = summary.Counters.Select(kv => MutableKeyValuePair <EventsCounterKey, EventsCounterValue> .FromKeyValue(kv)).ToArray();

            for (var i = 0; i < unprocessedCounters.Length; i++)
            {
                var firstEntry = unprocessedCounters[i];
                if (firstEntry.Value is null)
                { // already processed
                    continue;
                }
                var flagKey     = firstEntry.Key.Key;
                var flagDefault = firstEntry.Value.Default;

                _jsonWriter.WritePropertyName(flagKey);
                _jsonWriter.WriteStartObject();
                _jsonWriter.WritePropertyName("default");
                LdValueSerializer.Instance.WriteJson(_jsonWriter, flagDefault, _jsonSerializer);
                _jsonWriter.WritePropertyName("counters");
                _jsonWriter.WriteStartArray();

                for (var j = i; j < unprocessedCounters.Length; j++)
                {
                    var entry = unprocessedCounters[j];
                    var key   = entry.Key;
                    if (key.Key == flagKey && entry.Value != null)
                    {
                        var counter = entry.Value;
                        unprocessedCounters[j].Value = null; // mark as already processed

                        _jsonWriter.WriteStartObject();
                        if (key.Variation.HasValue)
                        {
                            _jsonWriter.WritePropertyName("variation");
                            _jsonWriter.WriteValue(key.Variation.Value);
                        }
                        _jsonWriter.WritePropertyName("value");
                        LdValueSerializer.Instance.WriteJson(_jsonWriter, counter.FlagValue, _jsonSerializer);
                        if (key.Version.HasValue)
                        {
                            _jsonWriter.WritePropertyName("version");
                            _jsonWriter.WriteValue(key.Version.Value);
                        }
                        else
                        {
                            _jsonWriter.WritePropertyName("unknown");
                            _jsonWriter.WriteValue(true);
                        }
                        _jsonWriter.WritePropertyName("count");
                        _jsonWriter.WriteValue(counter.Count);
                        _jsonWriter.WriteEndObject();
                    }
                }

                _jsonWriter.WriteEndArray();
                _jsonWriter.WriteEndObject();
            }

            _jsonWriter.WriteEndObject();

            _jsonWriter.WriteEndObject();
        }
Esempio n. 7
0
 internal void Clear()
 {
     _eventsState = new EventSummary();
 }
Esempio n. 8
0
 public EventSummarizer()
 {
     _eventsState = new EventSummary();
 }