1+ import * as os from 'os' ;
2+ import { Version } from '../../common/Version' ;
3+ import { GUAService } from './GUAService' ;
4+ import { AnalyticsBaseInfo , OperatingSystem } from './AnalyticsBaseInfo' ;
5+ import { ExtensionVersionInfo } from '../ExtensionVersionInfo' ;
6+ import * as ns from '../NsCliService' ;
7+
8+ export class AnalyticsService {
9+ private static _instance : AnalyticsService ;
10+
11+ private _baseInfo : AnalyticsBaseInfo ;
12+ private _gua : GUAService ;
13+
14+ public static getInstance ( ) : AnalyticsService {
15+ if ( ! this . _instance ) {
16+ this . _instance = new AnalyticsService ( ) ;
17+ }
18+ return this . _instance ;
19+ }
20+
21+ public static generateMachineId ( ) : string {
22+ let machineId = '' ;
23+ try {
24+ let netInterfaces = os . networkInterfaces ( ) ;
25+ Object . keys ( netInterfaces ) . forEach ( interfName => {
26+ netInterfaces [ interfName ] . forEach ( interf => {
27+ if ( ! interf . internal ) {
28+ machineId += `${ interf . mac } -` ;
29+ }
30+ } ) ;
31+ } ) ;
32+ } catch ( e ) { }
33+ return machineId ;
34+ }
35+
36+ constructor ( ) {
37+ let operatingSystem = OperatingSystem . Other ;
38+ switch ( process . platform ) {
39+ case 'win32' : { operatingSystem = OperatingSystem . Windows ; break ; }
40+ case 'darwin' : { operatingSystem = OperatingSystem . OSX ; break ; }
41+ case 'linux' :
42+ case 'freebsd' : { operatingSystem = OperatingSystem . Linux ; break ; }
43+ } ;
44+
45+ this . _baseInfo = {
46+ cliVersion : Version . stringify ( ns . CliVersionInfo . getInstalledCliVersion ( ) ) ,
47+ extensionVersion : Version . stringify ( ExtensionVersionInfo . getExtensionVersion ( ) ) ,
48+ operatingSystem : operatingSystem ,
49+ userId : AnalyticsService . generateMachineId ( ) ,
50+ hostname : 'ns-vs-extension.org'
51+ } ;
52+
53+ this . _gua = new GUAService ( 'UA-111455-29' , this . _baseInfo ) ;
54+ }
55+
56+ public launchDebugger ( request : string , platform : string , emulator : boolean ) : Promise < any > {
57+ try {
58+ return this . _gua . launchDebugger ( request , platform , emulator ) ;
59+ } catch ( e ) { }
60+ }
61+
62+ public runRunCommand ( platform : string , emulator : boolean ) : Promise < any > {
63+ try {
64+ return this . _gua . runRunCommand ( platform , emulator ) ;
65+ } catch ( e ) { }
66+ }
67+ }
0 commit comments