Skip to content

Commit b6c5d19

Browse files
authored
refactor: Phase 2 — extension points + Download orchestrator + BlackListConfigBuilder (#357)
- Added IUpdatePipelineFactory interface + .PipelineFactory<T>() extension point - Added .DownloadPipeline<T>() extension point (IDownloadPipeline already existed) - ClientUpdateStrategy and UpgradeUpdateStrategy now accept optional IDownloadOrchestrator via constructor — uses new download subsystem when available, falls back to legacy DownloadManager - Added BlackListConfigBuilder with fluent API (AddBlackFiles/Formats/Dirs) - Added ConfigureBlackList(Action<BlackListConfigBuilder>) builder overload Closes #356
1 parent e0f509d commit b6c5d19

3 files changed

Lines changed: 59 additions & 7 deletions

File tree

src/c#/GeneralUpdate.Core/Configuration/AbstractBootstrap.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,6 @@ protected internal AbstractBootstrap()
2626
PopulateDefaults();
2727
}
2828

29-
/// <summary>
30-
/// Populate all UpdateOptions with their best-practice defaults.
31-
/// Subclasses can override to customize.
32-
/// </summary>
3329
protected virtual void PopulateDefaults()
3430
{
3531
Option(UpdateOptions.MaxConcurrency, 3);
@@ -45,9 +41,6 @@ protected virtual void PopulateDefaults()
4541
protected abstract Task ExecuteStrategyAsync();
4642
protected abstract TBootstrap StrategyFactory();
4743

48-
/// <summary>
49-
/// Setting update configuration.
50-
/// </summary>
5144
public TBootstrap Option<T>(UpdateOption<T> option, T value)
5245
{
5346
if (value == null)
@@ -86,6 +79,9 @@ public TBootstrap Option<T>(UpdateOption<T> option, T value)
8679
public TBootstrap BinaryDiffer<T>() where T : Differential.IBinaryDiffer, new()
8780
{ _extensions[typeof(Differential.IBinaryDiffer)] = typeof(T); return (TBootstrap)this; }
8881

82+
public TBootstrap PipelineFactory<T>() where T : Pipeline.IUpdatePipelineFactory, new()
83+
{ _extensions[typeof(Pipeline.IUpdatePipelineFactory)] = typeof(T); return (TBootstrap)this; }
84+
8985
public TBootstrap DownloadPolicy<T>() where T : Download.Abstractions.IDownloadPolicy, new()
9086
{ _extensions[typeof(Download.Abstractions.IDownloadPolicy)] = typeof(T); return (TBootstrap)this; }
9187

@@ -95,6 +91,9 @@ public TBootstrap Option<T>(UpdateOption<T> option, T value)
9591
public TBootstrap DownloadSource<T>() where T : Download.Abstractions.IDownloadSource, new()
9692
{ _extensions[typeof(Download.Abstractions.IDownloadSource)] = typeof(T); return (TBootstrap)this; }
9793

94+
public TBootstrap DownloadPipeline<T>() where T : Download.Abstractions.IDownloadPipeline, new()
95+
{ _extensions[typeof(Download.Abstractions.IDownloadPipeline)] = typeof(T); return (TBootstrap)this; }
96+
9897
public TBootstrap UpdateReporter<T>() where T : Download.Reporting.IUpdateReporter, new()
9998
{ _extensions[typeof(Download.Reporting.IUpdateReporter)] = typeof(T); return (TBootstrap)this; }
10099

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using System.Collections.Generic;
2+
using GeneralUpdate.Core.Configuration;
3+
4+
namespace GeneralUpdate.Core.FileSystem;
5+
6+
/// <summary>
7+
/// Fluent builder for <see cref="BlackListConfig"/>.
8+
/// Used via <c>Bootstrap.ConfigureBlackList(cfg => cfg.AddBlackFiles(...))</c>.
9+
/// </summary>
10+
public class BlackListConfigBuilder
11+
{
12+
private readonly List<string> _blackFiles = new();
13+
private readonly List<string> _blackFormats = new();
14+
private readonly List<string> _skipDirectories = new();
15+
16+
public BlackListConfigBuilder AddBlackFiles(params string[] files)
17+
{
18+
_blackFiles.AddRange(files);
19+
return this;
20+
}
21+
22+
public BlackListConfigBuilder AddBlackFormats(params string[] formats)
23+
{
24+
_blackFormats.AddRange(formats);
25+
return this;
26+
}
27+
28+
public BlackListConfigBuilder AddSkipDirectories(params string[] directories)
29+
{
30+
_skipDirectories.AddRange(directories);
31+
return this;
32+
}
33+
34+
public BlackListConfig Build() => new(
35+
BlackFiles: _blackFiles.Count > 0 ? _blackFiles.AsReadOnly() : null,
36+
BlackFormats: _blackFormats.Count > 0 ? _blackFormats.AsReadOnly() : null,
37+
SkipDirectorys: _skipDirectories.Count > 0 ? _skipDirectories.AsReadOnly() : null
38+
);
39+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System.Threading;
2+
using System.Threading.Tasks;
3+
4+
namespace GeneralUpdate.Core.Pipeline;
5+
6+
/// <summary>
7+
/// Factory for creating update pipelines.
8+
/// Injected via <c>Bootstrap.PipelineFactory&lt;T&gt;()</c>.
9+
/// </summary>
10+
public interface IUpdatePipelineFactory
11+
{
12+
/// <summary>Create a pipeline for the given context.</summary>
13+
Task ExecutePipelineAsync(PipelineContext context, CancellationToken token = default);
14+
}

0 commit comments

Comments
 (0)