| | |
| | | public class EditModel : PageModel |
| | | { |
| | | private readonly ILogger<EditModel> _logger; |
| | | private readonly HttpClient _httpClient; |
| | | private readonly IHttpClientFactory _httpClientFactory; |
| | | |
| | | public EditModel(ILogger<EditModel> logger, IHttpClientFactory httpClientFactory) |
| | | { |
| | | _logger = logger; |
| | | _httpClient = httpClientFactory.CreateClient(); |
| | | _httpClient.BaseAddress = new Uri($"{Request.Scheme}://{Request.Host}"); |
| | | _httpClientFactory = httpClientFactory; |
| | | } |
| | | |
| | | [BindProperty] |
| | |
| | | |
| | | try |
| | | { |
| | | var response = await _httpClient.GetAsync($"/api/SimulatorInstances/{Uri.EscapeDataString(id)}"); |
| | | var httpClient = _httpClientFactory.CreateClient(); |
| | | httpClient.BaseAddress = new Uri($"{Request.Scheme}://{Request.Host}"); |
| | | |
| | | var response = await httpClient.GetAsync($"/api/SimulatorInstances/{Uri.EscapeDataString(id)}"); |
| | | |
| | | if (response.IsSuccessStatusCode) |
| | | { |
| | |
| | | IsRunning = CurrentInstance?.Status == InstanceStatus.Running; |
| | | |
| | | // Load existing config |
| | | var configResponse = await _httpClient.GetAsync($"/api/SimulatorInstances"); |
| | | var configResponse = await httpClient.GetAsync($"/api/SimulatorInstances"); |
| | | if (configResponse.IsSuccessStatusCode) |
| | | { |
| | | var allInstances = await configResponse.Content.ReadFromJsonAsync<List<InstanceState>>(); |
| | |
| | | |
| | | try |
| | | { |
| | | // 创建HttpClient并设置BaseAddress |
| | | var httpClient = _httpClientFactory.CreateClient(); |
| | | httpClient.BaseAddress = new Uri($"{Request.Scheme}://{Request.Host}"); |
| | | |
| | | var config = new InstanceConfig |
| | | { |
| | | Id = Input.Id, |
| | |
| | | } |
| | | }; |
| | | |
| | | var response = await _httpClient.PutAsJsonAsync($"/api/SimulatorInstances/{Uri.EscapeDataString(Input.Id)}", config); |
| | | var response = await httpClient.PutAsJsonAsync($"/api/SimulatorInstances/{Uri.EscapeDataString(Input.Id)}", config); |
| | | |
| | | if (response.IsSuccessStatusCode) |
| | | { |
| | |
| | | { |
| | | try |
| | | { |
| | | var response = await _httpClient.GetAsync($"/api/SimulatorInstances/{Uri.EscapeDataString(id)}"); |
| | | var httpClient = _httpClientFactory.CreateClient(); |
| | | httpClient.BaseAddress = new Uri($"{Request.Scheme}://{Request.Host}"); |
| | | |
| | | var response = await httpClient.GetAsync($"/api/SimulatorInstances/{Uri.EscapeDataString(id)}"); |
| | | if (response.IsSuccessStatusCode) |
| | | { |
| | | CurrentInstance = await response.Content.ReadFromJsonAsync<InstanceState>(); |