提交 233bd32b 编写于 作者: H Heejae Chang

initial work to make primary workspace synced

上级 a223f744
......@@ -17,6 +17,11 @@ public bool TryGetStateChecksums(out ProjectStateChecksums stateChecksums)
return _lazyChecksums.TryGetValue(out stateChecksums);
}
public Task<ProjectStateChecksums> GetStateChecksumsAsync(CancellationToken cancellationToken)
{
return _lazyChecksums.GetValueAsync(cancellationToken);
}
public async Task<Checksum> GetChecksumAsync(CancellationToken cancellationToken)
{
var collection = await _lazyChecksums.GetValueAsync(cancellationToken).ConfigureAwait(false);
......
......@@ -15,6 +15,11 @@ public bool TryGetStateChecksums(out SolutionStateChecksums stateChecksums)
return _lazyChecksums.TryGetValue(out stateChecksums);
}
public Task<SolutionStateChecksums> GetStateChecksumsAsync(CancellationToken cancellationToken)
{
return _lazyChecksums.GetValueAsync(cancellationToken);
}
public async Task<Checksum> GetChecksumAsync(CancellationToken cancellationToken)
{
var collection = await _lazyChecksums.GetValueAsync(cancellationToken).ConfigureAwait(false);
......
......@@ -15,6 +15,11 @@ public bool TryGetStateChecksums(out DocumentStateChecksums stateChecksums)
return _lazyChecksums.TryGetValue(out stateChecksums);
}
public Task<DocumentStateChecksums> GetStateChecksumsAsync(CancellationToken cancellationToken)
{
return _lazyChecksums.GetValueAsync(cancellationToken);
}
public async Task<Checksum> GetChecksumAsync(CancellationToken cancellationToken)
{
var collection = await _lazyChecksums.GetValueAsync(cancellationToken).ConfigureAwait(false);
......
......@@ -73,7 +73,8 @@
<Compile Include="Services\ProjectCacheHostServiceFactory.cs" />
<Compile Include="Services\RoslynServices.cs" />
<Compile Include="Services\SolutionService.cs" />
<Compile Include="Services\RemoteWorkspace.cs" />
<Compile Include="Storage\RemotePersistentStorageLocationService.cs" />
</ItemGroup>
<Import Project="..\..\..\..\build\Targets\Imports.targets" />
</Project>
</Project>
\ No newline at end of file
......@@ -18,8 +18,8 @@ internal class AssetStorage
{
public static readonly AssetStorage Default = new AssetStorage();
private const int CleanupInterval = 3; // 3 minutes
private const int PurgeAfter = 30; // 30 minutes
private const int CleanupInterval = 1; // 1 minutes
private const int PurgeAfter = 3; // 3 minutes
private static readonly TimeSpan s_purgeAfterTimeSpan = TimeSpan.FromMinutes(PurgeAfter);
private static readonly TimeSpan s_cleanupIntervalTimeSpan = TimeSpan.FromMinutes(CleanupInterval);
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Threading;
using Roslyn.Utilities;
namespace Microsoft.CodeAnalysis.Remote
{
/// <summary>
/// this let us have isolated workspace services between solutions such as option services
/// </summary>
internal class RemoteWorkspace : Workspace
{
public RemoteWorkspace()
: base(RoslynServices.HostServices, workspaceKind: SolutionService.WorkspaceKind_RemoteWorkspace)
{
}
public override bool CanApplyChange(ApplyChangesKind feature)
{
// all kinds supported.
return true;
}
public override bool CanOpenDocuments
{
get
{
// enables simulation of having documents open.
return true;
}
}
/// <summary>
/// Clears all projects and documents from the workspace.
/// </summary>
public new void ClearSolution()
{
base.ClearSolution();
}
/// <summary>
/// Adds an entire solution to the workspace, replacing any existing solution.
/// </summary>
public Solution AddSolution(SolutionInfo solutionInfo)
{
if (solutionInfo == null)
{
throw new ArgumentNullException(nameof(solutionInfo));
}
this.OnSolutionAdded(solutionInfo);
this.UpdateReferencesAfterAdd();
return this.CurrentSolution;
}
/// <summary>
/// update primary solution
/// </summary>
public Solution UpdateSolution(Solution solution)
{
if (solution == null)
{
throw new ArgumentNullException(nameof(solution));
}
var oldSolution = this.CurrentSolution;
Contract.ThrowIfFalse(oldSolution.Id == solution.Id && oldSolution.FilePath == solution.FilePath);
// TODO: under serialization lock ?
var newSolution = this.SetCurrentSolution(solution);
this.RaiseWorkspaceChangedEventAsync(WorkspaceChangeKind.SolutionChanged, oldSolution, newSolution);
this.UpdateReferencesAfterAdd();
return this.CurrentSolution;
}
/// <summary>
/// Puts the specified document into the open state.
/// </summary>
public override void OpenDocument(DocumentId documentId, bool activate = true)
{
var doc = this.CurrentSolution.GetDocument(documentId);
if (doc != null)
{
var text = doc.GetTextAsync(CancellationToken.None).WaitAndGetResult_CanCallOnBackground(CancellationToken.None);
this.OnDocumentOpened(documentId, text.Container, activate);
}
}
/// <summary>
/// Puts the specified document into the closed state.
/// </summary>
public override void CloseDocument(DocumentId documentId)
{
var doc = this.CurrentSolution.GetDocument(documentId);
if (doc != null)
{
var text = doc.GetTextAsync(CancellationToken.None).WaitAndGetResult_CanCallOnBackground(CancellationToken.None);
var version = doc.GetTextVersionAsync(CancellationToken.None).WaitAndGetResult_CanCallOnBackground(CancellationToken.None);
var loader = TextLoader.From(TextAndVersion.Create(text, version, doc.FilePath));
this.OnDocumentClosed(documentId, loader);
}
}
/// <summary>
/// Puts the specified additional document into the open state.
/// </summary>
public override void OpenAdditionalDocument(DocumentId documentId, bool activate = true)
{
var doc = this.CurrentSolution.GetAdditionalDocument(documentId);
if (doc != null)
{
var text = doc.GetTextAsync(CancellationToken.None).WaitAndGetResult_CanCallOnBackground(CancellationToken.None);
this.OnAdditionalDocumentOpened(documentId, text.Container, activate);
}
}
/// <summary>
/// Puts the specified additional document into the closed state
/// </summary>
public override void CloseAdditionalDocument(DocumentId documentId)
{
var doc = this.CurrentSolution.GetAdditionalDocument(documentId);
if (doc != null)
{
var text = doc.GetTextAsync(CancellationToken.None).WaitAndGetResult_CanCallOnBackground(CancellationToken.None);
var version = doc.GetTextVersionAsync(CancellationToken.None).WaitAndGetResult_CanCallOnBackground(CancellationToken.None);
var loader = TextLoader.From(TextAndVersion.Create(text, version, doc.FilePath));
this.OnAdditionalDocumentClosed(documentId, loader);
}
}
}
}
......@@ -64,8 +64,7 @@ public async Task SynchronizePrimaryWorkspaceAsync(byte[] solutionChecksum)
{
try
{
// cause all assets belong to the given solution to sync to remote host
await RoslynServices.AssetService.SynchronizeSolutionAssetsAsync(checksum, CancellationToken).ConfigureAwait(false);
await RoslynServices.SolutionService.UpdatePrimaryWorkspaceAsync(checksum, CancellationToken).ConfigureAwait(false);
}
catch (IOException)
{
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册