示例#1
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);
        }
示例#2
0
        // <summary>
        // Creates an object instance from a Baml stream and it's Uri
        // </summary>
        internal static object BamlConverter(Stream stream, Uri baseUri, bool canUseTopLevelBrowser, bool sandboxExternalContent, bool allowAsync, bool isJournalNavigation, out XamlReader asyncObjectConverter)
        {
            asyncObjectConverter = null;

            // If this stream comes from outside the application throw
            //
            if (!BaseUriHelper.IsPackApplicationUri(baseUri))
            {
                throw new InvalidOperationException(SR.Get(SRID.BamlIsNotSupportedOutsideOfApplicationResources));
            }

            // If this stream comes from a content file also throw
            Uri    partUri = PackUriHelper.GetPartUri(baseUri);
            string partName, assemblyName, assemblyVersion, assemblyKey;

            BaseUriHelper.GetAssemblyNameAndPart(partUri, out partName, out assemblyName, out assemblyVersion, out assemblyKey);
            if (ContentFileHelper.IsContentFile(partName))
            {
                throw new InvalidOperationException(SR.Get(SRID.BamlIsNotSupportedOutsideOfApplicationResources));
            }

            ParserContext pc = new ParserContext();

            pc.BaseUri = baseUri;
            pc.SkipJournaledProperties = isJournalNavigation;

            return(Application.LoadBamlStreamWithSyncInfo(stream, pc));
        }
示例#3
0
        public IActionResult GetFile(string appName, string filePath)
        {
            try
            {
                var alias        = _tenantResolver.GetAlias();
                var fullFilePath = ContentFileHelper.GetFilePath(_hostingEnvironment.ContentRootPath, alias, Route, appName, filePath);
                if (string.IsNullOrEmpty(fullFilePath))
                {
                    return(NotFound());
                }

                var fileBytes = System.IO.File.ReadAllBytes(fullFilePath);
                var mimeType  = ContentFileHelper.GetMimeType(fullFilePath);

                return(mimeType.StartsWith("image") ? File(fileBytes, mimeType) :
                       new FileContentResult(fileBytes, mimeType)
                {
                    FileDownloadName = Path.GetFileName(fullFilePath)
                });
            }
            catch
            {
                return(NotFound());
            }
        }
        // Token: 0x06007A52 RID: 31314 RVA: 0x0022AA1C File Offset: 0x00228C1C
        private ResourceManagerWrapper GetResourceManagerWrapper(Uri uri, out string partName, out bool isContentFile)
        {
            ResourceManagerWrapper resourceManagerWrapper = ResourceContainer.ApplicationResourceManagerWrapper;

            isContentFile = false;
            string text;
            string text2;
            string text3;

            BaseUriHelper.GetAssemblyNameAndPart(uri, out partName, out text, out text2, out text3);
            if (!string.IsNullOrEmpty(text))
            {
                string text4 = text + text2 + text3;
                ResourceContainer._registeredResourceManagers.TryGetValue(text4.ToLowerInvariant(), out resourceManagerWrapper);
                if (resourceManagerWrapper == null)
                {
                    Assembly loadedAssembly = BaseUriHelper.GetLoadedAssembly(text, text2, text3);
                    if (loadedAssembly.Equals(Application.ResourceAssembly))
                    {
                        resourceManagerWrapper = ResourceContainer.ApplicationResourceManagerWrapper;
                    }
                    else
                    {
                        resourceManagerWrapper = new ResourceManagerWrapper(loadedAssembly);
                    }
                    ResourceContainer._registeredResourceManagers[text4.ToLowerInvariant()] = resourceManagerWrapper;
                }
            }
            if (resourceManagerWrapper == ResourceContainer.ApplicationResourceManagerWrapper)
            {
                if (resourceManagerWrapper == null)
                {
                    throw new IOException(SR.Get("EntryAssemblyIsNull"));
                }
                if (ContentFileHelper.IsContentFile(partName))
                {
                    isContentFile          = true;
                    resourceManagerWrapper = null;
                }
            }
            return(resourceManagerWrapper);
        }
示例#5
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);
                }
            }
        }
示例#6
0
        public async Task <IBlobData> Fetch(string virtualPath)
        {
            if (!SupportsPath(virtualPath))
            {
                return(null);
            }

            // Get appName and filePath.
            if (GetAppNameAndFilePath(virtualPath, out var appName, out var filePath))
            {
                return(null);
            }

            // Get route.
            var route = GetRoute(virtualPath);

            // Get alias.
            using var scope = _serviceProvider.CreateScope();
            var tenantResolver     = scope.ServiceProvider.GetRequiredService <ITenantResolver>();
            var hostingEnvironment = scope.ServiceProvider.GetRequiredService <IWebHostEnvironment>();
            var alias = tenantResolver.GetAlias();

            // Build physicalPath.
            var physicalPath = ContentFileHelper.GetFilePath(hostingEnvironment.ContentRootPath, alias, route, appName, filePath);

            if (string.IsNullOrEmpty(physicalPath))
            {
                throw new BlobMissingException($"Oqtane blob \"{filePath}\" not found.");
            }

            return(new BlobProviderFile()
            {
                Path = physicalPath,
                Exists = true,
                LastModifiedDateUtc = File.GetLastWriteTimeUtc(physicalPath)
            } as IBlobData);
        }
示例#7
0
        // Token: 0x06007A63 RID: 31331 RVA: 0x0022AD08 File Offset: 0x00228F08
        internal static object BamlConverter(Stream stream, Uri baseUri, bool canUseTopLevelBrowser, bool sandboxExternalContent, bool allowAsync, bool isJournalNavigation, out XamlReader asyncObjectConverter)
        {
            asyncObjectConverter = null;
            if (!BaseUriHelper.IsPackApplicationUri(baseUri))
            {
                throw new InvalidOperationException(SR.Get("BamlIsNotSupportedOutsideOfApplicationResources"));
            }
            Uri    partUri = PackUriHelper.GetPartUri(baseUri);
            string partName;
            string text;
            string text2;
            string text3;

            BaseUriHelper.GetAssemblyNameAndPart(partUri, out partName, out text, out text2, out text3);
            if (ContentFileHelper.IsContentFile(partName))
            {
                throw new InvalidOperationException(SR.Get("BamlIsNotSupportedOutsideOfApplicationResources"));
            }
            return(Application.LoadBamlStreamWithSyncInfo(stream, new ParserContext
            {
                BaseUri = baseUri,
                SkipJournaledProperties = isJournalNavigation
            }));
        }