Пример #1
0
        // Internal for unit testing
        internal ViewLocationCacheResult CreateCacheResult(
            HashSet <IChangeToken> expirationTokens,
            string relativePath,
            bool isMainPage)
        {
            var factoryResult  = _pageFactory.CreateFactory(relativePath);
            var viewDescriptor = factoryResult.ViewDescriptor;

            if (viewDescriptor?.ExpirationTokens != null)
            {
                for (var i = 0; i < viewDescriptor.ExpirationTokens.Count; i++)
                {
                    expirationTokens.Add(viewDescriptor.ExpirationTokens[i]);
                }
            }

            if (factoryResult.Success)
            {
                // Only need to lookup _ViewStarts for the main page.
                var viewStartPages = isMainPage ?
                                     GetViewStartPages(viewDescriptor.RelativePath, expirationTokens) :
                                     Array.Empty <ViewLocationCacheItem>();
                if (viewDescriptor.IsPrecompiled)
                {
                    _logger.PrecompiledViewFound(relativePath);
                }

                return(new ViewLocationCacheResult(
                           new ViewLocationCacheItem(factoryResult.RazorPageFactory, relativePath),
                           viewStartPages));
            }

            return(null);
        }
Пример #2
0
    // Internal for unit testing
    internal ViewLocationCacheResult?CreateCacheResult(
        HashSet <IChangeToken> expirationTokens,
        string relativePath,
        bool isMainPage)
    {
        var factoryResult  = _pageFactory.CreateFactory(relativePath);
        var viewDescriptor = factoryResult.ViewDescriptor;

        if (viewDescriptor?.ExpirationTokens != null)
        {
            var viewExpirationTokens = viewDescriptor.ExpirationTokens;
            // Read interface .Count once rather than per iteration
            var viewExpirationTokensCount = viewExpirationTokens.Count;
            for (var i = 0; i < viewExpirationTokensCount; i++)
            {
                expirationTokens.Add(viewExpirationTokens[i]);
            }
        }

        if (factoryResult.Success)
        {
            // Only need to lookup _ViewStarts for the main page.
            var viewStartPages = isMainPage ?
                                 GetViewStartPages(viewDescriptor !.RelativePath, expirationTokens) :
                                 Array.Empty <ViewLocationCacheItem>();

            return(new ViewLocationCacheResult(
                       new ViewLocationCacheItem(factoryResult.RazorPageFactory, relativePath),
                       viewStartPages));
        }

        return(null);
    }
Пример #3
0
        private ViewLocationCacheResult CreateCacheResult(
            HashSet<IChangeToken> expirationTokens,
            string relativePath,
            bool isMainPage)
        {
            var factoryResult = _pageFactory.CreateFactory(relativePath);
            if (factoryResult.ExpirationTokens != null)
            {
                for (var i = 0; i < factoryResult.ExpirationTokens.Count; i++)
                {
                    expirationTokens.Add(factoryResult.ExpirationTokens[i]);
                }
            }

            if (factoryResult.Success)
            {
                // Only need to lookup _ViewStarts for the main page.
                var viewStartPages = isMainPage ?
                    GetViewStartPages(relativePath, expirationTokens) :
                    EmptyViewStartLocationCacheItems;

                return new ViewLocationCacheResult(
                    new ViewLocationCacheItem(factoryResult.RazorPageFactory, relativePath),
                    viewStartPages);
            }

            return null;
        }
        public RazorPageFactoryResult CreateFactory(string relativePath)
        {
            var pathString = new PathString(relativePath);
            var viewOverridesPathString = new PathString($"/Modules/{_moduleEnv.ApplicationName}").Add(pathString);
            var result = _appProvider.CreateFactory(viewOverridesPathString);

            if (result.Success)
            {
                return(result);
            }

            PathString remainingPath;

            // TODO: Need a better way to determine if the path is for a layout page
            if (pathString.StartsWithSegments("/Views/Shared/_Layout.cshtml", out remainingPath) &&
                remainingPath.Equals(PathString.Empty))
            {
                result = _appProvider.CreateFactory(pathString);
                if (result.Success)
                {
                    return(result);
                }
            }

            return(_defaultProvider.CreateFactory(relativePath));
        }
Пример #5
0
        private ModuleViewLocationCacheResult CreateCacheResult(
            HashSet <IChangeToken> expirationTokens,
            string relativePath)
        {
            var factoryResult  = _pageFactory.CreateFactory(relativePath);
            var viewDescriptor = factoryResult.ViewDescriptor;

            if (viewDescriptor?.ExpirationTokens != null)
            {
                var viewExpirationTokens      = viewDescriptor.ExpirationTokens;
                var viewExpirationTokensCount = viewExpirationTokens.Count;

                for (var i = 0; i < viewExpirationTokensCount; i++)
                {
                    expirationTokens.Add(viewExpirationTokens[i]);
                }
            }

            if (factoryResult.Success)
            {
                return(new ModuleViewLocationCacheResult(
                           new ModuleViewLocationCacheItem(factoryResult.RazorPageFactory, relativePath),
                           Array.Empty <ModuleViewLocationCacheItem>()));
            }

            return(null);
        }
Пример #6
0
        // Internal for testing.
        internal List <Func <IRazorPage> > GetViewStartFactories(CompiledPageActionDescriptor descriptor)
        {
            var viewStartFactories = new List <Func <IRazorPage> >();

            // Always pick up all _ViewStarts, including the ones outside the Pages root.
            foreach (var filePath in RazorFileHierarchy.GetViewStartPaths(descriptor.RelativePath))
            {
                var factoryResult = _razorPageFactoryProvider.CreateFactory(filePath);
                if (factoryResult.Success)
                {
                    viewStartFactories.Insert(0, factoryResult.RazorPageFactory);
                }
            }

            return(viewStartFactories);
        }