예제 #1
0
        public ResourcePart(Package container, Uri uri, string name, ResourceManagerWrapper rmWrapper) : 
            base(container, uri)
        { 
            if (rmWrapper == null)
            {
                throw new ArgumentNullException("rmWrapper");
            } 

            _rmWrapper.Value = rmWrapper; 
            _name = name; 
        }
예제 #2
0
        private static void ConstructFontResourceCache(Assembly entryAssembly, Dictionary<string, List<string>> folderResourceMap)
        {
            // For entryAssembly build a set of mapping from paths to entries that describe each resource.
            Dictionary<string, string> contentFiles = ContentFileHelper.GetContentFiles(entryAssembly);
            if (contentFiles != null)
            {
                foreach (string contentFile in contentFiles.Keys)
                {
                    AddResourceToFolderMap(folderResourceMap, contentFile);
                }
            }

            IList resourceList = new ResourceManagerWrapper(entryAssembly).ResourceList;
            if (resourceList != null)
            {
                foreach (string resource in resourceList)
                {
                    AddResourceToFolderMap(folderResourceMap, resource);
                }
            }
        }
예제 #3
0
        // <summary>
        // Searches the available ResourceManagerWrapper list for one that matches the given Uri.
        // It could be either ResourceManagerWrapper for specific libary assembly or Application
        // main assembly. Package enforces that all Uri will be correctly formated.
        // </summary>
        // <param name="uri">Assumed to be relative</param>
        // <param name="partName">The name of the file in the resource manager</param>
        // <param name="isContentFile">A flag to indicate that this path is a known loose file at compile time</param>
        // <returns></returns>
        private ResourceManagerWrapper GetResourceManagerWrapper(Uri uri, out string partName, out bool isContentFile)
        {
            string assemblyName;
            string assemblyVersion;
            string assemblyKey;
            ResourceManagerWrapper rmwResult = ApplicationResourceManagerWrapper;

            isContentFile = false;

            BaseUriHelper.GetAssemblyNameAndPart(uri, out partName, out assemblyName, out assemblyVersion, out assemblyKey);

            if (!String.IsNullOrEmpty(assemblyName))
            {
                string key = assemblyName + assemblyVersion + assemblyKey;

                _registeredResourceManagers.TryGetValue(key.ToLowerInvariant(), out rmwResult);

                // first time. Add this to the hash table
                if (rmwResult == null)
                {
                    Assembly assembly;

                    assembly = BaseUriHelper.GetLoadedAssembly(assemblyName, assemblyVersion, assemblyKey);

                    if (assembly.Equals(Application.ResourceAssembly))
                    {
                        // This Uri maps to Application Entry assembly even though it has ";component".

                        rmwResult = ApplicationResourceManagerWrapper;

                    }
                    else
                    {
                        rmwResult = new ResourceManagerWrapper(assembly);
                    }

                    _registeredResourceManagers[key.ToLowerInvariant()] = rmwResult;

                }
            }

            if ((rmwResult == ApplicationResourceManagerWrapper))
            {
                if (rmwResult != null)
                {
                    // If this is not a resource from a component then it might be
                    // a content file and not an application resource.
                    if (ContentFileHelper.IsContentFile(partName))
                    {
                        isContentFile = true;
                        rmwResult = null;
                    }
                }
                else
                {
                    // Throw when Application.ResourceAssembly is null. 
                    throw new IOException(SR.Get(SRID.EntryAssemblyIsNull));
                }
            }

            return rmwResult;
        }