diff --git a/vscode-dotnet-runtime-extension/src/extension.ts b/vscode-dotnet-runtime-extension/src/extension.ts index 61617a3b..94d06828 100644 --- a/vscode-dotnet-runtime-extension/src/extension.ts +++ b/vscode-dotnet-runtime-extension/src/extension.ts @@ -70,11 +70,13 @@ export function activate(context: vscode.ExtensionContext, extensionContext?: IE extensionContext.extensionConfiguration : vscode.workspace.getConfiguration(configPrefix); + const extensionTelemetryEnabled = enableExtensionTelemetry(extensionConfiguration, configKeys.enableTelemetry); + const eventStreamContext = { displayChannelName, logPath: context.logPath, extensionId: dotnetCoreAcquisitionExtensionId, - enableTelemetry: enableExtensionTelemetry(extensionConfiguration, configKeys.enableTelemetry), + enableTelemetry: extensionTelemetryEnabled, telemetryReporter: extensionContext ? extensionContext.telemetryReporter : undefined, showLogCommand: `${commandPrefix}.${commandKeys.showAcquisitionLog}`, packageJson, @@ -112,7 +114,8 @@ export function activate(context: vscode.ExtensionContext, extensionContext?: IE installationValidator: new InstallationValidator(eventStream), timeoutValue: resolvedTimeoutSeconds, installDirectoryProvider: new RuntimeInstallationDirectoryProvider(context.globalStoragePath), - proxyUrl: proxyLink + proxyUrl: proxyLink, + isExtensionTelemetryInitiallyEnabled: extensionTelemetryEnabled }); const existingPathResolver = new ExistingPathResolver(); const versionResolver = new VersionResolver(context.globalState, eventStream, resolvedTimeoutSeconds, proxyLink); @@ -197,4 +200,5 @@ export function activate(context: vscode.ExtensionContext, extensionContext?: IE ensureDependenciesRegistration, reportIssueRegistration, ...eventStreamObservers); + } diff --git a/vscode-dotnet-runtime-library/src/EventStream/EventStreamRegistration.ts b/vscode-dotnet-runtime-library/src/EventStream/EventStreamRegistration.ts index ad8255ea..5441cf13 100644 --- a/vscode-dotnet-runtime-library/src/EventStream/EventStreamRegistration.ts +++ b/vscode-dotnet-runtime-library/src/EventStream/EventStreamRegistration.ts @@ -40,7 +40,7 @@ export function registerEventStream(context: IEventStreamContext): [EventStream, const logFile = path.join(context.logPath, `DotNetAcquisition-${context.extensionId}-${ new Date().getTime() }.txt`); const loggingObserver = new LoggingObserver(logFile); - let eventStreamObservers: IEventStreamObserver[] = + const eventStreamObservers: IEventStreamObserver[] = [ new StatusBarObserver(vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left, Number.MIN_VALUE), context.showLogCommand), new OutputChannelObserver(outputChannel), diff --git a/vscode-dotnet-runtime-library/src/EventStream/TelemetryObserver.ts b/vscode-dotnet-runtime-library/src/EventStream/TelemetryObserver.ts index be4a0dd6..f0af2ea7 100644 --- a/vscode-dotnet-runtime-library/src/EventStream/TelemetryObserver.ts +++ b/vscode-dotnet-runtime-library/src/EventStream/TelemetryObserver.ts @@ -80,7 +80,11 @@ export class TelemetryObserver implements IEventStreamObserver { if(!TelemetryObserver.isTelemetryEnabled(isExtensionTelemetryEnabled)) { TelemetryObserver.logTelemetryChange(`Before disabling .NET SDK telemetry:`, isExtensionTelemetryEnabled, eventStream); - new CommandExecutor(eventStream).setEnvironmentVariable('DOTNET_CLI_TELEMETRY_OPTOUT', 'true'); + + new CommandExecutor(eventStream).setEnvironmentVariable('DOTNET_CLI_TELEMETRY_OPTOUT', 'true', +`Telemetry is disabled for VS Code & the .NET Install Tool Extension, but the .NET SDK extension may still collect telemetry and we may not have successfully turned it off. +Please verify that .NET SDK telemetry is disabled by setting the environment variable DOTNET_CLI_TELEMETRY_OPTOUT to true.`); + TelemetryObserver.logTelemetryChange(`After disabling .NET SDK telemetry:`, isExtensionTelemetryEnabled, eventStream); } else diff --git a/vscode-dotnet-runtime-library/src/Utils/CommandExecutor.ts b/vscode-dotnet-runtime-library/src/Utils/CommandExecutor.ts index ca08f6ce..57491d5d 100644 --- a/vscode-dotnet-runtime-library/src/Utils/CommandExecutor.ts +++ b/vscode-dotnet-runtime-library/src/Utils/CommandExecutor.ts @@ -22,6 +22,7 @@ import path = require('path'); import { IEventStream } from '../EventStream/EventStream'; import * as vscode from 'vscode'; import * as os from 'os'; +import { WindowDisplayWorker } from '../EventStream/WindowDisplayWorker'; /* tslint:disable:no-any */ @@ -211,21 +212,51 @@ out: ${commandResult.stdout} err: ${commandResult.stderr}.`)); return [workingCommand, working]; } - public async setEnvironmentVariable(variable : string, value : string) + public async setEnvironmentVariable(variable : string, value : string, failureWarningMessage? : string) { // todo: verify this works on all os + const oldReturnStatusSetting = this.returnStatus; + this.returnStatus = true; + let environmentEditExitCode = 0; + process.env[variable] = value; if(os.platform() === 'win32') { const setShellVariable = `set ${variable}=${value}`; const setSystemVariable = `setx ${variable} "${value}"`; - await this.execute(setShellVariable); - await this.execute(setSystemVariable); + try + { + environmentEditExitCode = environmentEditExitCode || Number((await this.execute(setShellVariable))[0]); + environmentEditExitCode = environmentEditExitCode || Number((await this.execute(setSystemVariable))[0]); + } + catch(error) + { + if(failureWarningMessage) + { + new WindowDisplayWorker().showWarningMessage(failureWarningMessage, () => {/* No Callback */}, ); + } + } } else { const setVariable = `${variable}=${value} && export ${variable}` - await this.execute(setVariable); + try + { + environmentEditExitCode = environmentEditExitCode || Number((await this.execute(setVariable))[0]);; + } + catch(error) + { + if(failureWarningMessage) + { + new WindowDisplayWorker().showWarningMessage(failureWarningMessage, () => {/* No Callback */}, ); + } + } } + + if(environmentEditExitCode && failureWarningMessage) + { + new WindowDisplayWorker().showWarningMessage(failureWarningMessage, () => {/* No Callback */}, ); + } + this.returnStatus = oldReturnStatusSetting; } } diff --git a/vscode-dotnet-runtime-library/src/Utils/FileUtilities.ts b/vscode-dotnet-runtime-library/src/Utils/FileUtilities.ts index 4a1e8353..9043340b 100644 --- a/vscode-dotnet-runtime-library/src/Utils/FileUtilities.ts +++ b/vscode-dotnet-runtime-library/src/Utils/FileUtilities.ts @@ -214,7 +214,6 @@ export class FileUtilities extends IFileUtilities public async getFileHash(filePath : string) : Promise { - const res = await this.sha512Hasher(filePath); return res; } diff --git a/vscode-dotnet-runtime-library/src/Utils/IFileUtilities.ts b/vscode-dotnet-runtime-library/src/Utils/IFileUtilities.ts index 1a0d032f..b5700595 100644 --- a/vscode-dotnet-runtime-library/src/Utils/IFileUtilities.ts +++ b/vscode-dotnet-runtime-library/src/Utils/IFileUtilities.ts @@ -4,7 +4,7 @@ * ------------------------------------------------------------------------------------------ */ /* tslint:disable:no-any */ -import { IEventStream } from "../EventStream/EventStream"; +import { IEventStream } from '../EventStream/EventStream'; export abstract class IFileUtilities { diff --git a/vscode-dotnet-runtime-library/src/Utils/WebRequestWorker.ts b/vscode-dotnet-runtime-library/src/Utils/WebRequestWorker.ts index 60925ff0..2d27d640 100644 --- a/vscode-dotnet-runtime-library/src/Utils/WebRequestWorker.ts +++ b/vscode-dotnet-runtime-library/src/Utils/WebRequestWorker.ts @@ -189,14 +189,14 @@ export class WebRequestWorker return; } - const finished = promisify(stream.finished); + const isFinished = promisify(stream.finished); const file = fs.createWriteStream(dest, { flags: 'wx' }); const options = await this.getAxiosOptions(3, {responseType: 'stream', transformResponse: (x : any) => x}, false); await this.axiosGet(url, options) .then(response => { response.data.pipe(file); - return finished(file); + return isFinished(file); }); } diff --git a/vscode-dotnet-runtime-library/src/test/mocks/MockObjects.ts b/vscode-dotnet-runtime-library/src/test/mocks/MockObjects.ts index 356c562d..5d22aaee 100644 --- a/vscode-dotnet-runtime-library/src/test/mocks/MockObjects.ts +++ b/vscode-dotnet-runtime-library/src/test/mocks/MockObjects.ts @@ -295,9 +295,9 @@ export class MockFileUtilities extends IFileUtilities { private trueUtilities = new FileUtilities(); - public writeFileOntoDisk(content : string, path : string) + public writeFileOntoDisk(content : string, filePath : string) { - return this.trueUtilities.writeFileOntoDisk(content, path, new MockEventStream()); + return this.trueUtilities.writeFileOntoDisk(content, filePath, new MockEventStream()); } public wipeDirectory(directoryToWipe : string) diff --git a/vscode-dotnet-runtime-library/src/test/unit/DotnetCoreAcquisitionWorker.test.ts b/vscode-dotnet-runtime-library/src/test/unit/DotnetCoreAcquisitionWorker.test.ts index b67bf399..8a91905c 100644 --- a/vscode-dotnet-runtime-library/src/test/unit/DotnetCoreAcquisitionWorker.test.ts +++ b/vscode-dotnet-runtime-library/src/test/unit/DotnetCoreAcquisitionWorker.test.ts @@ -56,7 +56,8 @@ suite('DotnetCoreAcquisitionWorker Unit Tests', function () { installationValidator: new MockInstallationValidator(eventStream), timeoutValue: 10, installDirectoryProvider: runtimeInstall ? new RuntimeInstallationDirectoryProvider('') : new SdkInstallationDirectoryProvider(''), - installingArchitecture: arch + installingArchitecture: arch, + isExtensionTelemetryInitiallyEnabled: true }); return [acquisitionWorker, eventStream, context]; } @@ -72,6 +73,7 @@ suite('DotnetCoreAcquisitionWorker Unit Tests', function () { installationValidator: new MockInstallationValidator(eventStream), timeoutValue: 10, installDirectoryProvider: runtimeInstall ? new RuntimeInstallationDirectoryProvider('') : new SdkInstallationDirectoryProvider(''), + isExtensionTelemetryInitiallyEnabled: true }); return [acquisitionWorker, eventStream, context]; } @@ -304,6 +306,7 @@ suite('DotnetCoreAcquisitionWorker Unit Tests', function () { installationValidator: new MockInstallationValidator(eventStream), timeoutValue: 10, installDirectoryProvider: new RuntimeInstallationDirectoryProvider(''), + isExtensionTelemetryInitiallyEnabled: true }); return assert.isRejected(acquisitionWorker.acquireRuntime('1.0'), '.NET Acquisition Failed: Installation failed: Rejecting message'); diff --git a/vscode-dotnet-runtime-library/src/test/unit/TestUtility.ts b/vscode-dotnet-runtime-library/src/test/unit/TestUtility.ts index 7a7b439c..91f0f098 100644 --- a/vscode-dotnet-runtime-library/src/test/unit/TestUtility.ts +++ b/vscode-dotnet-runtime-library/src/test/unit/TestUtility.ts @@ -21,6 +21,7 @@ export function getMockAcquiringContext(runtimeInstall: boolean, timeoutTime : n installationValidator: new MockInstallationValidator(eventStream), timeoutValue: timeoutTime, installDirectoryProvider: runtimeInstall ? new RuntimeInstallationDirectoryProvider('') : new SdkInstallationDirectoryProvider(''), + isExtensionTelemetryInitiallyEnabled: true }; return workerContext; } diff --git a/vscode-dotnet-runtime-library/src/test/unit/WebRequestWorker.test.ts b/vscode-dotnet-runtime-library/src/test/unit/WebRequestWorker.test.ts index db049858..5ea08a51 100644 --- a/vscode-dotnet-runtime-library/src/test/unit/WebRequestWorker.test.ts +++ b/vscode-dotnet-runtime-library/src/test/unit/WebRequestWorker.test.ts @@ -51,6 +51,7 @@ suite('WebRequestWorker Unit Tests', () => { installationValidator: new MockInstallationValidator(eventStream), timeoutValue: 10, installDirectoryProvider: new RuntimeInstallationDirectoryProvider(''), + isExtensionTelemetryInitiallyEnabled: true }); return assert.isRejected(acquisitionWorker.acquireRuntime('1.0'), Error, '.NET Acquisition Failed'); }); diff --git a/vscode-dotnet-runtime-library/src/test/unit/WinMacGlobalInstaller.test.ts b/vscode-dotnet-runtime-library/src/test/unit/WinMacGlobalInstaller.test.ts index 0d70a1a4..624e8366 100644 --- a/vscode-dotnet-runtime-library/src/test/unit/WinMacGlobalInstaller.test.ts +++ b/vscode-dotnet-runtime-library/src/test/unit/WinMacGlobalInstaller.test.ts @@ -29,6 +29,7 @@ suite('Windows & Mac Global Installer Tests', () => installationValidator: new MockInstallationValidator(eventStream), timeoutValue: standardTimeoutTime, installDirectoryProvider: runtimeInstall ? new RuntimeInstallationDirectoryProvider('') : new SdkInstallationDirectoryProvider(''), + isExtensionTelemetryInitiallyEnabled: true, }; return workerContext; } diff --git a/vscode-dotnet-sdk-extension/src/extension.ts b/vscode-dotnet-sdk-extension/src/extension.ts index 8182aa01..c9b4ecf8 100644 --- a/vscode-dotnet-sdk-extension/src/extension.ts +++ b/vscode-dotnet-sdk-extension/src/extension.ts @@ -74,11 +74,12 @@ export function activate(context: vscode.ExtensionContext, extensionContext?: IE extensionContext.extensionConfiguration : vscode.workspace.getConfiguration(configPrefix); + const isExtensionTelemetryEnabled = enableExtensionTelemetry(extensionConfiguration, configKeys.enableTelemetry); const eventStreamContext = { displayChannelName, logPath: context.logPath, extensionId: dotnetCoreAcquisitionExtensionId, - enableTelemetry: enableExtensionTelemetry(extensionConfiguration, configKeys.enableTelemetry), + enableTelemetry: isExtensionTelemetryEnabled, telemetryReporter: extensionContext ? extensionContext.telemetryReporter : undefined, showLogCommand: `${commandPrefix}.${commandKeys.showAcquisitionLog}`, packageJson, @@ -116,12 +117,6 @@ export function activate(context: vscode.ExtensionContext, extensionContext?: IE } } - vscode.env.onDidChangeTelemetryEnabled((_: boolean) => - { - console.log('foo'); - }); - - const acquisitionWorker = new DotnetCoreAcquisitionWorker({ storagePath, extensionState: context.globalState, @@ -130,7 +125,8 @@ export function activate(context: vscode.ExtensionContext, extensionContext?: IE installationValidator: new InstallationValidator(eventStream), timeoutValue: resolvedTimeoutSeconds, installDirectoryProvider: new SdkInstallationDirectoryProvider(storagePath), - acquisitionContext : null + acquisitionContext : null, + isExtensionTelemetryInitiallyEnabled : isExtensionTelemetryEnabled }); const versionResolver = new VersionResolver(context.globalState, eventStream, resolvedTimeoutSeconds); diff --git a/vscode-dotnet-sdk-extension/src/test/functional/DotnetCoreAcquisitionExtension.test.ts b/vscode-dotnet-sdk-extension/src/test/functional/DotnetCoreAcquisitionExtension.test.ts index 9f67aa4b..2f513db9 100644 --- a/vscode-dotnet-sdk-extension/src/test/functional/DotnetCoreAcquisitionExtension.test.ts +++ b/vscode-dotnet-sdk-extension/src/test/functional/DotnetCoreAcquisitionExtension.test.ts @@ -153,6 +153,7 @@ suite('DotnetCoreAcquisitionExtension End to End', function() installationValidator: new MockInstallationValidator(eventStream), timeoutValue: 10, installDirectoryProvider, + isExtensionTelemetryInitiallyEnabled: true }); const version = currentSDKVersion; @@ -202,6 +203,7 @@ suite('DotnetCoreAcquisitionExtension End to End', function() installationValidator: new MockInstallationValidator(eventStream), timeoutValue: 10, installDirectoryProvider, + isExtensionTelemetryInitiallyEnabled: true, }); const version = currentSDKVersion;