public async Task ReloadCacheAsync(ICustomContext context) { foreach (var item in _cache) { await item.Value.ReloadDataAsync(context); } }
public async Task ReloadCacheAsync(ICustomContext context, string cacheName) { if (_cache.TryGetValue(cacheName, out IData <dynamic> cache)) { await cache.ReloadDataAsync(context); } }
public static string GetTableName <T>(this ICustomContext context) where T : class { var mapping = context.Model.FindEntityType(typeof(T)); var tableName = $"[{mapping.GetSchema()}].[{mapping.GetTableName()}]"; return(tableName); }
public async Task <T> GetItemFromCache <T>(ICustomContext context, string cacheName, bool forceImmediateReload = false) where T : class { if (_cache.TryGetValue(cacheName, out IData <dynamic> cachedDataObject)) { return(await cachedDataObject.GetAsync(context, forceImmediateReload)); } return(null); }
public async Task <T> GetAsync(ICustomContext context, bool forceReload = false) { if (IsExpired || forceReload) { await ReloadDataAsync(context); } var data = DeepCopy.ObjectCloner.Clone(_cachedData, false); return(data); }
public virtual ICustomContext GetLocalContext(IWorkerContext context) { try { ICustomContext cc = context.Get(GetContextKey()); if (null != cc) { return(cc); } throw new PipelineException(String.Format(LocaleMessages.GetInstance().GetMessage(LocaleMessages.OWN_CONTEXT_404), this.GetType().FullName)); } catch (NoCustomContextException e) { throw new PipelineException(String.Format(LocaleMessages.GetInstance().GetMessage(LocaleMessages.OWN_CONTEXT_404), this.GetType().FullName), e); } }
public ServiceConstructor(ICacheContainer cacheContainer, ICustomContext context, string username, Expression <Func <T, bool> > cacheLoadFilter = null, Func <IQueryable <T>, IIncludableQueryable <T, object> > includeInCache = null, int cacheTimeoutInMinutes = 10, bool isSharedContext = true) { CacheContainer = cacheContainer; Context = context; IsSharedContext = isSharedContext; CacheLoadFilter = cacheLoadFilter; CacheTimoutInMinutes = cacheTimeoutInMinutes; Username = username; IncludePropertiesInCache = includeInCache; }
public async Task <T> GetAndLoadCacheItemAsync <T>(ICustomContext context, string cacheName, Func <ICustomContext, Task <T> > reloadMethodAsync, bool forceImmediateReload = false, int timeoutInMinutes = 10) where T : class { var cachedRec = await GetItemFromCache <T>(context, cacheName, forceImmediateReload); if (cachedRec != null) { return(cachedRec); } var data = await reloadMethodAsync(context); AddItemToCache(cacheName, data, reloadMethodAsync, forceImmediateReload, timeoutInMinutes); return(data); }
protected BaseService(IServiceConstructor <T> constructor) { CurrentUsername = constructor.Username; Context = constructor.Context; IsSharedContext = constructor.IsSharedContext; Repo = new GenericRepository <T, SqlParameter, int>(this.Context, CurrentUsername); CacheContainer = constructor.CacheContainer; cacheLoadFilter = constructor.CacheLoadFilter; cacheTimeoutInMinutes = constructor.CacheTimoutInMinutes; includePropertiesInCache = constructor.IncludePropertiesInCache; reloadMethod = async(context) => { IGenericRepository <T, int> repo = new GenericRepository <T, SqlParameter, int>(context, "System"); var data = await repo.GetAsync(cacheLoadFilter, includePropertiesInCache); var detachedData = data.Select(t => repo.CreateDetachedEntity(t)).ToList(); return(detachedData); }; }
public static void UpdateAllPropertiesToValue <TEntity, TEntityValue>(this ICustomContext context, TEntity entity, string propertyName, TEntityValue value) where TEntity : class { if (entity.GetType().GetProperty(propertyName) != null) { var propertyType = entity.GetType().GetProperty(propertyName).PropertyType; propertyType = Nullable.GetUnderlyingType(propertyType) ?? propertyType; if (propertyType != value.GetType()) { throw new InvalidCastException($"The type doesn't match the property that is being inserted for {entity.GetType()} - {propertyName}. {propertyType.ToString()} != {value.GetType().ToString()}"); } entity.GetType().GetProperty(propertyName).SetValue(entity, value); if (context.Entry(entity).State != EntityState.Detached) { context.Entry(entity).Property(propertyName).IsModified = true; } } foreach (var property in entity.GetType().GetProperties()) { if (property.PropertyType.IsClass && property.PropertyType.IsByRef) { UpdateAllPropertiesToValue(context, property, propertyName, value); } if (property.PropertyType.IsInterface && property.PropertyType.GetInterface(typeof(IEnumerable <>).FullName) != null) { var propValue = entity.GetType().GetProperty(property.Name).GetValue(entity); if (propValue == null) { continue; } foreach (var propValueCollectionItem in (System.Collections.IEnumerable)propValue) { UpdateAllPropertiesToValue(context, propValueCollectionItem, propertyName, value); } } } }
public static void SetFieldsAsNotModified <TEntity>(this ICustomContext context, TEntity entity, string[] excludedProperties = null) where TEntity : class { foreach (var property in entity.GetType().GetProperties()) { if ((property.PropertyType.IsClass || property.PropertyType.IsPrimitive || property.PropertyType.IsValueType) && excludedProperties.Contains(property.Name)) { context.Entry(entity).Property(property.Name).IsModified = false; } else if (property.PropertyType.IsInterface && property.PropertyType.GetInterface(typeof(IEnumerable <>).FullName) != null) { var propValue = entity.GetType().GetProperty(property.Name).GetValue(entity); if (propValue == null) { continue; } foreach (var propValueCollectionItem in (System.Collections.IEnumerable)propValue) { SetFieldsAsNotModified(context, propValueCollectionItem); } } } }
public Actmgr_Actividades(ICustomContext context) : base(context) { }
public BaseContext(ICustomContext Contexto) { this.Contexto = Contexto; }
public StudentService(ICustomContext context, string currentUsername) : base(context, currentUsername) { }
public Business(ICustomContext context) { this.context = context; }
public async Task ReloadDataAsync(ICustomContext context) { _cachedData = await _reloadMethodAsync(context); Updated = DateTime.Now; }
public Actmgr_Proyectos(ICustomContext Contexto) : base(Contexto) { }
public CourseService(ICustomContext context, string currentUsername) : base(context, currentUsername) { }
public AttributeCommaSeparated() { _reflectionService = (ReflectionService)ServiceLocator.ServiceProvider.GetService(typeof(IReflectionService)); _sitecoreService = (ISitecoreService)ServiceLocator.ServiceProvider.GetService(typeof(ISitecoreService)); _customContext = (ICustomContext)ServiceLocator.ServiceProvider.GetService(typeof(ICustomContext)); }
/** * Convenience method. * @param key the key to store the CustomContext for. * @param context the CustomContext to store. */ virtual public void Put(String key, ICustomContext context) { mc[key] = context; }
protected GenericServiceContainer(ICustomContext context) { this.context = context; }
/** * Convenience method. * @param key the key to store the CustomContext for. * @param context the CustomContext to store. */ virtual public void Put(String key, ICustomContext context) { mc[key] = context; }
public BaseService(ICustomContext context, string currentUsername) { Context = context; CurrentUsername = currentUsername; Repo = new GenericRepository <T, SqlParameter, int>(Context, CurrentUsername); }
public GenericRepositoryBase(ICustomContext context) { this.context = context; this.dbSet = this.context.Set <T>(); }
public GenericRepository(ICustomContext context, string currentUser, string parameterPrefix = "@") : base(context) { CurrentUser = currentUser; this.parameterPrefix = parameterPrefix; }
public MvcContext(ISitecoreService sitecoreService, IReflectionService reflectionService, ICustomContext customContext) { SitecoreService = sitecoreService; _reflectionService = reflectionService; _customContext = customContext; }
public CustomRepository(ICustomContext context) { _context = context; }