Exemplo n.º 1
0
        public T Get(int id)
        {
            lock (repositoryLocker)
            {
                if (_cachedDictionary.ContainsKey(id))
                {
                    return(_cachedDictionary[id]);
                }

                Dictionary <string, string> item = null;

                if (_loadingMode == RepositoryMode.Lazy)
                {
                    item = _repositoryProvider.Get(id.ToString());
                }

                if (item == null)
                {
                    throw new InvalidOperationException("id error");
                }

                var entity = _converter.ToEntity(item);
                _cachedDictionary.Add(entity.getId(), entity);

                return(_cachedDictionary[id]);
            }
        }
Exemplo n.º 2
0
        private T _Get(int id)
        {
            CheckInitialization();
            if (_entityCache.ContainsKey(id))
            {
                return(_entityCache[id]);
            }

            // it won't exist only if it was set to lazy init, otherwise cache should update with any operation
            if (_initType == InitType.Lazy)
            {
                // try to get that entry
                Dictionary <string, string> entry = _repositoryProvider.Get(id);
                if (entry != null)
                {
                    // add that entity to the cache
                    T entity = (T)_entityTranslator.ParseEntity(entry);
                    _entityCache.Add(entity.Id, entity);
                    return(entity);
                }
            }

            return(null);
        }
        public async Task<ServiceResponse> Get(int idProvider)
        {
            var sr = new ServiceResponse();

            try
            {
                sr.Data = _mapper.Map<ProductDto>(await _repositoryProvider.Get(idProvider));
            }
            catch (Exception ex)
            {
                sr.AddError(ex);
            }

            return sr;
        }
Exemplo n.º 4
0
        public Models.Repository Get(Models.Repository dummy)
        {
            var cacheKey = GetCacheKey(dummy);
            var o        = (Repository)dummy.ObjectCache().Get(cacheKey);

            if (o == null)
            {
                o = inner.Get(dummy);
                if (o == null)
                {
                    return(o);
                }
                dummy.ObjectCache().Add(cacheKey, o, Kooboo.CMS.Caching.ObjectCacheExtensions.DefaultCacheItemPolicy);
            }
            return(o);
        }
Exemplo n.º 5
0
        public Models.Repository Get(Models.Repository dummy)
        {
            var cacheKey = GetCacheKey(dummy);
            var o        = (Repository)dummy.ObjectCache().Get(cacheKey);

            if (o == null)
            {
                o = inner.Get(dummy);
                if (o == null)
                {
                    return(o);
                }
                dummy.ObjectCache().Add(cacheKey, o, CacheProviderFactory.DefaultCacheItemPolicy);
            }
            return(o);
        }
Exemplo n.º 6
0
 /// <summary>
 /// 通过一组主键值返回一个实体对象。
 /// </summary>
 /// <param name="primaryValues">一组主键值。</param>
 /// <returns></returns>
 public TEntity Get(params PropertyValue[] primaryValues)
 {
     return(repositoryProxy.Get(primaryValues));
 }
Exemplo n.º 7
0
 public Repository Get(Repository dummy)
 {
     return(inner.Get(dummy));
 }
Exemplo n.º 8
0
 /// <summary>
 /// 通过一组主键值返回一个实体对象。
 /// </summary>
 /// <param name="primaryValues">一组主键值。</param>
 /// <returns></returns>
 public TEntity Get(params object[] primaryValues)
 {
     return(repositoryProxy.Get(primaryValues));
 }