@@ -4,12 +4,18 @@ namespace Snyk.VisualStudio.Extension.Shared.Service
44{
55 using System ;
66 using System . IO ;
7+ using System . Linq ;
8+ using System . Reflection ;
79 using System . Threading ;
810 using System . Threading . Tasks ;
11+ using System . Xml ;
12+ using System . Xml . Linq ;
913 using EnvDTE ;
1014 using EnvDTE80 ;
1115 using Microsoft . VisualStudio . Settings ;
16+ using Microsoft . VisualStudio . Shell . Interop ;
1217 using Microsoft . VisualStudio . Shell . Settings ;
18+ using Newtonsoft . Json . Linq ;
1319 using Serilog ;
1420 using Snyk . Analytics ;
1521 using Snyk . Code . Library . Service ;
@@ -34,7 +40,7 @@ public class SnykService : ISnykServiceProvider, ISnykService
3440 private static readonly ILogger Logger = LogManager . ForContext < SnykService > ( ) ;
3541
3642 private readonly IAsyncServiceProvider serviceProvider ;
37-
43+ private readonly string vsVersion ;
3844 private SettingsManager settingsManager ;
3945
4046 private SnykVsThemeService vsThemeService ;
@@ -61,7 +67,12 @@ public class SnykService : ISnykServiceProvider, ISnykService
6167 /// Initializes a new instance of the <see cref="SnykService"/> class.
6268 /// </summary>
6369 /// <param name="serviceProvider">Snyk service provider implementation.</param>
64- public SnykService ( IAsyncServiceProvider serviceProvider ) => this . serviceProvider = serviceProvider ;
70+ /// <param name="vsVersion">The version of the IDE</param>
71+ public SnykService ( IAsyncServiceProvider serviceProvider , string vsVersion = "" )
72+ {
73+ this . serviceProvider = serviceProvider ;
74+ this . vsVersion = vsVersion ;
75+ }
6576
6677 /// <summary>
6778 /// Gets Snyk options implementation.
@@ -172,7 +183,7 @@ public ISnykApiService ApiService
172183 {
173184 if ( this . apiService == null )
174185 {
175- this . apiService = new SnykApiService ( this . Options ) ;
186+ this . apiService = new SnykApiService ( this . Options , this . vsVersion , SnykExtension . Version ) ;
176187
177188 this . Options . SettingsChanged += this . OnSettingsChanged ;
178189 }
@@ -221,13 +232,6 @@ public ISentryService SentryService
221232 /// <returns>Result VS service instance</returns>
222233 public async Task < object > GetServiceAsync ( Type serviceType ) => await this . serviceProvider . GetServiceAsync ( serviceType ) ;
223234
224- /// <summary>
225- /// Get Visual Studio service by type (not async method).
226- /// </summary>
227- /// <param name="serviceType">Needed service type.</param>
228- /// <returns>Result VS service instance</returns>
229- public object GetService ( Type serviceType ) => null ;
230-
231235 /// <summary>
232236 /// Initialize service.
233237 /// </summary>
@@ -238,7 +242,7 @@ public async Task InitializeAsync(CancellationToken cancellationToken)
238242 try
239243 {
240244 Logger . Information ( "Initialize Snyk services" ) ;
241-
245+ Logger . Information ( "Plugin version is {Version}" , SnykExtension . Version ) ;
242246 await this . Package . JoinableTaskFactory . SwitchToMainThreadAsync ( cancellationToken ) ;
243247
244248 this . settingsManager = new ShellSettingsManager ( this . Package ) ;
@@ -269,7 +273,7 @@ public async Task InitializeAsync(CancellationToken cancellationToken)
269273 /// Create new instance of SnykCli class with Options and Logger parameters.
270274 /// </summary>
271275 /// <returns>New SnykCli instance.</returns>
272- public ICli NewCli ( ) => new SnykCli ( this . Options ) ;
276+ public ICli NewCli ( ) => new SnykCli ( this . Options , this . vsVersion ) ;
273277
274278 private void OnSettingsChanged ( object sender , SnykSettingsChangedEventArgs e ) => this . SetupSnykCodeService ( ) ;
275279
@@ -278,15 +282,17 @@ private void SetupSnykCodeService()
278282 try
279283 {
280284 var options = this . Options ;
281-
282285 string endpoint = new ApiEndpointResolver ( this . Options ) . GetSnykCodeApiUrl ( ) ;
286+ var httpClient = HttpClientFactory . NewHttpClient ( options . ApiToken , endpoint )
287+ . WithUserAgent ( this . vsVersion , SnykExtension . Version ) ;
283288
284289 this . snykCodeService = CodeServiceFactory . CreateSnykCodeService (
285290 options . ApiToken ,
286291 endpoint ,
287292 this . SolutionService . FileProvider ,
288293 SnykExtension . IntegrationName ,
289- options . Organization ?? string . Empty ) ;
294+ options . Organization ?? string . Empty ,
295+ httpClient ) ;
290296
291297 VsStatusBarNotificationService . Instance . InitializeEventListeners ( this . snykCodeService , options ) ;
292298 }
0 commit comments