Skip to content

Commit

Permalink
Merge pull request #56903 from dotnet/merges/main-to-main-vs-deps
Browse files Browse the repository at this point in the history
Merge main to main-vs-deps
  • Loading branch information
dotnet-bot authored Oct 2, 2021
2 parents bbed65d + 4ac4de5 commit 14b9d5b
Show file tree
Hide file tree
Showing 13 changed files with 48 additions and 264 deletions.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,6 @@ public IdeCoreBenchmarksCloudCacheServiceProvider()
}

public AbstractPersistentStorageService Create(IPersistentStorageConfiguration configuration)
{
return new MockCloudCachePersistentStorageService(
configuration, @"C:\github\roslyn", cs =>
{
if (cs is IAsyncDisposable asyncDisposable)
{
asyncDisposable.DisposeAsync().AsTask().Wait();
}
else if (cs is IDisposable disposable)
{
disposable.Dispose();
}
});
}
=> new MockCloudCachePersistentStorageService(configuration, @"C:\github\roslyn");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,7 @@ public class CloudCachePersistentStorageTests : AbstractPersistentStorageTests
internal override AbstractPersistentStorageService GetStorageService(
IMefHostExportProvider exportProvider, IPersistentStorageConfiguration configuration, IPersistentStorageFaultInjector? faultInjector, string relativePathBase)
{
var threadingContext = exportProvider.GetExports<IThreadingContext>().Single().Value;
return new MockCloudCachePersistentStorageService(
configuration,
relativePathBase,
cs =>
{
if (cs is IAsyncDisposable asyncDisposable)
{
threadingContext.JoinableTaskFactory.Run(
() => asyncDisposable.DisposeAsync().AsTask());
}
else if (cs is IDisposable disposable)
{
disposable.Dispose();
}
});
return new MockCloudCachePersistentStorageService(configuration, relativePathBase);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Host;
Expand All @@ -19,22 +18,16 @@ namespace Microsoft.CodeAnalysis.UnitTests.WorkspaceServices.Mocks
internal class MockCloudCachePersistentStorageService : AbstractCloudCachePersistentStorageService
{
private readonly string _relativePathBase;
private readonly Action<ICacheService> _disposeCacheService;

public MockCloudCachePersistentStorageService(
IPersistentStorageConfiguration configuration,
string relativePathBase,
Action<ICacheService> disposeCacheService)
string relativePathBase)
: base(configuration)
{
_relativePathBase = relativePathBase;
_disposeCacheService = disposeCacheService;
}

protected override void DisposeCacheService(ICacheService cacheService)
=> _disposeCacheService(cacheService);

protected override async ValueTask<ICacheService> CreateCacheServiceAsync(CancellationToken cancellationToken)
protected override async ValueTask<ICacheService> CreateCacheServiceAsync(string solutionFolder, CancellationToken cancellationToken)
{
// Directly access VS' CacheService through their library and not as a brokered service. Then create our
// wrapper CloudCacheService directly on that instance.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Host;
using Microsoft.CodeAnalysis.Shared.Utilities;
using Microsoft.CodeAnalysis.Storage;
using Microsoft.VisualStudio.RpcContracts.Caching;
using Roslyn.Utilities;
Expand All @@ -22,8 +23,7 @@ protected AbstractCloudCachePersistentStorageService(IPersistentStorageConfigura
{
}

protected abstract void DisposeCacheService(ICacheService cacheService);
protected abstract ValueTask<ICacheService> CreateCacheServiceAsync(CancellationToken cancellationToken);
protected abstract ValueTask<ICacheService> CreateCacheServiceAsync(string solutionFolder, CancellationToken cancellationToken);

protected sealed override string GetDatabaseFilePath(string workingFolderPath)
{
Expand All @@ -40,13 +40,16 @@ protected sealed override bool ShouldDeleteDatabase(Exception exception)
protected sealed override async ValueTask<IChecksummedPersistentStorage?> TryOpenDatabaseAsync(
SolutionKey solutionKey, string workingFolderPath, string databaseFilePath, CancellationToken cancellationToken)
{
var cacheService = await this.CreateCacheServiceAsync(cancellationToken).ConfigureAwait(false);
var solutionFolder = IOUtilities.PerformIO(() => Path.GetDirectoryName(solutionKey.FilePath));
if (RoslynString.IsNullOrEmpty(solutionFolder))
return null;

var cacheService = await this.CreateCacheServiceAsync(solutionFolder, cancellationToken).ConfigureAwait(false);
var relativePathBase = await cacheService.GetRelativePathBaseAsync(cancellationToken).ConfigureAwait(false);
if (string.IsNullOrEmpty(relativePathBase))
return null;

return new CloudCachePersistentStorage(
cacheService, solutionKey, workingFolderPath, relativePathBase, databaseFilePath, this.DisposeCacheService);
return new CloudCachePersistentStorage(cacheService, solutionKey, workingFolderPath, relativePathBase, databaseFilePath);
}
}
}
18 changes: 3 additions & 15 deletions src/VisualStudio/Core/Def/Storage/CloudCachePersistentStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,37 +43,25 @@ internal class CloudCachePersistentStorage : AbstractPersistentStorage
/// Underlying cache service (owned by platform team) responsible for actual storage and retrieval of data.
/// </summary>
private readonly ICacheService _cacheService;
private readonly Action<ICacheService> _disposeCacheService;

public CloudCachePersistentStorage(
ICacheService cacheService,
SolutionKey solutionKey,
string workingFolderPath,
string relativePathBase,
string databaseFilePath,
Action<ICacheService> disposeCacheService)
string databaseFilePath)
: base(workingFolderPath, relativePathBase, databaseFilePath)
{
_cacheService = cacheService;
_disposeCacheService = disposeCacheService;
_projectToContainerKeyCacheCallback = ps => new ProjectContainerKeyCache(relativePathBase, ProjectKey.ToProjectKey(solutionKey, ps));
}

public sealed override void Dispose()
=> _disposeCacheService(_cacheService);
=> (_cacheService as IDisposable)?.Dispose();

public sealed override ValueTask DisposeAsync()
{
if (_cacheService is IAsyncDisposable asyncDisposable)
{
return asyncDisposable.DisposeAsync();
}
else if (_cacheService is IDisposable disposable)
{
disposable.Dispose();
return ValueTaskFactory.CompletedTask;
}

Dispose();
return ValueTaskFactory.CompletedTask;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Collections.Immutable;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.Host;
using Microsoft.ServiceHub.Framework;
using Microsoft.VisualStudio.RpcContracts.Caching;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.ServiceBroker;
Expand All @@ -17,36 +17,25 @@ namespace Microsoft.VisualStudio.LanguageServices.Storage
internal class VisualStudioCloudCacheStorageService : AbstractCloudCachePersistentStorageService
{
private readonly IAsyncServiceProvider _serviceProvider;
private readonly IThreadingContext _threadingContext;

public VisualStudioCloudCacheStorageService(IAsyncServiceProvider serviceProvider, IThreadingContext threadingContext, IPersistentStorageConfiguration configuration)
public VisualStudioCloudCacheStorageService(IAsyncServiceProvider serviceProvider, IPersistentStorageConfiguration configuration)
: base(configuration)
{
_serviceProvider = serviceProvider;
_threadingContext = threadingContext;
}

protected sealed override void DisposeCacheService(ICacheService cacheService)
{
if (cacheService is IAsyncDisposable asyncDisposable)
{
_threadingContext.JoinableTaskFactory.Run(
() => asyncDisposable.DisposeAsync().AsTask());
}
else if (cacheService is IDisposable disposable)
{
disposable.Dispose();
}
}

protected sealed override async ValueTask<ICacheService> CreateCacheServiceAsync(CancellationToken cancellationToken)
protected sealed override async ValueTask<ICacheService> CreateCacheServiceAsync(string solutionFolder, CancellationToken cancellationToken)
{
var serviceContainer = await _serviceProvider.GetServiceAsync<SVsBrokeredServiceContainer, IBrokeredServiceContainer>().ConfigureAwait(false);
var serviceBroker = serviceContainer.GetFullAccessServiceBroker();

#pragma warning disable ISB001 // Dispose of proxies
// cache service will be disposed inside VisualStudioCloudCachePersistentStorage.Dispose
var cacheService = await serviceBroker.GetProxyAsync<ICacheService>(VisualStudioServices.VS2019_10.CacheService, cancellationToken: cancellationToken).ConfigureAwait(false);
var cacheService = await serviceBroker.GetProxyAsync<ICacheService>(
VisualStudioServices.VS2019_10.CacheService,
// replace with CacheService.RelativePathBaseActivationArgKey once available.
new ServiceActivationOptions { ActivationArguments = ImmutableDictionary<string, string>.Empty.Add("RelativePathBase", solutionFolder) },
cancellationToken).ConfigureAwait(false);
#pragma warning restore ISB001 // Dispose of proxies

Contract.ThrowIfNull(cacheService);
Expand Down
Loading

0 comments on commit 14b9d5b

Please sign in to comment.