Skip to content

Commit

Permalink
代码优化、编译优化、支持动态修改页面内容
Browse files Browse the repository at this point in the history
  • Loading branch information
Light committed Sep 3, 2024
1 parent 6f044ca commit af16539
Show file tree
Hide file tree
Showing 18 changed files with 137 additions and 210 deletions.
31 changes: 14 additions & 17 deletions .github/workflows/dotnet-publish-prerelease.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: .NET
name: Build Pre-Release

on:
push:
Expand All @@ -18,10 +18,15 @@ jobs:
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x
- name: Publish for Linux-x64
run: dotnet publish -c Release -r linux-x64 --self-contained -p:PublishTrimmed=true -p:PublishSingleFile=true -o app/linux-x64
- name: Publish for Windows-x64
run: dotnet publish -c Release -r win-x64 --self-contained -p:PublishTrimmed=true -p:PublishSingleFile=true -o app/win-x64
- name: Publish
run: |
dotnet publish -c Release -r linux-x64 --self-contained -p:PublishTrimmed=true -p:PublishSingleFile=true -o app/linux-x64
dotnet publish -c Release -r win-x64 --self-contained -p:PublishTrimmed=true -p:PublishSingleFile=true -o app/win-x64
cd app
mv linux-x64/appsettings.Example.json linux-x64/appsettings.json
zip -r ${{ github.ref_name }}-linux-x64.zip linux-x64/*
mv win-x64/appsettings.Example.json win-x64/appsettings.json
zip -r ${{ github.ref_name }}-win-x64.zip win-x64/*
- name: Upload artifacts
uses: actions/upload-artifact@v3
with:
Expand All @@ -39,14 +44,6 @@ jobs:
with:
name: app
path: app

- name: Zip artifact
run: |
cd app
mv linux-x64/appsettings.Example.json linux-x64/appsettings.json
zip -r linux-x64.zip linux-x64/*
mv win-x64/appsettings.Example.json win-x64/appsettings.json
zip -r win-x64.zip win-x64/*

- name: Create Release
id: create_release
Expand All @@ -66,8 +63,8 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: app/linux-x64.zip
asset_name: linux-x64.zip
asset_path: app/${{ github.ref_name }}-linux-x64.zip
asset_name: ${{ github.ref_name }}-linux-x64.zip
asset_content_type: application/zip

- name: Upload Release Asset for Windows-x64
Expand All @@ -77,8 +74,8 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: app/win-x64.zip
asset_name: win-x64.zip
asset_path: app/${{ github.ref_name }}-win-x64.zip
asset_name: ${{ github.ref_name }}-win-x64.zip
asset_content_type: application/zip

cleanup:
Expand Down
31 changes: 14 additions & 17 deletions .github/workflows/dotnet-publish-release.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: .NET
name: Build Release

on:
push:
Expand All @@ -18,10 +18,15 @@ jobs:
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x
- name: Publish for Linux-x64
run: dotnet publish -c Release -r linux-x64 --self-contained -p:PublishTrimmed=true -p:PublishSingleFile=true -o app/linux-x64
- name: Publish for Windows-x64
run: dotnet publish -c Release -r win-x64 --self-contained -p:PublishTrimmed=true -p:PublishSingleFile=true -o app/win-x64
- name: Publish
run: |
dotnet publish -c Release -r linux-x64 --self-contained -p:PublishTrimmed=true -p:PublishSingleFile=true -o app/linux-x64
dotnet publish -c Release -r win-x64 --self-contained -p:PublishTrimmed=true -p:PublishSingleFile=true -o app/win-x64
cd app
mv linux-x64/appsettings.Example.json linux-x64/appsettings.json
zip -r ${{ github.ref_name }}-linux-x64.zip linux-x64/*
mv win-x64/appsettings.Example.json win-x64/appsettings.json
zip -r ${{ github.ref_name }}-win-x64.zip win-x64/*
- name: Upload artifacts
uses: actions/upload-artifact@v3
with:
Expand All @@ -39,14 +44,6 @@ jobs:
with:
name: app
path: app

- name: Zip artifact
run: |
cd app
mv linux-x64/appsettings.Example.json linux-x64/appsettings.json
zip -r linux-x64.zip linux-x64/*
mv win-x64/appsettings.Example.json win-x64/appsettings.json
zip -r win-x64.zip win-x64/*

- name: Create Release
id: create_release
Expand All @@ -66,8 +63,8 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: app/linux-x64.zip
asset_name: linux-x64.zip
asset_path: app/${{ github.ref_name }}-linux-x64.zip
asset_name: ${{ github.ref_name }}-linux-x64.zip
asset_content_type: application/zip

- name: Upload Release Asset for Windows-x64
Expand All @@ -77,8 +74,8 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: app/win-x64.zip
asset_name: win-x64.zip
asset_path: app/${{ github.ref_name }}-win-x64.zip
asset_name: ${{ github.ref_name }}-win-x64.zip
asset_content_type: application/zip

cleanup:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -366,3 +366,4 @@ FodyWeavers.xsd
/src/TokenPay/EVMChains.json
/src/TokenPay/EVMChains.Development.json
/src/TokenPay/手续费钱包私钥.txt
/src/TokenPay/.config
58 changes: 18 additions & 40 deletions src/TokenPay/BgServices/BaseScheduledService.cs
Original file line number Diff line number Diff line change
@@ -1,60 +1,38 @@
namespace TokenPay.BgServices
{
public abstract class BaseScheduledService : IHostedService, IDisposable
public abstract class BaseScheduledService : BackgroundService
{
private readonly Timer _timer;
protected readonly string jobName;
private readonly TimeSpan _period;
protected readonly ILogger Logger;
private readonly PeriodicTimer _timer;

protected BaseScheduledService(string JobName, TimeSpan period, ILogger logger)
{
Logger = logger;
jobName = JobName;
_period = period;
_timer = new Timer(Execute, null, Timeout.InfiniteTimeSpan, Timeout.InfiniteTimeSpan);
_timer = new PeriodicTimer(period);
}

public void Execute(object? state = null)
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
try
{

ExecuteAsync().Wait();
//Logger.LogInformation("Begin execute service");
}
catch (Exception ex)
{
Logger.LogError(ex, $"定时任务[{jobName}]执行出现错误");
}
finally
Logger.LogInformation("Service {JobName} is starting.", jobName);
do
{
//Logger.LogInformation("Execute finished");
_timer.Change(_period, Timeout.InfiniteTimeSpan);
}
try
{
await ExecuteAsync();
}
catch (Exception ex)
{
Logger.LogError(ex, $"定时任务[{jobName}]执行出现错误");
}
} while (!stoppingToken.IsCancellationRequested && await _timer.WaitForNextTickAsync(stoppingToken));
}

protected abstract Task ExecuteAsync();

public virtual void Dispose()
{
_timer?.Dispose();
}

public Task StartAsync(CancellationToken cancellationToken)
{
Logger.LogInformation("Service {JobName} is starting.", jobName);
_timer.Change(TimeSpan.FromSeconds(3), Timeout.InfiniteTimeSpan);
return Task.CompletedTask;
}

public Task StopAsync(CancellationToken cancellationToken)
public override Task StopAsync(CancellationToken cancellationToken)
{
Logger.LogInformation("Service {JobName} is stopping.", jobName);

_timer?.Change(Timeout.Infinite, 0);

return Task.CompletedTask;
_timer.Dispose();
return base.StopAsync(cancellationToken);
}
}
}
10 changes: 4 additions & 6 deletions src/TokenPay/BgServices/CollectionTRONService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class CollectionTRONService : BaseScheduledService
{
private readonly IConfiguration _configuration;
private readonly TelegramBot _bot;
private readonly IServiceProvider _serviceProvider;
private readonly IFreeSql freeSql;
private readonly ILogger<CollectionTRONService> _logger;
/// <summary>
/// 是否启用归集功能
Expand Down Expand Up @@ -63,14 +63,13 @@ public class CollectionTRONService : BaseScheduledService
public CollectionTRONService(
IConfiguration configuration,
TelegramBot bot,
IServiceProvider serviceProvider,
IFreeSql freeSql,
ILogger<CollectionTRONService> logger) : base("TRON归集任务", TimeSpan.FromHours(configuration.GetValue("Collection:CheckTime", 1)), logger)
{
this._configuration = configuration;
this._serviceProvider = serviceProvider;
this._logger = logger;
this._bot = bot;

this.freeSql = freeSql;
}
protected override async Task ExecuteAsync()
{
Expand Down Expand Up @@ -160,8 +159,7 @@ await _bot.SendTextMessageAsync(@$"归集收款地址余额
当前TRX余额:{trx} USDT
当前USDT余额:{usdt} USDT");
}
using IServiceScope scope = _serviceProvider.CreateScope();
var _repository = scope.ServiceProvider.GetRequiredService<IBaseRepository<Tokens>>();
var _repository = freeSql.GetRepository<Tokens>();
var list = await _repository.Where(x => x.Currency == TokenCurrency.TRX).Where(x => ForceCheckAllAddress || (x.USDT > MinUSDT || x.Value > 0.5m)).ToListAsync();
var count = 0;
foreach (var item in list)
Expand Down
17 changes: 4 additions & 13 deletions src/TokenPay/BgServices/OrderCheckEVMBaseService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,35 +16,27 @@ public class OrderCheckEVMBaseService : BaseScheduledService
private readonly IHostEnvironment _env;
private readonly Channel<TokenOrders> _channel;
private readonly List<EVMChain> _chains;
private readonly IServiceProvider _serviceProvider;
private readonly FlurlClient client;
private readonly IFreeSql freeSql;
private bool UseDynamicAddress => _configuration.GetValue("UseDynamicAddress", true);
private bool UseDynamicAddressAmountMove => _configuration.GetValue("DynamicAddressConfig:AmountMove", false);
public OrderCheckEVMBaseService(ILogger<OrderCheckEVMBaseService> logger,
IConfiguration configuration,
IHostEnvironment env,
Channel<TokenOrders> channel,
List<EVMChain> Chains,
IServiceProvider serviceProvider) : base("ETH订单检测", TimeSpan.FromSeconds(15), logger)
IFreeSql freeSql) : base("ETH订单检测", TimeSpan.FromSeconds(15), logger)
{
_logger = logger;
this._configuration = configuration;
this._env = env;
this._channel = channel;
_chains = Chains;
_serviceProvider = serviceProvider;
var WebProxy = configuration.GetValue<string>("WebProxy");
client = new FlurlClient();
if (!string.IsNullOrEmpty(WebProxy))
{
client.Settings.HttpClientFactory = new ProxyHttpClientFactory(WebProxy);
}
this.freeSql = freeSql;
}

protected override async Task ExecuteAsync()
{
using IServiceScope scope = _serviceProvider.CreateScope();
var _repository = scope.ServiceProvider.GetRequiredService<IBaseRepository<TokenOrders>>();
var _repository = freeSql.GetRepository<TokenOrders>();
foreach (var chain in _chains)
{
if (chain == null || !chain.Enable) continue;
Expand Down Expand Up @@ -87,7 +79,6 @@ protected override async Task ExecuteAsync()
var req = BaseUrl
.AppendPathSegment($"api")
.SetQueryParams(query)
.WithClient(client)
.WithTimeout(15);
var result = await req
.GetJsonAsync<BaseResponse<EthTransaction>>();
Expand Down
17 changes: 4 additions & 13 deletions src/TokenPay/BgServices/OrderCheckEVMERC20Service.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,35 +17,27 @@ public class OrderCheckEVMERC20Service : BaseScheduledService
private readonly IHostEnvironment _env;
private readonly List<EVMChain> _chains;
private readonly Channel<TokenOrders> _channel;
private readonly IServiceProvider _serviceProvider;
private readonly FlurlClient client;
private readonly IFreeSql freeSql;
private bool UseDynamicAddress => _configuration.GetValue("UseDynamicAddress", true);
private bool UseDynamicAddressAmountMove => _configuration.GetValue("DynamicAddressConfig:AmountMove", false);
public OrderCheckEVMERC20Service(ILogger<OrderCheckEVMERC20Service> logger,
IConfiguration configuration,
IHostEnvironment env,
List<EVMChain> Chains,
Channel<TokenOrders> channel,
IServiceProvider serviceProvider) : base("ERC20订单检测", TimeSpan.FromSeconds(15), logger)
IFreeSql freeSql) : base("ERC20订单检测", TimeSpan.FromSeconds(15), logger)
{
_logger = logger;
this._configuration = configuration;
this._env = env;
_chains = Chains;
this._channel = channel;
_serviceProvider = serviceProvider;
var WebProxy = configuration.GetValue<string>("WebProxy");
client = new FlurlClient();
if (!string.IsNullOrEmpty(WebProxy))
{
client.Settings.HttpClientFactory = new ProxyHttpClientFactory(WebProxy);
}
this.freeSql = freeSql;
}

protected override async Task ExecuteAsync()
{
using IServiceScope scope = _serviceProvider.CreateScope();
var _repository = scope.ServiceProvider.GetRequiredService<IBaseRepository<TokenOrders>>();
var _repository = freeSql.GetRepository<TokenOrders>();
foreach (var chain in _chains)
{
if (chain == null || !chain.Enable || chain.ERC20 == null) continue;
Expand Down Expand Up @@ -108,7 +100,6 @@ private async Task ERC20(IBaseRepository<TokenOrders> _repository, string Curren
var req = BaseUrl
.AppendPathSegment($"api")
.SetQueryParams(query)
.WithClient(client)
.WithTimeout(15);
var result = await req
.GetJsonAsync<BaseResponse<ERC20Transaction>>();
Expand Down
12 changes: 6 additions & 6 deletions src/TokenPay/BgServices/OrderCheckTRC20Service.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,27 @@ public class OrderCheckTRC20Service : BaseScheduledService
private readonly IConfiguration _configuration;
private readonly IHostEnvironment _env;
private readonly Channel<TokenOrders> _channel;
private readonly IServiceProvider _serviceProvider;
private readonly IFreeSql freeSql;

private bool UseDynamicAddress => _configuration.GetValue("UseDynamicAddress", true);
private bool UseDynamicAddressAmountMove => _configuration.GetValue("DynamicAddressConfig:AmountMove", false);
public OrderCheckTRC20Service(ILogger<OrderCheckTRC20Service> logger,
IConfiguration configuration,
IHostEnvironment env,
Channel<TokenOrders> channel,
IServiceProvider serviceProvider) : base("TRC20订单检测", TimeSpan.FromSeconds(3), logger)
IFreeSql freeSql) : base("TRC20订单检测", TimeSpan.FromSeconds(3), logger)
{
_logger = logger;
this._configuration = configuration;
this._env = env;
this._channel = channel;
_serviceProvider = serviceProvider;
this.freeSql = freeSql;
}

protected override async Task ExecuteAsync()
{
using IServiceScope scope = _serviceProvider.CreateScope();
var _repository = scope.ServiceProvider.GetRequiredService<IBaseRepository<TokenOrders>>();
var _TokensRepository = scope.ServiceProvider.GetRequiredService<IBaseRepository<Tokens>>();
var _repository = freeSql.GetRepository<TokenOrders>();
var _TokensRepository = freeSql.GetRepository<Tokens>();

var Address = await _repository
.Where(x => x.Status == OrderStatus.Pending)
Expand Down
Loading

0 comments on commit af16539

Please sign in to comment.