Beispiel #1
0
        protected Workspace(HostServices host)
        {
            _services = host.CreateWorkspaceServices(this);

            // queue used for sending events
            var workspaceTaskSchedulerFactory = _services.GetRequiredService <IWorkspaceTaskSchedulerFactory>();

            _taskQueue = workspaceTaskSchedulerFactory.CreateEventingTaskQueue();

            // initialize with empty document set
            _latestDocuments = new WorkspaceDocuments(ImmutableDictionary <DocumentId, Document> .Empty);
        }
Beispiel #2
0
        /// <summary>
        /// Apply changes made to a solution back to the workspace.
        ///
        /// The specified solution must be one that originated from this workspace. If it is not, or the workspace
        /// has been updated since the solution was obtained from the workspace, then this method returns false. This method
        /// will still throw if the solution contains changes that are not supported according to the <see cref="CanApplyChange(ApplyChangesKind)"/>
        /// method.
        /// </summary>
        /// <exception cref="NotSupportedException">Thrown if the solution contains changes not supported according to the
        /// <see cref="CanApplyChange(ApplyChangesKind)"/> method.</exception>
        public virtual bool TryApplyChanges(WorkspaceDocuments newDocuments)
        {
            var currentDocuments = CurrentDocuments;

            foreach (var newDocument in newDocuments.Documents)
            {
                var currentDocument = currentDocuments.GetDocument(newDocument.Id);
                if (currentDocument != null && currentDocument.SourceText != newDocument.SourceText)
                {
                    ApplyDocumentTextChanged(currentDocument.Id, newDocument.SourceText);
                }
            }

            return(true);
        }
Beispiel #3
0
        /// <summary>
        /// Sets the <see cref="CurrentDocuments"/> of this workspace. This method does not raise a <see cref="WorkspaceChanged"/> event.
        /// </summary>
        protected WorkspaceDocuments SetCurrentDocuments(WorkspaceDocuments documents)
        {
            var currentDocuments = Volatile.Read(ref _latestDocuments);

            if (documents == currentDocuments)
            {
                // No change
                return(documents);
            }

            while (true)
            {
                var replacedSolution = Interlocked.CompareExchange(ref _latestDocuments, documents, currentDocuments);
                if (replacedSolution == currentDocuments)
                {
                    return(documents);
                }

                currentDocuments = replacedSolution;
            }
        }