commonProperties.ts 2.8 KB
Newer Older
E
Erich Gamma 已提交
1 2 3 4 5
/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/

6 7
import * as Platform from 'vs/base/common/platform';
import * as os from 'os';
8
import { TPromise } from 'vs/base/common/winjs.base';
9
import * as uuid from 'vs/base/common/uuid';
10

11
export function resolveCommonProperties(commit: string, version: string, source: string, machineId: string): TPromise<{ [name: string]: string; }> {
12
	const result: { [name: string]: string; } = Object.create(null);
13
	// __GDPR__COMMON__ "common.machineId" : { "classification": "EndUserPseudonymizedInformation", "purpose": "FeatureInsight" }
14
	result['common.machineId'] = machineId;
15
	// __GDPR__COMMON__ "sessionID" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
16
	result['sessionID'] = uuid.generateUuid() + Date.now();
17
	// __GDPR__COMMON__ "commitHash" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
18
	result['commitHash'] = commit;
19
	// __GDPR__COMMON__ "version" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
20
	result['version'] = version;
21
	// __GDPR__COMMON__ "common.osVersion" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
22
	result['common.osVersion'] = os.release();
K
kieferrm 已提交
23
	// __GDPR__COMMON__ "common.platform" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
24
	result['common.platform'] = Platform.Platform[Platform.platform];
25
	// __GDPR__COMMON__ "common.nodePlatform" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
26
	result['common.nodePlatform'] = process.platform;
27
	// __GDPR__COMMON__ "common.nodeArch" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
28
	result['common.nodeArch'] = process.arch;
29
	// __GDPR__COMMON__ "common.source" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
30
	result['common.source'] = source;
31

32 33 34 35
	// dynamic properties which value differs on each call
	let seq = 0;
	const startTime = Date.now();
	Object.defineProperties(result, {
36
		// __GDPR__COMMON__ "timestamp" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
37 38 39 40
		'timestamp': {
			get: () => new Date(),
			enumerable: true
		},
41
		// __GDPR__COMMON__ "common.timesincesessionstart" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
42 43 44 45
		'common.timesincesessionstart': {
			get: () => Date.now() - startTime,
			enumerable: true
		},
46
		// __GDPR__COMMON__ "common.sequence" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
47 48 49 50 51 52
		'common.sequence': {
			get: () => seq++,
			enumerable: true
		}
	});

53
	return TPromise.as(result);
54
}