2023-02-08 14:33:22 +01:00
|
|
|
|
using System.Text;
|
|
|
|
|
using MediatR;
|
|
|
|
|
|
|
|
|
|
namespace Application.Game.Server;
|
|
|
|
|
|
2023-02-10 17:46:44 +01:00
|
|
|
|
public record GetDataQuery(string Host, string Scheme) : IRequest<string>;
|
2023-02-08 14:33:22 +01:00
|
|
|
|
|
|
|
|
|
public class GetDataQueryHandler : IRequestHandler<GetDataQuery, string>
|
|
|
|
|
{
|
|
|
|
|
private readonly IEventManagerService eventManagerService;
|
|
|
|
|
|
|
|
|
|
public GetDataQueryHandler(IEventManagerService eventManagerService)
|
|
|
|
|
{
|
|
|
|
|
this.eventManagerService = eventManagerService;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task<string> Handle(GetDataQuery request, CancellationToken cancellationToken)
|
|
|
|
|
{
|
|
|
|
|
var response = "count=0\n" +
|
2023-02-22 19:22:04 +01:00
|
|
|
|
"nexttime=180";
|
2023-02-08 14:33:22 +01:00
|
|
|
|
if (!eventManagerService.UseEvents())
|
|
|
|
|
{
|
|
|
|
|
return Task.FromResult(response);
|
|
|
|
|
}
|
2023-02-10 17:46:44 +01:00
|
|
|
|
|
|
|
|
|
var urlBase = $"{request.Scheme}://{request.Host}/events/";
|
2023-02-08 14:33:22 +01:00
|
|
|
|
var dataString = new StringBuilder();
|
|
|
|
|
var events = eventManagerService.GetEvents();
|
|
|
|
|
var count = 0;
|
|
|
|
|
foreach (var pair in events.Select((@event, i) => new {Value = @event, Index = i}))
|
|
|
|
|
{
|
|
|
|
|
var value = pair.Value;
|
|
|
|
|
var index = pair.Index;
|
|
|
|
|
var fileUrl = $"{urlBase}{value.Name}";
|
|
|
|
|
var eventString = $"{index},{fileUrl},{value.NotBefore},{value.NotAfter},{value.Md5},{value.Index}";
|
|
|
|
|
dataString.Append(eventString).Append('\n');
|
|
|
|
|
count++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
response = $"count={count}\n" +
|
2023-02-26 19:43:13 +01:00
|
|
|
|
"nexttime=1\n" +
|
2023-02-08 14:33:22 +01:00
|
|
|
|
$"{dataString}";
|
|
|
|
|
|
|
|
|
|
return Task.FromResult(response);
|
|
|
|
|
}
|
|
|
|
|
}
|