From 570c069225602faa67d4d38f259ad57bd27a3245 Mon Sep 17 00:00:00 2001 From: "Martin Hinshelwood nkdAgility.com" Date: Wed, 4 Sep 2024 16:31:04 +0100 Subject: [PATCH] + fix for small --disableTelemetry issue! --- .../Properties/launchSettings.json | 2 +- .../Commands/CommandBase.cs | 143 +++++++++--------- 2 files changed, 72 insertions(+), 73 deletions(-) diff --git a/src/MigrationTools.ConsoleFull/Properties/launchSettings.json b/src/MigrationTools.ConsoleFull/Properties/launchSettings.json index 4b06ceb4e..321faa533 100644 --- a/src/MigrationTools.ConsoleFull/Properties/launchSettings.json +++ b/src/MigrationTools.ConsoleFull/Properties/launchSettings.json @@ -9,7 +9,7 @@ }, "execute": { "commandName": "Project", - "commandLineArgs": "execute -c \"configuration.json\" --debugTrace" + "commandLineArgs": "execute -c \"configuration.json\" --disableTelemetry --debugTrace" }, "execute --help": { "commandName": "Project", diff --git a/src/MigrationTools.Host/Commands/CommandBase.cs b/src/MigrationTools.Host/Commands/CommandBase.cs index 373d7535c..13d8fc1e3 100644 --- a/src/MigrationTools.Host/Commands/CommandBase.cs +++ b/src/MigrationTools.Host/Commands/CommandBase.cs @@ -57,33 +57,32 @@ public CommandBase( Services = services; Configuration = configuration; this.ActivitySource = activitySource; + } public Activity CommandActivity { get; private set; } public sealed override async Task ExecuteAsync(CommandContext context, TSettings settings) { - // Disable Telemetry - if (settings.DisableTelemetry) - { - Log.Debug("Disabling Telemetry {CommandName}", this.GetType().Name); - CommandActivity.AddTag("DisableTelemetry", settings.DisableTelemetry); - CommandActivity.Stop(); - ActivitySourceProvider.DisableActivitySource(); - } - //Enable Debug Trace - if (settings.DebugTrace) - { - Log.Debug("Enabling Telemetry DebugTrace {CommandName}", this.GetType().Name); - ActivitySourceProvider.EnableTelemeteryDebug(); - } - using (CommandActivity = ActivitySource.StartActivity(this.GetType().Name)) { CommandActivity.SetTagsFromObject(settings); CommandActivity?.Start(); - - + // Disable Telemetry + if (settings.DisableTelemetry) + { + Log.Debug("Disabling Telemetry {CommandName}", this.GetType().Name); + CommandActivity.AddTag("DisableTelemetry", settings.DisableTelemetry); + CommandActivity.Stop(); + ActivitySourceProvider.DisableActivitySource(); + } + //Enable Debug Trace + if (settings.DebugTrace) + { + Log.Debug("Enabling Telemetry DebugTrace {CommandName}", this.GetType().Name); + ActivitySourceProvider.EnableTelemeteryDebug(); + } + // Run the command Log.Verbose("Starting {CommandName}", this.GetType().Name); CommandActivity.AddEvent(new ActivityEvent("Starting")); @@ -119,73 +118,73 @@ internal virtual async Task ExecuteInternalAsync(CommandContext context, TS public void RunStartupLogic(TSettings settings) { - ApplicationStartup(settings); - if (!settings.skipVersionCheck && _detectOnlineService.IsOnline()) + ApplicationStartup(settings); + if (!settings.skipVersionCheck && _detectOnlineService.IsOnline()) + { + _logger.LogTrace("Package Management Info:"); + Log.Debug(" IsPackageManagerInstalled: {IsPackageManagerInstalled}", _detectVersionService.IsPackageManagerInstalled); + Log.Debug(" IsPackageInstalled: {IsPackageInstalled}", _detectVersionService.IsPackageInstalled); + Log.Debug(" IsUpdateAvailable: {IsUpdateAvailable}", _detectVersionService.IsUpdateAvailable); + Log.Debug(" IsNewLocalVersionAvailable: {IsNewLocalVersionAvailable}", _detectVersionService.IsNewLocalVersionAvailable); + Log.Debug(" IsRunningInDebug: {IsRunningInDebug}", _detectVersionService.IsRunningInDebug); + Log.Verbose("Full version data: ${_detectVersionService}", _detectVersionService); + + Log.Information("Verion Info:"); + Log.Information(" Running: {RunningVersion}", _detectVersionService.RunningVersion); + Log.Information(" Installed: {InstalledVersion}", _detectVersionService.InstalledVersion); + Log.Information(" Available: {AvailableVersion}", _detectVersionService.AvailableVersion); + + if (_detectVersionService.RunningVersion.Major == 0) { - _logger.LogTrace("Package Management Info:"); - Log.Debug(" IsPackageManagerInstalled: {IsPackageManagerInstalled}", _detectVersionService.IsPackageManagerInstalled); - Log.Debug(" IsPackageInstalled: {IsPackageInstalled}", _detectVersionService.IsPackageInstalled); - Log.Debug(" IsUpdateAvailable: {IsUpdateAvailable}", _detectVersionService.IsUpdateAvailable); - Log.Debug(" IsNewLocalVersionAvailable: {IsNewLocalVersionAvailable}", _detectVersionService.IsNewLocalVersionAvailable); - Log.Debug(" IsRunningInDebug: {IsRunningInDebug}", _detectVersionService.IsRunningInDebug); - Log.Verbose("Full version data: ${_detectVersionService}", _detectVersionService); - - Log.Information("Verion Info:"); - Log.Information(" Running: {RunningVersion}", _detectVersionService.RunningVersion); - Log.Information(" Installed: {InstalledVersion}", _detectVersionService.InstalledVersion); - Log.Information(" Available: {AvailableVersion}", _detectVersionService.AvailableVersion); - - if (_detectVersionService.RunningVersion.Major == 0) - { - Log.Information("Git Info:"); - Log.Information(" Repo: {GitRepositoryUrl}", ThisAssembly.Git.RepositoryUrl); - Log.Information(" Tag: {GitTag}", ThisAssembly.Git.Tag); - Log.Information(" Branch: {GitBranch}", ThisAssembly.Git.Branch); - Log.Information(" Commits: {GitCommits}", ThisAssembly.Git.Commits); + Log.Information("Git Info:"); + Log.Information(" Repo: {GitRepositoryUrl}", ThisAssembly.Git.RepositoryUrl); + Log.Information(" Tag: {GitTag}", ThisAssembly.Git.Tag); + Log.Information(" Branch: {GitBranch}", ThisAssembly.Git.Branch); + Log.Information(" Commits: {GitCommits}", ThisAssembly.Git.Commits); - } + } - if (!_detectVersionService.IsPackageManagerInstalled) - { - Log.Warning("Windows Client: The Windows Package Manager is not installed, we use it to determine if you have the latest version, and to make sure that this application is up to date. You can download and install it from https://aka.ms/getwinget. After which you can call `winget install {PackageId}` from the Windows Terminal to get a manged version of this program.", _detectVersionService.PackageId); - Log.Warning("Windows Server: If you are running on Windows Server you can use the experimental version of Winget, or you can still use Chocolatey to manage the install. Install chocolatey from https://chocolatey.org/install and then use `choco install vsts-sync-migrator` to install, and `choco upgrade vsts-sync-migrator` to upgrade to newer versions.", _detectVersionService.PackageId); - } - else + if (!_detectVersionService.IsPackageManagerInstalled) + { + Log.Warning("Windows Client: The Windows Package Manager is not installed, we use it to determine if you have the latest version, and to make sure that this application is up to date. You can download and install it from https://aka.ms/getwinget. After which you can call `winget install {PackageId}` from the Windows Terminal to get a manged version of this program.", _detectVersionService.PackageId); + Log.Warning("Windows Server: If you are running on Windows Server you can use the experimental version of Winget, or you can still use Chocolatey to manage the install. Install chocolatey from https://chocolatey.org/install and then use `choco install vsts-sync-migrator` to install, and `choco upgrade vsts-sync-migrator` to upgrade to newer versions.", _detectVersionService.PackageId); + } + else + { + if (!_detectVersionService.IsRunningInDebug) { - if (!_detectVersionService.IsRunningInDebug) + if (!_detectVersionService.IsPackageInstalled) { - if (!_detectVersionService.IsPackageInstalled) + Log.Information("It looks like this application has been installed from a zip, would you like to use the managed version?"); + Console.WriteLine("Do you want exit and install the managed version? (y/n)"); + if (Console.ReadKey().Key == ConsoleKey.Y) { - Log.Information("It looks like this application has been installed from a zip, would you like to use the managed version?"); - Console.WriteLine("Do you want exit and install the managed version? (y/n)"); - if (Console.ReadKey().Key == ConsoleKey.Y) - { - Thread.Sleep(2000); - Environment.Exit(0); - } - } - if (_detectVersionService.IsUpdateAvailable && _detectVersionService.IsPackageInstalled) - { - Log.Information("It looks like an updated version is available from Winget, would you like to exit and update?"); - Console.WriteLine("Do you want to exit and update? (y/n)"); - if (Console.ReadKey().Key == ConsoleKey.Y) - { - Thread.Sleep(2000); - Environment.Exit(0); - } + Thread.Sleep(2000); + Environment.Exit(0); } } - else + if (_detectVersionService.IsUpdateAvailable && _detectVersionService.IsPackageInstalled) { - Log.Information("Running in Debug! No further version checkes....."); + Log.Information("It looks like an updated version is available from Winget, would you like to exit and update?"); + Console.WriteLine("Do you want to exit and update? (y/n)"); + if (Console.ReadKey().Key == ConsoleKey.Y) + { + Thread.Sleep(2000); + Environment.Exit(0); + } } } + else + { + Log.Information("Running in Debug! No further version checkes....."); + } } - else - { - /// not online or you have specified not to - Log.Warning("You are either not online or have chosen `skipVersionCheck`. We will not check for a newer version of the tools.", _detectVersionService.PackageId); - } + } + else + { + /// not online or you have specified not to + Log.Warning("You are either not online or have chosen `skipVersionCheck`. We will not check for a newer version of the tools.", _detectVersionService.PackageId); + } }