2023-10-27 01:33:28 +00:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2023-11-02 22:14:16 +00:00
|
|
|
|
using ProtoBuf;
|
|
|
|
|
using System.IO;
|
2023-10-27 01:33:28 +00:00
|
|
|
|
|
|
|
|
|
namespace TCC.Controllers
|
|
|
|
|
{
|
|
|
|
|
[ApiController]
|
|
|
|
|
[Route("simulation")]
|
|
|
|
|
public class SimulationController : ControllerBase
|
|
|
|
|
{
|
|
|
|
|
public SimulationController()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet("harmonic-progression")]
|
|
|
|
|
public async Task<IActionResult> GetHarmonicProgression([FromQuery] int n)
|
|
|
|
|
{
|
2023-11-02 22:14:16 +00:00
|
|
|
|
double sum = 0;
|
2023-10-27 01:33:28 +00:00
|
|
|
|
for (int i = 1; i <= n; i++)
|
|
|
|
|
{
|
|
|
|
|
sum += 1.0f / i;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Ok(sum);
|
|
|
|
|
}
|
2023-10-29 22:01:13 +00:00
|
|
|
|
|
|
|
|
|
[HttpGet("json")]
|
2023-10-29 22:03:14 +00:00
|
|
|
|
public async Task<IActionResult> GetJsonResponse()
|
2023-10-29 22:01:13 +00:00
|
|
|
|
{
|
|
|
|
|
return Ok(new { message = "Hello World!" });
|
|
|
|
|
}
|
2023-11-02 22:14:16 +00:00
|
|
|
|
|
|
|
|
|
[HttpPost("protobuf")]
|
|
|
|
|
public async Task<IActionResult> PostProtobuf()
|
|
|
|
|
{
|
|
|
|
|
HelloWorld cliente;
|
|
|
|
|
byte[] response;
|
|
|
|
|
using (var stream = Request.BodyReader.AsStream())
|
|
|
|
|
{
|
|
|
|
|
cliente = ProtoBuf.Serializer.Deserialize<HelloWorld>(stream);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
using (var stream = new MemoryStream())
|
|
|
|
|
{
|
|
|
|
|
ProtoBuf.Serializer.Serialize(stream, cliente);
|
|
|
|
|
response = stream.ToArray();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await Response.Body.WriteAsync(response, 0, response.Length);
|
|
|
|
|
return new EmptyResult();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[ProtoContract()]
|
|
|
|
|
public class HelloWorld
|
|
|
|
|
{
|
|
|
|
|
[ProtoMember(1)]
|
|
|
|
|
public string Message { get; set; }
|
2023-10-27 01:33:28 +00:00
|
|
|
|
}
|
2023-11-02 22:14:16 +00:00
|
|
|
|
|
2023-10-27 01:33:28 +00:00
|
|
|
|
}
|