Files
ShaoHua 734b2c91f9 build: 升级目标框架到net10.0并完善模板配置
1. 将Hua.Cli.Tests、项目共享库、模块项目等所有项目的TargetFramework从net8.0/net9.0升级到net10.0
2. 完善dotnet-tools.json、模板配置文件,添加必要的构建和发布配置
3. 新增微服务、网关、应用程序的启动脚本和基础配置文件
4. 补充产品管理模块的领域、应用、Web层基础代码和多语言资源
2026-07-16 02:43:29 +08:00

147 lines
4.3 KiB
C#

using System;
using System.Net.Http;
using System.Threading.Tasks;
using Microsoft.Extensions.Options;
using ProductManagement;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Http.Client;
using Volo.Abp.Identity;
using Volo.Abp.IdentityModel;
using Volo.Abp.TenantManagement;
namespace Company.Project.ConsoleClientDemo;
public class ClientDemoService : ITransientDependency
{
private readonly IIdentityUserAppService _userAppService;
private readonly ITenantAppService _tenantAppService;
private readonly IProductAppService _productAppService;
private readonly IIdentityModelAuthenticationService _authenticator;
private readonly AbpRemoteServiceOptions _remoteServiceOptions;
public ClientDemoService(
IIdentityUserAppService userAppService,
IProductAppService productAppService,
IIdentityModelAuthenticationService authenticator,
IOptions<AbpRemoteServiceOptions> remoteServiceOptions,
ITenantAppService tenantAppService)
{
_userAppService = userAppService;
_authenticator = authenticator;
_tenantAppService = tenantAppService;
_remoteServiceOptions = remoteServiceOptions.Value;
_productAppService = productAppService;
}
public async Task RunAsync()
{
await TestWithHttpClient();
await TestIdentityService();
await TestTenantManagementService();
await TestProductService();
}
private async Task TestWithHttpClient()
{
Console.WriteLine();
Console.WriteLine("*** TestWithHttpClient ************************************");
try
{
using (var client = new HttpClient())
{
await _authenticator.TryAuthenticateAsync(client);
var url = GetServerUrl() + "Test/Index";
var response = await client.GetAsync(url);
if (!response.IsSuccessStatusCode)
{
Console.WriteLine(response.StatusCode);
}
else
{
var responseContent = await response.Content.ReadAsStringAsync();
Console.WriteLine(responseContent);
}
}
}
catch (Exception e)
{
Console.WriteLine(e);
}
}
private async Task TestIdentityService()
{
Console.WriteLine();
Console.WriteLine("*** TestIdentityService ************************************");
try
{
var output = await _userAppService.GetListAsync(new GetIdentityUsersInput());
Console.WriteLine("Total user count: " + output.TotalCount);
foreach (var user in output.Items)
{
Console.WriteLine($"- UserName={user.UserName}, Email={user.Email}, Name={user.Name}, Surname={user.Surname}");
}
}
catch (Exception e)
{
Console.WriteLine(e);
}
}
private async Task TestTenantManagementService()
{
Console.WriteLine();
Console.WriteLine("*** TestTenantManagementService ************************************");
try
{
var output = await _tenantAppService.GetListAsync(new GetTenantsInput());
Console.WriteLine("Total tenant count: " + output.TotalCount);
foreach (var tenant in output.Items)
{
Console.WriteLine($"- Id={tenant.Id}, Name={tenant.Name}");
}
}
catch (Exception e)
{
Console.WriteLine(e);
}
}
private async Task TestProductService()
{
Console.WriteLine();
Console.WriteLine("*** TestProductService ************************************");
try
{
var output = await _productAppService.GetListAsync();
Console.WriteLine("Total product count: " + output.Items.Count);
foreach (var product in output.Items)
{
Console.WriteLine($"- Code={product.Code}, Name={product.Name}, Price={product.Price}, StockCount={product.StockCount}");
}
}
catch (Exception e)
{
Console.WriteLine(e);
}
}
private string GetServerUrl()
{
return _remoteServiceOptions.RemoteServices.Default.BaseUrl.EnsureEndsWith('/');
}
}