Beispiel #1
0
        internal static ObjectItemAssemblyLoader CreateLoader(Assembly assembly, ObjectItemLoadingSessionData sessionData)
        {
            ImmutableAssemblyCacheEntry cacheEntry;

            // KnownAssembly -> NoOp
            // Inside the LockedAssemblyCache means it is an attribute based assembly -> Cachedassembly
            // Inside the OcCache on EdmItemCollection -> cachedassembly
            // If none of above, setup the LoaderFactory based on the current assembly and EdmItemCollection
            if (sessionData.KnownAssemblies.Contains(assembly, sessionData.ObjectItemAssemblyLoaderFactory, sessionData.EdmItemCollection))
            {
                return(new ObjectItemNoOpAssemblyLoader(assembly, sessionData));
            }
            else if (sessionData.LockedAssemblyCache.TryGetValue(assembly, out cacheEntry))
            {
                if (sessionData.ObjectItemAssemblyLoaderFactory == null)
                {
                    if (cacheEntry.TypesInAssembly.Count != 0)
                    {
                        // we are loading based on attributes now
                        sessionData.ObjectItemAssemblyLoaderFactory = ObjectItemAttributeAssemblyLoader.Create;
                    }
                    // if types in assembly are 0, don't commit to any loader yet
                }
                else if (sessionData.ObjectItemAssemblyLoaderFactory
                         != ObjectItemAttributeAssemblyLoader.Create)
                {
                    // we were loading in convention mode, and ran into an assembly that can't be loaded by convention
                    // we know this because all cached assemblies are attribute based at the moment.
                    sessionData.EdmItemErrors.Add(
                        new EdmItemError(Strings.Validator_OSpace_Convention_AttributeAssemblyReferenced(assembly.FullName)));
                }
                return(new ObjectItemCachedAssemblyLoader(assembly, cacheEntry, sessionData));
            }
            else if (sessionData.EdmItemCollection != null
                     &&
                     sessionData.EdmItemCollection.ConventionalOcCache.TryGetConventionalOcCacheFromAssemblyCache(
                         assembly, out cacheEntry))
            {
                sessionData.ObjectItemAssemblyLoaderFactory = ObjectItemConventionAssemblyLoader.Create;
                return(new ObjectItemCachedAssemblyLoader(assembly, cacheEntry, sessionData));
            }
            else if (sessionData.ObjectItemAssemblyLoaderFactory == null)
            {
                if (ObjectItemAttributeAssemblyLoader.IsSchemaAttributePresent(assembly))
                {
                    sessionData.ObjectItemAssemblyLoaderFactory = ObjectItemAttributeAssemblyLoader.Create;
                }
                else if (ObjectItemConventionAssemblyLoader.SessionContainsConventionParameters(sessionData))
                {
                    sessionData.ObjectItemAssemblyLoaderFactory = ObjectItemConventionAssemblyLoader.Create;
                }
            }

            if (sessionData.ObjectItemAssemblyLoaderFactory != null)
            {
                return(sessionData.ObjectItemAssemblyLoaderFactory(assembly, sessionData));
            }

            return(new ObjectItemNoOpAssemblyLoader(assembly, sessionData));
        }
        internal static ObjectItemAssemblyLoader CreateLoader(
            Assembly assembly,
            ObjectItemLoadingSessionData sessionData)
        {
            if (sessionData.KnownAssemblies.Contains(assembly, (object)sessionData.ObjectItemAssemblyLoaderFactory, sessionData.EdmItemCollection))
            {
                return((ObjectItemAssemblyLoader) new ObjectItemNoOpAssemblyLoader(assembly, sessionData));
            }
            ImmutableAssemblyCacheEntry cacheEntry;

            if (sessionData.LockedAssemblyCache.TryGetValue(assembly, out cacheEntry))
            {
                if (sessionData.ObjectItemAssemblyLoaderFactory == null)
                {
                    if (cacheEntry.TypesInAssembly.Count != 0)
                    {
                        sessionData.ObjectItemAssemblyLoaderFactory = new Func <Assembly, ObjectItemLoadingSessionData, ObjectItemAssemblyLoader>(ObjectItemAttributeAssemblyLoader.Create);
                    }
                }
                else if (sessionData.ObjectItemAssemblyLoaderFactory != new Func <Assembly, ObjectItemLoadingSessionData, ObjectItemAssemblyLoader>(ObjectItemAttributeAssemblyLoader.Create))
                {
                    sessionData.EdmItemErrors.Add(new EdmItemError(Strings.Validator_OSpace_Convention_AttributeAssemblyReferenced((object)assembly.FullName)));
                }
                return((ObjectItemAssemblyLoader) new ObjectItemCachedAssemblyLoader(assembly, cacheEntry, sessionData));
            }
            if (sessionData.EdmItemCollection != null && sessionData.EdmItemCollection.ConventionalOcCache.TryGetConventionalOcCacheFromAssemblyCache(assembly, out cacheEntry))
            {
                sessionData.ObjectItemAssemblyLoaderFactory = new Func <Assembly, ObjectItemLoadingSessionData, ObjectItemAssemblyLoader>(ObjectItemConventionAssemblyLoader.Create);
                return((ObjectItemAssemblyLoader) new ObjectItemCachedAssemblyLoader(assembly, cacheEntry, sessionData));
            }
            if (sessionData.ObjectItemAssemblyLoaderFactory == null)
            {
                if (ObjectItemAttributeAssemblyLoader.IsSchemaAttributePresent(assembly))
                {
                    sessionData.ObjectItemAssemblyLoaderFactory = new Func <Assembly, ObjectItemLoadingSessionData, ObjectItemAssemblyLoader>(ObjectItemAttributeAssemblyLoader.Create);
                }
                else if (ObjectItemConventionAssemblyLoader.SessionContainsConventionParameters(sessionData))
                {
                    sessionData.ObjectItemAssemblyLoaderFactory = new Func <Assembly, ObjectItemLoadingSessionData, ObjectItemAssemblyLoader>(ObjectItemConventionAssemblyLoader.Create);
                }
            }
            if (sessionData.ObjectItemAssemblyLoaderFactory != null)
            {
                return(sessionData.ObjectItemAssemblyLoaderFactory(assembly, sessionData));
            }
            return((ObjectItemAssemblyLoader) new ObjectItemNoOpAssemblyLoader(assembly, sessionData));
        }