Exemple #1
0
 public DefaultImportDocumentSnapshot(ProjectSnapshot project, RazorProjectItem item)
 {
     _project         = project;
     _importItem      = item;
     _version         = VersionStamp.Default;
     _generatedOutput = new DocumentGeneratedOutputTracker(null);
 }
        private async Task <RazorCodeDocument> GetGeneratedOutputInitializationTaskCore(ProjectSnapshot project, DocumentSnapshot document)
        {
            var tagHelpers = await project.GetTagHelpersAsync().ConfigureAwait(false);

            var imports = await GetImportsAsync(project, document);

            if (_older != null && _older.IsResultAvailable)
            {
                var tagHelperDifference = new HashSet <TagHelperDescriptor>(TagHelperDescriptorComparer.Default);
                tagHelperDifference.UnionWith(_older._tagHelpers);
                tagHelperDifference.SymmetricExceptWith(tagHelpers);

                var importDifference = new HashSet <ImportItem>();
                importDifference.UnionWith(_older._imports);
                importDifference.SymmetricExceptWith(imports);

                if (tagHelperDifference.Count == 0 && importDifference.Count == 0)
                {
                    // We can use the cached result.
                    var result = _older._task.Result;

                    // Drop reference so it can be GC'ed
                    _older = null;

                    // Cache the tag helpers and imports so the next version can use them
                    _tagHelpers = tagHelpers;
                    _imports    = imports;

                    return(result);
                }
            }

            // Drop reference so it can be GC'ed
            _older = null;

            // Cache the tag helpers and imports so the next version can use them
            _tagHelpers = tagHelpers;
            _imports    = imports;

            var importSources = new List <RazorSourceDocument>();

            foreach (var item in imports)
            {
                var sourceDocument = await GetRazorSourceDocumentAsync(item.Import);

                importSources.Add(sourceDocument);
            }

            var documentSource = await GetRazorSourceDocumentAsync(document);

            var projectEngine = project.GetProjectEngine();

            return(projectEngine.ProcessDesignTime(documentSource, importSources, tagHelpers));
        }
Exemple #3
0
        public DocumentState(DocumentState previous, ProjectDifference difference)
        {
            if (previous == null)
            {
                throw new ArgumentNullException(nameof(previous));
            }

            Services     = previous.Services;
            HostDocument = previous.HostDocument;
            Version      = previous.Version.GetNewerVersion();

            _generatedOutput = previous._generatedOutput?.ForkFor(this, difference);
        }
Exemple #4
0
        private async Task <RazorCodeDocument> GetGeneratedOutputInitializationTaskCore(ProjectSnapshot project, DocumentSnapshot document)
        {
            var tagHelpers = await project.GetTagHelpersAsync().ConfigureAwait(false);

            if (_older != null && _older.IsResultAvailable)
            {
                var difference = new HashSet <TagHelperDescriptor>(TagHelperDescriptorComparer.Default);
                difference.UnionWith(_older._tagHelpers);
                difference.SymmetricExceptWith(tagHelpers);

                if (difference.Count == 0)
                {
                    // We can use the cached result.
                    var result = _older._task.Result;

                    // Drop reference so it can be GC'ed
                    _older = null;

                    // Cache the tag helpers so the next version can use them
                    _tagHelpers = tagHelpers;

                    return(result);
                }
            }

            // Drop reference so it can be GC'ed
            _older = null;


            // Cache the tag helpers so the next version can use them
            _tagHelpers = tagHelpers;

            var projectEngine = project.GetProjectEngine();
            var projectItem   = projectEngine.FileSystem.GetItem(document.FilePath);

            return(projectItem == null ? null : projectEngine.ProcessDesignTime(projectItem));
        }
        public DocumentGeneratedOutputTracker(DocumentGeneratedOutputTracker older)
        {
            _older = older;

            _lock = new object();
        }