Ejemplo n.º 1
0
            internal Task OnProjectChangedAsync <T>(
                IDataProgressTrackerServiceRegistration registration,
                ConfiguredProject activeConfiguredProject,
                IProjectVersionedValue <T> update,
                Func <IProjectVersionedValue <T>, bool> hasChange,
                Action <IProjectVersionedValue <T>, IApplyChangesToWorkspaceContext, ContextState, CancellationToken> applyFunc)
            {
                return(ExecuteUnderLockAsync(ApplyProjectChangesUnderLockAsync, _tasksService.UnloadCancellationToken));

                Task ApplyProjectChangesUnderLockAsync(CancellationToken cancellationToken)
                {
                    // NOTE we cannot call CheckForInitialized here, as this method may be invoked during initialization
                    Assumes.NotNull(_contextAccessor);
                    Assumes.NotNull(_applyChangesToWorkspaceContext);

                    if (!hasChange(update))
                    {
                        // No change since the last update. We must still update operation progress, but can skip creating a batch.
                        UpdateProgressRegistration();
                        return(Task.CompletedTask);
                    }

                    return(ApplyInBatchAsync());

                    async Task ApplyInBatchAsync()
                    {
                        ContextState contextState = new(
                            isActiveEditorContext : _activeWorkspaceProjectContextTracker.IsActiveEditorContext(_contextAccessor.ContextId),
                            isActiveConfiguration : activeConfiguredProject == _project);

                        IWorkspaceProjectContext context = _contextAccessor.Context;

                        context.StartBatch();

                        try
                        {
                            applyFunc(update, _applyChangesToWorkspaceContext.Value, contextState, cancellationToken);
                        }
                        finally
                        {
                            await context.EndBatchAsync();

                            UpdateProgressRegistration();
                        }
                    }

                    void UpdateProgressRegistration()
                    {
                        // Notify operation progress that we've now processed these versions of our input, if they are
                        // up-to-date with the latest version that produced, then we no longer considered "in progress".
                        registration.NotifyOutputDataCalculated(update.DataSourceVersions);
                    }
                }
            }
 private void NotifyOutputDataCalculated(IImmutableDictionary <NamedIdentity, IComparable> dataSourceVersions, bool evaluation)
 {
     // Notify operation progress that we've now processed these versions of our input, if they are
     // up-to-date with the latest version that produced, then we no longer considered "in progress".
     if (evaluation)
     {
         _evaluationProgressRegistration.NotifyOutputDataCalculated(dataSourceVersions);
     }
     else
     {
         _projectBuildProgressRegistration.NotifyOutputDataCalculated(dataSourceVersions);
     }
 }