static CachingQueryable() { if (typeof(IData).IsAssignableFrom(typeof(T))) { _wrappingMethodInfo = StaticReflection.GetGenericMethodInfo(a => DataWrappingFacade.Wrap((IData)a)) .MakeGenericMethod(new[] { typeof(T) }); } }
public T GetDataFromDataSourceId <T>(DataSourceId dataSourceId, bool useCaching) where T : class, IData { if (null == dataSourceId) { throw new ArgumentNullException("dataSourceId"); } useCaching = useCaching && DataCachingFacade.IsTypeCacheable(typeof(T)); using (new DataScope(dataSourceId.DataScopeIdentifier, dataSourceId.LocaleScope)) { T resultData = null; string cacheKey = string.Empty; if (useCaching) { cacheKey = dataSourceId.ToString(); resultData = (T)_dataBySourceIdCache.Get(cacheKey); } if (resultData == null) { resultData = DataProviderPluginFacade.GetData <T>(dataSourceId.ProviderName, dataSourceId.DataId); if (useCaching && resultData != null && _dataBySourceIdCache.Enabled) { _dataBySourceIdCache.Add(cacheKey, resultData); } } if (useCaching && resultData != null) { resultData = DataWrappingFacade.Wrap(resultData); } DataInterceptor dataInterceptor; this.DataInterceptors.TryGetValue(typeof(T), out dataInterceptor); if (dataInterceptor != null) { try { resultData = dataInterceptor.InterceptGetDataFromDataSourceId <T>(resultData); } catch (Exception ex) { Log.LogError(LogTitle, "Calling data interceptor failed with the following exception"); Log.LogError(LogTitle, ex); } } return(resultData); } }
public T GetDataFromDataSourceId <T>(DataSourceId dataSourceId, bool useCaching) where T : class, IData { Verify.ArgumentNotNull(dataSourceId, nameof(dataSourceId)); useCaching = useCaching && DataCachingFacade.IsTypeCacheable(typeof(T)); using (new DataScope(dataSourceId.DataScopeIdentifier, dataSourceId.LocaleScope)) { T resultData = null; string cacheKey = string.Empty; if (useCaching) { cacheKey = dataSourceId.ToString(); resultData = (T)_dataBySourceIdCache.Get(cacheKey); } if (resultData == null) { resultData = DataProviderPluginFacade.GetData <T>(dataSourceId.ProviderName, dataSourceId.DataId); if (useCaching && resultData != null && _dataBySourceIdCache.Enabled) { _dataBySourceIdCache.Add(cacheKey, resultData); } } if (useCaching && resultData != null) { resultData = DataWrappingFacade.Wrap(resultData); } foreach (var dataInterceptor in GetDataInterceptors(typeof(T))) { try { resultData = dataInterceptor.InterceptGetDataFromDataSourceId <T>(resultData); } catch (Exception ex) { Log.LogError(LogTitle, ex); } } return(resultData); } }
public TDataType Get(TPropertyType key, bool forReadOnlyUsage) { TDataType result; string cacheKey = GetCacheKey(key); var cacheRecord = _innerCache.Get(cacheKey); if (cacheRecord != null) { result = cacheRecord.Value; } else { lock (this) { cacheRecord = _innerCache.Get(cacheKey); if (cacheRecord != null) { result = cacheRecord.Value; } else { ParameterExpression parameter = _propertyGetter.Parameters[0]; var newBody = Expression.Equal(_propertyGetter.Body, Expression.Constant(key, typeof(TPropertyType))); var newLabda = Expression.Lambda(newBody, new[] { parameter }) as Expression <Func <TDataType, bool> >; result = DataFacade.GetData <TDataType>(false).Where(newLabda).FirstOrDefault(); _innerCache.Add(cacheKey, new ExtendedNullable <TDataType> { Value = result }); } } } return(result == null || forReadOnlyUsage ? result : DataWrappingFacade.Wrap(result)); }
private static IPage CreateWrapper(IPage page) { return(DataWrappingFacade.Wrap(page)); }