<commit_before>﻿using Glimpse.WebForms.Inspector;
using Glimpse.WebForms.Model;
using Glimpse.WebForms.Tab;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Glimpse.WebForms.Support
{
	public class DataBindFormatter
	{
        public void Process(ControlTreeItemTrackModel root, IEnumerable<PageLifeCycleMessage> pageLifeCycleMessages)
		{
            ProcessRecord(root, (Dictionary<string, List<DataBindParameterModel>>)HttpContext.Current.Items["_GlimpseWebFormDataBindingInfo"], pageLifeCycleMessages.OrderByDescending(p => p.StartTime));
		}

        private void ProcessRecord(ControlTreeItemTrackModel item, Dictionary<string, List<DataBindParameterModel>> dataBindInfo, IEnumerable<PageLifeCycleMessage> pageLifeCycleMessages)
		{
			if (dataBindInfo.ContainsKey(item.ControlId))
			{
				item.Record.DataBindParameters = new Dictionary<string, object>();
                foreach (var parameterModel in dataBindInfo[item.ControlId])
				{
                    var dataBindParameters = new List<DataBindParameter>();
                    var time = DateTime.MinValue;
                    foreach (var parameter in parameterModel.DataBindParameters)
					{
                        dataBindParameters.Add(parameter);
					}
                    var endTime = pageLifeCycleMessages.First(p => parameterModel.Time <= p.StartTime).StartTime;
                    var lifeCycleEvent = pageLifeCycleMessages.First(p => p.StartTime <= parameterModel.Time && parameterModel.Time <= endTime);
                    if (item.Record.DataBindParameters.ContainsKey(lifeCycleEvent.EventName))
                    {
                        var multipleEventParameters = item.Record.DataBindParameters[lifeCycleEvent.EventName] as Dictionary<int, object>;
                        if (multipleEventParameters == null)
                        {
                            var existingEventParameters = (List<DataBindParameter>)item.Record.DataBindParameters[lifeCycleEvent.EventName];
                            multipleEventParameters = new Dictionary<int, object>();
                            item.Record.DataBindParameters[lifeCycleEvent.EventName] = multipleEventParameters;
                            multipleEventParameters[0] = existingEventParameters;
                        }
                        multipleEventParameters[multipleEventParameters.Count] = dataBindParameters;
                    }
                    else
                    {
                        item.Record.DataBindParameters[lifeCycleEvent.EventName] = dataBindParameters;
                    }
				}
			}<commit_msg>Can't get event check to work<commit_after>﻿using Glimpse.WebForms.Inspector;
using Glimpse.WebForms.Model;
using Glimpse.WebForms.Tab;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Glimpse.WebForms.Support
{
	public class DataBindFormatter
	{
        public void Process(ControlTreeItemTrackModel root, IEnumerable<PageLifeCycleMessage> pageLifeCycleMessages)
		{
            ProcessRecord(root, (Dictionary<string, List<DataBindParameterModel>>)HttpContext.Current.Items["_GlimpseWebFormDataBindingInfo"], pageLifeCycleMessages.OrderByDescending(p => p.StartTime));
		}

        private void ProcessRecord(ControlTreeItemTrackModel item, Dictionary<string, List<DataBindParameterModel>> dataBindInfo, IEnumerable<PageLifeCycleMessage> pageLifeCycleMessages)
		{
			if (dataBindInfo.ContainsKey(item.ControlId))
			{
				item.Record.DataBindParameters = new Dictionary<string, object>();
                foreach (var parameterModel in dataBindInfo[item.ControlId])
				{
                    var dataBindParameters = new List<DataBindParameter>();
                    var time = DateTime.MinValue;
                    foreach (var parameter in parameterModel.DataBindParameters)
					{
                        dataBindParameters.Add(parameter);
					}
                    var lifeCycleEvent = pageLifeCycleMessages.First(p => p.StartTime <= parameterModel.Time);
                    if (item.Record.DataBindParameters.ContainsKey(lifeCycleEvent.EventName))
                    {
                        var multipleEventParameters = item.Record.DataBindParameters[lifeCycleEvent.EventName] as Dictionary<int, object>;
                        if (multipleEventParameters == null)
                        {
                            var existingEventParameters = (List<DataBindParameter>)item.Record.DataBindParameters[lifeCycleEvent.EventName];
                            multipleEventParameters = new Dictionary<int, object>();
                            item.Record.DataBindParameters[lifeCycleEvent.EventName] = multipleEventParameters;
                            multipleEventParameters[0] = existingEventParameters;
                        }
                        multipleEventParameters[multipleEventParameters.Count] = dataBindParameters;
                    }
                    else
                    {
                        item.Record.DataBindParameters[lifeCycleEvent.EventName] = dataBindParameters;
                    }
				}
			}
{'fraction_non_alphanumeric': 0.07736720554272518, 'fraction_numerical': 0.00038491147036181676, 'mean_word_length': 2.421329822251481, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 30, 'https://': 0, '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': '3396581', 'n_tokens_mistral': 1300, 'n_tokens_neox': 1218, 'n_words': 206}