Example #1
0
        protected internal int CacheCompiledInfos(IDictionary <int, MappingCompiledInfo> mappingCompiledInfos)
        {
            Lock.EnterWriteLock();

            try
            {
                return(CompiledCache.CacheAll(mappingCompiledInfos));
            }
            finally
            {
                Lock.ExitWriteLock();
            }
        }
Example #2
0
        /// <summary>
        /// Clears all mappings and compiled caches.
        /// </summary>
        public void Clear()
        {
            Lock.EnterWriteLock();

            try
            {
                MappingRows.Clear();
                CompiledCache.Clear();
            }
            finally
            {
                Lock.ExitWriteLock();
            }
        }
Example #3
0
        public bool CacheCompiledInfo(Type destinationType, Type sourceType, MappingCompiledInfo mappingCompiledInfo)
        {
            var hash = Mapping.ComputeHash(destinationType, sourceType);

            Lock.EnterWriteLock();

            try
            {
                return(CompiledCache.Cache(hash, mappingCompiledInfo));
            }
            finally
            {
                Lock.ExitWriteLock();
            }
        }
Example #4
0
        /// <summary>
        /// Adds a mapping to <see cref="MapperContext"/>.
        /// </summary>
        /// <param name="item"></param>
        public void Add(Mapping item)
        {
            var hash = Mapping.ComputeHash(item);

            Lock.EnterWriteLock();

            try
            {
                MappingRows.Add(hash, item);
                CompiledCache.Miss(hash);
            }
            finally
            {
                Lock.ExitWriteLock();
            }
        }
Example #5
0
        /// <summary>
        /// Returns the <see cref="MappingCompiledInfo"/> using given destinationType and sourceType.
        /// </summary>
        /// <param name="destinationType"></param>
        /// <param name="sourceType"></param>
        /// <param name="mappingCompiledInfo"></param>
        /// <returns>A value indicating that value is found or not.</returns>
        public bool TryGetCompiledInfo(Type destinationType, Type sourceType,
                                       out MappingCompiledInfo mappingCompiledInfo)
        {
            var hash = Mapping.ComputeHash(destinationType, sourceType);

            Lock.EnterReadLock();

            try
            {
                return(CompiledCache.TryGetValue(hash, out mappingCompiledInfo));
            }
            finally
            {
                Lock.ExitReadLock();
            }
        }
Example #6
0
        /// <summary>
        /// Removes a mapping (and it's compiled cache) from <see cref="MapperContext"/>.
        /// </summary>
        /// <param name="destinationType"></param>
        /// <param name="sourceType"></param>
        /// <returns></returns>
        public bool Remove(Type destinationType, Type sourceType)
        {
            var hash = Mapping.ComputeHash(destinationType, sourceType);

            Lock.EnterWriteLock();

            try
            {
                var result = MappingRows.Remove(hash);
                CompiledCache.Miss(hash);
                return(result);
            }
            finally
            {
                Lock.ExitWriteLock();
            }
        }
Example #7
0
        /// <summary>
        /// Removes a mapping (and it's compiled cache) from <see cref="MapperContext"/>.
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        public bool Remove(Mapping item)
        {
            var hash = Mapping.ComputeHash(item);

            Lock.EnterWriteLock();

            try
            {
                var result = MappingRows.Remove(hash);
                CompiledCache.Miss(hash);
                return(result);
            }
            finally
            {
                Lock.ExitWriteLock();
            }
        }
Example #8
0
        public bool TryGetMappingAndCompiledInfo(Type destinationType, Type sourceType, out Mapping mapping,
                                                 out MappingCompiledInfo mappingCompiledInfo)
        {
            var hash = Mapping.ComputeHash(destinationType, sourceType);

            Lock.EnterReadLock();

            try
            {
                var result = MappingRows.TryGetValue(hash, out mapping);
                CompiledCache.TryGetValue(hash, out mappingCompiledInfo);
                return(result);
            }
            finally
            {
                Lock.ExitReadLock();
            }
        }
Example #9
0
        /// <summary>
        /// Adds a range of mappings to <see cref="MapperContext"/>.
        /// </summary>
        /// <param name="items"></param>
        public void AddRange(IEnumerable <Mapping> items)
        {
            var hashes = new List <int>();

            Lock.EnterWriteLock();

            try
            {
                foreach (var item in items)
                {
                    var hash = Mapping.ComputeHash(item);
                    MappingRows.Add(hash, item);
                    hashes.Add(hash);
                }

                CompiledCache.MissAll(hashes);
            }
            finally
            {
                Lock.ExitWriteLock();
            }
        }
Example #10
0
        /// <summary>
        /// Gets all mappings without equivalent compiled info. (Those which needing compilation).
        /// </summary>
        protected internal IDictionary <int, Mapping> GetMappingsWithoutCompiledInfo()
        {
            var result = new Dictionary <int, Mapping>();

            Lock.EnterReadLock();

            try
            {
                foreach (var row in MappingRows)
                {
                    if (!CompiledCache.Exists(row.Key))
                    {
                        result.Add(row.Key, row.Value);
                    }
                }

                return(result);
            }
            finally
            {
                Lock.ExitReadLock();
            }
        }