示例#1
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);
        }