Beispiel #1
0
 private Task <IProjectTreeServiceState> PublishTreeAsync(IProjectVersionedValue <IProjectSubscriptionUpdate> e)
 {
     try
     {
         // Make sure the tree matches the same version of the evaluation that we're handling
         return(_projectTree.TreeService.PublishTreeAsync(e.ToRequirements(), blockDuringLoadingTree: true));
     }
     catch (ActiveProjectConfigurationChangedException)
     {
         // Project configuration changed while we blocked waiting for the tree, instead of trying to match
         // exactly the same version, just give up and publish the latest tree. Note, don't need to handle
         // ActiveProjectConfigurationChangedException as it will retry if the configuration changed.
         return(_projectTree.TreeService.PublishLatestTreeAsync(blockDuringLoadingTree: true));
     }
 }
        public async Task HandleAsync(IProjectVersionedValue <IProjectSubscriptionUpdate> e, IProjectChangeDescription projectChange)
        {
            Requires.NotNull(e, nameof(e));
            Requires.NotNull(projectChange, nameof(projectChange));

            IProjectChangeDiff diff = projectChange.Difference;

            foreach (string filePath in diff.RemovedItems)
            {
                // Item includes are always relative to csproj/vbproj
                string fullPath = _project.MakeRooted(filePath);

                RemoveSourceFile(fullPath);
            }

            if (diff.AddedItems.Count > 0 || diff.RenamedItems.Count > 0 || diff.ChangedItems.Count > 0)
            {
                // Make sure the tree matches the same version of the evaluation that we're handling
                IProjectTreeServiceState treeState = await _projectTree.TreeService.PublishTreeAsync(e.ToRequirements(), blockDuringLoadingTree : true)
                                                     .ConfigureAwait(true);                               // TODO: https://github.com/dotnet/roslyn-project-system/issues/353

                foreach (string filePath in diff.AddedItems)
                {
                    string fullPath = _project.MakeRooted(filePath);

                    AddSourceFile(fullPath, treeState);
                }

                foreach (KeyValuePair <string, string> filePaths in diff.RenamedItems)
                {
                    string beforeFullPath = _project.MakeRooted(filePaths.Key);
                    string afterFullPath  = _project.MakeRooted(filePaths.Value);

                    RemoveSourceFile(beforeFullPath);
                    AddSourceFile(afterFullPath, treeState);
                }

                foreach (string filePath in diff.ChangedItems)
                {   // We add and then remove ChangedItems to handle Linked metadata changes
                    string fullPath = _project.MakeRooted(filePath);

                    RemoveSourceFile(fullPath);
                    AddSourceFile(fullPath);
                }
            }
        }