public ProjectState WithProjectWorkspaceState(ProjectWorkspaceState projectWorkspaceState)
        {
            if (ProjectWorkspaceState == projectWorkspaceState)
            {
                return(this);
            }

            if (ProjectWorkspaceState != null && ProjectWorkspaceState.Equals(projectWorkspaceState))
            {
                return(this);
            }

            var difference = ProjectDifference.ProjectWorkspaceStateChanged;
            var documents  = Documents.ToImmutableDictionary(kvp => kvp.Key, kvp => kvp.Value.WithProjectWorkspaceStateChange(), FilePathComparer.Instance);
            var state      = new ProjectState(this, difference, HostProject, projectWorkspaceState, documents, ImportsToRelatedDocuments);

            return(state);
        }
Example #2
0
        private ProjectState(
            ProjectState older,
            ProjectDifference difference,
            HostProject hostProject,
            ProjectWorkspaceState projectWorkspaceState,
            ImmutableDictionary <string, DocumentState> documents,
            ImmutableDictionary <string, ImmutableArray <string> > importsToRelatedDocuments)
        {
            if (older == null)
            {
                throw new ArgumentNullException(nameof(older));
            }

            if (hostProject == null)
            {
                throw new ArgumentNullException(nameof(hostProject));
            }

            if (documents == null)
            {
                throw new ArgumentNullException(nameof(documents));
            }

            if (importsToRelatedDocuments == null)
            {
                throw new ArgumentNullException(nameof(importsToRelatedDocuments));
            }

            Services = older.Services;
            Version  = older.Version.GetNewerVersion();

            HostProject               = hostProject;
            ProjectWorkspaceState     = projectWorkspaceState;
            Documents                 = documents;
            ImportsToRelatedDocuments = importsToRelatedDocuments;

            _lock = new object();

            if ((difference & ClearDocumentCollectionVersionMask) == 0)
            {
                // Document collection hasn't changed
                DocumentCollectionVersion = older.DocumentCollectionVersion;
            }
            else
            {
                DocumentCollectionVersion = Version;
            }

            if ((difference & ClearConfigurationVersionMask) == 0 && older._projectEngine != null)
            {
                // Optimistically cache the RazorProjectEngine.
                _projectEngine       = older.ProjectEngine;
                ConfigurationVersion = older.ConfigurationVersion;
            }
            else
            {
                ConfigurationVersion = Version;
            }

            if ((difference & ClearProjectWorkspaceStateVersionMask) == 0 ||
                ProjectWorkspaceState == older.ProjectWorkspaceState ||
                ProjectWorkspaceState?.Equals(older.ProjectWorkspaceState) == true)
            {
                ProjectWorkspaceStateVersion = older.ProjectWorkspaceStateVersion;
            }
            else
            {
                ProjectWorkspaceStateVersion = Version;
            }
        }