Ejemplo n.º 1
0
        /// <inheritdoc/>
        public RegistryEventReference AddEventInstance(IRegistryEvent effect)
        {
            int effectTypeId    = RegistryEventReference.GetTypeId(effect.GetType());
            int effectVersionId = RegistryEventReference.GetEffectInstanceId(effect);



            // Lazy initialzation
            if (!registar.ContainsKey(effectTypeId))
            {
                // Using Concurrent version of the dictionary to ovoid problem of reading while writing event though it should not happen.
                registar[effectTypeId] = new ConcurrentDictionary <int, IRegistryEvent>();
            }

            // Avoid duplicates
            if (!registar[effectTypeId].ContainsKey(effectVersionId))
            {
                registar[effectTypeId].TryAdd(effectVersionId, effect);
                OnNewElementRegistered();
            }

            return(new RegistryEventReference()
            {
                TypeId = effectTypeId, VersionId = effectVersionId
            });
        }
Ejemplo n.º 2
0
 public static int GetEffectInstanceId(IRegistryEvent effect)
 {
     return(effect.GetHashCode());
 }