コード例 #1
0
        internal static async Task <ImmutableDictionary <string, DesignerAttributeDocumentData> > TryAnalyzeProjectInCurrentProcessAsync(
            Project project, CancellationToken cancellationToken)
        {
            var projectVersion = await project.GetDependentVersionAsync(cancellationToken).ConfigureAwait(false);

            var semanticVersion = await project.GetDependentSemanticVersionAsync(cancellationToken).ConfigureAwait(false);

            // Get whatever data we've current persisted.
            var designerAttributeData = await DesignerAttributeProjectData.ReadAsync(
                project, cancellationToken).ConfigureAwait(false);

            // If we have no persisted data, or the persisted data is for a previous version of
            // the project, then compute the results for the current project snapshot.
            if (designerAttributeData == null ||
                !VersionStamp.CanReusePersistedVersion(semanticVersion, designerAttributeData.SemanticVersion))
            {
                designerAttributeData = await ComputeAndPersistDesignerAttributeProjectDataAsync(
                    project, semanticVersion, cancellationToken).ConfigureAwait(false);
            }

            return(designerAttributeData.PathToDocumentData);
        }
コード例 #2
0
        private static async Task <DesignerAttributeProjectData> ComputeAndPersistDesignerAttributeProjectDataAsync(
            Project project, VersionStamp semanticVersion, CancellationToken cancellationToken)
        {
            var service = project.LanguageServices.GetService <IDesignerAttributeService>();

            var tasks = project.Documents.Select(
                d => service.ScanDesignerAttributesAsync(d, cancellationToken)).ToArray();

            await Task.WhenAll(tasks).ConfigureAwait(false);

            var builder = ImmutableDictionary.CreateBuilder <string, DesignerAttributeDocumentData>();

            foreach (var task in tasks)
            {
                var result = await task.ConfigureAwait(false);

                builder[result.FilePath] = result;
            }

            var data = new DesignerAttributeProjectData(semanticVersion, builder.ToImmutable());
            await data.PersistAsync(project, cancellationToken).ConfigureAwait(false);

            return(data);
        }