-
Notifications
You must be signed in to change notification settings - Fork 74
Expand file tree
/
Copy pathUpgradeUpdateStrategy.cs
More file actions
95 lines (81 loc) · 3 KB
/
Copy pathUpgradeUpdateStrategy.cs
File metadata and controls
95 lines (81 loc) · 3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
using System;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using GeneralUpdate.Core.Configuration;
using GeneralUpdate.Core.Event;
namespace GeneralUpdate.Core.Strategy;
/// <summary>
/// Upgrade-side update strategy. Receives process info from the client side,
/// applies updates via the pipeline, and starts the main application.
/// </summary>
/// <remarks>
/// This is the AppType.UpgradeApp role strategy. It composes an OS-specific
/// strategy for platform operations (Windows/Linux/Mac).
///
/// <b>Design:</b> Upgrade does NOT validate versions or download packages.
/// The client has already validated versions, downloaded all packages, and
/// passed the results via ProcessInfo. Upgrade only applies updates and
/// starts the main application — zero network.
/// </remarks>
public class UpgradeUpdateStrategy : IStrategy
{
private GlobalConfigInfo? _configInfo;
private IStrategy? _osStrategy;
public void Create(GlobalConfigInfo parameter)
{
_configInfo = parameter ?? throw new ArgumentNullException(nameof(parameter));
_osStrategy = ResolveOsStrategy();
}
public async Task ExecuteAsync()
{
if (_configInfo == null) throw new InvalidOperationException("UpgradeUpdateStrategy not configured.");
try
{
GeneralTracer.Debug("UpgradeUpdateStrategy.ExecuteAsync start.");
ApplyRuntimeOptions();
_osStrategy!.Create(_configInfo);
// Apply updates via OS-specific pipeline (Hash → Compress → Patch)
if (_configInfo.UpdateVersions?.Count > 0)
{
GeneralTracer.Info($"UpgradeUpdateStrategy: applying {_configInfo.UpdateVersions.Count} update(s).");
await _osStrategy.ExecuteAsync();
}
else
{
GeneralTracer.Info("UpgradeUpdateStrategy: no updates to apply, starting application directly.");
}
_osStrategy.StartApp();
}
catch (Exception ex)
{
GeneralTracer.Error("UpgradeUpdateStrategy.ExecuteAsync failed.", ex);
EventManager.Instance.Dispatch(this, new ExceptionEventArgs(ex, ex.Message));
}
}
public void Execute()
{
ExecuteAsync().GetAwaiter().GetResult();
}
public void StartApp()
{
_osStrategy?.StartApp();
}
#region Helpers
private static IStrategy ResolveOsStrategy()
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
return new WindowsStrategy();
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
return new LinuxStrategy();
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
return new MacStrategy();
throw new PlatformNotSupportedException("The current operating system is not supported!");
}
private void ApplyRuntimeOptions()
{
_configInfo!.Encoding = Encoding.UTF8;
_configInfo.Format = Format.ZIP;
}
#endregion
}