dotnet-installer/src/Microsoft.DotNet.Configurer/DotnetFirstTimeUseConfigurer.cs
Livar Cunha 84f63029fe Almost all of the code to prime the NuGet cache from the archive.
- Created a Configurer class that is responsible for deciding when to run the dotnet first time use
experience and invoke the NuGetCachePrimer.
- Added the NuGetCachePrimer which extract the archive and primes the cache.
-- This is just missing creating the sentinel once restore succeeds.
- Added a shell for the NugetPackagesArchiver, which will be responsible for expanding the archive (likely
replaced in the future by an abstraction from Eric's code or its implementation will simply call Eric's code).
- Added a TemporaryFolder abstration to Internal Abstractions that handles deleting the temporary folder once
we are done with it.
2016-06-10 16:53:55 -07:00

49 lines
1.5 KiB
C#

// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System.IO;
using Microsoft.DotNet.Cli.Utils;
using Microsoft.Extensions.EnvironmentAbstractions;
namespace Microsoft.DotNet.Configurer
{
public class DotnetFirstTimeUseConfigurer
{
public static readonly string SENTINEL = $"{Product.Version}.dotnetSentinel";
private IFile _file;
private INuGetCachePrimer _nugetCachePrimer;
private INuGetCacheResolver _nugetCacheResolver;
public DotnetFirstTimeUseConfigurer(INuGetCachePrimer nugetCachePrimer, INuGetCacheResolver nugetCacheResolver)
: this(nugetCachePrimer, nugetCacheResolver, FileSystemWrapper.Default.File)
{
}
internal DotnetFirstTimeUseConfigurer(
INuGetCachePrimer nugetCachePrimer,
INuGetCacheResolver nugetCacheResolver,
IFile file)
{
_file = file;
_nugetCachePrimer = nugetCachePrimer;
_nugetCacheResolver = nugetCacheResolver;
}
public void Configure()
{
if(ShouldPrimeNugetCache())
{
_nugetCachePrimer.PrimeCache();
}
}
private bool ShouldPrimeNugetCache()
{
var nugetCachePath = _nugetCacheResolver.ResolveNugetCachePath();
var sentinel = Path.Combine(nugetCachePath, SENTINEL);
return !_file.Exists(sentinel);
}
}
}