Exemplo n.º 1
0
        private async Task NotifyCpsProjectSystemAsync(
            ProjectId projectId,
            IProjectItemDesignerTypeUpdateService updateService,
            IEnumerable <DesignerAttributeData> data,
            CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            // We may have updates for many different configurations of the same logical project system project.
            // However, the project system only associates designer attributes with one of those projects.  So just drop
            // the notifications for any sibling configurations.
            if (!_workspace.IsPrimaryProject(projectId))
            {
                return;
            }

            // Broadcast all the information about all the documents in parallel to CPS.

            using var _ = ArrayBuilder <Task> .GetInstance(out var tasks);

            foreach (var info in data)
            {
                cancellationToken.ThrowIfCancellationRequested();
                tasks.Add(NotifyCpsProjectSystemAsync(updateService, info, cancellationToken));
            }

            await Task.WhenAll(tasks).ConfigureAwait(false);
        }
        private async Task NotifyCpsProjectSystemAsync(
            IProjectItemDesignerTypeUpdateService updateService,
            DesignerAttributeData data,
            CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            try
            {
                await updateService.SetProjectItemDesignerTypeAsync(data.FilePath, data.Category).ConfigureAwait(false);
            }
            catch (ObjectDisposedException)
            {
                // we might call update service after project is already removed and get object disposed exception.
                // we will catch the exception and ignore.
                // see this PR for more detail - https://github.com/dotnet/roslyn/pull/35383
            }
        }
        private async Task NotifyCpsProjectSystemAsync(
            IProjectItemDesignerTypeUpdateService updateService,
            IEnumerable <DesignerAttributeData> data,
            CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            // Broadcast all the information about all the documents in parallel to CPS.

            using var _ = ArrayBuilder <Task> .GetInstance(out var tasks);

            foreach (var info in data)
            {
                cancellationToken.ThrowIfCancellationRequested();
                tasks.Add(NotifyCpsProjectSystemAsync(updateService, info, cancellationToken));
            }

            await Task.WhenAll(tasks).ConfigureAwait(false);
        }
 private async Task NotifyCpsDesignerAttributeAsync(Document document, string designerAttributeArgument, IProjectItemDesignerTypeUpdateService updateService)
 {
     using (_listener.BeginAsyncOperation("RegisterDesignerAttribute"))
     {
         try
         {
             await updateService.SetProjectItemDesignerTypeAsync(document.FilePath, designerAttributeArgument).ConfigureAwait(false);
         }
         catch (ObjectDisposedException)
         {
             // we might call update service after project is already removed and get object disposed exception.
             // we will catch the exception and ignore.
             // see this PR for more detail - https://github.com/dotnet/roslyn/pull/35383
         }
     }
 }