Exemplo n.º 1
0
        internal virtual Assembly ResolveAssembly(AssemblyName referenceName)
        {
            Assembly assembly = null;

            // look in the already loaded assemblies
            foreach (var current in GetAlreadyLoadedNonSystemAssemblies())
            {
                if (AssemblyName.ReferenceMatchesDefinition(referenceName, new AssemblyName(current.FullName)))
                {
                    return(current);
                }
            }

            // try to load this one specifically
            if (assembly == null)
            {
                assembly = MetadataAssemblyHelper.SafeLoadReferencedAssembly(referenceName);
                if (assembly != null)
                {
                    return(assembly);
                }
            }

            // try all the discoverable ones
            TryFindWildcardAssemblyMatch(referenceName, out assembly);

            return(assembly);
        }
Exemplo n.º 2
0
        /// <summary>
        ///     Implicit loading means that we are trying to help the user find the right
        ///     assembly, but they didn't explicitly ask for it. Our Implicit rules require that
        ///     we filter out assemblies with the Ecma or MicrosoftPublic PublicKeyToken on them
        ///     Load metadata from the type's assembly.
        /// </summary>
        /// <param name="type"> The type's assembly is loaded into the OSpace ItemCollection </param>
        /// <returns> true if the type and all its generic arguments are filtered out (did not attempt to load assembly) </returns>
        internal bool ImplicitLoadAssemblyForType(Type type, EdmItemCollection edmItemCollection)
        {
            bool result;

            if (!MetadataAssemblyHelper.ShouldFilterAssembly(type.Assembly))
            {
                // InternalLoadFromAssembly will check _knownAssemblies
                result = LoadAssemblyFromCache(this, type.Assembly, false /*loadAllReferencedAssemblies*/, edmItemCollection, null);
            }
            else
            {
                result = false;
            }

            if (type.IsGenericType)
            {
                // recursively load all generic types
                // interesting code paths are ObjectQuery<Nullable<Int32>>, ObjectQuery<IEnumerable<Product>>
                foreach (var t in type.GetGenericArguments())
                {
                    result |= ImplicitLoadAssemblyForType(t, edmItemCollection);
                }
            }
            return(result);
        }
Exemplo n.º 3
0
        private static void LoadAssembly(
            Assembly assembly,
            bool loadReferencedAssemblies,
            ObjectItemLoadingSessionData loadingData)
        {
            KnownAssemblyEntry entry;
            bool flag;

            if (loadingData.KnownAssemblies.TryGetKnownAssembly(assembly, (object)loadingData.ObjectItemAssemblyLoaderFactory, loadingData.EdmItemCollection, out entry))
            {
                flag = !entry.ReferencedAssembliesAreLoaded && loadReferencedAssemblies;
            }
            else
            {
                ObjectItemAssemblyLoader.CreateLoader(assembly, loadingData).Load();
                flag = loadReferencedAssemblies;
            }
            if (!flag)
            {
                return;
            }
            if (entry == null && loadingData.KnownAssemblies.TryGetKnownAssembly(assembly, (object)loadingData.ObjectItemAssemblyLoaderFactory, loadingData.EdmItemCollection, out entry) || entry != null)
            {
                entry.ReferencedAssembliesAreLoaded = true;
            }
            foreach (Assembly referencedAssembly in MetadataAssemblyHelper.GetNonSystemReferencedAssemblies(assembly))
            {
                AssemblyCache.LoadAssembly(referencedAssembly, loadReferencedAssemblies, loadingData);
            }
        }
Exemplo n.º 4
0
 // <summary>
 // The method loads the O-space metadata for all the referenced assemblies starting from the given assembly
 // in a recursive way.
 // The assembly should be from Assembly.GetCallingAssembly via one of our public API's.
 // </summary>
 // <param name="assembly"> assembly whose dependency list we are going to traverse </param>
 internal void ImplicitLoadAllReferencedAssemblies(Assembly assembly, EdmItemCollection edmItemCollection)
 {
     if (!MetadataAssemblyHelper.ShouldFilterAssembly(assembly))
     {
         LoadAssemblyFromCache(assembly, true, edmItemCollection, null);
     }
 }
Exemplo n.º 5
0
 private static bool ShouldFilterAssembly(AssemblyName assemblyName)
 {
     if (!MetadataAssemblyHelper.ArePublicKeyTokensEqual(assemblyName.GetPublicKeyToken(), MetadataAssemblyHelper._ecmaPublicKeyToken))
     {
         return(MetadataAssemblyHelper.ArePublicKeyTokensEqual(assemblyName.GetPublicKeyToken(), MetadataAssemblyHelper._msPublicKeyToken));
     }
     return(true);
 }
Exemplo n.º 6
0
 /// <summary>
 ///     Implicit loading means that we are trying to help the user find the right
 ///     assembly, but they didn't explicitly ask for it. Our Implicit rules require that
 ///     we filter out assemblies with the Ecma or MicrosoftPublic PublicKeyToken on them
 /// </summary>
 internal void ImplicitLoadFromAssembly(Assembly assembly, EdmItemCollection edmItemCollection)
 {
     if (!MetadataAssemblyHelper.ShouldFilterAssembly(assembly))
     {
         // it meets the Implicit rules Load it
         ExplicitLoadFromAssembly(assembly, edmItemCollection, null);
     }
 }
Exemplo n.º 7
0
 internal void ImplicitLoadAllReferencedAssemblies(
     Assembly assembly,
     EdmItemCollection edmItemCollection)
 {
     if (MetadataAssemblyHelper.ShouldFilterAssembly(assembly))
     {
         return;
     }
     this.LoadAssemblyFromCache(assembly, true, edmItemCollection, (Action <string>)null);
 }
Exemplo n.º 8
0
 private static IEnumerable <Assembly> GetAlreadyLoadedNonSystemAssemblies()
 {
     return(((IEnumerable <Assembly>)AppDomain.CurrentDomain.GetAssemblies()).Where <Assembly>((Func <Assembly, bool>)(a =>
     {
         if (a != (Assembly)null)
         {
             return !MetadataAssemblyHelper.ShouldFilterAssembly(a);
         }
         return false;
     })));
 }
Exemplo n.º 9
0
        // <summary>
        // This method returns a list of assemblies whose contents depend on whether we
        // are running in an ASP.NET environment. If we are indeed in a Web/ASP.NET
        // scenario, we pick up the assemblies that all page compilations need to
        // reference. If not, then we simply get the list of assemblies referenced by
        // the entry assembly.
        // </summary>
        // <returns> A list of assemblies </returns>
        private static IEnumerable <Assembly> GetAllDiscoverableAssemblies()
        {
            var assembly     = Assembly.GetEntryAssembly();
            var assemblyList = new HashSet <Assembly>(
                AssemblyComparer.Instance);

            foreach (var loadedAssembly in GetAlreadyLoadedNonSystemAssemblies())
            {
                assemblyList.Add(loadedAssembly);
            }

            var aspProxy = new AspProxy();

            if (!aspProxy.IsAspNetEnvironment())
            {
                if (assembly == null)
                {
                    return(assemblyList);
                }

                assemblyList.Add(assembly);

                foreach (var referenceAssembly in MetadataAssemblyHelper.GetNonSystemReferencedAssemblies(assembly))
                {
                    assemblyList.Add(referenceAssembly);
                }

                return(assemblyList);
            }

            if (aspProxy.HasBuildManagerType())
            {
                var referencedAssemblies = aspProxy.GetBuildManagerReferencedAssemblies();
                // filter out system assemblies
                if (referencedAssemblies != null)
                {
                    foreach (var referencedAssembly in referencedAssemblies)
                    {
                        if (MetadataAssemblyHelper.ShouldFilterAssembly(referencedAssembly))
                        {
                            continue;
                        }

                        assemblyList.Add(referencedAssembly);
                    }
                }
            }

            return(assemblyList.Where(a => a != null));
        }
Exemplo n.º 10
0
 internal static IEnumerable <Assembly> GetNonSystemReferencedAssemblies(
     Assembly assembly)
 {
     foreach (AssemblyName referencedAssembly in assembly.GetReferencedAssemblies())
     {
         if (!MetadataAssemblyHelper.ShouldFilterAssembly(referencedAssembly))
         {
             Assembly referenceAssembly = MetadataAssemblyHelper.SafeLoadReferencedAssembly(referencedAssembly);
             if (referenceAssembly != (Assembly)null)
             {
                 yield return(referenceAssembly);
             }
         }
     }
 }
Exemplo n.º 11
0
        private static void LoadAssembly(Assembly assembly, bool loadReferencedAssemblies, ObjectItemLoadingSessionData loadingData)
        {
            // Check if the assembly is already loaded
            KnownAssemblyEntry entry;
            var shouldLoadReferences = false;

            if (loadingData.KnownAssemblies.TryGetKnownAssembly(
                    assembly, loadingData.ObjectItemAssemblyLoaderFactory, loadingData.EdmItemCollection, out entry))
            {
                shouldLoadReferences = !entry.ReferencedAssembliesAreLoaded && loadReferencedAssemblies;
            }
            else
            {
                var loader = ObjectItemAssemblyLoader.CreateLoader(assembly, loadingData);
                loader.Load();
                shouldLoadReferences = loadReferencedAssemblies;
            }

            if (shouldLoadReferences)
            {
                if (entry == null
                    &&
                    loadingData.KnownAssemblies.TryGetKnownAssembly(
                        assembly, loadingData.ObjectItemAssemblyLoaderFactory, loadingData.EdmItemCollection, out entry)
                    ||
                    entry != null)
                {
                    entry.ReferencedAssembliesAreLoaded = true;
                }
                Debug.Assert(entry != null, "we should always have an entry, why don't we?");

                // We will traverse through all the statically linked assemblies and their dependencies.
                // Only assemblies with the EdmSchemaAttribute will be loaded and rest will be ignored

                // Even if the schema attribute is missing, we should still check all the dependent assemblies
                // any of the dependent assemblies can have the schema attribute

                // After the given assembly has been loaded, check on the flag in _knownAssemblies to see if it has already
                // been recursively loaded. The flag can be true if it was already loaded before this function was called
                foreach (var referencedAssembly in MetadataAssemblyHelper.GetNonSystemReferencedAssemblies(assembly))
                {
                    // filter out "known" assemblies to prevent unnecessary loading
                    // recursive call
                    LoadAssembly(referencedAssembly, loadReferencedAssemblies, loadingData);
                }
            }
        }
Exemplo n.º 12
0
        internal bool ImplicitLoadAssemblyForType(Type type, EdmItemCollection edmItemCollection)
        {
            bool flag = false;

            if (!MetadataAssemblyHelper.ShouldFilterAssembly(type.Assembly()))
            {
                flag = this.LoadAssemblyFromCache(type.Assembly(), false, edmItemCollection, (Action <string>)null);
            }
            if (type.IsGenericType())
            {
                foreach (Type genericArgument in type.GetGenericArguments())
                {
                    flag |= this.ImplicitLoadAssemblyForType(genericArgument, edmItemCollection);
                }
            }
            return(flag);
        }
Exemplo n.º 13
0
        internal void ImplicitLoadViewsFromAllReferencedAssemblies(Assembly assembly)
        {
            // we filter implicit loads
            if (MetadataAssemblyHelper.ShouldFilterAssembly(assembly))
            {
                return;
            }
            lock (this)
            {
                CollectIfViewGenAssembly(assembly);

                foreach (var referenceAssembly in MetadataAssemblyHelper.GetNonSystemReferencedAssemblies(assembly))
                {
                    CollectIfViewGenAssembly(referenceAssembly);
                }
            }
        }
Exemplo n.º 14
0
        private static IEnumerable <Assembly> GetAllDiscoverableAssemblies()
        {
            Assembly           entryAssembly = Assembly.GetEntryAssembly();
            HashSet <Assembly> source        = new HashSet <Assembly>((IEqualityComparer <Assembly>)DefaultAssemblyResolver.AssemblyComparer.Instance);

            foreach (Assembly nonSystemAssembly in DefaultAssemblyResolver.GetAlreadyLoadedNonSystemAssemblies())
            {
                source.Add(nonSystemAssembly);
            }
            AspProxy aspProxy = new AspProxy();

            if (!aspProxy.IsAspNetEnvironment())
            {
                if (entryAssembly == (Assembly)null)
                {
                    return((IEnumerable <Assembly>)source);
                }
                source.Add(entryAssembly);
                foreach (Assembly referencedAssembly in MetadataAssemblyHelper.GetNonSystemReferencedAssemblies(entryAssembly))
                {
                    source.Add(referencedAssembly);
                }
                return((IEnumerable <Assembly>)source);
            }
            if (aspProxy.HasBuildManagerType())
            {
                IEnumerable <Assembly> referencedAssemblies = aspProxy.GetBuildManagerReferencedAssemblies();
                if (referencedAssemblies != null)
                {
                    foreach (Assembly assembly in referencedAssemblies)
                    {
                        if (!MetadataAssemblyHelper.ShouldFilterAssembly(assembly))
                        {
                            source.Add(assembly);
                        }
                    }
                }
            }
            return(source.Where <Assembly>((Func <Assembly, bool>)(a => a != (Assembly)null)));
        }
Exemplo n.º 15
0
        internal virtual Assembly ResolveAssembly(AssemblyName referenceName)
        {
            Assembly assembly = (Assembly)null;

            foreach (Assembly nonSystemAssembly in DefaultAssemblyResolver.GetAlreadyLoadedNonSystemAssemblies())
            {
                if (AssemblyName.ReferenceMatchesDefinition(referenceName, new AssemblyName(nonSystemAssembly.FullName)))
                {
                    return(nonSystemAssembly);
                }
            }
            if (assembly == (Assembly)null)
            {
                assembly = MetadataAssemblyHelper.SafeLoadReferencedAssembly(referenceName);
                if (assembly != (Assembly)null)
                {
                    return(assembly);
                }
            }
            DefaultAssemblyResolver.TryFindWildcardAssemblyMatch(referenceName, out assembly);
            return(assembly);
        }
Exemplo n.º 16
0
        // <summary>
        // Return all assemblies loaded in the current AppDomain that are not signed
        // with the Microsoft Key.
        // </summary>
        // <returns> A list of assemblies </returns>
        private static IEnumerable <Assembly> GetAlreadyLoadedNonSystemAssemblies()
        {
            var assemblies = AppDomain.CurrentDomain.GetAssemblies();

            return(assemblies.Where(a => a != null && !MetadataAssemblyHelper.ShouldFilterAssembly(a)));
        }
Exemplo n.º 17
0
 private static bool ComputeShouldFilterAssembly(Assembly assembly)
 {
     return(MetadataAssemblyHelper.ShouldFilterAssembly(new AssemblyName(assembly.FullName)));
 }