Merge pull request #3579 from Priya91/rel/1.0.0-preview2

Remove showing firsttime eula for non verbs.
This commit is contained in:
Josh Free 2016-06-15 17:02:34 -07:00 committed by GitHub
commit ef9ad4044a
3 changed files with 82 additions and 53 deletions

View file

@ -55,11 +55,9 @@ namespace Microsoft.DotNet.Cli
try
{
ConfigureDotNetForFirstTimeUse();
using (PerfTrace.Current.CaptureTiming())
{
return ProcessArgs(args, new Telemetry());
return ProcessArgs(args);
}
}
catch (GracefulException e)
@ -78,7 +76,7 @@ namespace Microsoft.DotNet.Cli
}
}
internal static int ProcessArgs(string[] args, ITelemetry telemetryClient)
internal static int ProcessArgs(string[] args, ITelemetry telemetryClient = null)
{
// CommandLineApplication is a bit restrictive, so we parse things ourselves here. Individual apps should use CLA.
@ -86,6 +84,8 @@ namespace Microsoft.DotNet.Cli
var success = true;
var command = string.Empty;
var lastArg = 0;
using (INuGetCacheSentinel nugetCacheSentinel = new NuGetCacheSentinel())
{
for (; lastArg < args.Length; lastArg++)
{
if (IsArg(args[lastArg], "v", "verbose"))
@ -114,6 +114,8 @@ namespace Microsoft.DotNet.Cli
}
else
{
ConfigureDotNetForFirstTimeUse(nugetCacheSentinel);
// It's the command, and we're done!
command = args[lastArg];
break;
@ -125,6 +127,12 @@ namespace Microsoft.DotNet.Cli
return 1;
}
if (telemetryClient == null)
{
telemetryClient = new Telemetry(nugetCacheSentinel);
}
}
var appArgs = (lastArg + 1) >= args.Length ? Enumerable.Empty<string>() : args.Skip(lastArg + 1).ToArray();
if (verbose.HasValue)
@ -160,13 +168,11 @@ namespace Microsoft.DotNet.Cli
}
private static void ConfigureDotNetForFirstTimeUse()
private static void ConfigureDotNetForFirstTimeUse(INuGetCacheSentinel nugetCacheSentinel)
{
using (PerfTrace.Current.CaptureTiming())
{
using (var nugetPackagesArchiver = new NuGetPackagesArchiver())
{
using (var nugetCacheSentinel = new NuGetCacheSentinel())
{
var environmentProvider = new EnvironmentProvider();
var commandFactory = new DotNetCommandFactory();
@ -181,7 +187,6 @@ namespace Microsoft.DotNet.Cli
}
}
}
}
private static void InitializeProcess()
{

View file

@ -4,9 +4,11 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Threading.Tasks;
using Microsoft.ApplicationInsights;
using Microsoft.DotNet.Cli.Utils;
using Microsoft.DotNet.Configurer;
using Microsoft.DotNet.InternalAbstractions;
namespace Microsoft.DotNet.Cli
@ -30,9 +32,11 @@ namespace Microsoft.DotNet.Cli
public bool Enabled { get; }
public Telemetry()
public Telemetry () : this(null) { }
public Telemetry(INuGetCacheSentinel sentinel)
{
Enabled = !Env.GetEnvironmentVariableAsBool(TelemetryOptout);
Enabled = !Env.GetEnvironmentVariableAsBool(TelemetryOptout) && PermissionExists(sentinel);
if (!Enabled)
{
@ -43,6 +47,16 @@ namespace Microsoft.DotNet.Cli
_trackEventTask = Task.Factory.StartNew(() => InitializeTelemetry());
}
private bool PermissionExists(INuGetCacheSentinel sentinel)
{
if (sentinel == null)
{
return false;
}
return sentinel.Exists();
}
public void TrackEvent(string eventName, IDictionary<string, string> properties, IDictionary<string, double> measurements)
{
if (!Enabled)

View file

@ -15,7 +15,8 @@ namespace Microsoft.DotNet.Tests
{
public class GivenThatTheUserIsRunningDotNetForTheFirstTime : TestBase
{
private static CommandResult _firstDotnetUseCommandResult;
private static CommandResult _firstDotnetNonVerbUseCommandResult;
private static CommandResult _firstDotnetVerbUseCommandResult;
private static DirectoryInfo _nugetCacheFolder;
static GivenThatTheUserIsRunningDotNetForTheFirstTime()
@ -28,7 +29,8 @@ namespace Microsoft.DotNet.Tests
command.Environment["NUGET_PACKAGES"] = testNugetCache;
command.Environment["DOTNET_SKIP_FIRST_TIME_EXPERIENCE"] = "";
_firstDotnetUseCommandResult = command.ExecuteWithCapturedOutput("new");
_firstDotnetNonVerbUseCommandResult = command.ExecuteWithCapturedOutput("--info");
_firstDotnetVerbUseCommandResult = command.ExecuteWithCapturedOutput("new");
_nugetCacheFolder = new DirectoryInfo(testNugetCache);
}
@ -36,7 +38,15 @@ namespace Microsoft.DotNet.Tests
[Fact]
public void Using_dotnet_for_the_first_time_succeeds()
{
_firstDotnetUseCommandResult.Should().Pass();
_firstDotnetVerbUseCommandResult.Should().Pass();
}
[Fact]
public void Using_dotnet_for_the_first_time_with_non_verbs_doesnt_print_eula()
{
const string firstTimeNonVerbUseMessage = @".NET Command Line Tools";
_firstDotnetNonVerbUseCommandResult.StdOut.Should().StartWith(firstTimeNonVerbUseMessage);
}
[Fact]
@ -54,7 +64,7 @@ Configuring...
-------------------
A command is running to initially populate your local package cache, to improve restore speed and enable offline access. This command will take up to a minute to complete and will only happen once.";
_firstDotnetUseCommandResult.StdOut.Should().StartWith(firstTimeUseWelcomeMessage);
_firstDotnetVerbUseCommandResult.StdOut.Should().StartWith(firstTimeUseWelcomeMessage);
}
[Fact]