<commit_before>﻿using abremir.AllMyBricks.DataSynchronizer.Interfaces;
using System;
using System.Collections.Generic;

namespace abremir.AllMyBricks.DataSynchronizer.Implementations
{
    public class DataSynchronizerEventManager : IDataSynchronizerEventManager
    {
        private static readonly Lazy<Dictionary<Type, List<Delegate>>> _lazyEventHandlers = new Lazy<Dictionary<Type, List<Delegate>>>(() => new Dictionary<Type, List<Delegate>>());

        private static Dictionary<Type, List<Delegate>> _eventHandlers => _lazyEventHandlers.Value;

        public void Register<T>(Action<T> eventHandler) where T : IDataSynchronizerEvent
        {
            var type = typeof(T);

            if (!_eventHandlers.ContainsKey(type))
            {
                _eventHandlers.Add(type, new List<Delegate>());
            }

            _eventHandlers[typeof(T)].Add(eventHandler);
        }

        public void Raise<T>(T dataSynchronizerEvent) where T : IDataSynchronizerEvent
        {
            foreach(var handler in _eventHandlers[dataSynchronizerEvent.GetType()])
            {
                var action = (Action<T>)handler;

                action(dataSynchronizerEvent);
            }
        }
    }
}<commit_msg>prevent exceptions in event manager when key does not exist in dictionary<commit_after>﻿using abremir.AllMyBricks.DataSynchronizer.Interfaces;
using System;
using System.Collections.Generic;

namespace abremir.AllMyBricks.DataSynchronizer.Implementations
{
    public class DataSynchronizerEventManager : IDataSynchronizerEventManager
    {
        private static readonly Lazy<Dictionary<Type, List<Delegate>>> _lazyEventHandlers = new Lazy<Dictionary<Type, List<Delegate>>>(() => new Dictionary<Type, List<Delegate>>());

        private static Dictionary<Type, List<Delegate>> _eventHandlers => _lazyEventHandlers.Value;

        public void Register<T>(Action<T> eventHandler) where T : IDataSynchronizerEvent
        {
            var type = typeof(T);

            if (!_eventHandlers.ContainsKey(type))
            {
                _eventHandlers.Add(type, new List<Delegate>());
            }

            _eventHandlers[type].Add(eventHandler);
        }

        public void Raise<T>(T dataSynchronizerEvent) where T : IDataSynchronizerEvent
        {
            var type = dataSynchronizerEvent.GetType();

            if (!_eventHandlers.ContainsKey(type))
            {
                return;
            }

            foreach (var handler in _eventHandlers[type])
            {
                var action = (Action<T>)handler;

                action(dataSynchronizerEvent);
            }
        }
    }
}
{'fraction_non_alphanumeric': 0.09443190368698269, 'fraction_numerical': 0.0, 'mean_word_length': 2.6474622770919067, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 37, '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': '4157872', 'n_tokens_mistral': 728, 'n_tokens_neox': 706, 'n_words': 140}