public async Task DeleteAsync(TEntity entity, DbConnection conn, DbTransaction trans) { try { if (entity is ISoftDelete) { _deletionAuditDapperActionFilter.ExecuteFilter(entity); await UpdateAsync(entity, conn, trans); } else { conn.Delete(entity, trans); if (CPlatformAppConfig.CacheSectionOptions.IsEnableRepositoryCache) { CacheFactory.CreateCacheProvider().Remove(listCacheKey, string.Format(getCacheKey, entity.Id)); } } } catch (Exception ex) { if (_logger.IsEnabled(LogLevel.Error)) { _logger.LogError(ex.Message, ex); } throw new DataAccessException(ex.Message, ex); } }
//Private constructor private MemcachedClient(string name, string[] hosts) { if (String.IsNullOrEmpty(name)) { throw new ConfigurationErrorsException("Name of MemcachedClient instance cannot be empty."); } Name = name; serverPool = new ServerPool(hosts); string cacheName = ""; try { cacheName = ConfigurationManager.AppSettings["NCache.CacheName"]; if (String.IsNullOrEmpty(cacheName)) { Exception ex = new Exception("Unable to read NCache Name from configuration"); throw ex; } } catch (Exception e) { throw e; } try { memcachedProvider = CacheFactory.CreateCacheProvider(cacheName); } catch (Exception e) { } }
public async Task <IEnumerable <TEntity> > GetAllAsync(Expression <Func <TEntity, bool> > predicate) { try { if (CPlatformAppConfig.CacheSectionOptions.IsEnableRepositoryCache) { return((await GetAllAsync()).AsQueryable().Where(predicate)); } else { using (var conn = GetDbConnection()) { predicate = _softDeleteQueryFilter.ExecuteFilter <TEntity, TPrimaryKey>(predicate); var pg = predicate.ToPredicateGroup <TEntity, TPrimaryKey>(); var list = conn.GetList <TEntity>(pg); if (CPlatformAppConfig.CacheSectionOptions.IsEnableRepositoryCache) { CacheFactory.CreateCacheProvider().Update(listCacheKey, list); } return(list); } } } catch (Exception ex) { if (_logger.IsEnabled(LogLevel.Error)) { _logger.LogError(ex.Message, ex); } throw new DataAccessException(ex.Message, ex); } }
public async Task InsertOrUpdateAsync(TEntity entity) { try { if (entity.Id == null) { _creationActionFilter.ExecuteFilter(entity); await InsertAsync(entity); if (CPlatformAppConfig.CacheSectionOptions.IsEnableRepositoryCache) { CacheFactory.CreateCacheProvider().RemoveAsync(listCacheKey); } } else { var existEntity = await SingleOrDefaultAsync(p => p.Id.Equals(entity.Id)); if (existEntity == null) { _creationActionFilter.ExecuteFilter(entity); await InsertAsync(entity); if (CPlatformAppConfig.CacheSectionOptions.IsEnableRepositoryCache) { CacheFactory.CreateCacheProvider().RemoveAsync(listCacheKey); } } else { _modificationActionFilter.ExecuteFilter(entity); await UpdateAsync(entity); if (CPlatformAppConfig.CacheSectionOptions.IsEnableRepositoryCache) { CacheFactory.CreateCacheProvider().Remove(listCacheKey, string.Format(getCacheKey, entity.Id)); } } } } catch (Exception ex) { if (_logger.IsEnabled(LogLevel.Error)) { _logger.LogError(ex.Message, ex); } throw new DataAccessException(ex.Message, ex); } }
public async Task InsertAsync(TEntity entity, DbConnection conn, DbTransaction trans) { try { _creationActionFilter.ExecuteFilter(entity); conn.Insert <TEntity>(entity, trans); if (CPlatformAppConfig.CacheSectionOptions.IsEnableRepositoryCache) { CacheFactory.CreateCacheProvider().RemoveAsync(listCacheKey); } } catch (Exception ex) { if (_logger.IsEnabled(LogLevel.Error)) { _logger.LogError(ex.Message, ex); } throw new DataAccessException(ex.Message, ex); } }
public async Task <TPrimaryKey> InsertAndGetIdAsync(TEntity entity) { try { using (var conn = GetDbConnection()) { _creationActionFilter.ExecuteFilter(entity); conn.Insert(entity); if (CPlatformAppConfig.CacheSectionOptions.IsEnableRepositoryCache) { CacheFactory.CreateCacheProvider().RemoveAsync(listCacheKey); } return(entity.Id); } } catch (Exception ex) { if (_logger.IsEnabled(LogLevel.Error)) { _logger.LogError(ex.Message, ex); } throw new DataAccessException(ex.Message, ex); } }
public async Task UpdateAsync(TEntity entity) { try { using (var conn = GetDbConnection()) { _modificationActionFilter.ExecuteFilter(entity); conn.Update(entity); if (CPlatformAppConfig.CacheSectionOptions.IsEnableRepositoryCache) { CacheFactory.CreateCacheProvider().Remove(listCacheKey, string.Format(getCacheKey, entity.Id)); } } } catch (Exception ex) { if (_logger.IsEnabled(LogLevel.Error)) { _logger.LogError(ex.Message, ex); } throw new DataAccessException(ex.Message, ex); } }
public ExecutionManager(LogManager logManager) { _cacheProvider = CacheFactory.CreateCacheProvider(MemConfiguration.CacheName); _logManager = logManager; }
public async Task <TEntity> GetAsync(TPrimaryKey id) { return(await CacheFactory.CreateCacheProvider().GetAsyn(string.Format(getCacheKey, id), async() => { return await SingleAsync(CreateEqualityExpressionForId(id)); })); }