BondInEtwLinqpadDriver.BondDynamicDriver.CreateEventTree C# (CSharp) Method

CreateEventTree() private method

Create schema tree that appears on the left pane below the driver connection name.
private CreateEventTree ( EventStatistics>.IDictionary stat ) : List
stat EventStatistics>.IDictionary Available event types and statistics.
return List
        private List<ExplorerItem> CreateEventTree(IDictionary<Type, EventStatistics> stat)
        {
            var result = new List<ExplorerItem>();

            KeyValuePair<Type, EventStatistics>[] eventTypes =
                (from pair in stat orderby pair.Key.Name select pair).ToArray();

            ExplorerItem scope = null;
            string currentName = null;

            foreach (var eventType in eventTypes)
            {
                if (eventType.Key.Name == currentName)
                {
                    continue;
                }

                if (scope == null)
                {
                    scope = new ExplorerItem(eventType.Key.Name, ExplorerItemKind.Schema, ExplorerIcon.Schema)
                    {
                        Children = new List<ExplorerItem>()
                    };

                    result.Add(scope);
                    currentName = eventType.Key.Name;
                }
                result = scope.Children;
            }

            // Defining the features for each event type.
            foreach (var pair in eventTypes)
            {
                ExplorerItem eventType;

                if (pair.Value.EventsPerSecond == 0 && pair.Value.AverageByteSize == 0)
                {
                    eventType = new ExplorerItem(pair.Key.Name, ExplorerItemKind.QueryableObject, ExplorerIcon.Table)
                    {
                        ToolTipText =
                            "Statistics " + "\n" + "Occurences: " + pair.Value.EventCount + "\n" + "ByteSize: " + pair.Value.ByteSize + "\n",

                        DragText = "playback.GetObservable<" + pair.Key.Name + ">()",
                        Children = new List<ExplorerItem>(),
                        IsEnumerable = true
                    };
                }
                else
                {
                    eventType = new ExplorerItem(pair.Key.Name, ExplorerItemKind.QueryableObject, ExplorerIcon.Table)
                    {
                        ToolTipText =
                            "Statistics " + "\n" + "Occurences: " + pair.Value.EventCount + "\n" + "Events per second: " + pair.Value.EventsPerSecond + "\n" +
                                "ByteSize: " + pair.Value.ByteSize + "\n" + "Average Byte Size: " + pair.Value.AverageByteSize + "\n",

                        DragText = "playback.GetObservable<" + pair.Key.Name + ">()",
                        Children = new List<ExplorerItem>(),
                        IsEnumerable = true
                    };
                }

                scope.Children.Add(eventType);

                // Get the nested properties (columns) for each event type.

                foreach (var property in pair.Key.GetProperties())
                {
                    var propertyType = new ExplorerItem(property.Name, ExplorerItemKind.Property, ExplorerIcon.Column)
                    {
                        ToolTipText = "Property Type: " + property.PropertyType.Name,
                        DragText = property.Name,
                        Children = new List<ExplorerItem>(),
                        IsEnumerable = true
                    };

                    eventType.Children.Add(propertyType);

                    if (!(property.PropertyType.IsPrimitive || property.PropertyType.Namespace.Contains("System")))
                    {
                        this.AddNestedPropertyToTree(property.PropertyType.GetProperties(), propertyType);
                    }
                }
            }

            return result;
        }