Skip to content

Commit 4bb0969

Browse files
committed
feat: The OSS update to the start function adds pre - and post-processing custom function injections
1 parent 06f54d4 commit 4bb0969

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

src/c#/GeneralUpdate.Common/Shared/Object/GlobalConfigInfoOSS.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ public class GlobalConfigInfoOSS
2020
[JsonPropertyName("Encoding")]
2121
public string Encoding { get; set; }
2222

23+
[JsonPropertyName("Extend")]
24+
public string Extend { get; set; }
25+
26+
[JsonPropertyName("Extend2")]
27+
public string Extend2 { get; set; }
28+
2329
public GlobalConfigInfoOSS()
2430
{
2531
}

src/c#/GeneralUpdate.Core/GeneralUpdateOSS.cs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,30 @@ namespace GeneralUpdate.Core
1111
{
1212
public sealed class GeneralUpdateOSS
1313
{
14+
private static Func<string, bool>? _beforeFunc;
15+
private static Action<string>? _afterFunc;
16+
1417
private GeneralUpdateOSS() { }
1518

1619
#region Public Methods
1720

21+
/// <summary>
22+
/// Starting an OSS update for windows,Linux,mac platform.
23+
/// </summary>
24+
/// <param name="beforeFunc">Inject a custom pre-processing method, which will be executed before updating. whose parameters use the Extend.</param>
25+
/// <param name="afterFunc">Injects a post-processing method whose parameters use the Extend2</param>
26+
public static async Task Start(Func<string, bool> beforeFunc, Action<string> afterFunc)
27+
{
28+
_beforeFunc = beforeFunc;
29+
_afterFunc = afterFunc;
30+
await BaseStart();
31+
}
32+
1833
/// <summary>
1934
/// Starting an OSS update for windows,Linux,mac platform.
2035
/// </summary>
2136
/// <returns></returns>
22-
public static async Task Start()=> await BaseStart();
37+
public static async Task Start() => await BaseStart();
2338

2439
#endregion Public Methods
2540

@@ -37,9 +52,17 @@ private static async Task BaseStart()
3752
return;
3853

3954
var parameter = JsonSerializer.Deserialize<GlobalConfigInfoOSS>(json, GlobalConfigInfoOSSJsonContext.Default.GlobalConfigInfoOSS);
55+
var result = _beforeFunc?.Invoke(parameter?.Extend);
56+
if (_beforeFunc is not null)
57+
{
58+
if (result == false)
59+
return;
60+
}
61+
4062
var strategy = new OSSStrategy();
4163
strategy.Create(parameter);
4264
await strategy.ExecuteAsync();
65+
_afterFunc?.Invoke(parameter?.Extend2);
4366
}
4467
catch (Exception exception)
4568
{

0 commit comments

Comments
 (0)