Skip to content

Commit 16f371f

Browse files
committed
代码优化、编译优化、支持动态修改页面内容
1 parent 7888822 commit 16f371f

31 files changed

+202
-262
lines changed

Diff for: .github/workflows/dotnet-publish-prerelease.yml

+31-34
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: .NET
1+
name: Build Pre-Release
22

33
on:
44
push:
@@ -17,11 +17,16 @@ jobs:
1717
- name: Setup .NET
1818
uses: actions/setup-dotnet@v4
1919
with:
20-
dotnet-version: 6.0.x
21-
- name: Publish for Linux-x64
22-
run: dotnet publish -c Release -r linux-x64 --self-contained -p:PublishTrimmed=true -p:PublishSingleFile=true -p:PublishReadyToRun=true -o app/linux-x64
23-
- name: Publish for Windows-x64
24-
run: dotnet publish -c Release -r win-x64 --self-contained -p:PublishTrimmed=true -p:PublishSingleFile=true -p:PublishReadyToRun=true -o app/win-x64
20+
dotnet-version: 8.0.x
21+
- name: Publish
22+
run: |
23+
dotnet publish -c Release -r linux-x64 --self-contained -p:PublishTrimmed=true -p:PublishSingleFile=true -o app/linux-x64
24+
dotnet publish -c Release -r win-x64 --self-contained -p:PublishTrimmed=true -p:PublishSingleFile=true -o app/win-x64
25+
dotnet publish -c Release -r linux-arm64 --self-contained -p:PublishTrimmed=true -p:PublishSingleFile=true -o app/linux-arm64
26+
cd app
27+
find . -type f -name 'appsettings.Example.json' -execdir mv {} appsettings.json \;
28+
find . -maxdepth 1 -type d ! -name '.' | xargs -I {} sh -c 'cd "{}" && zip -r "../${{ github.ref_name }}-$(basename {}).zip" *'
29+
find . -maxdepth 1 -type d ! -name '.' -exec rm -rf {} +
2530
- name: Upload artifacts
2631
uses: actions/upload-artifact@v3
2732
with:
@@ -39,14 +44,6 @@ jobs:
3944
with:
4045
name: app
4146
path: app
42-
43-
- name: Zip artifact
44-
run: |
45-
cd app
46-
mv linux-x64/appsettings.Example.json linux-x64/appsettings.json
47-
zip -r linux-x64.zip linux-x64/*
48-
mv win-x64/appsettings.Example.json win-x64/appsettings.json
49-
zip -r win-x64.zip win-x64/*
5047

5148
- name: Create Release
5249
id: create_release
@@ -59,27 +56,27 @@ jobs:
5956
draft: false
6057
prerelease: true
6158

62-
- name: Upload Release Asset for Linux-x64
63-
id: upload_linux
64-
uses: actions/upload-release-asset@v1
65-
env:
66-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
67-
with:
68-
upload_url: ${{ steps.create_release.outputs.upload_url }}
69-
asset_path: app/linux-x64.zip
70-
asset_name: linux-x64.zip
71-
asset_content_type: application/zip
72-
73-
- name: Upload Release Asset for Windows-x64
74-
id: upload_win
75-
uses: actions/upload-release-asset@v1
76-
env:
77-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
59+
- name: Upload ZIP files to Release
60+
id: upload_zip
61+
uses: actions/github-script@v3
7862
with:
79-
upload_url: ${{ steps.create_release.outputs.upload_url }}
80-
asset_path: app/win-x64.zip
81-
asset_name: win-x64.zip
82-
asset_content_type: application/zip
63+
github-token: ${{secrets.GITHUB_TOKEN}}
64+
script: |
65+
const path = require('path');
66+
const fs = require('fs');
67+
const release_id = '${{ steps.create_release.outputs.id }}';
68+
for (let file of await fs.readdirSync('app/')) {
69+
if (path.extname(file) === '.zip') {
70+
console.log('uploadReleaseAsset', file);
71+
await github.repos.uploadReleaseAsset({
72+
owner: context.repo.owner,
73+
repo: context.repo.repo,
74+
release_id: release_id,
75+
name: file,
76+
data: await fs.readFileSync(`app/${file}`)
77+
});
78+
}
79+
}
8380
8481
cleanup:
8582
name: Cleanup

Diff for: .github/workflows/dotnet-publish-release.yml

+31-34
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: .NET
1+
name: Build Release
22

33
on:
44
push:
@@ -17,11 +17,16 @@ jobs:
1717
- name: Setup .NET
1818
uses: actions/setup-dotnet@v4
1919
with:
20-
dotnet-version: 6.0.x
21-
- name: Publish for Linux-x64
22-
run: dotnet publish -c Release -r linux-x64 --self-contained -p:PublishTrimmed=true -p:PublishSingleFile=true -p:PublishReadyToRun=true -o app/linux-x64
23-
- name: Publish for Windows-x64
24-
run: dotnet publish -c Release -r win-x64 --self-contained -p:PublishTrimmed=true -p:PublishSingleFile=true -p:PublishReadyToRun=true -o app/win-x64
20+
dotnet-version: 8.0.x
21+
- name: Publish
22+
run: |
23+
dotnet publish -c Release -r linux-x64 --self-contained -p:PublishTrimmed=true -p:PublishSingleFile=true -o app/linux-x64
24+
dotnet publish -c Release -r win-x64 --self-contained -p:PublishTrimmed=true -p:PublishSingleFile=true -o app/win-x64
25+
dotnet publish -c Release -r linux-arm64 --self-contained -p:PublishTrimmed=true -p:PublishSingleFile=true -o app/linux-arm64
26+
cd app
27+
find . -type f -name 'appsettings.Example.json' -execdir mv {} appsettings.json \;
28+
find . -maxdepth 1 -type d ! -name '.' | xargs -I {} sh -c 'cd "{}" && zip -r "../${{ github.ref_name }}-$(basename {}).zip" *'
29+
find . -maxdepth 1 -type d ! -name '.' -exec rm -rf {} +
2530
- name: Upload artifacts
2631
uses: actions/upload-artifact@v3
2732
with:
@@ -39,14 +44,6 @@ jobs:
3944
with:
4045
name: app
4146
path: app
42-
43-
- name: Zip artifact
44-
run: |
45-
cd app
46-
mv linux-x64/appsettings.Example.json linux-x64/appsettings.json
47-
zip -r linux-x64.zip linux-x64/*
48-
mv win-x64/appsettings.Example.json win-x64/appsettings.json
49-
zip -r win-x64.zip win-x64/*
5047

5148
- name: Create Release
5249
id: create_release
@@ -59,27 +56,27 @@ jobs:
5956
draft: false
6057
prerelease: false
6158

62-
- name: Upload Release Asset for Linux-x64
63-
id: upload_linux
64-
uses: actions/upload-release-asset@v1
65-
env:
66-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
67-
with:
68-
upload_url: ${{ steps.create_release.outputs.upload_url }}
69-
asset_path: app/linux-x64.zip
70-
asset_name: linux-x64.zip
71-
asset_content_type: application/zip
72-
73-
- name: Upload Release Asset for Windows-x64
74-
id: upload_win
75-
uses: actions/upload-release-asset@v1
76-
env:
77-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
59+
- name: Upload ZIP files to Release
60+
id: upload_zip
61+
uses: actions/github-script@v3
7862
with:
79-
upload_url: ${{ steps.create_release.outputs.upload_url }}
80-
asset_path: app/win-x64.zip
81-
asset_name: win-x64.zip
82-
asset_content_type: application/zip
63+
github-token: ${{secrets.GITHUB_TOKEN}}
64+
script: |
65+
const path = require('path');
66+
const fs = require('fs');
67+
const release_id = '${{ steps.create_release.outputs.id }}';
68+
for (let file of await fs.readdirSync('app/')) {
69+
if (path.extname(file) === '.zip') {
70+
console.log('uploadReleaseAsset', file);
71+
await github.repos.uploadReleaseAsset({
72+
owner: context.repo.owner,
73+
repo: context.repo.repo,
74+
release_id: release_id,
75+
name: file,
76+
data: await fs.readFileSync(`app/${file}`)
77+
});
78+
}
79+
}
8380
8481
cleanup:
8582
name: Cleanup

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -366,3 +366,4 @@ FodyWeavers.xsd
366366
/src/TokenPay/EVMChains.json
367367
/src/TokenPay/EVMChains.Development.json
368368
/src/TokenPay/手续费钱包私钥.txt
369+
/src/TokenPay/.config

Diff for: src/TokenPay.sln

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ EndProject
88
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{D54245C4-8D70-442B-91C0-0053856152B0}"
99
ProjectSection(SolutionItems) = preProject
1010
.dockerignore = .dockerignore
11-
.editorconfig = .editorconfig
1211
.gitattributes = .gitattributes
1312
.gitignore = .gitignore
1413
docker-compose.yml = docker-compose.yml

Diff for: src/TokenPay/BgServices/BaseScheduledService.cs

+18-40
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,38 @@
11
namespace TokenPay.BgServices
22
{
3-
public abstract class BaseScheduledService : IHostedService, IDisposable
3+
public abstract class BaseScheduledService : BackgroundService
44
{
5-
private readonly Timer _timer;
65
protected readonly string jobName;
7-
private readonly TimeSpan _period;
86
protected readonly ILogger Logger;
7+
private readonly PeriodicTimer _timer;
98

109
protected BaseScheduledService(string JobName, TimeSpan period, ILogger logger)
1110
{
1211
Logger = logger;
1312
jobName = JobName;
14-
_period = period;
15-
_timer = new Timer(Execute, null, Timeout.InfiniteTimeSpan, Timeout.InfiniteTimeSpan);
13+
_timer = new PeriodicTimer(period);
1614
}
17-
18-
public void Execute(object? state = null)
15+
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
1916
{
20-
try
21-
{
22-
23-
ExecuteAsync().Wait();
24-
//Logger.LogInformation("Begin execute service");
25-
}
26-
catch (Exception ex)
27-
{
28-
Logger.LogError(ex, $"定时任务[{jobName}]执行出现错误");
29-
}
30-
finally
17+
Logger.LogInformation("Service {JobName} is starting.", jobName);
18+
do
3119
{
32-
//Logger.LogInformation("Execute finished");
33-
_timer.Change(_period, Timeout.InfiniteTimeSpan);
34-
}
20+
try
21+
{
22+
await ExecuteAsync();
23+
}
24+
catch (Exception ex)
25+
{
26+
Logger.LogError(ex, $"定时任务[{jobName}]执行出现错误");
27+
}
28+
} while (!stoppingToken.IsCancellationRequested && await _timer.WaitForNextTickAsync(stoppingToken));
3529
}
36-
3730
protected abstract Task ExecuteAsync();
38-
39-
public virtual void Dispose()
40-
{
41-
_timer?.Dispose();
42-
}
43-
44-
public Task StartAsync(CancellationToken cancellationToken)
45-
{
46-
Logger.LogInformation("Service {JobName} is starting.", jobName);
47-
_timer.Change(TimeSpan.FromSeconds(3), Timeout.InfiniteTimeSpan);
48-
return Task.CompletedTask;
49-
}
50-
51-
public Task StopAsync(CancellationToken cancellationToken)
31+
public override Task StopAsync(CancellationToken cancellationToken)
5232
{
5333
Logger.LogInformation("Service {JobName} is stopping.", jobName);
54-
55-
_timer?.Change(Timeout.Infinite, 0);
56-
57-
return Task.CompletedTask;
34+
_timer.Dispose();
35+
return base.StopAsync(cancellationToken);
5836
}
5937
}
6038
}

Diff for: src/TokenPay/BgServices/CollectionTRONService.cs

+4-6
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public class CollectionTRONService : BaseScheduledService
1616
{
1717
private readonly IConfiguration _configuration;
1818
private readonly TelegramBot _bot;
19-
private readonly IServiceProvider _serviceProvider;
19+
private readonly IFreeSql freeSql;
2020
private readonly ILogger<CollectionTRONService> _logger;
2121
/// <summary>
2222
/// 是否启用归集功能
@@ -63,14 +63,13 @@ public class CollectionTRONService : BaseScheduledService
6363
public CollectionTRONService(
6464
IConfiguration configuration,
6565
TelegramBot bot,
66-
IServiceProvider serviceProvider,
66+
IFreeSql freeSql,
6767
ILogger<CollectionTRONService> logger) : base("TRON归集任务", TimeSpan.FromHours(configuration.GetValue("Collection:CheckTime", 1)), logger)
6868
{
6969
this._configuration = configuration;
70-
this._serviceProvider = serviceProvider;
7170
this._logger = logger;
7271
this._bot = bot;
73-
72+
this.freeSql = freeSql;
7473
}
7574
protected override async Task ExecuteAsync()
7675
{
@@ -160,8 +159,7 @@ await _bot.SendTextMessageAsync(@$"归集收款地址余额
160159
当前TRX余额:{trx} USDT
161160
当前USDT余额:{usdt} USDT");
162161
}
163-
using IServiceScope scope = _serviceProvider.CreateScope();
164-
var _repository = scope.ServiceProvider.GetRequiredService<IBaseRepository<Tokens>>();
162+
var _repository = freeSql.GetRepository<Tokens>();
165163
var list = await _repository.Where(x => x.Currency == TokenCurrency.TRX).Where(x => ForceCheckAllAddress || (x.USDT > MinUSDT || x.Value > 0.5m)).ToListAsync();
166164
var count = 0;
167165
foreach (var item in list)

Diff for: src/TokenPay/BgServices/OrderCheckEVMBaseService.cs

+4-13
Original file line numberDiff line numberDiff line change
@@ -16,35 +16,27 @@ public class OrderCheckEVMBaseService : BaseScheduledService
1616
private readonly IHostEnvironment _env;
1717
private readonly Channel<TokenOrders> _channel;
1818
private readonly List<EVMChain> _chains;
19-
private readonly IServiceProvider _serviceProvider;
20-
private readonly FlurlClient client;
19+
private readonly IFreeSql freeSql;
2120
private bool UseDynamicAddress => _configuration.GetValue("UseDynamicAddress", true);
2221
private bool UseDynamicAddressAmountMove => _configuration.GetValue("DynamicAddressConfig:AmountMove", false);
2322
public OrderCheckEVMBaseService(ILogger<OrderCheckEVMBaseService> logger,
2423
IConfiguration configuration,
2524
IHostEnvironment env,
2625
Channel<TokenOrders> channel,
2726
List<EVMChain> Chains,
28-
IServiceProvider serviceProvider) : base("ETH订单检测", TimeSpan.FromSeconds(15), logger)
27+
IFreeSql freeSql) : base("ETH订单检测", TimeSpan.FromSeconds(15), logger)
2928
{
3029
_logger = logger;
3130
this._configuration = configuration;
3231
this._env = env;
3332
this._channel = channel;
3433
_chains = Chains;
35-
_serviceProvider = serviceProvider;
36-
var WebProxy = configuration.GetValue<string>("WebProxy");
37-
client = new FlurlClient();
38-
if (!string.IsNullOrEmpty(WebProxy))
39-
{
40-
client.Settings.HttpClientFactory = new ProxyHttpClientFactory(WebProxy);
41-
}
34+
this.freeSql = freeSql;
4235
}
4336

4437
protected override async Task ExecuteAsync()
4538
{
46-
using IServiceScope scope = _serviceProvider.CreateScope();
47-
var _repository = scope.ServiceProvider.GetRequiredService<IBaseRepository<TokenOrders>>();
39+
var _repository = freeSql.GetRepository<TokenOrders>();
4840
foreach (var chain in _chains)
4941
{
5042
if (chain == null || !chain.Enable) continue;
@@ -87,7 +79,6 @@ protected override async Task ExecuteAsync()
8779
var req = BaseUrl
8880
.AppendPathSegment($"api")
8981
.SetQueryParams(query)
90-
.WithClient(client)
9182
.WithTimeout(15);
9283
var result = await req
9384
.GetJsonAsync<BaseResponse<EthTransaction>>();

0 commit comments

Comments
 (0)