private static List <MetadataArtifactLoaderResource> LoadResources(
            string assemblyName,
            string resourceName,
            ICollection <string> uriRegistry,
            MetadataArtifactAssemblyResolver resolver)
        {
            List <MetadataArtifactLoaderResource> loaders = new List <MetadataArtifactLoaderResource>();

            if (assemblyName == MetadataArtifactLoader.wildcard)
            {
                foreach (Assembly wildcardAssembly in resolver.GetWildcardAssemblies())
                {
                    if (MetadataArtifactLoaderCompositeResource.AssemblyContainsResource(wildcardAssembly, ref resourceName))
                    {
                        MetadataArtifactLoaderCompositeResource.LoadResourcesFromAssembly(wildcardAssembly, resourceName, uriRegistry, loaders);
                    }
                }
            }
            else
            {
                MetadataArtifactLoaderCompositeResource.LoadResourcesFromAssembly(MetadataArtifactLoaderCompositeResource.ResolveAssemblyName(assemblyName, resolver), resourceName, uriRegistry, loaders);
            }
            if (resourceName != null && loaders.Count == 0)
            {
                throw new System.Data.Entity.Core.MetadataException(Strings.UnableToLoadResource);
            }
            return(loaders);
        }
 private static void LoadAllResourcesFromAssembly(
     Assembly assembly,
     ICollection <string> uriRegistry,
     List <MetadataArtifactLoaderResource> loaders)
 {
     foreach (string resourceName in MetadataArtifactLoaderCompositeResource.GetManifestResourceNamesForAssembly(assembly))
     {
         MetadataArtifactLoaderCompositeResource.CreateAndAddSingleResourceLoader(assembly, resourceName, uriRegistry, loaders);
     }
 }
        private static void CreateAndAddSingleResourceLoader(
            Assembly assembly,
            string resourceName,
            ICollection <string> uriRegistry,
            List <MetadataArtifactLoaderResource> loaders)
        {
            string resPath = MetadataArtifactLoaderCompositeResource.CreateResPath(assembly, resourceName);

            if (uriRegistry.Contains(resPath))
            {
                return;
            }
            loaders.Add(new MetadataArtifactLoaderResource(assembly, resourceName, uriRegistry));
        }
 private static bool AssemblyContainsResource(Assembly assembly, ref string resourceName)
 {
     if (resourceName == null)
     {
         return(true);
     }
     foreach (string b in MetadataArtifactLoaderCompositeResource.GetManifestResourceNamesForAssembly(assembly))
     {
         if (string.Equals(resourceName, b, StringComparison.OrdinalIgnoreCase))
         {
             resourceName = b;
             return(true);
         }
     }
     return(false);
 }
        internal MetadataArtifactLoaderResource(
            Assembly assembly,
            string resourceName,
            ICollection <string> uriRegistry)
        {
            this._assembly     = assembly;
            this._resourceName = resourceName;
            string resPath = MetadataArtifactLoaderCompositeResource.CreateResPath(this._assembly, this._resourceName);

            this._alreadyLoaded = uriRegistry.Contains(resPath);
            if (this._alreadyLoaded)
            {
                return;
            }
            uriRegistry.Add(resPath);
        }
示例#6
0
        [ResourceConsumption(ResourceScope.Machine)] //For CheckArtifactExtension method call. But the path is not created in this method.
        internal static MetadataArtifactLoader Create(
            string path,
            ExtensionCheck extensionCheck,
            string validExtension,
            ICollection <string> uriRegistry,
            MetadataArtifactAssemblyResolver resolver)
        {
            DebugCheck.NotNull(path);
            DebugCheck.NotNull(resolver);

            // res:// -based artifacts
            //
            if (PathStartsWithResPrefix(path))
            {
                return(MetadataArtifactLoaderCompositeResource.CreateResourceLoader(
                           path, extensionCheck, validExtension, uriRegistry, resolver));
            }

            // Files and Folders
            //
            var normalizedPath = NormalizeFilePaths(path);

            if (Directory.Exists(normalizedPath))
            {
                return(new MetadataArtifactLoaderCompositeFile(normalizedPath, uriRegistry));
            }
            else if (File.Exists(normalizedPath))
            {
                switch (extensionCheck)
                {
                case ExtensionCheck.Specific:
                    CheckArtifactExtension(normalizedPath, validExtension);
                    break;

                case ExtensionCheck.All:
                    if (!IsValidArtifact(normalizedPath))
                    {
                        throw new MetadataException(Strings.InvalidMetadataPath);
                    }
                    break;
                }

                return(new MetadataArtifactLoaderFile(normalizedPath, uriRegistry));
            }

            throw new MetadataException(Strings.InvalidMetadataPath);
        }
 private static void LoadResourcesFromAssembly(
     Assembly assembly,
     string resourceName,
     ICollection <string> uriRegistry,
     List <MetadataArtifactLoaderResource> loaders)
 {
     if (resourceName == null)
     {
         MetadataArtifactLoaderCompositeResource.LoadAllResourcesFromAssembly(assembly, uriRegistry, loaders);
     }
     else
     {
         if (!MetadataArtifactLoaderCompositeResource.AssemblyContainsResource(assembly, ref resourceName))
         {
             throw new System.Data.Entity.Core.MetadataException(Strings.UnableToLoadResource);
         }
         MetadataArtifactLoaderCompositeResource.CreateAndAddSingleResourceLoader(assembly, resourceName, uriRegistry, loaders);
     }
 }
        internal static MetadataArtifactLoader CreateResourceLoader(
            string path,
            MetadataArtifactLoader.ExtensionCheck extensionCheck,
            string validExtension,
            ICollection <string> uriRegistry,
            MetadataArtifactAssemblyResolver resolver)
        {
            string assemblyName = (string)null;
            string resourceName = (string)null;

            MetadataArtifactLoaderCompositeResource.ParseResourcePath(path, out assemblyName, out resourceName);
            bool flag = assemblyName != null && (resourceName == null || assemblyName.Trim() == MetadataArtifactLoader.wildcard);

            MetadataArtifactLoaderCompositeResource.ValidateExtension(extensionCheck, validExtension, resourceName);
            if (flag)
            {
                return((MetadataArtifactLoader) new MetadataArtifactLoaderCompositeResource(path, assemblyName, resourceName, uriRegistry, resolver));
            }
            return((MetadataArtifactLoader) new MetadataArtifactLoaderResource(MetadataArtifactLoaderCompositeResource.ResolveAssemblyName(assemblyName, resolver), resourceName, uriRegistry));
        }
        // <summary>
        // Constructor - loads the resource stream
        // </summary>
        // <param name="uriRegistry"> The global registry of URIs </param>
        internal MetadataArtifactLoaderResource(Assembly assembly, string resourceName, ICollection <string> uriRegistry)
        {
            DebugCheck.NotNull(assembly);
            DebugCheck.NotNull(resourceName);

            _assembly     = assembly;
            _resourceName = resourceName;

            var tempPath = MetadataArtifactLoaderCompositeResource.CreateResPath(_assembly, _resourceName);

            _alreadyLoaded = uriRegistry.Contains(tempPath);
            if (!_alreadyLoaded)
            {
                uriRegistry.Add(tempPath);

                // '_alreadyLoaded' is not set because while we would like to prevent
                // other instances of MetadataArtifactLoaderFile that wrap the same
                // _path from being added to the list of paths/readers, we do want to
                // include this particular instance.
            }
        }
        internal static MetadataArtifactLoader Create(
            string path,
            MetadataArtifactLoader.ExtensionCheck extensionCheck,
            string validExtension,
            ICollection <string> uriRegistry,
            MetadataArtifactAssemblyResolver resolver)
        {
            if (MetadataArtifactLoader.PathStartsWithResPrefix(path))
            {
                return(MetadataArtifactLoaderCompositeResource.CreateResourceLoader(path, extensionCheck, validExtension, uriRegistry, resolver));
            }
            string str = MetadataArtifactLoader.NormalizeFilePaths(path);

            if (Directory.Exists(str))
            {
                return((MetadataArtifactLoader) new MetadataArtifactLoaderCompositeFile(str, uriRegistry));
            }
            if (!File.Exists(str))
            {
                throw new MetadataException(Strings.InvalidMetadataPath);
            }
            switch (extensionCheck)
            {
            case MetadataArtifactLoader.ExtensionCheck.Specific:
                MetadataArtifactLoader.CheckArtifactExtension(str, validExtension);
                break;

            case MetadataArtifactLoader.ExtensionCheck.All:
                if (!MetadataArtifactLoader.IsValidArtifact(str))
                {
                    throw new MetadataException(Strings.InvalidMetadataPath);
                }
                break;
            }
            return((MetadataArtifactLoader) new MetadataArtifactLoaderFile(str, uriRegistry));
        }
 internal MetadataArtifactLoaderCompositeResource(
     string originalPath,
     string assemblyName,
     string resourceName,
     ICollection <string> uriRegistry,
     MetadataArtifactAssemblyResolver resolver)
 {
     this._originalPath = originalPath;
     this._children     = new ReadOnlyCollection <MetadataArtifactLoaderResource>((IList <MetadataArtifactLoaderResource>)MetadataArtifactLoaderCompositeResource.LoadResources(assemblyName, resourceName, uriRegistry, resolver));
 }