Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions NVUpdateManager.Core/DriverManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.IO;
using System.Linq;
using System.Management;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using NVUpdateManager.Core.Data;
Expand All @@ -12,11 +11,17 @@ namespace NVUpdateManager.Core
{
internal sealed class DriverManager : IDriverManager
{
private readonly HttpClient _httpClient;
public DriverManager(HttpClient httpClient)
{
_httpClient = httpClient;
}

public Task<UpdateResult> InstallUpdate(string downloadLink)
{
return Task.Run(async () =>
{
var updatePath = await DownloadDriver(downloadLink);
var updatePath = await DownloadDriverAsync(downloadLink);
var extractedUpdatePath = ExtractUpdate(updatePath);
return UpdateResult.Success;
});
Expand Down Expand Up @@ -59,13 +64,13 @@ private string ExtractUpdate(string updatePath)
throw new NotImplementedException();
}

private async Task<string> DownloadDriver(string downloadLink)
private async Task<string> DownloadDriverAsync(string downloadLink)
{
var downloadPath = Path.GetRandomFileName();

using (var client = new HttpClient())

using (var response = await _httpClient.GetAsync(downloadPath))
{
var response = await client.GetAsync(downloadPath);
response.EnsureSuccessStatusCode();

var bytes = await response.Content.ReadAsByteArrayAsync();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public static class ServiceCollectionExtensions
{
public static IServiceCollection AddDriverManager(this IServiceCollection services)
{
services.AddHttpClient<IDriverManager, DriverManager>();
services.TryAddSingleton<IDriverManager, DriverManager>();
return services;
}
Expand Down
1 change: 1 addition & 0 deletions NVUpdateManager.Core/NVUpdateManager.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="9.0.1" />
<PackageReference Include="Microsoft.Extensions.Http" Version="9.0.1" />
<PackageReference Include="Microsoft.Windows.Compatibility" Version="9.0.1" />
</ItemGroup>
</Project>
8 changes: 1 addition & 7 deletions NVUpdateManager.NotificationService/INotificationService.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NVUpdateManager.NotificationService
namespace NVUpdateManager.NotificationService
{
internal interface INotificationService
{
Expand Down
7 changes: 2 additions & 5 deletions NVUpdateManager.Web/Extensions/ServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using NVUpdateManager.Core.Interfaces;
using System.Net.Http;

namespace NVUpdateManager.Web.Extensions
{
public static class ServiceCollectionExtensions
{
public static IServiceCollection AddUpdateFinder(this IServiceCollection services)
{
var client = new HttpClient();

services.TryAddSingleton<IUpdateFinder>(new UpdateFinder(client));

services.AddHttpClient<IUpdateFinder, UpdateFinder>();
services.TryAddSingleton<IUpdateFinder, UpdateFinder>();
return services;
}
}
Expand Down
1 change: 1 addition & 0 deletions NVUpdateManager.Web/NVUpdateManager.Web.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="AngleSharp" Version="1.2.0" />
<PackageReference Include="Microsoft.Extensions.Http" Version="9.0.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\NVUpdateManager.Core\NVUpdateManager.Core.csproj" />
Expand Down
2 changes: 1 addition & 1 deletion NVUpdateManager.Web/UpdateFinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace NVUpdateManager.Web
{
public class UpdateFinder : IUpdateFinder
internal sealed class UpdateFinder : IUpdateFinder
{
private readonly HttpClient _httpClient;

Expand Down