using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
using WIDESEAWCS_S7Simulator.Core.Entities;
|
using WIDESEAWCS_S7Simulator.Web.Services;
|
|
namespace WIDESEAWCS_S7Simulator.Web.Pages;
|
|
/// <summary>
|
/// 实例详情页
|
/// </summary>
|
public class DetailsModel : BasePageModel
|
{
|
private readonly ILogger<DetailsModel> _logger;
|
private readonly ApiHttpClient _apiClient;
|
|
public DetailsModel(ILogger<DetailsModel> logger, IConfiguration configuration, ApiHttpClient apiClient)
|
: base(configuration)
|
{
|
_logger = logger;
|
_apiClient = apiClient;
|
}
|
|
public InstanceState? Instance { get; private set; }
|
|
public List<S7ClientConnection> Clients { get; private set; } = new();
|
|
public async Task<IActionResult> OnGetAsync(string id)
|
{
|
if (string.IsNullOrWhiteSpace(id))
|
{
|
return BadRequest("实例ID不能为空");
|
}
|
|
try
|
{
|
Instance = await _apiClient.GetInstanceAsync(id);
|
|
if (Instance == null)
|
{
|
return NotFound($"实例 \"{id}\" 不存在");
|
}
|
|
// 客户端信息已包含在 InstanceState 中
|
if (Instance.Clients != null)
|
{
|
Clients = Instance.Clients;
|
}
|
}
|
catch (HttpRequestException ex)
|
{
|
_logger.LogError(ex, "Failed to load instance details for {InstanceId}", id);
|
ModelState.AddModelError(string.Empty, "加载实例详情失败,请稍后重试");
|
}
|
|
return Page();
|
}
|
}
|