33// See LICENSE file in the project root for full license information.
44//
55
6+ using Microsoft . ApplicationInsights ;
7+ using Microsoft . ApplicationInsights . DataContracts ;
8+ using Microsoft . Extensions . Configuration ;
69using nanoFramework . Tools . Debugger ;
7- using nanoFramework . Tools . FirmwareFlasher ;
810using Newtonsoft . Json ;
911using System ;
1012using System . Collections . Generic ;
1113using System . IO ;
1214using System . IO . Compression ;
1315using System . Linq ;
1416using System . Net . Http ;
17+ using System . Reflection ;
1518using System . Text . RegularExpressions ;
1619using System . Threading . Tasks ;
17- using Microsoft . ApplicationInsights ;
18- using Microsoft . ApplicationInsights . DataContracts ;
19- using Microsoft . Extensions . Configuration ;
20- using Microsoft . Extensions . Configuration . Json ;
21- using System . Reflection ;
2220
2321namespace nanoFramework . Tools . FirmwareFlasher
2422{
@@ -36,11 +34,8 @@ public abstract class FirmwarePackage : IDisposable
3634
3735 private readonly string _targetName ;
3836 private readonly bool _preview ;
39-
4037 private const string _readmeContent = "This folder contains nanoFramework firmware files. Can safely be removed." ;
4138
42- private static IConfigurationRoot _configuration ;
43-
4439 /// <summary>
4540 /// Path with the base location for firmware packages.
4641 /// </summary>
@@ -113,16 +108,6 @@ static FirmwarePackage()
113108 BaseAddress = new Uri ( "https://api.cloudsmith.io/v1/packages/net-nanoframework/" )
114109 } ;
115110 _cloudsmithClient . DefaultRequestHeaders . Add ( "Accept" , "*/*" ) ;
116-
117- if ( _configuration == null )
118- {
119-
120- var builder = new ConfigurationBuilder ( )
121- . SetBasePath ( Directory . GetCurrentDirectory ( ) )
122- . AddJsonFile ( "appsettings.json" ) ;
123-
124- _configuration = builder . Build ( ) ;
125- }
126111 }
127112
128113 /// <summary>
@@ -361,19 +346,11 @@ internal async Task<ExitCodes> DownloadAndExtractAsync()
361346 Console . ForegroundColor = ConsoleColor . White ;
362347 }
363348
364- //send app insight on successful download
365-
366- string insightConnectionString = _configuration [ "iConnectionString" ] ;
367- string optOut = Environment . GetEnvironmentVariable ( "NANOFRAMEWORK_TELEMETRY_OPTOUT" ) ;
368-
369349 stepSuccessful = true ;
370350
371- if ( ! string . IsNullOrEmpty ( insightConnectionString ) && optOut != "1" )
351+ // send telemetry data on successful download
352+ if ( NanoTelemetryClient . TelemetryClient is not null )
372353 {
373- TelemetryClient telemetryClient = new TelemetryClient ( new Microsoft . ApplicationInsights . Extensibility . TelemetryConfiguration ( )
374- {
375- ConnectionString = insightConnectionString
376- } ) ;
377354 AssemblyInformationalVersionAttribute nanoffVersion = null ;
378355
379356 try
@@ -385,18 +362,17 @@ internal async Task<ExitCodes> DownloadAndExtractAsync()
385362 }
386363 catch
387364 {
388-
365+ // OK to fail here, just telemetry
389366 }
367+
390368 var packageTelemetry = new EventTelemetry ( "PackageDownloaded" ) ;
391369 packageTelemetry . Properties . Add ( "TargetName" , _targetName ) ;
392370 packageTelemetry . Properties . Add ( "Version" , Version ) ;
393371 packageTelemetry . Properties . Add ( "nanoffVersion" , nanoffVersion == null ? "unknown" : nanoffVersion . InformationalVersion ) ;
394- telemetryClient . TrackEvent ( packageTelemetry ) ;
395- telemetryClient . Flush ( ) ;
396372
373+ NanoTelemetryClient . TelemetryClient . TrackEvent ( packageTelemetry ) ;
374+ NanoTelemetryClient . TelemetryClient . Flush ( ) ;
397375 }
398-
399-
400376 }
401377 catch
402378 {
0 commit comments