Exemplo n.º 1
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.º 2
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.º 3
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.º 4
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.º 5
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)));
        }