예제 #1
0
        private IQueryable <T> BuildQueryFromProviders <T>(IEnumerable <string> providerNames) where T : class, IData
        {
            if (providerNames == null)
            {
                providerNames = DataProviderRegistry.GetDataProviderNamesByInterfaceType(typeof(T));
            }

            var queries = new List <IQueryable <T> >();

            foreach (string providerName in providerNames)
            {
                IQueryable <T> query = DataProviderPluginFacade.GetData <T>(providerName);

                queries.Add(query);
            }

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

            if (resultIsCached)
            {
                return(queries[0]);
            }

            return(new DataFacadeQueryable <T>(queries));
        }
예제 #2
0
        private static bool DataProvidersSupportDataWrapping(Type T)
        {
            var providerNames = DataProviderRegistry.GetDataProviderNamesByInterfaceType(T);

            Verify.IsNotNull(providerNames, "Failed to get data provider names list");

            return(providerNames.All(DataProviderPluginFacade.AllowsResultsWrapping));
        }
        /// <summary>
        /// Copies all the data from the source data provider to the target data provider.
        /// </summary>
        public void FullCopy()
        {
            var allTypes = from type in DataFacade.GetAllInterfaces()
                           where DataProviderRegistry.GetDataProviderNamesByInterfaceType(type).Contains(this.SourceProviderName)
                           select type;

            Copy(allTypes);
        }
        private void EnsureInterfaces(IEnumerable <Type> allInterfaces)
        {
            var dataTypeDescriptors = new List <DataTypeDescriptor>();

            foreach (Type interfaceType in allInterfaces)
            {
                if (!DataProviderRegistry.GetDataProviderNamesByInterfaceType(interfaceType).Contains(this.TargetProviderName))
                {
                    var dataTypeDescriptor = DynamicTypeManager.BuildNewDataTypeDescriptor(interfaceType);

                    dataTypeDescriptor.Validate();

                    dataTypeDescriptors.Add(dataTypeDescriptor);
                }
            }

            DataProviderPluginFacade.CreateStores(this.TargetProviderName, dataTypeDescriptors);
        }
예제 #5
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);
        }