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), null));
                }
                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);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Explicit loading means that the user specifically asked us to load this assembly.
 /// We won't do any filtering, they "know what they are doing"
 /// </summary>
 internal void ExplicitLoadFromAssembly(Assembly assembly, EdmItemCollection edmItemCollection, Action <String> logLoadMessage)
 {
     LoadAssemblyFromCache(this, assembly, false /*loadAllReferencedAssemblies*/, edmItemCollection, logLoadMessage);
     //Since User called LoadFromAssembly, so we should collect the generated views if present
     //even if the schema attribute is not present
     if (IsCompiledViewGenAttributePresent(assembly) && !ObjectItemAttributeAssemblyLoader.IsSchemaAttributePresent(assembly))
     {
         CollectIfViewGenAssembly(assembly);
     }
 }
 internal static ObjectItemAssemblyLoader Create(Assembly assembly, ObjectItemLoadingSessionData sessionData)
 {
     if (ObjectItemAttributeAssemblyLoader.IsSchemaAttributePresent(assembly))
     {
         return(new ObjectItemAttributeAssemblyLoader(assembly, sessionData));
     }
     else
     {
         return(new ObjectItemNoOpAssemblyLoader(assembly, sessionData));
     }
 }
Ejemplo n.º 4
0
 internal static ObjectItemAssemblyLoader Create(Assembly assembly, ObjectItemLoadingSessionData sessionData)
 {
     if (!ObjectItemAttributeAssemblyLoader.IsSchemaAttributePresent(assembly))
     {
         return(new ObjectItemConventionAssemblyLoader(assembly, sessionData));
     }
     else
     {
         // we were loading in convention mode, and ran into an assembly that can't be loaded by convention
         sessionData.EdmItemErrors.Add(new EdmItemError(Strings.Validator_OSpace_Convention_AttributeAssemblyReferenced(assembly.FullName), null));
         return(new ObjectItemNoOpAssemblyLoader(assembly, sessionData));
     }
 }