Skip to content

Commit 92bdf9d

Browse files
committed
OSS AOT适配
1 parent df6e2b9 commit 92bdf9d

File tree

16 files changed

+123
-138
lines changed

16 files changed

+123
-138
lines changed

src/c#/GeneralUpdate.Client/GeneralUpdate.Client.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
<ImplicitUsings>enable</ImplicitUsings>
77
<Nullable>enable</Nullable>
88
<ApplicationManifest></ApplicationManifest>
9+
<PublishAot>true</PublishAot>
10+
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
911
</PropertyGroup>
1012

1113
<ItemGroup>

src/c#/GeneralUpdate.Client/Program.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
namespace GeneralUpdate.Client
1010
{
11-
internal class Progra
11+
internal class Program
1212
{
1313
private static void Main(string[] args)
1414
{
@@ -67,8 +67,14 @@ private static void Main(string[] args)
6767
.Option(UpdateOption.Format, Format.ZIP)
6868
.LaunchAsync();
6969
});*/
70-
71-
GeneralClientOSS.Start(new ParamsOSS("http://192.168.50.203/versions.json", "GeneralUpdate.Client.exe","1.0.0.0", "versions.json"));
70+
71+
var paramsOSS = new GlobalConfigInfoOSS();
72+
paramsOSS.Url = "http://192.168.50.203/versions.json";
73+
paramsOSS.CurrentVersion = "1.0.0.0";
74+
paramsOSS.VersionFileName = "versions.json";
75+
paramsOSS.AppName = "GeneralUpdate.Client.exe";
76+
paramsOSS.Encoding = Encoding.UTF8.WebName;
77+
GeneralClientOSS.Start(paramsOSS);
7278

7379
Console.Read();
7480
}
@@ -85,8 +91,7 @@ private static void OnMultiAllDownloadCompleted(object arg1, MultiAllDownloadCom
8591

8692
private static void OnMultiDownloadCompleted(object arg1, MultiDownloadCompletedEventArgs arg2)
8793
{
88-
var v = arg2.Version as VersionInfo;
89-
Debug.WriteLine(v.Version);
94+
var v = arg2.Version;
9095
}
9196

9297
private static void OnMultiDownloadStatistics(object arg1, MultiDownloadStatisticsEventArgs arg2)

src/c#/GeneralUpdate.ClientCore/GeneralClientOSS.cs

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,38 +23,37 @@ private GeneralClientOSS() { }
2323
/// <summary>
2424
/// Starting an OSS update for windows platform.
2525
/// </summary>
26-
public static async Task Start(ParamsOSS configParams, string upgradeAppName = "GeneralUpdate.Upgrade.exe")
26+
public static async Task Start(GlobalConfigInfoOSS configGlobalConfigInfo, string upgradeAppName = "GeneralUpdate.Upgrade.exe")
2727
{
2828
await Task.Run(() =>
2929
{
3030
try
3131
{
3232
var basePath = Thread.GetDomain().BaseDirectory;
3333
//Download the version information file from OSS to be updated.(JSON)
34-
var versionsFilePath = Path.Combine(basePath, configParams.VersionFileName);
35-
DownloadFile(configParams.Url, versionsFilePath);
34+
var versionsFilePath = Path.Combine(basePath, configGlobalConfigInfo.VersionFileName);
35+
DownloadFile(configGlobalConfigInfo.Url, versionsFilePath);
3636
if (!File.Exists(versionsFilePath)) return;
37-
var versions = GeneralFileManager.GetJson<List<VersionPO>>(versionsFilePath);
37+
var versions = GeneralFileManager.GetJson<List<VersionOSS>>(versionsFilePath);
3838
if (versions == null || versions.Count == 0) return;
3939
versions = versions.OrderByDescending(x => x.PubTime).ToList();
4040
var newVersion = versions.First();
4141
//Determine whether the current client version needs to be upgraded.
42-
if (!IsUpgrade(configParams.CurrentVersion, newVersion.Version))
42+
if (!IsUpgrade(configGlobalConfigInfo.CurrentVersion, newVersion.Version))
4343
return;
4444

45-
var json = JsonSerializer.Serialize(configParams);
46-
Environment.SetEnvironmentVariable("ParamsOSS", json, EnvironmentVariableTarget.User);
47-
4845
//If you confirm that an update is required, start the upgrade application.
4946
var appPath = Path.Combine(basePath, $"{upgradeAppName}");
5047
if (!File.Exists(appPath))
5148
throw new Exception($"The application does not exist {upgradeAppName} !");
5249

50+
var json = JsonSerializer.Serialize(configGlobalConfigInfo);
51+
Environment.SetEnvironmentVariable("GlobalConfigInfoOSS", json, EnvironmentVariableTarget.User);
5352
Process.Start(appPath);
5453
}
5554
catch (Exception ex)
5655
{
57-
EventManager.Instance.Dispatch(new GeneralClientOSS(), new ExceptionEventArgs(ex));
56+
throw new Exception(ex.Message + "\n" + ex.StackTrace);
5857
}
5958
finally
6059
{
@@ -86,13 +85,4 @@ private static void DownloadFile(string url, string path)
8685
using var webClient = new WebClient();
8786
webClient.DownloadFile(new Uri(url), path);
8887
}
89-
90-
public static void AddListenerException(Action<object, ExceptionEventArgs> callbackAction)
91-
=> AddListener(callbackAction);
92-
93-
private static void AddListener<TArgs>(Action<object, TArgs> callbackAction) where TArgs : EventArgs
94-
{
95-
Debug.Assert(callbackAction != null);
96-
EventManager.Instance.AddListener(callbackAction);
97-
}
9888
}

src/c#/GeneralUpdate.ClientCore/GeneralUpdate.ClientCore.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
</PropertyGroup>
1919

2020
<ItemGroup>
21-
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="9.0.0-rc.1.24452.1"/>
22-
<PackageReference Include="System.Collections.Immutable" Version="9.0.0-rc.1.24431.7"/>
21+
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="9.0.0"/>
22+
<PackageReference Include="System.Collections.Immutable" Version="9.0.0"/>
2323
<PackageReference Include="System.Net.Requests" Version="4.3.0"/>
2424
</ItemGroup>
2525

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
using System.Text.Json.Serialization;
2+
using GeneralUpdate.Common.Shared.Object;
3+
4+
namespace GeneralUpdate.Common.AOT.JsonContext;
5+
6+
[JsonSerializable(typeof(GlobalConfigInfoOSS))]
7+
public partial class GlobalConfigInfoOSSJsonContext : JsonSerializerContext;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
using System.Collections.Generic;
2+
using System.Text.Json.Serialization;
3+
using GeneralUpdate.Common.Shared.Object;
4+
5+
namespace GeneralUpdate.Common.AOT.JsonContext;
6+
7+
[JsonSerializable(typeof(List<VersionOSS>))]
8+
public partial class VersionOSSJsonContext : JsonSerializerContext;

src/c#/GeneralUpdate.Common/FileBasic/GeneralFileManager.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.IO;
44
using System.Linq;
55
using System.Text.Json;
6+
using System.Text.Json.Serialization.Metadata;
67
using System.Threading;
78
using GeneralUpdate.Common.HashAlgorithms;
89

@@ -60,11 +61,15 @@ public static void CreateJson<T>(string targetPath, T obj) where T : class
6061
File.WriteAllText(targetPath, jsonString);
6162
}
6263

63-
public static T? GetJson<T>(string path) where T : class
64+
public static T? GetJson<T>(string path, JsonTypeInfo<T>? typeInfo = null) where T : class
6465
{
6566
if (File.Exists(path))
6667
{
6768
var json = File.ReadAllText(path);
69+
if (typeInfo != null)
70+
{
71+
return JsonSerializer.Deserialize(json, typeInfo);
72+
}
6873
return JsonSerializer.Deserialize<T>(json);
6974
}
7075

src/c#/GeneralUpdate.Common/GeneralUpdate.Common.csproj

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,8 @@
77
</PropertyGroup>
88

99
<ItemGroup>
10-
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="9.0.0-rc.1.24431.7" />
11-
<PackageReference Include="System.Collections.Immutable" Version="9.0.0-rc.1.24431.7" />
12-
<PackageReference Include="System.Text.Json" Version="9.0.0-rc.1.24431.7" />
10+
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="9.0.0" />
11+
<PackageReference Include="System.Collections.Immutable" Version="9.0.0" />
12+
<PackageReference Include="System.Text.Json" Version="9.0.0" />
1313
</ItemGroup>
14-
15-
<ItemGroup>
16-
<None Remove="GeneralUpdate.Common.csproj.DotSettings" />
17-
</ItemGroup>
18-
1914
</Project>

src/c#/GeneralUpdate.Common/GeneralUpdate.Common.csproj.DotSettings

Lines changed: 0 additions & 2 deletions
This file was deleted.

src/c#/GeneralUpdate.Common/Internal/Event/EventManager.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ namespace GeneralUpdate.Common.Internal.Event
55
{
66
public class EventManager : IDisposable
77
{
8-
private static readonly object _lockObj = new object();
8+
private static readonly object _lockObj = new();
99
private static EventManager _instance;
10-
private Dictionary<Type, Delegate> _dicDelegates = new Dictionary<Type, Delegate>();
11-
private bool disposed = false;
10+
private Dictionary<Type, Delegate> _dicDelegates = new();
11+
private bool _disposed = false;
1212

1313
private EventManager() { }
1414

@@ -67,10 +67,10 @@ public void Dispatch<TEventArgs>(object sender, TEventArgs eventArgs) where TEve
6767

6868
public void Dispose()
6969
{
70-
if (!this.disposed)
70+
if (!this._disposed)
7171
{
7272
_dicDelegates.Clear();
73-
disposed = true;
73+
_disposed = true;
7474
}
7575
}
7676
}

0 commit comments

Comments
 (0)