示例#1
0
        // Token: 0x0600017F RID: 383 RVA: 0x00007068 File Offset: 0x00005268
        private ViewCompilerWorkItem CreatePrecompiledWorkItem(string normalizedPath, CompiledViewDescriptor precompiledView)
        {
            if (precompiledView.Item == null || !ChecksumValidator.IsRecompilationSupported(precompiledView.Item))
            {
                return(new ViewCompilerWorkItem
                {
                    SupportsCompilation = false,
                    ExpirationTokens = Array.Empty <IChangeToken>(),
                    Descriptor = precompiledView
                });
            }
            ViewCompilerWorkItem viewCompilerWorkItem = new ViewCompilerWorkItem
            {
                SupportsCompilation = true,
                Descriptor          = precompiledView,
                NormalizedPath      = normalizedPath,
                ExpirationTokens    = new List <IChangeToken>()
            };
            IReadOnlyList <IRazorSourceChecksumMetadata> checksumMetadata = RazorCompiledItemExtensions.GetChecksumMetadata(precompiledView.Item);

            for (int i = 0; i < checksumMetadata.Count; i++)
            {
                viewCompilerWorkItem.ExpirationTokens.Add(this._fileProvider.Watch(checksumMetadata[i].Identifier));
            }
            viewCompilerWorkItem.Descriptor = new CompiledViewDescriptor
            {
                ExpirationTokens = viewCompilerWorkItem.ExpirationTokens,
                IsPrecompiled    = true,
                Item             = precompiledView.Item,
                RelativePath     = precompiledView.RelativePath,
                ViewAttribute    = precompiledView.ViewAttribute
            };
            return(viewCompilerWorkItem);
        }
示例#2
0
    public void IsRecompilationSupported_NoChecksumAttributes_ReturnsFalse()
    {
        // Arrange
        var item = new TestRazorCompiledItem(typeof(string), "mvc.1.0.view", "/Views/Home/Index.cstml", new object[] { });

        // Act
        var result = ChecksumValidator.IsRecompilationSupported(item);

        // Assert
        Assert.False(result);
    }
示例#3
0
    public void IsRecompilationSupported_NoPrimaryChecksumAttribute_ReturnsFalse()
    {
        // Arrange
        var item = new TestRazorCompiledItem(typeof(string), "mvc.1.0.view", "/Views/Home/Index.cstml", new object[]
        {
            new RazorSourceChecksumAttribute("SHA1", GetChecksum("some import"), "/Views/Home/_ViewImports.cstml"),
        });

        // Act
        var result = ChecksumValidator.IsRecompilationSupported(item);

        // Assert
        Assert.False(result);
    }
示例#4
0
    private ViewCompilerWorkItem CreatePrecompiledWorkItem(string normalizedPath, CompiledViewDescriptor precompiledView)
    {
        // We have a precompiled view - but we're not sure that we can use it yet.
        //
        // We need to determine first if we have enough information to 'recompile' this view. If that's the case
        // we'll create change tokens for all of the files.
        //
        // Then we'll attempt to validate if any of those files have different content than the original sources
        // based on checksums.
        if (precompiledView.Item == null || !ChecksumValidator.IsRecompilationSupported(precompiledView.Item))
        {
            return(new ViewCompilerWorkItem()
            {
                // If we don't have a checksum for the primary source file we can't recompile.
                SupportsCompilation = false,

                ExpirationTokens = Array.Empty <IChangeToken>(), // Never expire because we can't recompile.
                Descriptor = precompiledView,                    // This will be used as-is.
            });
        }

        var item = new ViewCompilerWorkItem()
        {
            SupportsCompilation = true,

            Descriptor = precompiledView, // This might be used, if the checksums match.

            // Used to validate and recompile
            NormalizedPath = normalizedPath,

            ExpirationTokens = GetExpirationTokens(precompiledView),
        };

        // We also need to create a new descriptor, because the original one doesn't have expiration tokens on
        // it. These will be used by the view location cache, which is like an L1 cache for views (this class is
        // the L2 cache).
        item.Descriptor = new CompiledViewDescriptor()
        {
            ExpirationTokens = item.ExpirationTokens,
            Item             = precompiledView.Item,
            RelativePath     = precompiledView.RelativePath,
        };

        return(item);
    }
示例#5
0
        private ViewCompilerWorkItem CreatePrecompiledWorkItem(string normalizedPath, CompiledViewDescriptor precompiledView)
        {
            if (precompiledView.Item == null || !ChecksumValidator.IsRecompilationSupported(precompiledView.Item))
            {
                return(new ViewCompilerWorkItem()
                {
                    SupportsCompilation = false,

                    ExpirationTokens = Array.Empty <IChangeToken>(),
                    Descriptor = precompiledView,
                });
            }

            var item = new ViewCompilerWorkItem()
            {
                SupportsCompilation = true,

                Descriptor = precompiledView,

                NormalizedPath   = normalizedPath,
                ExpirationTokens = new List <IChangeToken>(),
            };

            var checksums = precompiledView.Item.GetChecksumMetadata();

            for (var i = 0; i < checksums.Count; i++)
            {
                item.ExpirationTokens.Add(_fileProvider.Watch(checksums[i].Identifier));
            }

            item.Descriptor = new CompiledViewDescriptor()
            {
                ExpirationTokens = item.ExpirationTokens,
                IsPrecompiled    = true,
                Item             = precompiledView.Item,
                RelativePath     = precompiledView.RelativePath,
                ViewAttribute    = precompiledView.ViewAttribute,
            };

            return(item);
        }