wcs_server_s7_baoying/WcsMain/ApiServe/Controllers/TestController.cs

72 lines
1.7 KiB
C#
Raw Normal View History

2024-06-20 09:23:01 +08:00
using System.Diagnostics;
using Microsoft.AspNetCore.Mvc;
using WcsMain.ApiServe.ControllerFilter;
namespace WcsMain.ApiServe.Controllers;
/// <summary>
/// 测试接口,用于测试接口是否通断
/// </summary>
/// <remarks>
/// 构造函数,注入显示类
/// </remarks>
/// <param name="logger"></param>
[ApiController]
[Route("api/Test")]
[ServiceFilter<ResponseFilterAttribute>]
public class TestController(ILogger<TestController> logger) : ControllerBase
{
private readonly ILogger<TestController> _logger = logger;
/// <summary>
/// Get测试
/// </summary>
/// <returns></returns>
[HttpGet("GetTest")]
public string GetTest()
{
_logger.LogInformation("正常");
return "正常";
}
/// <summary>
/// Get测试
/// </summary>
/// <returns></returns>
[HttpGet("RestartTest")]
public string RestartTest()
{
string? path = Process.GetCurrentProcess().MainModule?.FileName;
Process process = new();
process.StartInfo.FileName = path;
process.Start();
Process.GetCurrentProcess().Kill();
return "正常";
}
/// <summary>
/// Post测试
/// </summary>
/// <param name="body"></param>
/// <returns></returns>
[HttpPost("PostTest")]
public string PostTest([FromBody] string body)
{
return $"正常,收到的信息为:{body}";
}
/// <summary>
/// Post异常测试
/// </summary>
/// <param name="body"></param>
/// <returns></returns>
[HttpPost("PostErrorTest")]
public string PostErrorTest([FromBody] string body)
{
throw new Exception($"异常异常:{body}");
}
}