public IQueryable <T> GetData <T>(bool useCaching, IEnumerable <string> providerNames)
            where T : class, IData
        {
            IQueryable <T> resultQueryable;

            if (DataProviderRegistry.AllInterfaces.Contains(typeof(T)))
            {
                if (useCaching &&
                    providerNames == null &&
                    DataCachingFacade.IsDataAccessCacheEnabled(typeof(T)))
                {
                    resultQueryable = DataCachingFacade.GetDataFromCache <T>(
                        () => BuildQueryFromProviders <T>(null));
                }
                else
                {
                    resultQueryable = BuildQueryFromProviders <T>(providerNames);
                }
            }
            else
            {
                DataProviderRegistry.CheckInitializationErrors(typeof(T));

                if (!typeof(T).GetCustomInterfaceAttributes <AutoUpdatebleAttribute>().Any())
                {
                    throw new ArgumentException($"The given interface type ({typeof (T)}) is not supported by any data providers");
                }

                resultQueryable = new List <T>().AsQueryable();
            }

            foreach (var dataInterceptor in GetDataInterceptors(typeof(T)))
            {
                try
                {
                    resultQueryable = dataInterceptor.InterceptGetData <T>(resultQueryable);
                }
                catch (Exception ex)
                {
                    Log.LogError(LogTitle, ex);
                }
            }

            return(resultQueryable);
        }
Beispiel #2
0
        public IQueryable <T> GetData <T>(bool useCaching, IEnumerable <string> providerNames)
            where T : class, IData
        {
            IQueryable <T> resultQueryable;

            if (DataProviderRegistry.AllInterfaces.Contains(typeof(T)))
            {
                if (useCaching && DataCachingFacade.IsDataAccessCacheEnabled(typeof(T)))
                {
                    resultQueryable = DataCachingFacade.GetDataFromCache <T>();
                }
                else
                {
                    if (providerNames == null)
                    {
                        providerNames = DataProviderRegistry.GetDataProviderNamesByInterfaceType(typeof(T));
                    }

                    List <IQueryable <T> > queryables = new List <IQueryable <T> >();
                    foreach (string providerName in providerNames)
                    {
                        IQueryable <T> queryable = DataProviderPluginFacade.GetData <T>(providerName);

                        queryables.Add(queryable);
                    }

                    bool resultIsCached = queryables.Count == 1 && queryables[0] is ICachedQuery;

                    if (resultIsCached)
                    {
                        resultQueryable = queryables[0];
                    }
                    else
                    {
                        var multipleSourceQueryable = new DataFacadeQueryable <T>(queryables);

                        resultQueryable = multipleSourceQueryable;
                    }
                }
            }
            else
            {
                DataProviderRegistry.CheckInitializationErrors(typeof(T));

                if (!typeof(T).GetCustomInterfaceAttributes <AutoUpdatebleAttribute>().Any())
                {
                    throw new ArgumentException(string.Format("The given interface type ({0}) is not supported by any data providers", typeof(T)));
                }

                resultQueryable = new List <T>().AsQueryable();
            }


            DataInterceptor dataInterceptor;

            this.DataInterceptors.TryGetValue(typeof(T), out dataInterceptor);
            if (dataInterceptor != null)
            {
                try
                {
                    resultQueryable = dataInterceptor.InterceptGetData <T>(resultQueryable);
                }
                catch (Exception ex)
                {
                    Log.LogError(LogTitle, "Calling data interceptor failed with the following exception");
                    Log.LogError(LogTitle, ex);
                }
            }

            return(resultQueryable);
        }