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 try
{ {
ConfigureDotNetForFirstTimeUse();
using (PerfTrace.Current.CaptureTiming()) using (PerfTrace.Current.CaptureTiming())
{ {
return ProcessArgs(args, new Telemetry()); return ProcessArgs(args);
} }
} }
catch (GracefulException e) 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. // 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 success = true;
var command = string.Empty; var command = string.Empty;
var lastArg = 0; var lastArg = 0;
using (INuGetCacheSentinel nugetCacheSentinel = new NuGetCacheSentinel())
{
for (; lastArg < args.Length; lastArg++) for (; lastArg < args.Length; lastArg++)
{ {
if (IsArg(args[lastArg], "v", "verbose")) if (IsArg(args[lastArg], "v", "verbose"))
@ -114,6 +114,8 @@ namespace Microsoft.DotNet.Cli
} }
else else
{ {
ConfigureDotNetForFirstTimeUse(nugetCacheSentinel);
// It's the command, and we're done! // It's the command, and we're done!
command = args[lastArg]; command = args[lastArg];
break; break;
@ -125,6 +127,12 @@ namespace Microsoft.DotNet.Cli
return 1; return 1;
} }
if (telemetryClient == null)
{
telemetryClient = new Telemetry(nugetCacheSentinel);
}
}
var appArgs = (lastArg + 1) >= args.Length ? Enumerable.Empty<string>() : args.Skip(lastArg + 1).ToArray(); var appArgs = (lastArg + 1) >= args.Length ? Enumerable.Empty<string>() : args.Skip(lastArg + 1).ToArray();
if (verbose.HasValue) 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 (PerfTrace.Current.CaptureTiming())
{ {
using (var nugetPackagesArchiver = new NuGetPackagesArchiver()) using (var nugetPackagesArchiver = new NuGetPackagesArchiver())
{
using (var nugetCacheSentinel = new NuGetCacheSentinel())
{ {
var environmentProvider = new EnvironmentProvider(); var environmentProvider = new EnvironmentProvider();
var commandFactory = new DotNetCommandFactory(); var commandFactory = new DotNetCommandFactory();
@ -181,7 +187,6 @@ namespace Microsoft.DotNet.Cli
} }
} }
} }
}
private static void InitializeProcess() private static void InitializeProcess()
{ {

View file

@ -4,9 +4,11 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.IO;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.ApplicationInsights; using Microsoft.ApplicationInsights;
using Microsoft.DotNet.Cli.Utils; using Microsoft.DotNet.Cli.Utils;
using Microsoft.DotNet.Configurer;
using Microsoft.DotNet.InternalAbstractions; using Microsoft.DotNet.InternalAbstractions;
namespace Microsoft.DotNet.Cli namespace Microsoft.DotNet.Cli
@ -30,9 +32,11 @@ namespace Microsoft.DotNet.Cli
public bool Enabled { get; } 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) if (!Enabled)
{ {
@ -43,6 +47,16 @@ namespace Microsoft.DotNet.Cli
_trackEventTask = Task.Factory.StartNew(() => InitializeTelemetry()); _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) public void TrackEvent(string eventName, IDictionary<string, string> properties, IDictionary<string, double> measurements)
{ {
if (!Enabled) if (!Enabled)

View file

@ -15,7 +15,8 @@ namespace Microsoft.DotNet.Tests
{ {
public class GivenThatTheUserIsRunningDotNetForTheFirstTime : TestBase public class GivenThatTheUserIsRunningDotNetForTheFirstTime : TestBase
{ {
private static CommandResult _firstDotnetUseCommandResult; private static CommandResult _firstDotnetNonVerbUseCommandResult;
private static CommandResult _firstDotnetVerbUseCommandResult;
private static DirectoryInfo _nugetCacheFolder; private static DirectoryInfo _nugetCacheFolder;
static GivenThatTheUserIsRunningDotNetForTheFirstTime() static GivenThatTheUserIsRunningDotNetForTheFirstTime()
@ -28,7 +29,8 @@ namespace Microsoft.DotNet.Tests
command.Environment["NUGET_PACKAGES"] = testNugetCache; command.Environment["NUGET_PACKAGES"] = testNugetCache;
command.Environment["DOTNET_SKIP_FIRST_TIME_EXPERIENCE"] = ""; command.Environment["DOTNET_SKIP_FIRST_TIME_EXPERIENCE"] = "";
_firstDotnetUseCommandResult = command.ExecuteWithCapturedOutput("new"); _firstDotnetNonVerbUseCommandResult = command.ExecuteWithCapturedOutput("--info");
_firstDotnetVerbUseCommandResult = command.ExecuteWithCapturedOutput("new");
_nugetCacheFolder = new DirectoryInfo(testNugetCache); _nugetCacheFolder = new DirectoryInfo(testNugetCache);
} }
@ -36,7 +38,15 @@ namespace Microsoft.DotNet.Tests
[Fact] [Fact]
public void Using_dotnet_for_the_first_time_succeeds() 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] [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."; 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] [Fact]