Skip to content

Commit 656468c

Browse files
authored
chore: Clean up redundant code and align model signatures (#417)
* chore: remove empty ClientCore dir, align DownloadResult with plan - Delete empty GeneralUpdate.ClientCore directory (bin/obj artifacts only) - DownloadResult.Url replaced with DownloadResult.Asset (full DownloadAsset) - IDownloadExecutor.ExecuteAsync now accepts DownloadAsset instead of string url Closes #411 * fix: update test stubs and model constructors for DownloadResult.Asset
1 parent 2bfdf3b commit 656468c

8 files changed

Lines changed: 21 additions & 19 deletions

File tree

src/c#/GeneralUpdate.Core/Download/Abstractions/IDownloadExecutor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace GeneralUpdate.Core.Download.Abstractions;
99
public interface IDownloadExecutor
1010
{
1111
Task<DownloadResult> ExecuteAsync(
12-
string url, string destPath,
12+
DownloadAsset asset, string destPath,
1313
IProgress<DownloadProgress>? progress = null,
1414
CancellationToken token = default);
1515
}

src/c#/GeneralUpdate.Core/Download/Executors/HttpDownloadExecutor.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public HttpDownloadExecutor(HttpClient client, TimeSpan? timeout = null, bool en
2626
}
2727

2828
public async Task<DownloadResult> ExecuteAsync(
29-
string url, string destPath,
29+
DownloadAsset asset, string destPath,
3030
IProgress<DownloadProgress>? progress = null,
3131
CancellationToken token = default)
3232
{
@@ -42,7 +42,7 @@ public async Task<DownloadResult> ExecuteAsync(
4242

4343
try
4444
{
45-
using var request = new HttpRequestMessage(HttpMethod.Get, url);
45+
using var request = new HttpRequestMessage(HttpMethod.Get, asset.Url);
4646
if (_enableResume && existingBytes > 0)
4747
request.Headers.Range = new System.Net.Http.Headers.RangeHeaderValue(existingBytes, null);
4848

@@ -74,12 +74,12 @@ public async Task<DownloadResult> ExecuteAsync(
7474
totalBytes > 0 ? totalBytes + existingBytes : null,
7575
100, DownloadStatus.Completed));
7676

77-
return new DownloadResult(url, destPath, downloaded, elapsed, retries, true, null);
77+
return new DownloadResult(asset, destPath, downloaded, elapsed, retries, true, null);
7878
}
7979
catch (Exception ex) when (ex is not OperationCanceledException)
8080
{
8181
sw.Stop();
82-
return new DownloadResult(url, null, existingBytes, sw.Elapsed, retries, false, ex.Message);
82+
return new DownloadResult(asset, null, existingBytes, sw.Elapsed, retries, false, ex.Message);
8383
}
8484
}
8585

src/c#/GeneralUpdate.Core/Download/Executors/OssDownloadExecutor.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ public OssDownloadExecutor(HttpClient client)
1717
=> _client = client ?? throw new ArgumentNullException(nameof(client));
1818

1919
public async Task<DownloadResult> ExecuteAsync(
20-
string url, string destPath,
20+
DownloadAsset asset, string destPath,
2121
IProgress<DownloadProgress>? progress = null,
2222
CancellationToken token = default)
2323
{
2424
var sw = System.Diagnostics.Stopwatch.StartNew();
2525
try
2626
{
27-
using var response = await _client.GetAsync(url, HttpCompletionOption.ResponseHeadersRead, token)
27+
using var response = await _client.GetAsync(asset.Url, HttpCompletionOption.ResponseHeadersRead, token)
2828
.ConfigureAwait(false);
2929
response.EnsureSuccessStatusCode();
3030
var total = response.Content.Headers.ContentLength ?? -1;
@@ -37,12 +37,12 @@ public async Task<DownloadResult> ExecuteAsync(
3737

3838
progress?.Report(new DownloadProgress(
3939
Path.GetFileName(destPath), downloaded, total > 0 ? total : null, 100, DownloadStatus.Completed));
40-
return new DownloadResult(url, destPath, downloaded, elapsed, 0, true, null);
40+
return new DownloadResult(asset, destPath, downloaded, elapsed, 0, true, null);
4141
}
4242
catch (Exception ex) when (ex is not OperationCanceledException)
4343
{
4444
sw.Stop();
45-
return new DownloadResult(url, null, 0, sw.Elapsed, 0, false, ex.Message);
45+
return new DownloadResult(asset, null, 0, sw.Elapsed, 0, false, ex.Message);
4646
}
4747
}
4848
}

src/c#/GeneralUpdate.Core/Download/Models/DownloadProgress.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ DownloadStatus Status
1515
);
1616

1717
public record DownloadResult(
18-
string? Url,
18+
DownloadAsset Asset,
1919
string? LocalPath,
2020
long DownloadedBytes,
2121
TimeSpan Duration,

src/c#/GeneralUpdate.Core/Download/Orchestrators/DefaultDownloadOrchestrator.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public async Task<DownloadReport> ExecuteAsync(
8080
{
8181
// Download
8282
var downloadResult = await executor.ExecuteAsync(
83-
asset.Url, destPath,
83+
asset, destPath,
8484
progress != null ? new AssetProgressReporter(progress, asset.Name) : null,
8585
ct).ConfigureAwait(false);
8686

@@ -100,7 +100,7 @@ public async Task<DownloadReport> ExecuteAsync(
100100
}
101101
catch (Exception ex)
102102
{
103-
return new DownloadResult(asset.Url, destPath,
103+
return new DownloadResult(asset, destPath,
104104
downloadResult.DownloadedBytes, downloadResult.Duration,
105105
downloadResult.RetryCount, false, $"SHA256 verification failed: {ex.Message}");
106106
}
@@ -122,7 +122,7 @@ public async Task<DownloadReport> ExecuteAsync(
122122

123123
// Dispatch all-completed event ONCE after all assets finish (only failed results)
124124
var failedDetails = results.Where(r => !r.Success)
125-
.Select(r => ((object)r.Url, r.ErrorMessage ?? "failed")).ToList();
125+
.Select(r => ((object)r.Asset.Url, r.ErrorMessage ?? "failed")).ToList();
126126
DownloadProgressReporter.DispatchAllCompleted(
127127
this,
128128
results.All(r => r.Success),

tests/CoreTest/Bootstrap/BootstrapFullParameterMatrixTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,9 @@ private sealed class StubDownloadPolicy : GeneralUpdate.Core.Download.Abstractio
129129

130130
private sealed class StubDownloadExecutor : GeneralUpdate.Core.Download.Abstractions.IDownloadExecutor
131131
{
132-
public Task<GeneralUpdate.Core.Download.Models.DownloadResult> ExecuteAsync(string url, string destPath,
132+
public Task<GeneralUpdate.Core.Download.Models.DownloadResult> ExecuteAsync(GeneralUpdate.Core.Download.Models.DownloadAsset asset, string destPath,
133133
IProgress<GeneralUpdate.Core.Download.Models.DownloadProgress>? progress = null, CancellationToken token = default)
134-
=> Task.FromResult(new GeneralUpdate.Core.Download.Models.DownloadResult(url, destPath, 0, TimeSpan.Zero, 0, true, null));
134+
=> Task.FromResult(new GeneralUpdate.Core.Download.Models.DownloadResult(asset, destPath, 0, TimeSpan.Zero, 0, true, null));
135135
}
136136

137137
private sealed class StubDownloadSource : GeneralUpdate.Core.Download.Abstractions.IDownloadSource

tests/CoreTest/Configuration/ConfigurationModelsTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ public void DownloadProgress_Failed()
219219
public void DownloadResult_Success()
220220
{
221221
var result = new DownloadResult(
222-
"https://cdn.example.com/update.zip",
222+
null!,
223223
"/tmp/update.zip",
224224
50L * 1024 * 1024,
225225
TimeSpan.FromSeconds(30),
@@ -236,7 +236,7 @@ public void DownloadResult_Success()
236236
public void DownloadResult_FailureWithRetries()
237237
{
238238
var result = new DownloadResult(
239-
"https://cdn.example.com/update.zip",
239+
null!,
240240
null,
241241
0,
242242
TimeSpan.FromSeconds(15),

tests/CoreTest/Download/OrchestratorOptionsBehaviourTests.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,8 +263,9 @@ public async Task HttpDownloadExecutor_EnableResumeFalse_DeletesExistingFile()
263263

264264
try
265265
{
266+
var asset = new DownloadAsset("file.bin", "http://example.com/file.bin", 0, null, "1.0.0");
266267
var result = await executor.ExecuteAsync(
267-
"http://example.com/file.bin", destPath, token: CancellationToken.None);
268+
asset, destPath, token: CancellationToken.None);
268269
Assert.True(result.Success, $"Download should succeed, error: {result.ErrorMessage}");
269270
Assert.True(File.Exists(destPath));
270271
}
@@ -308,8 +309,9 @@ public async Task HttpDownloadExecutor_WithRangeResponse_AppendsCorrectly()
308309

309310
try
310311
{
312+
var asset = new DownloadAsset("file.bin", "http://example.com/file.bin", 0, null, "1.0.0");
311313
var result = await executor.ExecuteAsync(
312-
"http://example.com/file.bin", destPath, token: CancellationToken.None);
314+
asset, destPath, token: CancellationToken.None);
313315
Assert.True(result.Success);
314316
// Partial content (30 bytes) appended to existing (20 bytes) = 50 total
315317
var fileInfo = new FileInfo(destPath);

0 commit comments

Comments
 (0)